git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Julian Phillips <julian@quantumfyre.co.uk>
To: Julian Phillips <julian@quantumfyre.co.uk>
Cc: Eric Raymond <esr@snark.thyrsus.com>,
	Junio C Hamano <gitster@pobox.com>, <git@vger.kernel.org>
Subject: [RFC/PATCH] status: Add a new NUL separated output format
Date: Sat, 10 Apr 2010 20:25:28 +0100	[thread overview]
Message-ID: <20100410192529.23731.79803.julian@quantumfyre.co.uk> (raw)
In-Reply-To: <9c7e1f33b7ec0dab68a92aa8f067989e@212.159.54.234>

Add a new output format option to git-status that is a more extreme
form of the -z output that places a NUL between all parts of the
record, and always has three entries per record, even when only two
are relevant.  This make the parsing of --porcelain output much
simpler for the consumer.

Signed-off-by: Julian Phillips <julian@quantumfyre.co.uk>
---

On Sat, 10 Apr 2010, Julian Phillips wrote:

> Not true.  If the second form was used, then you _can_ split on \0.  It
> will tokenise the data for you, and then you consume ether two or three
> tokens depending on the status flags.  So it would make the parsing
> simpler.  But to make it even easier, how about adding a -Z that makes the
> output format "XY\0file1\0[file2]\0" (i.e. always three tokens per record,
> with the third token being empty if there is no second filename)?  Though
> if future expandability was wanted you could end each record with \0\0 and
> then parsing would be a two stages of split on \0\0 for records and then
> split on \0 for entries?  The is already precedence for the -z option to
> change the output format, so a second similar switch should be ok?  Then
> the updated documentation could recommend --porcelain -Z for new users
> without affecting old ones.

Something like this for the first variant (fixed three entries per record)
perhaps ... (though a proper patch would probably want some tests too)

 builtin/commit.c |    6 ++++--
 wt-status.c      |   19 ++++++++++++++-----
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index c5ab683..acbcefc 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1025,8 +1025,10 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 		OPT_SET_INT(0, "porcelain", &status_format,
 			    "show porcelain output format",
 			    STATUS_FORMAT_PORCELAIN),
-		OPT_BOOLEAN('z', "null", &null_termination,
-			    "terminate entries with NUL"),
+		OPT_SET_INT('z', "null", &null_termination,
+			    "terminate entries with NUL", 1),
+		OPT_SET_INT('Z', "intense-null", &null_termination,
+			    "use NUL for all seperators, including absent values", 2),
 		{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
 		  "mode",
 		  "show untracked files, optional modes: all, normal, no. (Default: all)",
diff --git a/wt-status.c b/wt-status.c
index 8ca59a2..9f23ec6 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -663,7 +663,9 @@ static void wt_shortstatus_unmerged(int null_termination, struct string_list_ite
 	case 7: how = "UU"; break; /* both modified */
 	}
 	color_fprintf(s->fp, color(WT_STATUS_UNMERGED, s), "%s", how);
-	if (null_termination) {
+	if (null_termination == 2) {
+		fprintf(stdout, "%c%s%c%c", 0, it->string, 0, 0);
+	} else if (null_termination) {
 		fprintf(stdout, " %s%c", it->string, 0);
 	} else {
 		struct strbuf onebuf = STRBUF_INIT;
@@ -687,14 +689,19 @@ static void wt_shortstatus_status(int null_termination, struct string_list_item
 		color_fprintf(s->fp, color(WT_STATUS_CHANGED, s), "%c", d->worktree_status);
 	else
 		putchar(' ');
-	putchar(' ');
-	if (null_termination) {
-		fprintf(stdout, "%s%c", it->string, 0);
+	if (null_termination == 2) {
+		char *file2 = "";
+		if (d->head_path)
+			file2 = d->head_path;
+		fprintf(stdout, "%c%s%c%s%c", 0, it->string, 0, file2, 0);
+	} else if (null_termination) {
+		fprintf(stdout, " %s%c", it->string, 0);
 		if (d->head_path)
 			fprintf(stdout, "%s%c", d->head_path, 0);
 	} else {
 		struct strbuf onebuf = STRBUF_INIT;
 		const char *one;
+		putchar(' ');
 		if (d->head_path) {
 			one = quote_path(d->head_path, -1, &onebuf, s->prefix);
 			printf("%s -> ", one);
@@ -709,7 +716,9 @@ static void wt_shortstatus_status(int null_termination, struct string_list_item
 static void wt_shortstatus_untracked(int null_termination, struct string_list_item *it,
 			    struct wt_status *s)
 {
-	if (null_termination) {
+	if (null_termination == 2) {
+		fprintf(stdout, "??%c%s%c%c", 0, it->string, 0, 0);
+	} else if (null_termination) {
 		fprintf(stdout, "?? %s%c", it->string, 0);
 	} else {
 		struct strbuf onebuf = STRBUF_INIT;
-- 
1.7.0.4

  parent reply	other threads:[~2010-04-10 19:31 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-09 18:46 git status --porcelain is a mess that needs fixing Eric Raymond
2010-04-09 20:30 ` Junio C Hamano
2010-04-10  4:09 ` Jeff King
2010-04-10  5:46   ` Jonathan Nieder
2010-04-10  5:51     ` Jonathan Nieder
2010-04-10  6:03       ` Jeff King
2010-04-10  6:12         ` Jonathan Nieder
2010-04-10  6:32           ` Jeff King
2010-04-10  5:59   ` Eric Raymond
2010-04-10  7:40   ` [PATCH 0/5] "status --ignored" Junio C Hamano
2010-04-10  7:40     ` [PATCH 1/5] wt-status: remove unused workdir_untracked field Junio C Hamano
2010-04-10  7:40     ` [PATCH 2/5] wt-status: plug memory leak while collecting untracked files Junio C Hamano
2010-04-10  7:40     ` [PATCH 3/5] wt-status: collect ignored files Junio C Hamano
2010-04-10  7:48       ` Jeff King
2010-04-10  7:40     ` [PATCH 4/5] wt-status: rename and restructure status-print-untracked Junio C Hamano
2010-04-10  7:40     ` [PATCH 5/5] status: --ignored option shows ignored files Junio C Hamano
2010-04-10  7:44     ` [PATCH 0/5] "status --ignored" Jeff King
2010-04-10  7:48       ` Junio C Hamano
2010-04-10  8:40         ` Jeff King
2010-04-10 14:41           ` Eric Raymond
2010-04-10 18:27           ` Junio C Hamano
2010-04-10 19:20             ` Jakub Narebski
2010-04-11 10:35             ` Jeff King
2010-04-10 13:35   ` git status --porcelain is a mess that needs fixing Julian Phillips
2010-04-10 14:43     ` Eric Raymond
2010-04-10 14:56     ` Jon Seymour
2010-04-10 15:50       ` Julian Phillips
2010-04-10 23:33         ` Jon Seymour
2010-04-10 19:25     ` Julian Phillips [this message]
2010-04-10 19:50       ` [RFC/PATCH] status: Add a new NUL separated output format Eric Raymond
2010-04-10 20:34         ` Julian Phillips
2010-04-10 21:12           ` Eric Raymond
2010-04-10 23:03             ` [RFC/PATCH] status: Add json " Julian Phillips

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=20100410192529.23731.79803.julian@quantumfyre.co.uk \
    --to=julian@quantumfyre.co.uk \
    --cc=esr@snark.thyrsus.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).