Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tools] export snapshot as file tree. Fixes MER#1384
git-vault-export shell script exports git tree corresponding to the snapshot and resolves vault blobs symlinks to files. Vault C++ and QML API exportSnapshot() to expose this functionality. Signed-off-by: Denis Zalevskiy <denis.zalevskiy@jolla.com>
- Loading branch information
Denis Zalevskiy
committed
Oct 26, 2015
1 parent
1d44135
commit a27e19b
Showing
6 changed files
with
87 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
|
||
trace () { | ||
echo "`basename $0`: ${@:1}" 1>&2; | ||
} | ||
|
||
error() { | ||
trace $@ | ||
exit 1 | ||
} | ||
|
||
[ $# -eq 2 ] || error "Usage: $0 snapshot dst_dir" | ||
|
||
SNAP=$1 | ||
DST=$2 | ||
|
||
if [ "${SNAP:0:1}" != ">" ]; then | ||
SNAP=">$SNAP" | ||
fi | ||
|
||
git rev-parse --show-toplevel || error "Not a git dir $(pwd)" | ||
git rev-parse "$SNAP" >/dev/null || error "There is no snapshot $SNAP" | ||
[ -d $DST ] || error "There is no destination dir $DST" | ||
|
||
# only $DST itself is expected | ||
COUNT=$(find $DST -maxdepth 1 -not -name '.' | wc -l) | ||
if [ "x$COUNT" != "x1" ]; then | ||
error "Dst dir $DST should be empty, found $COUNT entries" | ||
fi | ||
|
||
trace "Export $SNAP to the $DST" | ||
|
||
GIT_DIR=$(pwd) | ||
(git archive --format=tar "$SNAP" | tar -C $DST -xf -) || \ | ||
error "Export of $SNAP to the $DST is failed" | ||
|
||
find $DST -type l | grep '/blobs/' | while read -r LINK | ||
do | ||
NAME=$(readlink $LINK) | ||
# match minimal relative blob ref (path inside the tree is unit/blobs/link) | ||
if [[ $NAME =~ \.\./\.\./\.git/blobs/ ]]; then | ||
FNAME=$(basename $NAME) | ||
DNAME="$GIT_DIR/.git/blobs/$(basename $(dirname $NAME))" | ||
[ -d $DNAME ] || error "There is no blob dir $DNAME for $LINK" | ||
FNAME="$DNAME/$FNAME" | ||
[ -f $FNAME ] || error "There is no blob file $FNAME for $LINK" | ||
unlink $LINK || error "Can't unlink $LINK" | ||
cp $FNAME $LINK || error "Can't copy $FNAME to $LINK" | ||
fi | ||
done |