]> arthur.barton.de Git - bup.git/commitdiff
index: make --fake-valid match the man page
authorJohannes Berg <johannes@sipsolutions.net>
Mon, 17 Feb 2020 20:02:11 +0000 (21:02 +0100)
committerRob Browning <rlb@defaultvalue.org>
Sun, 1 Mar 2020 22:54:49 +0000 (16:54 -0600)
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 <johannes@sipsolutions.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
cmd/index-cmd.py
t/test-save-smaller

index c2a22f913aa64bd2fe83f4a6b68812ed5837613b..f5ab59252eb30bacf3c11381d1a8e9cf808e9788 100755 (executable)
@@ -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:
index 6e625e6212a8e895b0192f875adbf79b91f86eff..7018c8498a347ff88442820f215057cef746669d 100755 (executable)
@@ -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"