Git development
 help / color / mirror / Atom feed
* [PATCH] get_tree_entry: map blank requested entry to tree root
@ 2007-01-09 16:11 Jeff King
  2007-01-09 16:15 ` Johannes Schindelin
  2007-01-09 23:48 ` Junio C Hamano
  0 siblings, 2 replies; 7+ messages in thread
From: Jeff King @ 2007-01-09 16:11 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

This means that
  git show HEAD:
will now return HEAD^{tree}, which is logically consistent with
  git show HEAD:Documentation

Signed-off-by: Jeff King <peff@peff.net>
---
 tree-walk.c |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/tree-walk.c b/tree-walk.c
index 22f4550..70f8999 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -199,10 +199,17 @@ int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned ch
 	int retval;
 	void *tree;
 	struct tree_desc t;
+	unsigned char root[20];
 
-	tree = read_object_with_reference(tree_sha1, tree_type, &t.size, NULL);
+	tree = read_object_with_reference(tree_sha1, tree_type, &t.size, root);
 	if (!tree)
 		return -1;
+
+	if (name[0] == '\0') {
+		hashcpy(sha1, root);
+		return 0;
+	}
+
 	t.buf = tree;
 	retval = find_tree_entry(&t, name, sha1, mode);
 	free(tree);
-- 
1.4.4.4.g9612-dirty

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

* Re: [PATCH] get_tree_entry: map blank requested entry to tree root
  2007-01-09 16:11 [PATCH] get_tree_entry: map blank requested entry to tree root Jeff King
@ 2007-01-09 16:15 ` Johannes Schindelin
  2007-01-09 23:48 ` Junio C Hamano
  1 sibling, 0 replies; 7+ messages in thread
From: Johannes Schindelin @ 2007-01-09 16:15 UTC (permalink / raw)
  To: Jeff King; +Cc: Junio C Hamano, git

Hi,

On Tue, 9 Jan 2007, Jeff King wrote:

> This means that
>   git show HEAD:
> will now return HEAD^{tree}, which is logically consistent with
>   git show HEAD:Documentation

Good idea!

Ciao,
Dscho

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

* Re: [PATCH] get_tree_entry: map blank requested entry to tree root
  2007-01-09 16:11 [PATCH] get_tree_entry: map blank requested entry to tree root Jeff King
  2007-01-09 16:15 ` Johannes Schindelin
@ 2007-01-09 23:48 ` Junio C Hamano
  2007-01-10  0:46   ` Jeff King
  1 sibling, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2007-01-09 23:48 UTC (permalink / raw)
  To: Jeff King; +Cc: git

Makes sense, although I somewhat worry about changing the
behaviour and potentially breaking the expectation of callers
of get_tree_entry() other than "git show".

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

* Re: [PATCH] get_tree_entry: map blank requested entry to tree root
  2007-01-09 23:48 ` Junio C Hamano
@ 2007-01-10  0:46   ` Jeff King
  2007-01-10  0:57     ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Jeff King @ 2007-01-10  0:46 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Tue, Jan 09, 2007 at 03:48:33PM -0800, Junio C Hamano wrote:

> Makes sense, although I somewhat worry about changing the
> behaviour and potentially breaking the expectation of callers
> of get_tree_entry() other than "git show".

Previously, trying to get an empty name would always return -1. Most of
the users besides sha1_name are getting the paths by enumerating the
index or an existing tree, so they will never be blank. The exceptions
are:
 - git-blame ''; this fails in both the root and a subdir (though with
   different errors); behavior is unchanged with my patch
 - git-archive feeds the 'prefix' variable to get_tree_entry; it works
   fine in the root with or without the patch. I seem to be getting an
   error, with or without my patch, when doing a git-archive from a
   subdirectory:
     $ git-archive --format=tar origin >/dev/null
     $ cd Documentation
     $ git-archive --format=tar origin >/dev/null
     fatal: cannot read c87c61af00c6d2cd7212240e260809000000aaab
   but I haven't been able to track it down further. It's clearly
   unrelated to my patch, though.

The main difference is that looking up a ref through sha1_name used to
fail to match 'HEAD:'; now it does. So if you were trying to match a
file 'HEAD:' without using '--', you're out of luck.

-Peff

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

* Re: [PATCH] get_tree_entry: map blank requested entry to tree root
  2007-01-10  0:46   ` Jeff King
@ 2007-01-10  0:57     ` Junio C Hamano
  2007-01-10  0:57       ` Jeff King
  0 siblings, 1 reply; 7+ messages in thread
From: Junio C Hamano @ 2007-01-10  0:57 UTC (permalink / raw)
  To: Jeff King; +Cc: git

Jeff King <peff@peff.net> writes:

>  - git-archive feeds the 'prefix' variable to get_tree_entry; it works
>    fine in the root with or without the patch. I seem to be getting an
>    error, with or without my patch, when doing a git-archive from a
>    subdirectory:
>      $ git-archive --format=tar origin >/dev/null
>      $ cd Documentation
>      $ git-archive --format=tar origin >/dev/null
>      fatal: cannot read c87c61af00c6d2cd7212240e260809000000aaab
>    but I haven't been able to track it down further. It's clearly
>    unrelated to my patch, though.

I've noticed this while looking at your patch and fixed it in my
tree already.

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

* Re: [PATCH] get_tree_entry: map blank requested entry to tree root
  2007-01-10  0:57     ` Junio C Hamano
@ 2007-01-10  0:57       ` Jeff King
  2007-01-10  1:04         ` Junio C Hamano
  0 siblings, 1 reply; 7+ messages in thread
From: Jeff King @ 2007-01-10  0:57 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Tue, Jan 09, 2007 at 04:57:11PM -0800, Junio C Hamano wrote:

> I've noticed this while looking at your patch and fixed it in my
> tree already.

Thanks, I will stop looking, then. :)

-Peff

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

* Re: [PATCH] get_tree_entry: map blank requested entry to tree root
  2007-01-10  0:57       ` Jeff King
@ 2007-01-10  1:04         ` Junio C Hamano
  0 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2007-01-10  1:04 UTC (permalink / raw)
  To: Jeff King; +Cc: git

Jeff King <peff@peff.net> writes:

> On Tue, Jan 09, 2007 at 04:57:11PM -0800, Junio C Hamano wrote:
>
>> I've noticed this while looking at your patch and fixed it in my
>> tree already.
>
> Thanks, I will stop looking, then. :)

-- >8 --
[PATCH] builtin-archive: do not free a tree held by the object layer.

Found by running "git archive --format=tar HEAD" in Documentation/
directory.

It's surprising that nobody has noticed this from the beginning...

Signed-off-by: Junio C Hamano <junkio@cox.net>
---
 builtin-archive.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

diff --git a/builtin-archive.c b/builtin-archive.c
index 391cf43..32737d3 100644
--- a/builtin-archive.c
+++ b/builtin-archive.c
@@ -137,7 +137,6 @@ void parse_treeish_arg(const char **argv, struct archiver_args *ar_args,
 		if (err || !S_ISDIR(mode))
 			die("current working directory is untracked");
 
-		free(tree);
 		tree = parse_tree_indirect(tree_sha1);
 	}
 	ar_args->tree = tree;

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

end of thread, other threads:[~2007-01-10  1:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-09 16:11 [PATCH] get_tree_entry: map blank requested entry to tree root Jeff King
2007-01-09 16:15 ` Johannes Schindelin
2007-01-09 23:48 ` Junio C Hamano
2007-01-10  0:46   ` Jeff King
2007-01-10  0:57     ` Junio C Hamano
2007-01-10  0:57       ` Jeff King
2007-01-10  1:04         ` 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