git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] read-tree: abort if no trees are given
@ 2010-09-10 10:06 Jan Krüger
  2010-09-10 11:29 ` Johannes Sixt
  0 siblings, 1 reply; 5+ messages in thread
From: Jan Krüger @ 2010-09-10 10:06 UTC (permalink / raw)
  To: Git ML

Currently, read-tree silently accepts an invocation without any
tree-ishs given and simply clobbers the index in that case. This
contradicts the usage synopsis and it's also probably not what anyone
would want to happen. So, instead, abort with a fatal error.

Signed-off-by: Jan Krüger <jk@jk.gs>
---
Someone in #git got confused by this.

 builtin/read-tree.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 9ad1e66..67eb08e 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -166,6 +166,8 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
 			die("failed to unpack tree object %s", arg);
 		stage++;
 	}
+	if (nr_trees == 0)
+		die("no trees specified to read");
 	if (1 < opts.index_only + opts.update)
 		die("-u and -i at the same time makes no sense");
 	if ((opts.update||opts.index_only) && !opts.merge)
-- 
1.7.2.3.392.g02377.dirty

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

* Re: [PATCH] read-tree: abort if no trees are given
  2010-09-10 10:06 [PATCH] read-tree: abort if no trees are given Jan Krüger
@ 2010-09-10 11:29 ` Johannes Sixt
  2010-09-10 13:28   ` [PATCH] read-tree: deprecate syntax without tree-ish args Jan Krüger
  0 siblings, 1 reply; 5+ messages in thread
From: Johannes Sixt @ 2010-09-10 11:29 UTC (permalink / raw)
  To: Jan Krüger; +Cc: Git ML

Am 9/10/2010 12:06, schrieb Jan Krüger:
> Currently, read-tree silently accepts an invocation without any
> tree-ishs given and simply clobbers the index in that case. This
> contradicts the usage synopsis and it's also probably not what anyone
> would want to happen. So, instead, abort with a fatal error.

See

http://thread.gmane.org/gmane.comp.version-control.git/135280/focus=135407

and the discussion that ensued; perhaps intersting is

http://thread.gmane.org/gmane.comp.version-control.git/135280/focus=135462

(where Junio suggest to make this a warning for now).

-- Hannes

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

* [PATCH] read-tree: deprecate syntax without tree-ish args
  2010-09-10 11:29 ` Johannes Sixt
