git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 2/2] Teach name-rev to identify revisions containing a certain blob

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 17, 2007, 23:52 UTC
Message-ID
<Pine.LNX.4.63.0702180049210.22628@wbgn013.biozentrum.uni-wuerzburg.de>
In-Reply-To
<7vr6sotzft.fsf@assigned-by-dhcp.cox.net>
Hi,
On Sat, 17 Feb 2007, Junio C Hamano wrote:
Show 15 quoted lines
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > If you want to know which revisions contained a certain version
> > of a file, just say
> >
> > 	git name-rev --file <filename>
> >
> > which will read the file, and give you a list of revisions
> > containing a file with the same contents. If <filename> is "-",
> > it will read the contents from stdin. Of course, this is a really
> > expensive operation.
> 
> I expected this to take arbitrary object name and let the caller
> to do 'hash-object', so that you could also find a certain tree,
> not just blob.
That was easier than I feared. Here's a patch on top of 2/2:

-- [PATCH] name-rev --file: also accept SHA1 of blobs and trees

This allows you to say
	git name-rev --file master:t/

to see in which revisions the whole directory "t" is identical to what it is in "master".

The first hunk is a bugfix for a potential segv.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin-name-rev.c |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
diff --git a/builtin-name-rev.c b/builtin-name-rev.c
index f08b065..e4addc7 100644
--- a/builtin-name-rev.c
+++ b/builtin-name-rev.c
@@ -43,7 +43,7 @@ struct object_name {
 static struct object_name *name_file(struct tree *tree)
 {
 	static struct object_name null_name = { 0, NULL };
-	struct object_name *name;
+	struct object_name *name = NULL;
 	struct tree_desc desc;
 	struct name_entry entry;
 
@@ -141,7 +141,8 @@ copy_data:
 		return;
 
 	if (file_sha1 && !(commit->object.flags & CONTAINS_FILE) &&
-			(file_name = name_file(commit->tree))) {
+			((file_name = name_file(commit->tree)) ||
+			 !hashcmp(commit->tree->object.sha1, file_sha1))) {
 		commit->object.flags |= CONTAINS_FILE;
 		add_object_array(&commit->object, NULL, &file_commits);
 	}
@@ -270,7 +271,8 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
 			} else if (!strcmp(*argv, "--file")) {
 				if (argc != 2)
 					usage(name_rev_usage);
-				if (get_file(argv[1]))
+				if (get_file(argv[1]) &&
+						get_sha1(argv[1], file_sha1))
 					die("Could not read '%s'", argv[1]);
 				cutoff = 0;
 				argc = 1;
@@ -313,7 +315,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
 			printf("%s", rev_name->tip_name);
 			if (rev_name->generation)
 				printf("^%d", rev_name->generation);
-			printf(":%s\n", obj_name->name);
+			printf(":%s\n", obj_name ? obj_name->name : "");
 		}
 		return 0;
 	}
-- 
1.5.0.2139.gdafc9-dirty
Previous: Junio C HamanoNext: Johannes Schindelin
Message 3 of 9 in “Teach name-rev to identify revisions containing a certain blob”
  1. 2/2 Teach name-rev to identify revisions containing a certain blobJohannes Schindelin, Feb 17, 2007
  2. Junio C HamanoFeb 17, 2007
  3. Johannes SchindelinFeb 17, 2007
  4. Johannes SchindelinFeb 18, 2007
  5. Junio C HamanoFeb 17, 2007
  6. Johannes SchindelinFeb 17, 2007
  7. Junio C HamanoFeb 18, 2007
  8. Junio C HamanoFeb 18, 2007
  9. Johannes SchindelinFeb 18, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.