Skip to content

Commit

Permalink
commit: add "lookup_commit_reference()" helper function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Linus Torvalds committed May 18, 2005
1 parent fbab835 commit 961784e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
29 changes: 23 additions & 6 deletions commit.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,32 @@
#include "tag.h"
#include "commit.h"
#include "cache.h"
#include <string.h>
#include <limits.h>

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);
Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions commit.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct commit {
extern const char *commit_type;

struct commit *lookup_commit(unsigned char *sha1);
struct commit *lookup_commit_reference(unsigned char *sha1);

int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size);

Expand Down

0 comments on commit 961784e

Please sign in to comment.