Skip to content

Commit 5971b08

Browse files
bk2204gitster
authored andcommitted
sequencer: ensure labels that are object IDs are rewritten
When writing the todo script for --rebase-merges, we try to find a label for certain commits. If the label ends up being a valid object ID, such as when we merge a detached commit, we want to rewrite it so it is no longer a valid object ID. However, the code path that does this checks for its length to be equivalent to GIT_SHA1_RAWSZ, which isn't correct, since what we are reading is a hex object ID. Instead, check for the length being equivalent to that of a hex object ID. Use the_hash_algo so this code works regardless of the hash size. Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 35d515b commit 5971b08

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

sequencer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3534,7 +3534,7 @@ static const char *label_oid(struct object_id *oid, const char *label,
35343534
p[i] = save;
35353535
}
35363536
}
3537-
} else if (((len = strlen(label)) == GIT_SHA1_RAWSZ &&
3537+
} else if (((len = strlen(label)) == the_hash_algo->hexsz &&
35383538
!get_oid_hex(label, &dummy)) ||
35393539
(len == 1 && *label == '#') ||
35403540
hashmap_get_from_hash(&state->labels,

t/t3430-rebase-merges.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ test_expect_success 'create completely different structure' '
7070
merge -C H second
7171
merge onebranch # Merge the topic branch '\''onebranch'\''
7272
EOF
73+
cp script-from-scratch script-from-scratch-orig &&
7374
test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
7475
test_tick &&
7576
git rebase -i -r A &&
@@ -241,4 +242,20 @@ test_expect_success 'refuse to merge ancestors of HEAD' '
241242
test_cmp_rev HEAD $before
242243
'
243244

245+
test_expect_success 'labels that are object IDs are rewritten' '
246+
git checkout -b third B &&
247+
test_tick &&
248+
test_commit I &&
249+
third=$(git rev-parse HEAD) &&
250+
git checkout -b labels master &&
251+
git merge --no-commit third &&
252+
test_tick &&
253+
git commit -m "Merge commit '\''$third'\'' into labels" &&
254+
cp script-from-scratch-orig script-from-scratch &&
255+
test_config sequence.editor \""$PWD"/replace-editor.sh\" &&
256+
test_tick &&
257+
git rebase -i -r A &&
258+
! grep "^label $third$" .git/ORIGINAL-TODO
259+
'
260+
244261
test_done

0 commit comments

Comments
 (0)