summaryrefslogtreecommitdiff
path: root/commit.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-18 23:14:22 (GMT)
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-05-18 23:14:22 (GMT)
commit961784ee422c22075e131292b2235782e378c612 (patch)
treed79eca9b37e7ec984fb64b3f33bdc8d43f25c4be /commit.c
parentfbab835c03f1c73e4de920d00cd26519506d33fe (diff)
downloadgit-961784ee422c22075e131292b2235782e378c612.zip
git-961784ee422c22075e131292b2235782e378c612.tar.gz
git-961784ee422c22075e131292b2235782e378c612.tar.bz2
commit: add "lookup_commit_reference()" helper function
It's pretty much the same as "lookup_commit()", but it will take tags too, and look up the commit (if any) associated with them.
Diffstat (limited to 'commit.c')
-rw-r--r--commit.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/commit.c b/commit.c
index 706c7cb..e830564 100644
--- a/commit.c
+++ b/commit.c
@@ -1,3 +1,4 @@
+#include "tag.h"
#include "commit.h"
#include "cache.h"
#include <string.h>
@@ -5,6 +6,27 @@
const char *commit_type = "commit";
+static struct commit *check_commit(struct object *obj, unsigned char *sha1)
+{
+ if (obj->type != commit_type) {
+ error("Object %s is a %s, not a commit",
+ sha1_to_hex(sha1), obj->type);
+ return NULL;
+ }
+ return (struct commit *) obj;
+}
+
+struct commit *lookup_commit_reference(unsigned char *sha1)
+{
+ struct object *obj = parse_object(sha1);
+
+ if (!obj)
+ return NULL;
+ if (obj->type == tag_type)
+ obj = ((struct tag *)obj)->tagged;
+ return check_commit(obj, sha1);
+}
+
struct commit *lookup_commit(unsigned char *sha1)
{
struct object *obj = lookup_object(sha1);
@@ -15,12 +37,7 @@ struct commit *lookup_commit(unsigned char *sha1)
ret->object.type = commit_type;
return ret;
}
- if (obj->type != commit_type) {
- error("Object %s is a %s, not a commit",
- sha1_to_hex(sha1), obj->type);
- return NULL;
- }
- return (struct commit *) obj;
+ return check_commit(obj, sha1);
}
static unsigned long parse_commit_date(const char *buf)