git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] status: add --long for default format
@ 2012-10-16 16:22 Nguyễn Thái Ngọc Duy
  2012-10-16 17:22 ` Jeff King
  2012-10-18  1:57 ` [PATCH v2 1/2] status: refactor output format to represent "default" Nguyễn Thái Ngọc Duy
  0 siblings, 2 replies; 10+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2012-10-16 16:22 UTC (permalink / raw)
  To: git; +Cc: Nguyễn Thái Ngọc Duy

This could be useful when the user sets an alias to "status --short"
and wants to get back the default format temporarily.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/git-status.txt | 3 +++
 builtin/commit.c             | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/Documentation/git-status.txt b/Documentation/git-status.txt
index 67e5f53..9f1ef9a 100644
--- a/Documentation/git-status.txt
+++ b/Documentation/git-status.txt
@@ -38,6 +38,9 @@ OPTIONS
 	across git versions and regardless of user configuration. See
 	below for details.
 
+--long::
+	Give the output in the long-format. This is the default.
+
 -u[<mode>]::
 --untracked-files[=<mode>]::
 	Show untracked files.
diff --git a/builtin/commit.c b/builtin/commit.c
index a17a5df..5adab33 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1159,6 +1159,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 		OPT_SET_INT(0, "porcelain", &status_format,
 			    N_("machine-readable output"),
 			    STATUS_FORMAT_PORCELAIN),
+		OPT_SET_INT(0, "long", &status_format,
+			    N_("show status in long format (default)"), STATUS_FORMAT_LONG),
 		OPT_BOOLEAN('z', "null", &s.null_termination,
 			    N_("terminate entries with NUL")),
 		{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
-- 
1.8.0.rc2.21.g0695653

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] status: add --long for default format
  2012-10-16 16:22 [PATCH] status: add --long for default format Nguyễn Thái Ngọc Duy
