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 <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nguyễn Thái Ngọc Duy committed
Dec 27, 2017 at 17:18 UTC
5134ccde642ae9ed6a244c92864c26734d100f4c
2 files changed
+29
-26
wt-status.c
+26
-24
@@ -361,8 +361,8 @@ static void wt_longstatus_print_change_data(struct wt_status *s,
361
switch (change_type) {
362
case WT_STATUS_UPDATED:
363
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;
366
break;
367
case WT_STATUS_CHANGED:
368
if (d->new_submodule_commits || d->dirty_submodule) {
@@ -392,7 +392,7 @@ static void wt_longstatus_print_change_data(struct wt_status *s,
392
die("BUG: unhandled diff status %c", status);
393
len = label_width - utf8_strwidth(what);
394
assert(len >= 0);
395
- if (status == DIFF_STATUS_COPIED || status == DIFF_STATUS_RENAMED)
395
+ if (one_name != two_name)
396
status_printf_more(s, c, "%s%.*s%s -> %s",
397
what, len, padding, one, two);
398
else
@@ -532,8 +532,9 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
532
533
case DIFF_STATUS_COPIED:
534
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;
538
/* fallthru */
539
case DIFF_STATUS_MODIFIED:
540
case DIFF_STATUS_TYPE_CHANGED:
@@ -1691,13 +1692,14 @@ static void wt_shortstatus_status(struct string_list_item *it,
1692
putchar(' ');
1693
if (s->null_termination) {
1694
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);
1697
} else {
1698
struct strbuf onebuf = STRBUF_INIT;
1699
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);
1703
if (*one != '"' && strchr(one, ' ') != NULL) {
1704
putchar('"');
1705
strbuf_addch(&onebuf, '"');
@@ -2001,10 +2003,10 @@ static void wt_porcelain_v2_print_changed_entry(
2003
struct wt_status *s)
2004
{
2005
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;
2010
char key[3];
2011
char submodule_token[5];
2012
char sep_char, eol_char;
@@ -2023,8 +2025,8 @@ static void wt_porcelain_v2_print_changed_entry(
2025
*/
2026
sep_char = '\0';
2027
eol_char = '\0';
2026
- path_index = it->string;
2027
- path_head = d->head_path;
2028
+ path = it->string;
2029
+ path_from = d->rename_source;
2030
} else {
2031
/*
2032
* Path(s) are C-quoted if necessary. Current path is ALWAYS first.
@@ -2034,27 +2036,27 @@ static void wt_porcelain_v2_print_changed_entry(
2036
*/
2037
sep_char = '\t';
2038
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);
2042
}
2043
2042
- if (path_head)
2044
+ if (path_from)
2045
fprintf(s->fp, "2 %s %s %06o %06o %06o %s %s %c%d %s%c%s%c",
2046
key, submodule_token,
2047
d->mode_head, d->mode_index, d->mode_worktree,
2048
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);
2051
else
2052
fprintf(s->fp, "1 %s %s %06o %06o %06o %s %s %s%c",
2053
key, submodule_token,
2054
d->mode_head, d->mode_index, d->mode_worktree,
2055
oid_to_hex(&d->oid_head), oid_to_hex(&d->oid_index),
2054
- path_index, eol_char);
2056
+ path, eol_char);
2057
2056
- strbuf_release(&buf_index);
2057
- strbuf_release(&buf_head);
2058
+ strbuf_release(&buf);
2059
+ strbuf_release(&buf_from);
2060
}
2061
2062
/*
wt-status.h
+3
-2
@@ -38,10 +38,11 @@ struct wt_status_change_data {
38
int worktree_status;
39
int index_status;
40
int stagemask;
41
- int score;
41
int mode_head, mode_index, mode_worktree;
42
struct object_id oid_head, oid_index;
44
- char *head_path;
43
+ int rename_status;
44
+ int rename_score;
45
+ char *rename_source;
46
unsigned dirty_submodule : 2;
47
unsigned new_submodule_commits : 1;
48
};