Skip to content

Commit 1f9beca

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent fa3bff2 commit 1f9beca

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

commit-graph.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1388,7 +1388,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
13881388

13891389
f = hashfd(fd, ctx->graph_name);
13901390
} 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);
13921393
fd = lk.tempfile->fd;
13931394
f = hashfd(lk.tempfile->fd, lk.tempfile->filename.buf);
13941395
}

t/t5318-commit-graph.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ test_expect_success 'setup full repo' '
1212
test_oid_init
1313
'
1414

15+
test_expect_success POSIXPERM 'tweak umask for modebit tests' '
16+
umask 022
17+
'
18+
1519
test_expect_success 'verify graph with no graph file' '
1620
cd "$TRASH_DIRECTORY/full" &&
1721
git commit-graph verify
@@ -96,6 +100,13 @@ test_expect_success 'write graph' '
96100
graph_read_expect "3"
97101
'
98102

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+
99110
graph_git_behavior 'graph exists' full commits/3 commits/1
100111

101112
test_expect_success 'Add more commits' '
@@ -421,7 +432,8 @@ GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES))
421432
corrupt_graph_setup() {
422433
cd "$TRASH_DIRECTORY/full" &&
423434
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
425437
}
426438

427439
corrupt_graph_verify() {
@@ -435,6 +447,7 @@ corrupt_graph_verify() {
435447
fi &&
436448
git status --short &&
437449
GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD=true git commit-graph write &&
450+
chmod u+w $objdir/info/commit-graph &&
438451
git commit-graph verify
439452
}
440453

t/t6600-test-reach.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ test_expect_success 'setup' '
5151
done &&
5252
git commit-graph write --reachable &&
5353
mv .git/objects/info/commit-graph commit-graph-full &&
54+
chmod u+w commit-graph-full &&
5455
git show-ref -s commit-5-5 | git commit-graph write --stdin-commits &&
5556
mv .git/objects/info/commit-graph commit-graph-half &&
57+
chmod u+w commit-graph-half &&
5658
git config core.commitGraph true
5759
'
5860

0 commit comments

Comments
 (0)