@ 2012-10-16 17:22 ` Jeff King
  2012-10-16 18:32   ` Jeff King
  2012-10-18  1:57 ` [PATCH v2 1/2] status: refactor output format to represent "default" Nguyễn Thái Ngọc Duy
  1 sibling, 1 reply; 10+ messages in thread
From: Jeff King @ 2012-10-16 17:22 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

On Tue, Oct 16, 2012 at 11:22:49PM +0700, Nguyen Thai Ngoc Duy wrote:

> This could be useful when the user sets an alias to "status --short"
> and wants to get back the default format temporarily.

Makes sense, but...

> diff --git a/builtin/commit.c b/builtin/commit.c
> index a17a5df..5adab33 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -1159,6 +1159,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
>  		OPT_SET_INT(0, "porcelain", &status_format,
>  			    N_("machine-readable output"),
>  			    STATUS_FORMAT_PORCELAIN),
> +		OPT_SET_INT(0, "long", &status_format,
> +			    N_("show status in long format (default)"), STATUS_FORMAT_LONG),
>  		OPT_BOOLEAN('z', "null", &s.null_termination,
>  			    N_("terminate entries with NUL")),
>  		{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,

I'm pretty sure we use STATUS_FORMAT_LONG elsewhere as a synonym for
"the user has not set anything".

Ah, here it is:

  $ git grep -nA1 '== STATUS_FORMAT_LONG'
  1073:   if (s->null_termination && status_format == STATUS_FORMAT_LONG)
  1074-           status_format = STATUS_FORMAT_PORCELAIN;
  --
  1201:   if (s.null_termination && status_format == STATUS_FORMAT_LONG)
  1202-           status_format = STATUS_FORMAT_PORCELAIN;

I think you would want something like this. I had originally intended to
make it a refactoring patch that would come before yours, but some of
the cleanups are tied to actually adding --long. So I think you would
want to squash it together with your patch and combine the commit
messages.

-- >8 --
Subject: [PATCH] status: refactor output format to represent "default"

When deciding which output format to use, we default an
internal enum to STATUS_FORMAT_LONG and modify it if
"--porcelain" or "--short" is given. If this enum is set to
LONG, then we know the user has not specified any format,
and we can kick in default behaviors. This works because
there is no "--long" which they could use to explicitly
specify LONG.

Let's expand the enum to have an explicit STATUS_FORMAT_NONE,
in preparation for adding "--long". Then we can distinguish
between LONG and NONE when setting other defaults. There are
two such cases:

  1. The user has asked for NUL termination. With NONE, we
     currently default to turning on the porcelain mode.
     With an explicit --long, we would in theory use NUL
     termination with the long mode, but it does not support
     it. So we can just complain and die.

  2. When an output format is given to "git commit", we
     default to "--dry-run". This behavior would now kick in
     when "--long" is given, too.

Signed-off-by: Jeff King <peff@peff.net>
---
 builtin/commit.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index 00ac35b..ec299f4 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -112,10 +112,11 @@ static enum {
 static struct strbuf message = STRBUF_INIT;
 
 static enum {
+	STATUS_FORMAT_NONE = 0,
 	STATUS_FORMAT_LONG,
 	STATUS_FORMAT_SHORT,
 	STATUS_FORMAT_PORCELAIN
-} status_format = STATUS_FORMAT_LONG;
+} status_format;
 
 static int mention_abandoned_message;
 static void maybe_mention_abandoned_message(void)
@@ -464,6 +465,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
 	case STATUS_FORMAT_PORCELAIN:
 		wt_porcelain_print(s);
 		break;
+	case STATUS_FORMAT_NONE:
 	case STATUS_FORMAT_LONG:
 		wt_status_print(s);
 		break;
@@ -1070,9 +1072,13 @@ static int parse_and_validate_options(int argc, const char *argv[],
 	if (all && argc > 0)
 		die(_("Paths with -a does not make sense."));
 
-	if (s->null_termination && status_format == STATUS_FORMAT_LONG)
-		status_format = STATUS_FORMAT_PORCELAIN;
-	if (status_format != STATUS_FORMAT_LONG)
+	if (s->null_termination) {
+		if (status_format == STATUS_FORMAT_NONE)
+			status_format = STATUS_FORMAT_PORCELAIN;
+		else if (status_format == STATUS_FORMAT_LONG)
+			die("--long and -z are incompatible");
+	}
+	if (status_format != STATUS_FORMAT_NONE)
 		dry_run = 1;
 
 	return argc;
@@ -1198,8 +1204,12 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 			     builtin_status_usage, 0);
 	finalize_colopts(&s.colopts, -1);
 
-	if (s.null_termination && status_format == STATUS_FORMAT_LONG)
-		status_format = STATUS_FORMAT_PORCELAIN;
+	if (s.null_termination) {
+		if (status_format == STATUS_FORMAT_NONE)
+			status_format = STATUS_FORMAT_PORCELAIN;
+		else if (status_format == STATUS_FORMAT_LONG)
+			die("--long and -z are incompatible");
+	}
 
 	handle_untracked_files_arg(&s);
 	if (show_ignored_in_status)
@@ -1228,6 +1238,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 	case STATUS_FORMAT_PORCELAIN:
 		wt_porcelain_print(&s);
 		break;
+	case STATUS_FORMAT_NONE:
 	case STATUS_FORMAT_LONG:
 		s.verbose = verbose;
 		s.ignore_submodule_arg = ignore_submodule_arg;
-- 
1.8.0.rc2.5.gecca26e

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] status: add --long for default format
  2012-10-16 17:22 ` Jeff King
