Skip to content

Commit 4df4aed

Browse files
phil-blaingitster
authored andcommitted
wt-status: also abbreviate 'merge' and 'fixup -C' lines during rebase
When "git status" is invoked during a rebase, we print the last commands done and the next commands to do, and abbreviate commit hashes found in those lines. However, we only abbreviate hashes in 'pick', 'squash' and plain 'fixup' lines, not those in 'merge -C' and 'fixup -C' lines, as the parsing done in wt-status.c::abbrev_oid_in_line is not prepared for such lines. Improve the parsing done by this function by special casing 'fixup' and 'merge' such that the hash to abbreviate is the string found in the third field of 'split', instead of the second one for other commands. Introduce a 'hash' strbuf pointer to point to the correct field in all cases. Signed-off-by: Philippe Blain <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0c088a0 commit 4df4aed

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

wt-status.c

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,9 +1342,11 @@ static int split_commit_in_progress(struct wt_status *s)
13421342

13431343
/*
13441344
* Turn
1345-
* "pick d6a2f0303e897ec257dd0e0a39a5ccb709bc2047 some message"
1345+
* "pick d6a2f0303e897ec257dd0e0a39a5ccb709bc2047 some message" and
1346+
* "merge -C d6a2f0303e897ec257dd0e0a39a5ccb709bc2047 some-branch"
13461347
* into
1347-
* "pick d6a2f03 some message"
1348+
* "pick d6a2f03 some message" and
1349+
* "merge -C d6a2f03 some-branch"
13481350
*
13491351
* The function assumes that the line does not contain useless spaces
13501352
* before or after the command.
@@ -1360,20 +1362,31 @@ static void abbrev_oid_in_line(struct strbuf *line)
13601362
starts_with(line->buf, "l "))
13611363
return;
13621364

1363-
split = strbuf_split_max(line, ' ', 3);
1365+
split = strbuf_split_max(line, ' ', 4);
13641366
if (split[0] && split[1]) {
13651367
struct object_id oid;
1366-
1368+
struct strbuf *hash;
1369+
1370+
if ((!strcmp(split[0]->buf, "merge ") ||
1371+
!strcmp(split[0]->buf, "m " ) ||
1372+
!strcmp(split[0]->buf, "fixup ") ||
1373+
!strcmp(split[0]->buf, "f " )) &&
1374+
(!strcmp(split[1]->buf, "-C ") ||
1375+
!strcmp(split[1]->buf, "-c "))) {
1376+
hash = split[2];
1377+
} else {
1378+
hash = split[1];
1379+
}
13671380
/*
13681381
* strbuf_split_max left a space. Trim it and re-add
13691382
* it after abbreviation.
13701383
*/
1371-
strbuf_trim(split[1]);
1372-
if (!repo_get_oid(the_repository, split[1]->buf, &oid)) {
1373-
strbuf_reset(split[1]);
1374-
strbuf_add_unique_abbrev(split[1], &oid,
1384+
strbuf_trim(hash);
1385+
if (!repo_get_oid(the_repository, hash->buf, &oid)) {
1386+
strbuf_reset(hash);
1387+
strbuf_add_unique_abbrev(hash, &oid,
13751388
DEFAULT_ABBREV);
1376-
strbuf_addch(split[1], ' ');
1389+
strbuf_addch(hash, ' ');
13771390
strbuf_reset(line);
13781391
for (i = 0; split[i]; i++)
13791392
strbuf_addbuf(line, split[i]);

0 commit comments

Comments
 (0)