aboutsummaryrefslogtreecommitdiff
path: root/wt-status.c
diff options
context:
space:
mode:
authorJeff Hostetler <jeffhost@microsoft.com>2016-08-11 10:45:57 -0400
committerJunio C Hamano <gitster@pobox.com>2016-08-11 11:14:43 -0700
commit1ecdecce621009a4d039d061d514056501d0ed8f (patch)
tree72410b769113d19892d13cd0ca727631f170a239 /wt-status.c
parentc4f596b98ed305ceb594857fa34524fedc30a031 (diff)
downloadgit-1ecdecce621009a4d039d061d514056501d0ed8f.tar.gz
git-1ecdecce621009a4d039d061d514056501d0ed8f.tar.xz
status: collect per-file data for --porcelain=v2
Collect extra per-file data for porcelain V2 format. The output of `git status --porcelain` leaves out many details about the current status that clients might like to have. This can force them to be less efficient as they may need to launch secondary commands (and try to match the logic within git) to accumulate this extra information. For example, a GUI IDE might want the file mode to display the correct icon for a changed item (without having to stat it afterwards). Signed-off-by: Jeff Hostetler <jeffhost@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'wt-status.c')
-rw-r--r--wt-status.c64
1 files changed, 62 insertions, 2 deletions
diff --git a/wt-status.c b/wt-status.c
index e0dda24ae..dd0a1ab26 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -434,6 +434,31 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
if (S_ISGITLINK(p->two->mode))
d->new_submodule_commits = !!oidcmp(&p->one->oid,
&p->two->oid);
+
+ switch (p->status) {
+ case DIFF_STATUS_ADDED:
+ die("BUG: worktree status add???");
+ break;
+
+ case DIFF_STATUS_DELETED:
+ d->mode_index = p->one->mode;
+ oidcpy(&d->oid_index, &p->one->oid);
+ /* mode_worktree is zero for a delete. */
+ break;
+
+ case DIFF_STATUS_MODIFIED:
+ case DIFF_STATUS_TYPE_CHANGED:
+ case DIFF_STATUS_UNMERGED:
+ d->mode_index = p->one->mode;
+ d->mode_worktree = p->two->mode;
+ oidcpy(&d->oid_index, &p->one->oid);
+ break;
+
+ case DIFF_STATUS_UNKNOWN:
+ die("BUG: worktree status unknown???");
+ break;
+ }
+
}
}
@@ -479,12 +504,36 @@ static void wt_status_collect_updated_cb(struct diff_queue_struct *q,
if (!d->index_status)
d->index_status = p->status;
switch (p->status) {
+ case DIFF_STATUS_ADDED:
+ /* Leave {mode,oid}_head zero for an add. */
+ d->mode_index = p->two->mode;
+ oidcpy(&d->oid_index, &p->two->oid);
+ break;
+ case DIFF_STATUS_DELETED:
+ d->mode_head = p->one->mode;
+ oidcpy(&d->oid_head, &p->one->oid);
+ /* Leave {mode,oid}_index zero for a delete. */
+ break;
+
case DIFF_STATUS_COPIED:
case DIFF_STATUS_RENAMED:
d->head_path = xstrdup(p->one->path);
+ d->score = p->score * 100 / MAX_SCORE;
+ /* fallthru */
+ case DIFF_STATUS_MODIFIED:
+ case DIFF_STATUS_TYPE_CHANGED:
+ d->mode_head = p->one->mode;
+ d->mode_index = p->two->mode;
+ oidcpy(&d->oid_head, &p->one->oid);
+ oidcpy(&d->oid_index, &p->two->oid);
break;
case DIFF_STATUS_UNMERGED:
d->stagemask = unmerged_mask(p->two->path);
+ /*
+ * Don't bother setting {mode,oid}_{head,index} since the print
+ * code will output the stage values directly and not use the
+ * values in these fields.
+ */
break;
}
}
@@ -565,9 +614,17 @@ static void wt_status_collect_changes_initial(struct wt_status *s)
if (ce_stage(ce)) {
d->index_status = DIFF_STATUS_UNMERGED;
d->stagemask |= (1 << (ce_stage(ce) - 1));
- }
- else
+ /*
+ * Don't bother setting {mode,oid}_{head,index} since the print
+ * code will output the stage values directly and not use the
+ * values in these fields.
+ */
+ } else {
d->index_status = DIFF_STATUS_ADDED;
+ /* Leave {mode,oid}_head zero for adds. */
+ d->mode_index = ce->ce_mode;
+ hashcpy(d->oid_index.hash, ce->sha1);
+ }
}
}
@@ -1764,6 +1821,9 @@ void wt_status_print(struct wt_status *s)
case STATUS_FORMAT_PORCELAIN:
wt_porcelain_print(s);
break;
+ case STATUS_FORMAT_PORCELAIN_V2:
+ /* TODO */
+ break;
case STATUS_FORMAT_UNSPECIFIED:
die("BUG: finalize_deferred_config() should have been called");
break;