On 25/12/2017 19:26, Igor Djordjevic wrote:
>
> But I`ve noticed that "--porcelain=v2" output might still be buggy -
> this is what having both files staged shows:
>
> $ git status --porcelain=v2
> 2 R. N... 100644 100644 100644 12f00e90b6ef79117ce6e650416b8cf517099b78
> 12f00e90b6ef79117ce6e650416b8cf517099b78 R100 new-file original-file
>
> ..., where having old/deleted file unstaged, and new/created file
> staged with `git add -N` shows this:
>
> $ git status --porcelain=v2
> 1 .R N... 100644 100644 100644 12f00e90b6ef79117ce6e650416b8cf517099b78
> 12f00e90b6ef79117ce6e650416b8cf517099b78 new-file
>
> So even though unstaged value is correctly recognized as "R" (renamed),
> first number is "1" (instead of "2" to signal rename/copy), and both
> rename score and original file name are missing.
As an exercise, might be something like this as a fixup on top of
your patch could work.
I`ve tried to follow your lead on what you did yourself, but please
note that, besides being relatively new to Git codebase, this is my
first C code for almost 10 years (since university), so... :)
I guess an additional test for this would be good, too.
Regards, Buga
---
wt-status.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/wt-status.c b/wt-status.c
index f0b5b3d46..55c0ad249 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -2050,7 +2050,7 @@ static void wt_porcelain_v2_print_changed_entry(
const char *path_head = NULL;
char key[3];
char submodule_token[5];
- char sep_char, eol_char;
+ char sep_char, eol_char, score_char;
wt_porcelain_v2_fix_up_changed(it, s);
wt_porcelain_v2_submodule_state(d, submodule_token);
@@ -2059,6 +2059,8 @@ static void wt_porcelain_v2_print_changed_entry(
key[1] = d->worktree_status ? d->worktree_status : '.';
key[2] = 0;
+ path_head = d->head_path ? d->head_path : d->worktree_path;
+ score_char = d->index_status ? key[0] : key[1];
if (s->null_termination) {
/*
* In -z mode, we DO NOT C-quote pathnames. Current path is
ALWAYS first.
@@ -2067,7 +2069,6 @@ static void wt_porcelain_v2_print_changed_entry(
sep_char = '\0';
eol_char = '\0';
path_index = it->string;
- path_head = d->head_path;
} else {
/*
* Path(s) are C-quoted if necessary. Current path is ALWAYS
first.
@@ -2078,8 +2079,8 @@ static void wt_porcelain_v2_print_changed_entry(
sep_char = '\t';
eol_char = '\n';
path_index = quote_path(it->string, s->prefix, &buf_index);
- if (d->head_path)
- path_head = quote_path(d->head_path, s->prefix,
&buf_head);
+ if (path_head)
+ path_head = quote_path(path_head, s->prefix, &buf_head);
}
if (path_head)
@@ -2087,7 +2088,7 @@ static void wt_porcelain_v2_print_changed_entry(
key, submodule_token,
d->mode_head, d->mode_index, d->mode_worktree,
oid_to_hex(&d->oid_head),
oid_to_hex(&d->oid_index),
- key[0], d->score,
+ score_char, d->score,
path_index, sep_char, path_head, eol_char);
else
fprintf(s->fp, "1 %s %s %06o %06o %06o %s %s %s%c",
--
2.15.1.windows.2