@ 2012-10-16 18:32   ` Jeff King
  0 siblings, 0 replies; 10+ messages in thread
From: Jeff King @ 2012-10-16 18:32 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git

On Tue, Oct 16, 2012 at 01:22:04PM -0400, Jeff King wrote:

>   2. When an output format is given to "git commit", we
>      default to "--dry-run". This behavior would now kick in
>      when "--long" is given, too.

I forgot to mention in my previous message: your patch should probably
add "--long" to git-commit for consistency.

-Peff

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/2] status: refactor output format to represent "default"
  2012-10-16 16:22 [PATCH] status: add --long for default format Nguyễn Thái Ngọc Duy
  2012-10-16 17:22 ` Jeff King
@ 2012-10-18  1:57 ` Nguyễn Thái Ngọc Duy
  2012-10-18  1:58   ` [PATCH v2 2/2] status: add --long for default format Nguyễn Thái Ngọc Duy
  2012-10-18  2:03   ` [PATCH v2 1/2] status: refactor output format to represent "default" Jeff King
  1 sibling, 2 replies; 10+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2012-10-18  1:57 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Jeff King, Nguyễn Thái Ngọc Duy

From: Jeff King <peff@peff.net>

When deciding which output format to use, we default an
internal enum to STATUS_FORMAT_LONG and modify it if
"--porcelain" or "--short" is given. If this enum is set to
LONG, then we know the user has not specified any format,
and we can kick in default behaviors. This works because
there is no "--long" which they could use to explicitly
specify LONG.

Let's expand the enum to have an explicit STATUS_FORMAT_NONE,
in preparation for adding "--long". Then we can distinguish
between LONG and NONE when setting other defaults. There are
two such cases:

  1. The user has asked for NUL termination. With NONE, we
     currently default to turning on the porcelain mode.
     With an explicit --long, we would in theory use NUL
     termination with the long mode, but it does not support
     it. So we can just complain and die.

  2. When an output format is given to "git commit", we
     default to "--dry-run". This behavior would now kick in
     when "--long" is given, too.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Two die()s with --long are moved to the next patch where --long is
 introduced.

 builtin/commit.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/builtin/commit.c b/builtin/commit.c
index a17a5df..984e29c 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -112,10 +112,11 @@ static const char *only_include_assumed;
 static struct strbuf message = STRBUF_INIT;
 
 static enum {
+	STATUS_FORMAT_NONE = 0,
 	STATUS_FORMAT_LONG,
 	STATUS_FORMAT_SHORT,
 	STATUS_FORMAT_PORCELAIN
-} status_format = STATUS_FORMAT_LONG;
+} status_format;
 
 static int opt_parse_m(const struct option *opt, const char *arg, int unset)
 {
@@ -454,6 +455,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
 	case STATUS_FORMAT_PORCELAIN:
 		wt_porcelain_print(s);
 		break;
+	case STATUS_FORMAT_NONE:
 	case STATUS_FORMAT_LONG:
 		wt_status_print(s);
 		break;
@@ -1058,9 +1060,11 @@ static int parse_and_validate_options(int argc, const char *argv[],
 	if (all && argc > 0)
 		die(_("Paths with -a does not make sense."));
 
-	if (s->null_termination && status_format == STATUS_FORMAT_LONG)
-		status_format = STATUS_FORMAT_PORCELAIN;
-	if (status_format != STATUS_FORMAT_LONG)
+	if (s->null_termination) {
+		if (status_format == STATUS_FORMAT_NONE)
+			status_format = STATUS_FORMAT_PORCELAIN;
+	}
+	if (status_format != STATUS_FORMAT_NONE)
 		dry_run = 1;
 
 	return argc;
@@ -1186,8 +1190,10 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 			     builtin_status_usage, 0);
 	finalize_colopts(&s.colopts, -1);
 
-	if (s.null_termination && status_format == STATUS_FORMAT_LONG)
-		status_format = STATUS_FORMAT_PORCELAIN;
+	if (s.null_termination) {
+		if (status_format == STATUS_FORMAT_NONE)
+			status_format = STATUS_FORMAT_PORCELAIN;
+	}
 
 	handle_untracked_files_arg(&s);
 	if (show_ignored_in_status)
@@ -1216,6 +1222,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 	case STATUS_FORMAT_PORCELAIN:
 		wt_porcelain_print(&s);
 		break;
+	case STATUS_FORMAT_NONE:
 	case STATUS_FORMAT_LONG:
 		s.verbose = verbose;
 		s.ignore_submodule_arg = ignore_submodule_arg;
-- 
1.8.0.rc2.32.g1729c8c

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 2/2] status: add --long for default format
  2012-10-18  1:57 ` [PATCH v2 1/2] status: refactor output format to represent "default" Nguyễn Thái Ngọc Duy
