@matheusbsbs / matheus-bagliano / commits / 1f9becaedc
Fork 0

commit-graph.c: write non-split graphs as read-only

In the previous commit, Git learned 'hold_lock_file_for_update_mode' to allow the caller to specify the permission bits (prior to further adjustment by the umask and shared repository permissions) used when acquiring a temporary file. Use this in the commit-graph machinery for writing a non-split graph to acquire an opened temporary file with permissions read-only permissions to match the split behavior. (In the split case, Git uses git_mkstemp_mode' for each of the commit-graph layers with permission bits '0444'). One can notice this discrepancy when moving a non-split graph to be part of a new chain. This causes a commit-graph chain where all layers have read-only permission bits, except for the base layer, which is writable for the current user. Resolve this discrepancy by using the new 'hold_lock_file_for_update_mode' and passing the desired permission bits. Doing so causes some test fallout in t5318 and t6600. In t5318, this occurs in tests that corrupt a commit-graph file by writing into it. For these, 'chmod u+w'-ing the file beforehand resolves the issue. The additional spot in 'corrupt_graph_verify' is necessary because of the extra 'git commit-graph write' beforehand (which *does* rewrite the commit-graph file). In t6600, this is caused by copying a read-only commit-graph file into place and then trying to replace it. For these, make these files writable. Helped-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Taylor Blau committed Apr 29, 2020 at 11:36 UTC 1f9becaedc9266651145a146fb63b84c3ee79d95
3 files changed +18 -2
commit-graph.c
+2 -1
@@ -1388,7 +1388,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
1388
1389 f = hashfd(fd, ctx->graph_name);
1390 } else {
1391 - hold_lock_file_for_update(&lk, ctx->graph_name, LOCK_DIE_ON_ERROR);
1391 + hold_lock_file_for_update_mode(&lk, ctx->graph_name,
1392 + LOCK_DIE_ON_ERROR, 0444);
1393 fd = lk.tempfile->fd;
1394 f = hashfd(lk.tempfile->fd, lk.tempfile->filename.buf);
1395 }
t/t5318-commit-graph.sh
+14 -1
@@ -12,6 +12,10 @@ test_expect_success 'setup full repo' '
12 test_oid_init
13 '
14
15 +test_expect_success POSIXPERM 'tweak umask for modebit tests' '
16 + umask 022
17 +'
18 +
19 test_expect_success 'verify graph with no graph file' '
20 cd "$TRASH_DIRECTORY/full" &&
21 git commit-graph verify
@@ -96,6 +100,13 @@ test_expect_success 'write graph' '
100 graph_read_expect "3"
101 '
102
103 +test_expect_success POSIXPERM 'write graph has correct permissions' '
104 + test_path_is_file $objdir/info/commit-graph &&
105 + echo "-r--r--r--" >expect &&
106 + test_modebits $objdir/info/commit-graph >actual &&
107 + test_cmp expect actual
108 +'
109 +
110 graph_git_behavior 'graph exists' full commits/3 commits/1
111
112 test_expect_success 'Add more commits' '
@@ -421,7 +432,8 @@ GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES))
432 corrupt_graph_setup() {
433 cd "$TRASH_DIRECTORY/full" &&
434 test_when_finished mv commit-graph-backup $objdir/info/commit-graph &&
424 - cp $objdir/info/commit-graph commit-graph-backup
435 + cp $objdir/info/commit-graph commit-graph-backup &&
436 + chmod u+w $objdir/info/commit-graph
437 }
438
439 corrupt_graph_verify() {
@@ -435,6 +447,7 @@ corrupt_graph_verify() {
447 fi &&
448 git status --short &&
449 GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD=true git commit-graph write &&
450 + chmod u+w $objdir/info/commit-graph &&
451 git commit-graph verify
452 }
453
t/t6600-test-reach.sh
+2
@@ -51,8 +51,10 @@ test_expect_success 'setup' '
51 done &&
52 git commit-graph write --reachable &&
53 mv .git/objects/info/commit-graph commit-graph-full &&
54 + chmod u+w commit-graph-full &&
55 git show-ref -s commit-5-5 | git commit-graph write --stdin-commits &&
56 mv .git/objects/info/commit-graph commit-graph-half &&
57 + chmod u+w commit-graph-half &&
58 git config core.commitGraph true
59 '
60