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.
This commit is contained in:
parent
fbab835c03
commit
961784ee42
29
commit.c
29
commit.c
@ -1,3 +1,4 @@
|
|||||||
|
#include "tag.h"
|
||||||
#include "commit.h"
|
#include "commit.h"
|
||||||
#include "cache.h"
|
#include "cache.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@ -5,6 +6,27 @@
|
|||||||
|
|
||||||
const char *commit_type = "commit";
|
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 commit *lookup_commit(unsigned char *sha1)
|
||||||
{
|
{
|
||||||
struct object *obj = lookup_object(sha1);
|
struct object *obj = lookup_object(sha1);
|
||||||
@ -15,12 +37,7 @@ struct commit *lookup_commit(unsigned char *sha1)
|
|||||||
ret->object.type = commit_type;
|
ret->object.type = commit_type;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if (obj->type != commit_type) {
|
return check_commit(obj, sha1);
|
||||||
error("Object %s is a %s, not a commit",
|
|
||||||
sha1_to_hex(sha1), obj->type);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return (struct commit *) obj;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned long parse_commit_date(const char *buf)
|
static unsigned long parse_commit_date(const char *buf)
|
||||||
|
1
commit.h
1
commit.h
@ -19,6 +19,7 @@ struct commit {
|
|||||||
extern const char *commit_type;
|
extern const char *commit_type;
|
||||||
|
|
||||||
struct commit *lookup_commit(unsigned char *sha1);
|
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);
|
int parse_commit_buffer(struct commit *item, void *buffer, unsigned long size);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user