@ 2012-10-18  1:58   ` Nguyễn Thái Ngọc Duy
  2012-10-18  2:03   ` [PATCH v2 1/2] status: refactor output format to represent "default" Jeff King
  1 sibling, 0 replies; 10+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2012-10-18  1:58 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Jeff King, Nguyễn Thái Ngọc Duy

This could be useful when the user sets an alias to "status --short"
and wants to get the default format back temporarily.

git-commit also learns --long mostly for consistency as there's little
chance that someone adds an alias for "git commit --short" then wants
a one shot --long output.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/git-commit.txt |  4 ++++
 Documentation/git-status.txt |  3 +++
 builtin/commit.c             | 10 ++++++++++
 3 files changed, 17 insertions(+)

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 9594ac8..3acf2e7 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -109,6 +109,10 @@ OPTIONS
 	format. See linkgit:git-status[1] for details. Implies
 	`--dry-run`.
 
+--long::
+	When doing a dry-run, give the output in a the long-format.
+	Implies `--dry-run`.
+
 -z::
 --null::
 	When showing `short` or `porcelain` status output, terminate
diff --git a/Documentation/git-status.txt b/Documentation/git-status.txt
index 67e5f53..9f1ef9a 100644
--- a/Documentation/git-status.txt
+++ b/Documentation/git-status.txt
@@ -38,6 +38,9 @@ OPTIONS
 	across git versions and regardless of user configuration. See
 	below for details.
 
+--long::
+	Give the output in the long-format. This is the default.
+
 -u[<mode>]::
 --untracked-files[=<mode>]::
 	Show untracked files.
