Skip to content

Commit

Permalink
deserialize-status: silently fallback if we cannot read cache file
Browse files Browse the repository at this point in the history
Teach Git to not throw a fatal error when an explicitly-specified
status-cache file (`git status --deserialize=<foo>`) could not be
found or opened for reading and silently fallback to a traditional
scan.

This matches the behavior when the status-cache file is implicitly
given via a config setting.

Note: the current version causes a test to start failing. Mark this as
an expected result for now.

Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com>
Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
  • Loading branch information
jeffhostetler authored and dscho committed Aug 16, 2023
1 parent 7b1c084 commit 03f2efc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
18 changes: 12 additions & 6 deletions builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,18 @@ static int opt_parse_deserialize(const struct option *opt, const char *arg, int
free(deserialize_path);
deserialize_path = xstrdup(arg);
}
if (deserialize_path && *deserialize_path
&& (access(deserialize_path, R_OK) != 0))
die("cannot find serialization file '%s'",
deserialize_path);

do_explicit_deserialize = 1;
if (!deserialize_path || !*deserialize_path)
do_explicit_deserialize = 1; /* read stdin */
else if (access(deserialize_path, R_OK) == 0)
do_explicit_deserialize = 1; /* can read from this file */
else {
/*
* otherwise, silently fallback to the normal
* collection scan
*/
do_implicit_deserialize = 0;
do_explicit_deserialize = 0;
}
}

return 0;
Expand Down
16 changes: 16 additions & 0 deletions t/t7522-serialized-status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,20 @@ test_expect_success 'ensure deserialize -v does not crash' '
grep -q "deserialize/reject:args/verbose" verbose_test.log_v
'

test_expect_success 'fallback when implicit' '
git init -b main implicit_fallback_test &&
git -C implicit_fallback_test -c status.deserializepath=foobar status
'

test_expect_success 'fallback when explicit' '
git init -b main explicit_fallback_test &&
git -C explicit_fallback_test status --deserialize=foobar
'

test_expect_success 'deserialize from stdin' '
git init -b main stdin_test &&
git -C stdin_test status --serialize >serialized_status.dat &&
cat serialize_status.dat | git -C stdin_test status --deserialize
'

test_done

0 comments on commit 03f2efc

Please sign in to comment.