git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff Hostetler <git@jeffhostetler.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, Johannes.Schindelin@gmx.de,
	Jeff Hostetler <jeffhost@microsoft.com>,
	Jeff Hostetler <git@jeffhostetler.com>
Subject: [PATCH v4 4/8] status: per-file data collection for --porcelain=v2
Date: Tue,  2 Aug 2016 10:12:13 -0400	[thread overview]
Message-ID: <1470147137-17498-5-git-send-email-git@jeffhostetler.com> (raw)
In-Reply-To: <1470147137-17498-1-git-send-email-git@jeffhostetler.com>

From: Jeff Hostetler <jeffhost@microsoft.com>

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: Jeff Hostetler <git@jeffhostetler.com>
---
 builtin/commit.c |  3 +++
 wt-status.c      | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 wt-status.h      |  4 ++++
 3 files changed, 69 insertions(+), 1 deletion(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index c3ae2c3..93ce28c 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -153,6 +153,8 @@ static int opt_parse_porcelain(const struct option *opt, const char *arg, int un
 		*value = STATUS_FORMAT_PORCELAIN;
 	else if (!strcmp(arg, "v1") || !strcmp(arg,"1"))
 		*value = STATUS_FORMAT_PORCELAIN;
+	else if (!strcmp(arg, "v2") || !strcmp(arg, "2"))
+		*value = STATUS_FORMAT_PORCELAIN_V2;
 	else
 		die("unsupported porcelain version '%s'", arg);
 
@@ -1104,6 +1106,7 @@ static struct status_deferred_config {
 static void finalize_deferred_config(struct wt_status *s)
 {
 	int use_deferred_config = (status_format != STATUS_FORMAT_PORCELAIN &&
+				   status_format != STATUS_FORMAT_PORCELAIN_V2 &&
 				   !s->null_termination);
 
 	if (s->null_termination) {
diff --git a/wt-status.c b/wt-status.c
index a9031e4..15d3349 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,18 @@ 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));
+			/*
+			 * 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
+		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 +1822,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;
diff --git a/wt-status.h b/wt-status.h
index a859a12..89a6d43 100644
--- a/wt-status.h
+++ b/wt-status.h
@@ -38,6 +38,9 @@ struct wt_status_change_data {
 	int worktree_status;
 	int index_status;
 	int stagemask;
+	int score;
+	int mode_head, mode_index, mode_worktree;
+	struct object_id oid_head, oid_index;
 	char *head_path;
 	unsigned dirty_submodule       : 2;
 	unsigned new_submodule_commits : 1;
@@ -48,6 +51,7 @@ struct wt_status_change_data {
 	STATUS_FORMAT_LONG,
 	STATUS_FORMAT_SHORT,
 	STATUS_FORMAT_PORCELAIN,
+	STATUS_FORMAT_PORCELAIN_V2,
 
 	STATUS_FORMAT_UNSPECIFIED
  };
-- 
2.8.0.rc4.17.gac42084.dirty


  parent reply	other threads:[~2016-08-02 14:16 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-02 14:12 [PATCH v4 0/8] status: V2 porcelain status Jeff Hostetler
2016-08-02 14:12 ` [PATCH v4 1/8] status: rename long-format print routines Jeff Hostetler
2016-08-03 21:28   ` Junio C Hamano
2016-08-04 12:30     ` Jeff Hostetler
2016-08-02 14:12 ` [PATCH v4 2/8] status: cleanup API to wt_status_print Jeff Hostetler
2016-08-03 21:36   ` Junio C Hamano
2016-08-04 12:35     ` Jeff Hostetler
2016-08-02 14:12 ` [PATCH v4 3/8] status: support --porcelain[=<version>] Jeff Hostetler
2016-08-03 21:37   ` Junio C Hamano
2016-08-02 14:12 ` Jeff Hostetler [this message]
2016-08-02 14:12 ` [PATCH v4 5/8] status: print per-file porcelain v2 status data Jeff Hostetler
2016-08-05 21:02   ` Jeff King
2016-08-05 21:09     ` Junio C Hamano
2016-08-05 21:14       ` Jeff King
2016-08-05 21:21         ` Junio C Hamano
2016-08-05 21:43         ` Stefan Beller
2016-08-05 21:47           ` Stefan Beller
2016-08-05 21:27     ` Jeff Hostetler
2016-08-02 14:12 ` [PATCH v4 6/8] status: print branch info with --porcelain=v2 --branch Jeff Hostetler
2016-08-05 17:01   ` Junio C Hamano
2016-08-05 18:11     ` Jeff Hostetler
2016-08-02 14:12 ` [PATCH v4 7/8] git-status.txt: describe --porcelain=v2 format Jeff Hostetler
2016-08-05 17:50   ` Junio C Hamano
2016-08-05 18:27     ` Jeff Hostetler
2016-08-02 14:12 ` [PATCH v4 8/8] status: tests for --porcelain=v2 Jeff Hostetler
2016-08-05 18:12   ` Junio C Hamano
2016-08-05 18:31     ` Jeff Hostetler
2016-08-03 15:09 ` [PATCH v4 0/8] status: V2 porcelain status Johannes Schindelin
2016-08-03 15:23   ` Junio C Hamano
2016-08-03 16:10     ` Johannes Schindelin
2016-08-03 16:59       ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1470147137-17498-5-git-send-email-git@jeffhostetler.com \
    --to=git@jeffhostetler.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jeffhost@microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).