diff --git a/builtin/commit.c b/builtin/commit.c
index 984e29c..1dd2ec5 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -1063,6 +1063,8 @@ static int parse_and_validate_options(int argc, const char *argv[],
 	if (s->null_termination) {
 		if (status_format == STATUS_FORMAT_NONE)
 			status_format = STATUS_FORMAT_PORCELAIN;
+		else if (status_format == STATUS_FORMAT_LONG)
+			die(_("--long and -z are incompatible"));
 	}
 	if (status_format != STATUS_FORMAT_NONE)
 		dry_run = 1;
@@ -1163,6 +1165,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 		OPT_SET_INT(0, "porcelain", &status_format,
 			    N_("machine-readable output"),
 			    STATUS_FORMAT_PORCELAIN),
+		OPT_SET_INT(0, "long", &status_format,
+			    N_("show status in long format (default)"),
+			    STATUS_FORMAT_LONG),
 		OPT_BOOLEAN('z', "null", &s.null_termination,
 			    N_("terminate entries with NUL")),
 		{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
@@ -1193,6 +1198,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 	if (s.null_termination) {
 		if (status_format == STATUS_FORMAT_NONE)
 			status_format = STATUS_FORMAT_PORCELAIN;
+		else if (status_format == STATUS_FORMAT_LONG)
+			die(_("--long and -z are incompatible"));
 	}
 
 	handle_untracked_files_arg(&s);
@@ -1393,6 +1400,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		OPT_BOOLEAN(0, "branch", &s.show_branch, N_("show branch information")),
 		OPT_SET_INT(0, "porcelain", &status_format,
 			    N_("machine-readable output"), STATUS_FORMAT_PORCELAIN),
+		OPT_SET_INT(0, "long", &status_format,
+			    N_("show status in long format (default)"),
+			    STATUS_FORMAT_LONG),
 		OPT_BOOLEAN('z', "null", &s.null_termination,
 			    N_("terminate entries with NUL")),
 		OPT_BOOLEAN(0, "amend", &amend, N_("amend previous commit")),
-- 
1.8.0.rc2.32.g1729c8c

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 1/2] status: refactor output format to represent "default"
  2012-10-18  1:57 ` [PATCH v2 1/2] status: refactor output format to represent "default" Nguyễn Thái Ngọc Duy
  2012-10-18  1:58   ` [PATCH v2 2/2] status: add --long for default format Nguyễn Thái Ngọc Duy
@ 2012-10-18  2:03   ` Jeff King
  2012-10-18 14:15     ` [PATCH v3] status: refactor output format to represent "default" and add --long Nguyễn Thái Ngọc Duy
  1 sibling, 1 reply; 10+ messages in thread
From: Jeff King @ 2012-10-18  2:03 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git, Junio C Hamano

On Thu, Oct 18, 2012 at 08:57:59AM +0700, Nguyen Thai Ngoc Duy wrote:

> From: Jeff King <peff@peff.net>
> 
> When deciding which output format to use, we default an
> internal enum to STATUS_FORMAT_LONG and modify it if
> "--porcelain" or "--short" is given. If this enum is set to
> LONG, then we know the user has not specified any format,
> and we can kick in default behaviors. This works because
> there is no "--long" which they could use to explicitly
> specify LONG.
> 
> Let's expand the enum to have an explicit STATUS_FORMAT_NONE,
> in preparation for adding "--long". Then we can distinguish
> between LONG and NONE when setting other defaults. There are
> two such cases:
> 
>   1. The user has asked for NUL termination. With NONE, we
>      currently default to turning on the porcelain mode.
>      With an explicit --long, we would in theory use NUL
>      termination with the long mode, but it does not support
>      it. So we can just complain and die.
> 
>   2. When an output format is given to "git commit", we
>      default to "--dry-run". This behavior would now kick in
>      when "--long" is given, too.
> 
> Signed-off-by: Jeff King <peff@peff.net>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  Two die()s with --long are moved to the next patch where --long is
>  introduced.

I think that is fine to split it like this, but you would want to update
the commit message above. Probably just remove those two cases and say
something like:

  Note that you cannot actually trigger STATUS_FORMAT_LONG, as we do
  not yet have "--long"; that will come in a follow-on patch.

And then move the reasoning for how "--long" works with each case into
the commit message of the next patch.

Other than that, the patches look OK to me.

-Peff

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v3] status: refactor output format to represent "default" and add --long
  2012-10-18  2:03   ` [PATCH v2 1/2] status: refactor output format to represent "default" Jeff King
@ 2012-10-18 14:15     ` Nguyễn Thái Ngọc Duy
  2012-10-18 20:26       ` Jeff King
  2012-10-18 21:16       ` Junio C Hamano
  0 siblings, 2 replies; 10+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2012-10-18 14:15 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Jeff King, Nguyễn Thái Ngọc Duy

From: Jeff King <peff@peff.net>

When deciding which output format to use, we default an internal enum
to STATUS_FORMAT_LONG and modify it if "--porcelain" or "--short" is
given. If this enum is set to LONG, then we know the user has not
specified any format, and we can kick in default behaviors. This works
because there is no "--long" which they could use to explicitly
specify LONG.

