Skip to content

Commit 8f61321

Browse files
pks-tgitster
authored andcommitted
wt-status: read HEAD and ORIG_HEAD via the refdb
We read both the HEAD and ORIG_HEAD references directly from the filesystem in order to figure out whether we're currently splitting a commit. If both of the following are true: - HEAD points to the same object as "rebase-merge/amend". - ORIG_HEAD points to the same object as "rebase-merge/orig-head". Then we are currently splitting commits. The current code only works by chance because we only have a single reference backend implementation. Refactor it to instead read both refs via the refdb layer so that we'll also be compatible with alternate reference backends. There are some subtleties involved here: - We pass `RESOLVE_REF_READING` so that a missing ref will cause `read_ref_full()` to return an error. - We pass `RESOLVE_REF_NO_RECURSE` so that we do not try to resolve symrefs. The old code didn't resolve symrefs either, and we only ever write object IDs into the refs in "rebase-merge/". - In the same spirit we verify that successfully-read refs are not symbolic refs. Signed-off-by: Patrick Steinhardt <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1a87c84 commit 8f61321

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

wt-status.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,26 +1295,32 @@ static char *read_line_from_git_path(const char *filename)
12951295
static int split_commit_in_progress(struct wt_status *s)
12961296
{
12971297
int split_in_progress = 0;
1298-
char *head, *orig_head, *rebase_amend, *rebase_orig_head;
1298+
struct object_id head_oid, orig_head_oid;
1299+
char *rebase_amend, *rebase_orig_head;
1300+
int head_flags, orig_head_flags;
12991301

13001302
if ((!s->amend && !s->nowarn && !s->workdir_dirty) ||
13011303
!s->branch || strcmp(s->branch, "HEAD"))
13021304
return 0;
13031305

1304-
head = read_line_from_git_path("HEAD");
1305-
orig_head = read_line_from_git_path("ORIG_HEAD");
1306+
if (read_ref_full("HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1307+
&head_oid, &head_flags) ||
1308+
read_ref_full("ORIG_HEAD", RESOLVE_REF_READING | RESOLVE_REF_NO_RECURSE,
1309+
&orig_head_oid, &orig_head_flags))
1310+
return 0;
1311+
if (head_flags & REF_ISSYMREF || orig_head_flags & REF_ISSYMREF)
1312+
return 0;
1313+
13061314
rebase_amend = read_line_from_git_path("rebase-merge/amend");
13071315
rebase_orig_head = read_line_from_git_path("rebase-merge/orig-head");
13081316

1309-
if (!head || !orig_head || !rebase_amend || !rebase_orig_head)
1317+
if (!rebase_amend || !rebase_orig_head)
13101318
; /* fall through, no split in progress */
13111319
else if (!strcmp(rebase_amend, rebase_orig_head))
1312-
split_in_progress = !!strcmp(head, rebase_amend);
1313-
else if (strcmp(orig_head, rebase_orig_head))
1320+
split_in_progress = !!strcmp(oid_to_hex(&head_oid), rebase_amend);
1321+
else if (strcmp(oid_to_hex(&orig_head_oid), rebase_orig_head))
13141322
split_in_progress = 1;
13151323

1316-
free(head);
1317-
free(orig_head);
13181324
free(rebase_amend);
13191325
free(rebase_orig_head);
13201326

0 commit comments

Comments
 (0)