From: Johannes Berg Date: Mon, 17 Feb 2020 20:02:11 +0000 (+0100) Subject: index: make --fake-valid match the man page X-Git-Tag: 0.31~92 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=bup.git;a=commitdiff_plain;h=a79de5af5c6fcdf730a94ae8d1b839dfbbc2dc59 index: make --fake-valid match the man page The index command currently clobbers the hash of a file when marking it as valid, but the man page states: --fake-valid mark specified paths as up-to-date even if they aren't. This can be useful for testing, or to avoid unnecessarily backing up files that you know are boring. The latter part ("avoid unnecessarily backing up [...]") cannot be implemented with --fake-valid as is, because of the clobbering of the hash: the fake invented hash will not exist in the repository, and thus save checks and saves the file. Fix this by clobbering the hash only if it's the invalid EMPTY_SHA. Add a test for this to test-save-smaller, just because that's where we discovered it. Signed-off-by: Johannes Berg Reviewed-by: Rob Browning --- diff --git a/cmd/index-cmd.py b/cmd/index-cmd.py index c2a22f9..f5ab592 100755 --- a/cmd/index-cmd.py +++ b/cmd/index-cmd.py @@ -150,7 +150,8 @@ def update_index(top, excluded_paths, exclude_rxs, xdev_exceptions, out=None): need_repack = True if not (rig.cur.flags & index.IX_HASHVALID): if fake_hash: - rig.cur.gitmode, rig.cur.sha = fake_hash(path) + if rig.cur.sha == index.EMPTY_SHA: + rig.cur.gitmode, rig.cur.sha = fake_hash(path) rig.cur.flags |= index.IX_HASHVALID need_repack = True if opt.fake_invalid: diff --git a/t/test-save-smaller b/t/test-save-smaller index 6e625e6..7018c84 100755 --- a/t/test-save-smaller +++ b/t/test-save-smaller @@ -42,4 +42,16 @@ WVFAIL test -f "$tmpdir/restore2/big1" # and not the new one either WVFAIL test -f "$tmpdir/restore2/big2" +WVSTART "index --fake-valid / save" +WVPASS echo bigbigbigbigbig02 > "$tmpdir/save/big1" +WVPASS echo bigbigbigbigbig03 > "$tmpdir/save/big2" +WVPASS bup index "$tmpdir/save" +WVPASS bup index --fake-valid "$tmpdir/save/big1" "$tmpdir/save/big2" +WVPASS bup save -vv -n test "$tmpdir/save" +WVPASS mkdir "$tmpdir/restore3" +WVPASS bup restore -v --outdir="$tmpdir/restore3/" "/test/latest$tmpdir/save/" +WVPASS cmp "$tmpdir/restore3/small" "$tmpdir/save/small" +WVPASSEQ "$(sha1sum < "$tmpdir/restore3/big1")" "$big1sha" +WVPASS cmp "$tmpdir/restore3/big2" "$tmpdir/save/big2" + WVPASS rm -rf "$tmpdir"