Let's expand the enum to have an explicit STATUS_FORMAT_NONE, in
preparation for adding "--long", which can be used to override --short
or --porcelain. Then we can distinguish between LONG and NONE when
setting other defaults. There are two such cases:

  1. The user has asked for NUL termination. With NONE, we
     currently default to turning on the porcelain mode.
     With an explicit --long, we would in theory use NUL
     termination with the long mode, but it does not support
     it. So we can just complain and die.

  2. When an output format is given to "git commit", we
     default to "--dry-run". This behavior would now kick in
     when "--long" is given, too.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 On Thu, Oct 18, 2012 at 9:03 AM, Jeff King <peff@peff.net> wrote:
 > I think that is fine to split it like this, but you would want to update
 > the commit message above. Probably just remove those two cases and say
 > something like:
 >
 >   Note that you cannot actually trigger STATUS_FORMAT_LONG, as we do
 >   not yet have "--long"; that will come in a follow-on patch.
 >
 > And then move the reasoning for how "--long" works with each case into
 > the commit message of the next patch.

 Nope, it's hard to split the explanation in two (at least to me),
 which may mean that the split does not make sense.

 Documentation/git-commit.txt |  4 ++++
 Documentation/git-status.txt |  3 +++
 builtin/commit.c             | 29 +++++++++++++++++++++++------
 3 files changed, 30 insertions(+), 6 deletions(-)

diff --git a/Documentation/git-commit.txt b/Documentation/git-commit.txt
index 9594ac8..3acf2e7 100644
--- a/Documentation/git-commit.txt
+++ b/Documentation/git-commit.txt
@@ -109,6 +109,10 @@ OPTIONS
 	format. See linkgit:git-status[1] for details. Implies
 	`--dry-run`.
 
+--long::
+	When doing a dry-run, give the output in a the long-format.
+	Implies `--dry-run`.
+
 -z::
 --null::
 	When showing `short` or `porcelain` status output, terminate
diff --git a/Documentation/git-status.txt b/Documentation/git-status.txt
index 67e5f53..9f1ef9a 100644
--- a/Documentation/git-status.txt
+++ b/Documentation/git-status.txt
@@ -38,6 +38,9 @@ OPTIONS
 	across git versions and regardless of user configuration. See
 	below for details.
 
+--long::
+	Give the output in the long-format. This is the default.
+
 -u[<mode>]::
 --untracked-files[=<mode>]::
 	Show untracked files.
