Re: [PATCH v2 5/8] status: print per-file porcelain v2 status data
On 07/25/2016 04:23 PM, Junio C Hamano wrote: Jeff Hostetlerwrites: +static void wt_porcelain_v2_print(struct wt_status *s); + There is no point in this forward declaration, if you just place the implementation of these functions here, no? Right. I just did it that way to make the diffs with the previous commit draw a little cleaner. But I can take it out. +/* + * Print porcelain v2 info for tracked entries with changes. + */ +static void wt_porcelain_v2_print_changed_entry( + struct string_list_item *it, + struct wt_status *s) +{ +... + fprintf(s->fp, "%c %s %s %06o %06o %06o %s %s R%d %s", It is misleading to always say R in the output when there is no rename, isn't it? Yes, especially if we add it for copied entries too. I was just looking for a way to have a fixed format. If we make the R%d field optional, then the first pathname is ambiguous. That gets me back to an earlier draft where we have rename and non-rename line types. I'll split this up into 1 pathname and 2 pathname forms, and only include the R%d (or the C%d) field in the latter. +* Note that this is a last-one-wins for each the individual +* stage [123] columns in the event of multiple cache rows +* for a stage. Just FYI, the usual lingo we use for that is "multiple cache entries for the same stage", I would think. thanks. +*/ + memset(stages, 0, sizeof(stages)); + sum = 0; + pos = cache_name_pos(it->string, strlen(it->string)); + assert(pos < 0); + pos = -pos-1; + while (pos < active_nr) { + ce = active_cache[pos++]; + stage = ce_stage(ce); + if (strcmp(ce->name, it->string) || !stage) + break; + stages[stage - 1].mode = ce->ce_mode; + hashcpy(stages[stage - 1].oid.hash, ce->sha1); + sum++; + } + if (!sum) + die("BUG: unmerged entry without any stages"); Hmm, we seem to already have d->stagemask; if you call that variable "sum" anyway, perhaps its computation can be more like sum |= 1 << (stage - 1); so that you can compare it with d->stagemask for this sanity check? good point. thanks jeff -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH v2 5/8] status: print per-file porcelain v2 status data
Jeff Hostetlerwrites: > +static void wt_porcelain_v2_print(struct wt_status *s); > + There is no point in this forward declaration, if you just place the implementation of these functions here, no? > +/* > + * Print porcelain v2 info for tracked entries with changes. > + */ > +static void wt_porcelain_v2_print_changed_entry( > + struct string_list_item *it, > + struct wt_status *s) > +{ > +... > + fprintf(s->fp, "%c %s %s %06o %06o %06o %s %s R%d %s", It is misleading to always say R in the output when there is no rename, isn't it? > + * Note that this is a last-one-wins for each the individual > + * stage [123] columns in the event of multiple cache rows > + * for a stage. Just FYI, the usual lingo we use for that is "multiple cache entries for the same stage", I would think. > + */ > + memset(stages, 0, sizeof(stages)); > + sum = 0; > + pos = cache_name_pos(it->string, strlen(it->string)); > + assert(pos < 0); > + pos = -pos-1; > + while (pos < active_nr) { > + ce = active_cache[pos++]; > + stage = ce_stage(ce); > + if (strcmp(ce->name, it->string) || !stage) > + break; > + stages[stage - 1].mode = ce->ce_mode; > + hashcpy(stages[stage - 1].oid.hash, ce->sha1); > + sum++; > + } > + if (!sum) > + die("BUG: unmerged entry without any stages"); Hmm, we seem to already have d->stagemask; if you call that variable "sum" anyway, perhaps its computation can be more like sum |= 1 << (stage - 1); so that you can compare it with d->stagemask for this sanity check? -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[PATCH v2 5/8] status: print per-file porcelain v2 status data
Print per-file information in porcelain v2 format. Signed-off-by: Jeff Hostetler--- wt-status.c | 285 +++- 1 file changed, 284 insertions(+), 1 deletion(-) diff --git a/wt-status.c b/wt-status.c index 54aedc1..ffdfe11 100644 --- a/wt-status.c +++ b/wt-status.c @@ -1864,6 +1864,8 @@ static void wt_porcelain_print(struct wt_status *s) wt_shortstatus_print(s); } +static void wt_porcelain_v2_print(struct wt_status *s); + void wt_status_print(struct wt_status *s) { switch (s->status_format) { @@ -1874,7 +1876,7 @@ void wt_status_print(struct wt_status *s) wt_porcelain_print(s); break; case STATUS_FORMAT_PORCELAIN_V2: - /* TODO */ + wt_porcelain_v2_print(s); break; case STATUS_FORMAT_UNSPECIFIED: die("BUG: finalize_deferred_config() should have been called"); @@ -1885,3 +1887,284 @@ void wt_status_print(struct wt_status *s) break; } } + +/* + * Convert various submodule status values into a + * string of characters in the buffer provided. + */ +static void wt_porcelain_v2_submodule_state( + struct wt_status_change_data *d, + char sub[5]) +{ + if (S_ISGITLINK(d->aux.porcelain_v2.mode_head) || + S_ISGITLINK(d->aux.porcelain_v2.mode_index) || + S_ISGITLINK(d->aux.porcelain_v2.mode_worktree)) { + sub[0] = 'S'; + sub[1] = d->new_submodule_commits ? 'C' : '.'; + sub[2] = (d->dirty_submodule & DIRTY_SUBMODULE_MODIFIED) ? 'M' : '.'; + sub[3] = (d->dirty_submodule & DIRTY_SUBMODULE_UNTRACKED) ? 'U' : '.'; + } else { + sub[0] = 'N'; + sub[1] = '.'; + sub[2] = '.'; + sub[3] = '.'; + } + sub[4] = 0; +} + +/* + * Fix-up changed entries before we print them. + */ +static void wt_porcelain_v2_fix_up_changed( + struct string_list_item *it, + struct wt_status *s) +{ + struct wt_status_change_data *d = it->util; + + if (!d->index_status) { + /* +* This entry is unchanged in the index (relative to the head). +* Therefore, the collect_updated_cb was never called for this +* entry (during the head-vs-index scan) and so the head column +* fields were never set. +* +* We must have data for the index column (from the +* index-vs-worktree scan (otherwise, this entry should not be +* in the list of changes)). +* +* Copy index column fields to the head column, so that our +* output looks complete. +*/ + assert(d->aux.porcelain_v2.mode_head == 0); + d->aux.porcelain_v2.mode_head = d->aux.porcelain_v2.mode_index; + oidcpy(>aux.porcelain_v2.oid_head, >aux.porcelain_v2.oid_index); + } + + if (!d->worktree_status) { + /* +* This entry is unchanged in the worktree (relative to the index). +* Therefore, the collect_changed_cb was never called for this entry +* (during the index-vs-worktree scan) and so the worktree column +* fields were never set. +* +* We must have data for the index column (from the head-vs-index +* scan). +* +* Copy the index column fields to the worktree column so that +* our output looks complete. +* +* Note that we only have a mode field in the worktree column +* because the scan code tries really hard to not have to compute it. +*/ + assert(d->aux.porcelain_v2.mode_worktree == 0); + d->aux.porcelain_v2.mode_worktree = d->aux.porcelain_v2.mode_index; + } +} + +/* + * Print porcelain v2 info for tracked entries with changes. + */ +static void wt_porcelain_v2_print_changed_entry( + struct string_list_item *it, + struct wt_status *s) +{ + struct wt_status_change_data *d = it->util; + struct strbuf buf_current = STRBUF_INIT; + struct strbuf buf_rename_src = STRBUF_INIT; + const char *path_current = NULL; + const char *path_rename_src = NULL; + char key[3]; + char submodule_token[5]; + char changed_prefix = 'c'; + char sep_char, eol_char; + + wt_porcelain_v2_fix_up_changed(it, s); + wt_porcelain_v2_submodule_state(d, submodule_token); + + key[0] = d->index_status ? d->index_status : '.'; + key[1] = d->worktree_status ? d->worktree_status : '.'; + key[2] = 0; + + if (s->null_termination) { + /* +* In -z mode, we DO NOT C-Quote