From 4262c1b0c38613a8c5ae729bd4d3f18f0df3ec44 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 18 Apr 2006 20:31:41 -0700 Subject: [PATCH 1/2] Fix uninteresting tags in new revision parsing When I unified the revision argument parsing, I introduced a simple bug wrt tags that had been marked uninteresting. When it was preparing for the revision walk, it would mark all the parent commits of an uninteresting tag correctly uninteresting, but it would forget about the commit itself. This means that when I just did my 2.6.17-rc2 release, and my scripts generated the log for "v2.6.17-rc1..v2.6.17-rc2", everything was fine, except the commit pointed to by 2.6.17-rc1 (which shouldn't have been there) was included. Even though it should obviously have been marked as being uninteresting. Not a huge deal, and the fix is trivial. Signed-off-by: Linus Torvalds Signed-off-by: Junio C Hamano --- revision.c | 1 + 1 file changed, 1 insertion(+) diff --git a/revision.c b/revision.c index dbd54da5ba..113dd5a89f 100644 --- a/revision.c +++ b/revision.c @@ -152,6 +152,7 @@ static struct commit *handle_commit(struct rev_info *revs, struct object *object if (parse_commit(commit) < 0) die("unable to parse commit %s", name); if (flags & UNINTERESTING) { + commit->object.flags |= UNINTERESTING; mark_parents_uninteresting(commit); revs->limited = 1; } From 5119602a99f46aaa7b3bb2a0f5085b1df46b54ec Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Tue, 18 Apr 2006 16:45:16 -0700 Subject: [PATCH 2/2] get_sha1() shorthands for blob/tree objects This is a fairly straightforward patch to allow "get_sha1()" to also have shorthands for tree and blob objects. The syntax is very simple and intuitive: you can specify a tree or a blob by simply specifying :, and get_sha1() will do the SHA1 lookup from the tree for you. You can currently do it with "git ls-tree " and parsing the output, but that's actually pretty awkward. With this, you can do something like git cat-file blob v1.2.4:Makefile to get the contents of "Makefile" at revision v1.2.4. Now, this isn't necessarily something you really need all that often, but the concept itself is actually pretty powerful. We could, for example, allow things like git diff v0.99.6:git-commit-script..v1.3.0:git-commit.sh to see the difference between two arbitrary files in two arbitrary revisions. To do that, the only thing we'd have to do is to make git-diff-tree accept two blobs to diff, in addition to the two trees it now expects. Signed-off-by: Junio C Hamano --- sha1_name.c | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 1 deletion(-) diff --git a/sha1_name.c b/sha1_name.c index 4f92e12a8d..0cd1139e06 100644 --- a/sha1_name.c +++ b/sha1_name.c @@ -3,6 +3,7 @@ #include "commit.h" #include "tree.h" #include "blob.h" +#include "diff.h" static int find_short_object_filename(int len, const char *name, unsigned char *sha1) { @@ -449,12 +450,76 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1) return get_short_sha1(name, len, sha1, 0); } +static int get_tree_entry(const unsigned char *, const char *, unsigned char *); + +static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char *result) +{ + int namelen = strlen(name); + while (t->size) { + const char *entry; + const unsigned char *sha1; + int entrylen, cmp; + unsigned mode; + + sha1 = tree_entry_extract(t, &entry, &mode); + update_tree_entry(t); + entrylen = strlen(entry); + if (entrylen > namelen) + continue; + cmp = memcmp(name, entry, entrylen); + if (cmp > 0) + continue; + if (cmp < 0) + break; + if (entrylen == namelen) { + memcpy(result, sha1, 20); + return 0; + } + if (name[entrylen] != '/') + continue; + if (!S_ISDIR(mode)) + break; + if (++entrylen == namelen) { + memcpy(result, sha1, 20); + return 0; + } + return get_tree_entry(sha1, name + entrylen, result); + } + return -1; +} + +static int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned char *sha1) +{ + int retval; + void *tree; + struct tree_desc t; + + tree = read_object_with_reference(tree_sha1, tree_type, &t.size, NULL); + if (!tree) + return -1; + t.buf = tree; + retval = find_tree_entry(&t, name, sha1); + free(tree); + return retval; +} + /* * This is like "get_sha1_basic()", except it allows "sha1 expressions", * notably "xyz^" for "parent of xyz" */ int get_sha1(const char *name, unsigned char *sha1) { + int ret; + prepare_alt_odb(); - return get_sha1_1(name, strlen(name), sha1); + ret = get_sha1_1(name, strlen(name), sha1); + if (ret < 0) { + const char *cp = strchr(name, ':'); + if (cp) { + unsigned char tree_sha1[20]; + if (!get_sha1_1(name, cp-name, tree_sha1)) + return get_tree_entry(tree_sha1, cp+1, sha1); + } + } + return ret; }