Skip to content

Commit 5134ccd

Browse files
pcloudsgitster
authored andcommitted
wt-status.c: rename rename-related fields in wt_status_change_data
These field "head_path" is used for rename display only. In the next patch we introduce another rename pair where the rename source is no longer HEAD. Rename it to something more generic. While at there, rename "score" as well and store the rename diff code in a separate field instead of hardcoding key[0] (i.e. diff-index) in porcelain v2 code. Signed-off-by: Nguyễn Thái Ngọc Duy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ea56f97 commit 5134ccd

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

wt-status.c

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ static void wt_longstatus_print_change_data(struct wt_status *s,
361361
switch (change_type) {
362362
case WT_STATUS_UPDATED:
363363
status = d->index_status;
364-
if (d->head_path)
365-
one_name = d->head_path;
364+
if (d->rename_source)
365+
one_name = d->rename_source;
366366
break;
367367
case WT_STATUS_CHANGED:
368368
if (d->new_submodule_commits || d->dirty_submodule) {
@@ -392,7 +392,7 @@ static void wt_longstatus_print_change_data(struct wt_status *s,
392392
die("BUG: unhandled diff status %c", status);
393393
len = label_width - utf8_strwidth(what);
394394
assert(len >= 0);
395-
if (status == DIFF_STATUS_COPIED || status == DIFF_STATUS_RENAMED)
395+
if (one_name != two_name)
396396
status_printf_more(s, c, "%s%.*s%s -> %s",
397397
what, len, padding, one, two);
398398
else
@@ -532,8 +532,9 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
532532

533533
case DIFF_STATUS_COPIED:
534534
case DIFF_STATUS_RENAMED:
535-
d->head_path = xstrdup(p->one->path);
536-
d->score = p->score * 100 / MAX_SCORE;
535+
d->rename_source = xstrdup(p->one->path);
536+
d->rename_score = p->score * 100 / MAX_SCORE;
537+
d->rename_status = p->status;
537538
/* fallthru */
538539
case DIFF_STATUS_MODIFIED:
539540
case DIFF_STATUS_TYPE_CHANGED:
@@ -1691,13 +1692,14 @@ static void wt_shortstatus_status(struct string_list_item *it,
16911692
putchar(' ');
16921693
if (s->null_termination) {
16931694
fprintf(stdout, "%s%c", it->string, 0);
1694-
if (d->head_path)
1695-
fprintf(stdout, "%s%c", d->head_path, 0);
1695+
if (d->rename_source)
1696+
fprintf(stdout, "%s%c", d->rename_source, 0);
16961697
} else {
16971698
struct strbuf onebuf = STRBUF_INIT;
16981699
const char *one;
1699-
if (d->head_path) {
1700-
one = quote_path(d->head_path, s->prefix, &onebuf);
1700+
1701+
if (d->rename_source) {
1702+
one = quote_path(d->rename_source, s->prefix, &onebuf);
17011703
if (*one != '"' && strchr(one, ' ') != NULL) {
17021704
putchar('"');
17031705
strbuf_addch(&onebuf, '"');
@@ -2001,10 +2003,10 @@ static void wt_porcelain_v2_print_changed_entry(
20012003
struct wt_status *s)
20022004
{
20032005
struct wt_status_change_data *d = it->util;
2004-
struct strbuf buf_index = STRBUF_INIT;
2005-
struct strbuf buf_head = STRBUF_INIT;
2006-
const char *path_index = NULL;
2007-
const char *path_head = NULL;
2006+
struct strbuf buf = STRBUF_INIT;
2007+
struct strbuf buf_from = STRBUF_INIT;
2008+
const char *path = NULL;
2009+
const char *path_from = NULL;
20082010
char key[3];
20092011
char submodule_token[5];
20102012
char sep_char, eol_char;
@@ -2023,8 +2025,8 @@ static void wt_porcelain_v2_print_changed_entry(
20232025
*/
20242026
sep_char = '\0';
20252027
eol_char = '\0';
2026-
path_index = it->string;
2027-
path_head = d->head_path;
2028+
path = it->string;
2029+
path_from = d->rename_source;
20282030
} else {
20292031
/*
20302032
* Path(s) are C-quoted if necessary. Current path is ALWAYS first.
@@ -2034,27 +2036,27 @@ static void wt_porcelain_v2_print_changed_entry(
20342036
*/
20352037
sep_char = '\t';
20362038
eol_char = '\n';
2037-
path_index = quote_path(it->string, s->prefix, &buf_index);
2038-
if (d->head_path)
2039-
path_head = quote_path(d->head_path, s->prefix, &buf_head);
2039+
path = quote_path(it->string, s->prefix, &buf);
2040+
if (d->rename_source)
2041+
path_from = quote_path(d->rename_source, s->prefix, &buf_from);
20402042
}
20412043

2042-
if (path_head)
2044+
if (path_from)
20432045
fprintf(s->fp, "2 %s %s %06o %06o %06o %s %s %c%d %s%c%s%c",
20442046
key, submodule_token,
20452047
d->mode_head, d->mode_index, d->mode_worktree,
20462048
oid_to_hex(&d->oid_head), oid_to_hex(&d->oid_index),
2047-
key[0], d->score,
2048-
path_index, sep_char, path_head, eol_char);
2049+
d->rename_status, d->rename_score,
2050+
path, sep_char, path_from, eol_char);
20492051
else
20502052
fprintf(s->fp, "1 %s %s %06o %06o %06o %s %s %s%c",
20512053
key, submodule_token,
20522054
d->mode_head, d->mode_index, d->mode_worktree,
20532055
oid_to_hex(&d->oid_head), oid_to_hex(&d->oid_index),
2054-
path_index, eol_char);
2056+
path, eol_char);
20552057

2056-
strbuf_release(&buf_index);
2057-
strbuf_release(&buf_head);
2058+
strbuf_release(&buf);
2059+
strbuf_release(&buf_from);
20582060
}
20592061

20602062
/*

wt-status.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ struct wt_status_change_data {
3838
int worktree_status;
3939
int index_status;
4040
int stagemask;
41-
int score;
4241
int mode_head, mode_index, mode_worktree;
4342
struct object_id oid_head, oid_index;
44-
char *head_path;
43+
int rename_status;
44+
int rename_score;
45+
char *rename_source;
4546
unsigned dirty_submodule : 2;
4647
unsigned new_submodule_commits : 1;
4748
};

0 commit comments

Comments
 (0)