@ 2010-09-10 13:28   ` Jan Krüger
  2010-09-10 13:53     ` Sverre Rabbelier
  2010-09-10 15:36     ` Junio C Hamano
  0 siblings, 2 replies; 5+ messages in thread
From: Jan Krüger @ 2010-09-10 13:28 UTC (permalink / raw)
  To: Johannes Sixt; +Cc: Git ML, Junio C Hamano, Sverre Rabbelier

Currently, read-tree can be run without tree-ish arguments, in which
case it will empty the index. Since this behavior is undocumented and
perhaps a bit too invasive to be the "default" action for read-tree,
deprecate it in favor of a new --empty option that does the same thing.

Signed-off-by: Jan Krüger <jk@jk.gs>
---
On Fri, 10 Sep 2010 13:29:19 +0200, Johannes Sixt wrote:

> See
> 
> http://thread.gmane.org/gmane.comp.version-control.git/135280/focus=135407
> 
> and the discussion that ensued; perhaps intersting is
> 
> http://thread.gmane.org/gmane.comp.version-control.git/135280/focus=135462
> 
> (where Junio suggest to make this a warning for now).

Thanks for the pointer. I don't really agree that undocumented
behaviour (that has never even been sighted in the wild, no less) needs
to be protected quite this much, but then again I would be much less
visibly responsible for the consequences than Junio, wouldn't I? :)

This patch effectively combines Sverre's and Junio's suggestions from
the old discussion; it deprecates the current behavior with a warning
message and also introduces --empty as a replacement. [Cc'ing both]

The alternative would be to simply match up the documentation with the
way read-tree currently works. I prefer my approach due to the
reasoning in the commit message.

 Documentation/git-read-tree.txt |    6 +++++-
 builtin/read-tree.c             |   10 +++++++++-
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/Documentation/git-read-tree.txt b/Documentation/git-read-tree.txt
index 2e78da4..e88e9c2 100644
--- a/Documentation/git-read-tree.txt
+++ b/Documentation/git-read-tree.txt
@@ -11,7 +11,7 @@ SYNOPSIS
 'git read-tree' [[-m [--trivial] [--aggressive] | --reset | --prefix=<prefix>]
 		[-u [--exclude-per-directory=<gitignore>] | -i]]
 		[--index-output=<file>] [--no-sparse-checkout]
-		<tree-ish1> [<tree-ish2> [<tree-ish3>]]
+		(--empty | <tree-ish1> [<tree-ish2> [<tree-ish3>]])
 
 
 DESCRIPTION
@@ -114,6 +114,10 @@ OPTIONS
 	Disable sparse checkout support even if `core.sparseCheckout`
 	is true.
 
+--empty::
+	Instead of reading tree object(s) into the index, just empty
+	it.
+
 <tree-ish#>::
 	The id of the tree object(s) to be read/merged.
 
diff --git a/builtin/read-tree.c b/builtin/read-tree.c
index 9ad1e66..eb1e3e7 100644
--- a/builtin/read-tree.c
+++ b/builtin/read-tree.c
@@ -16,6 +16,7 @@
 #include "resolve-undo.h"
 
 static int nr_trees;
+static int read_empty;
 static struct tree *trees[MAX_UNPACK_TREES];
 
 static int list_tree(unsigned char *sha1)
@@ -32,7 +33,7 @@ static int list_tree(unsigned char *sha1)
 }
 
 static const char * const read_tree_usage[] = {
-	"git read-tree [[-m [--trivial] [--aggressive] | --reset | --prefix=<prefix>] [-u [--exclude-per-directory=<gitignore>] | -i]] [--no-sparse-checkout] [--index-output=<file>] <tree-ish1> [<tree-ish2> [<tree-ish3>]]",
+	"git read-tree [[-m [--trivial] [--aggressive] | --reset | --prefix=<prefix>] [-u [--exclude-per-directory=<gitignore>] | -i]] [--no-sparse-checkout] [--index-output=<file>] (--empty | <tree-ish1> [<tree-ish2> [<tree-ish3>]])",
 	NULL
 };
 
@@ -106,6 +107,8 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
 		{ OPTION_CALLBACK, 0, "index-output", NULL, "FILE",
 		  "write resulting index to <FILE>",
 		  PARSE_OPT_NONEG, index_output_cb },
+		OPT_SET_INT(0, "empty", &read_empty,
+			    "only empty the index", 1),
 		OPT__VERBOSE(&opts.verbose_update),
 		OPT_GROUP("Merging"),
 		OPT_SET_INT('m', NULL, &opts.merge,
@@ -166,6 +169,11 @@ int cmd_read_tree(int argc, const char **argv, const char *unused_prefix)
 			die("failed to unpack tree object %s", arg);
 		stage++;
 	}
+	if (nr_trees == 0 && !read_empty)
+		warning("read-tree: emptying the index with no arguments is deprecated; use --empty");
+	else if (nr_trees > 0 && read_empty)
+		die("passing trees as arguments contradicts --empty");
+
 	if (1 < opts.index_only + opts.update)
 		die("-u and -i at the same time makes no sense");
 	if ((opts.update||opts.index_only) && !opts.merge)
-- 
1.7.2.3.392.g02377.dirty

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

* Re: [PATCH] read-tree: deprecate syntax without tree-ish args
  2010-09-10 13:28   ` [PATCH] read-tree: deprecate syntax without tree-ish args Jan Krüger
@ 2010-09-10 13:53     ` Sverre Rabbelier
  2010-09-10 15:36     ` Junio C Hamano
  1 sibling, 0 replies; 5+ messages in thread
From: Sverre Rabbelier @ 2010-09-10 13:53 UTC (permalink / raw)
  To: Jan Krüger; +Cc: Johannes Sixt, Git ML, Junio C Hamano

Heya,

On Fri, Sep 10, 2010 at 08:28, Jan Krüger <jk@jk.gs> wrote:
> Currently, read-tree can be run without tree-ish arguments, in which
> case it will empty the index. Since this behavior is undocumented and
> perhaps a bit too invasive to be the "default" action for read-tree,
> deprecate it in favor of a new --empty option that does the same thing.

FWIW, I still like it.

-- 
Cheers,

Sverre Rabbelier

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

* Re: [PATCH] read-tree: deprecate syntax without tree-ish args
  2010-09-10 13:28   ` [PATCH] read-tree: deprecate syntax without tree-ish args Jan Krüger
  2010-09-10 13:53     ` Sverre Rabbelier
@ 2010-09-10 15:36     ` Junio C Hamano
  1 sibling, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2010-09-10 15:36 UTC (permalink / raw)
  To: Jan Krüger; +Cc: Johannes Sixt, Git ML, Sverre Rabbelier

Jan Krüger <jk@jk.gs> writes:

> Currently, read-tree can be run without tree-ish arguments, in which
> case it will empty the index. Since this behavior is undocumented and
> perhaps a bit too invasive to be the "default" action for read-tree,
> deprecate it in favor of a new --empty option that does the same thing.
>
> Signed-off-by: Jan Krüger <jk@jk.gs>

Sounds sensible; will queue.  Thanks.

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

end of thread, other threads:[~2010-09-10 15:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-10 10:06 [PATCH] read-tree: abort if no trees are given Jan Krüger
2010-09-10 11:29 ` Johannes Sixt
2010-09-10 13:28   ` [PATCH] read-tree: deprecate syntax without tree-ish args Jan Krüger
2010-09-10 13:53     ` Sverre Rabbelier
2010-09-10 15:36     ` Junio C Hamano

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 NNTP newsgroup(s).