diff --git a/builtin/commit.c b/builtin/commit.c
index a17a5df..1dd2ec5 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -112,10 +112,11 @@ static const char *only_include_assumed;
 static struct strbuf message = STRBUF_INIT;
 
 static enum {
+	STATUS_FORMAT_NONE = 0,
 	STATUS_FORMAT_LONG,
 	STATUS_FORMAT_SHORT,
 	STATUS_FORMAT_PORCELAIN
-} status_format = STATUS_FORMAT_LONG;
+} status_format;
 
 static int opt_parse_m(const struct option *opt, const char *arg, int unset)
 {
@@ -454,6 +455,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
 	case STATUS_FORMAT_PORCELAIN:
 		wt_porcelain_print(s);
 		break;
+	case STATUS_FORMAT_NONE:
 	case STATUS_FORMAT_LONG:
 		wt_status_print(s);
 		break;
@@ -1058,9 +1060,13 @@ static int parse_and_validate_options(int argc, const char *argv[],
 	if (all && argc > 0)
 		die(_("Paths with -a does not make sense."));
 
-	if (s->null_termination && status_format == STATUS_FORMAT_LONG)
-		status_format = STATUS_FORMAT_PORCELAIN;
-	if (status_format != STATUS_FORMAT_LONG)
+	if (s->null_termination) {
+		if (status_format == STATUS_FORMAT_NONE)
+			status_format = STATUS_FORMAT_PORCELAIN;
+		else if (status_format == STATUS_FORMAT_LONG)
+			die(_("--long and -z are incompatible"));
+	}
+	if (status_format != STATUS_FORMAT_NONE)
 		dry_run = 1;
 
 	return argc;
@@ -1159,6 +1165,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 		OPT_SET_INT(0, "porcelain", &status_format,
 			    N_("machine-readable output"),
 			    STATUS_FORMAT_PORCELAIN),
+		OPT_SET_INT(0, "long", &status_format,
+			    N_("show status in long format (default)"),
+			    STATUS_FORMAT_LONG),
 		OPT_BOOLEAN('z', "null", &s.null_termination,
 			    N_("terminate entries with NUL")),
 		{ OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
@@ -1186,8 +1195,12 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 			     builtin_status_usage, 0);
 	finalize_colopts(&s.colopts, -1);
 
-	if (s.null_termination && status_format == STATUS_FORMAT_LONG)
-		status_format = STATUS_FORMAT_PORCELAIN;
+	if (s.null_termination) {
+		if (status_format == STATUS_FORMAT_NONE)
+			status_format = STATUS_FORMAT_PORCELAIN;
+		else if (status_format == STATUS_FORMAT_LONG)
+			die(_("--long and -z are incompatible"));
+	}
 
 	handle_untracked_files_arg(&s);
 	if (show_ignored_in_status)
@@ -1216,6 +1229,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
 	case STATUS_FORMAT_PORCELAIN:
 		wt_porcelain_print(&s);
 		break;
+	case STATUS_FORMAT_NONE:
 	case STATUS_FORMAT_LONG:
 		s.verbose = verbose;
 		s.ignore_submodule_arg = ignore_submodule_arg;
@@ -1386,6 +1400,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
 		OPT_BOOLEAN(0, "branch", &s.show_branch, N_("show branch information")),
 		OPT_SET_INT(0, "porcelain", &status_format,
 			    N_("machine-readable output"), STATUS_FORMAT_PORCELAIN),
+		OPT_SET_INT(0, "long", &status_format,
+			    N_("show status in long format (default)"),
+			    STATUS_FORMAT_LONG),
 		OPT_BOOLEAN('z', "null", &s.null_termination,
 			    N_("terminate entries with NUL")),
 		OPT_BOOLEAN(0, "amend", &amend, N_("amend previous commit")),
-- 
1.8.0.rc2.22.gad9383a

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v3] status: refactor output format to represent "default" and add --long
  2012-10-18 14:15     ` [PATCH v3] status: refactor output format to represent "default" and add --long Nguyễn Thái Ngọc Duy
@ 2012-10-18 20:26       ` Jeff King
  2012-10-18 21:16       ` Junio C Hamano
  1 sibling, 0 replies; 10+ messages in thread
From: Jeff King @ 2012-10-18 20:26 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git, Junio C Hamano

On Thu, Oct 18, 2012 at 09:15:50PM +0700, Nguyen Thai Ngoc Duy wrote:

>  On Thu, Oct 18, 2012 at 9:03 AM, Jeff King <peff@peff.net> wrote:
>  > I think that is fine to split it like this, but you would want to update
>  > the commit message above. Probably just remove those two cases and say
>  > something like:
>  >
>  >   Note that you cannot actually trigger STATUS_FORMAT_LONG, as we do
>  >   not yet have "--long"; that will come in a follow-on patch.
>  >
>  > And then move the reasoning for how "--long" works with each case into
>  > the commit message of the next patch.
> 
>  Nope, it's hard to split the explanation in two (at least to me),
>  which may mean that the split does not make sense.

Yeah, that was the same place that I had difficulty when writing the
original. This version looks OK to me.

-Peff

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3] status: refactor output format to represent "default" and add --long
  2012-10-18 14:15     ` [PATCH v3] status: refactor output format to represent "default" and add --long Nguyễn Thái Ngọc Duy
  2012-10-18 20:26       ` Jeff King
@ 2012-10-18 21:16       ` Junio C Hamano
  2012-10-18 21:20         ` Jeff King
  1 sibling, 1 reply; 10+ messages in thread
From: Junio C Hamano @ 2012-10-18 21:16 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git, Jeff King

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> From: Jeff King <peff@peff.net>
>
> When deciding which output format to use, we default an internal enum
> to STATUS_FORMAT_LONG and modify it if "--porcelain" or "--short" is
> given. If this enum is set to LONG, then we know the user has not
> specified any format, and we can kick in default behaviors. This works
> because there is no "--long" which they could use to explicitly
> specify LONG.
>
> Let's expand the enum to have an explicit STATUS_FORMAT_NONE, in
> preparation for adding "--long", which can be used to override --short
> or --porcelain. Then we can distinguish between LONG and NONE when
> setting other defaults. There are two such cases:
>
>   1. The user has asked for NUL termination. With NONE, we
>      currently default to turning on the porcelain mode.
>      With an explicit --long, we would in theory use NUL
>      termination with the long mode, but it does not support
>      it. So we can just complain and die.
>
>   2. When an output format is given to "git commit", we
>      default to "--dry-run". This behavior would now kick in
>      when "--long" is given, too.
>
> Signed-off-by: Jeff King <peff@peff.net>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
>  On Thu, Oct 18, 2012 at 9:03 AM, Jeff King <peff@peff.net> wrote:
>  > I think that is fine to split it like this, but you would want to update
>  > the commit message above. Probably just remove those two cases and say
>  > something like:
>  >
>  >   Note that you cannot actually trigger STATUS_FORMAT_LONG, as we do
>  >   not yet have "--long"; that will come in a follow-on patch.
>  >
>  > And then move the reasoning for how "--long" works with each case into
>  > the commit message of the next patch.
>
>  Nope, it's hard to split the explanation in two (at least to me),
>  which may mean that the split does not make sense.

I guess combining both is fine, but then the commit is no longer "in
preparation for adding" the option, but it already adds "--long", I
would think.

Will queue.

Thanks.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v3] status: refactor output format to represent "default" and add --long
  2012-10-18 21:16       ` Junio C Hamano
@ 2012-10-18 21:20         ` Jeff King
  0 siblings, 0 replies; 10+ messages in thread
From: Jeff King @ 2012-10-18 21:20 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Nguyễn Thái Ngọc Duy, git

On Thu, Oct 18, 2012 at 02:16:11PM -0700, Junio C Hamano wrote:

> I guess combining both is fine, but then the commit is no longer "in
> preparation for adding" the option, but it already adds "--long", I
> would think.

Maybe a better commit message is:

-- >8 --
Subject: status: add --long output format option

You can currently set the output format to --short or
--porcelain. There is no --long, because we default to it
already. However, you may want to override an alias that
uses "--short" to get back to the default.

This requires a little bit of refactoring, because currently
we use STATUS_FORMAT_LONG internally to mean the same as
"the user did not specify anything". By expanding the enum
to include STATUS_FORMAT_NONE, we can distinguish between
the implicit and explicit cases. This effects these
conditions:

  1. The user has asked for NUL termination. With NONE, we
     currently default to turning on the porcelain mode.
     With an explicit --long, we would in theory use NUL
     termination with the long mode, but it does not support
     it. So we can just complain and die.

  2. When an output format is given to "git commit", we
     default to "--dry-run". This behavior would now kick in
     when "--long" is given, too.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2012-10-18 21:21 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-16 16:22 [PATCH] status: add --long for default format Nguyễn Thái Ngọc Duy
2012-10-16 17:22 ` Jeff King
2012-10-16 18:32   ` Jeff King
2012-10-18  1:57 ` [PATCH v2 1/2] status: refactor output format to represent "default" Nguyễn Thái Ngọc Duy
2012-10-18  1:58   ` [PATCH v2 2/2] status: add --long for default format Nguyễn Thái Ngọc Duy
2012-10-18  2:03   ` [PATCH v2 1/2] status: refactor output format to represent "default" Jeff King
2012-10-18 14:15     ` [PATCH v3] status: refactor output format to represent "default" and add --long Nguyễn Thái Ngọc Duy
2012-10-18 20:26       ` Jeff King
2012-10-18 21:16       ` Junio C Hamano
2012-10-18 21:20         ` Jeff King

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).