@matheusbsbs / matheus-bagliano / commits / 19a7e7151d
Fork 0

git-rev-list: do not forget non-commit refs

What happens is that the new logic decides that if it can't look up a commit reference (ie "get_commit_reference()" returns NULL), the thing must be a pathname. Fair enough. But wrong. The thing is, it may be a perfectly fine ref that _isn't_ a commit. In git, you have a tag that points to your PGP key, and in the kernel, I have a tag that points to a tree (and a direct ref that points to that tree too, for that matter). So the rule is (as for all the other programs that mix revs and pathnames) not that we only accept commit references, but _any_ valid object ref. If the object then isn't a commit ref, git-rev-list will either ignore it, or add it to the list of non-commit objects (if using "--objects"). The solution is to move the "get_sha1()" out of get_commit_reference(), and into the callers. In fact, we already _have_ the SHA1 in the case of the handle_all() loop, since for_each_ref() will have done it for us, so this is the correct thing to do anyway. This patch (on top of the original one) does exactly that. Signed-off-by: Junio C Hamano <junkio@cox.net>

Linus Torvalds committed Oct 26, 2005 at 08:18 UTC 19a7e7151d0dfd22619daabbaa72a24715fae0ca
1 file changed +14 -12
rev-list.c
+14 -12
@@ -613,13 +613,10 @@ static void add_pending_object(struct object *obj, const char *name)
613 add_object(obj, &pending_objects, name);
614 }
615
616 -static struct commit *get_commit_reference(const char *name, unsigned int flags)
616 +static struct commit *get_commit_reference(const char *name, const unsigned char *sha1, unsigned int flags)
617 {
618 - unsigned char sha1[20];
618 struct object *object;
619
621 - if (get_sha1(name, sha1))
622 - return NULL;
620 object = parse_object(sha1);
621 if (!object)
622 die("bad object %s", name);
@@ -697,7 +694,7 @@ static struct commit_list **global_lst;
694
695 static int include_one_commit(const char *path, const unsigned char *sha1)
696 {
700 - struct commit *com = get_commit_reference(path, 0);
697 + struct commit *com = get_commit_reference(path, sha1, 0);
698 handle_one_commit(com, global_lst);
699 return 0;
700 }
@@ -720,6 +717,7 @@ int main(int argc, const char **argv)
717 const char *arg = argv[i];
718 char *dotdot;
719 struct commit *commit;
720 + unsigned char sha1[20];
721
722 if (!strncmp(arg, "--max-count=", 12)) {
723 max_count = atoi(arg + 12);
@@ -808,15 +806,19 @@ int main(int argc, const char **argv)
806 flags = 0;
807 dotdot = strstr(arg, "..");
808 if (dotdot) {
809 + unsigned char from_sha1[20];
810 char *next = dotdot + 2;
812 - struct commit *exclude = NULL;
813 - struct commit *include = NULL;
811 *dotdot = 0;
812 if (!*next)
813 next = "HEAD";
817 - exclude = get_commit_reference(arg, UNINTERESTING);
818 - include = get_commit_reference(next, 0);
819 - if (exclude && include) {
814 + if (!get_sha1(arg, from_sha1) && !get_sha1(next, sha1)) {
815 + struct commit *exclude;
816 + struct commit *include;
817 +
818 + exclude = get_commit_reference(arg, from_sha1, UNINTERESTING);
819 + include = get_commit_reference(next, sha1, 0);
820 + if (!exclude || !include)
821 + die("Invalid revision range %s..%s", arg, next);
822 limited = 1;
823 handle_one_commit(exclude, &list);
824 handle_one_commit(include, &list);
@@ -829,9 +831,9 @@ int main(int argc, const char **argv)
831 arg++;
832 limited = 1;
833 }
832 - commit = get_commit_reference(arg, flags);
833 - if (!commit)
834 + if (get_sha1(arg, sha1) < 0)
835 break;
836 + commit = get_commit_reference(arg, sha1, flags);
837 handle_one_commit(commit, &list);
838 }
839