summaryrefslogtreecommitdiff
path: root/sha1_name.c
diff options
context:
space:
mode:
Diffstat (limited to 'sha1_name.c')
-rw-r--r--sha1_name.c59
1 files changed, 31 insertions, 28 deletions
diff --git a/sha1_name.c b/sha1_name.c
index 8eec9f7..5126853 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -241,7 +241,7 @@ static int disambiguate_committish_only(const struct object_id *oid, void *cb_da
return 0;
/* We need to do this the hard way... */
- obj = deref_tag(parse_object(oid->hash), NULL, 0);
+ obj = deref_tag(parse_object(oid), NULL, 0);
if (obj && obj->type == OBJ_COMMIT)
return 1;
return 0;
@@ -265,7 +265,7 @@ static int disambiguate_treeish_only(const struct object_id *oid, void *cb_data_
return 0;
/* We need to do this the hard way... */
- obj = deref_tag(parse_object(oid->hash), NULL, 0);
+ obj = deref_tag(parse_object(oid), NULL, 0);
if (obj && (obj->type == OBJ_TREE || obj->type == OBJ_COMMIT))
return 1;
return 0;
@@ -354,14 +354,14 @@ static int show_ambiguous_object(const struct object_id *oid, void *data)
type = sha1_object_info(oid->hash, NULL);
if (type == OBJ_COMMIT) {
- struct commit *commit = lookup_commit(oid->hash);
+ struct commit *commit = lookup_commit(oid);
if (commit) {
struct pretty_print_context pp = {0};
pp.date_mode.type = DATE_SHORT;
format_commit_message(commit, " %ad - %s", &desc, &pp);
}
} else if (type == OBJ_TAG) {
- struct tag *tag = lookup_tag(oid->hash);
+ struct tag *tag = lookup_tag(oid);
if (!parse_tag(tag) && tag->tag)
strbuf_addf(&desc, " %s", tag->tag);
}
@@ -660,8 +660,8 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
if (reflog_len) {
int nth, i;
- unsigned long at_time;
- unsigned long co_time;
+ timestamp_t at_time;
+ timestamp_t co_time;
int co_tz, co_cnt;
/* Is it asking for N-th entry, or approxidate? */
@@ -722,14 +722,14 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1,
static int get_parent(const char *name, int len,
unsigned char *result, int idx)
{
- unsigned char sha1[20];
- int ret = get_sha1_1(name, len, sha1, GET_SHA1_COMMITTISH);
+ struct object_id oid;
+ int ret = get_sha1_1(name, len, oid.hash, GET_SHA1_COMMITTISH);
struct commit *commit;
struct commit_list *p;
if (ret)
return ret;
- commit = lookup_commit_reference(sha1);
+ commit = lookup_commit_reference(&oid);
if (parse_commit(commit))
return -1;
if (!idx) {
@@ -750,14 +750,14 @@ static int get_parent(const char *name, int len,
static int get_nth_ancestor(const char *name, int len,
unsigned char *result, int generation)
{
- unsigned char sha1[20];
+ struct object_id oid;
struct commit *commit;
int ret;
- ret = get_sha1_1(name, len, sha1, GET_SHA1_COMMITTISH);
+ ret = get_sha1_1(name, len, oid.hash, GET_SHA1_COMMITTISH);
if (ret)
return ret;
- commit = lookup_commit_reference(sha1);
+ commit = lookup_commit_reference(&oid);
if (!commit)
return -1;
@@ -776,7 +776,7 @@ struct object *peel_to_type(const char *name, int namelen,
if (name && !namelen)
namelen = strlen(name);
while (1) {
- if (!o || (!o->parsed && !parse_object(o->oid.hash)))
+ if (!o || (!o->parsed && !parse_object(&o->oid)))
return NULL;
if (expected_type == OBJ_ANY || o->type == expected_type)
return o;
@@ -798,7 +798,7 @@ struct object *peel_to_type(const char *name, int namelen,
static int peel_onion(const char *name, int len, unsigned char *sha1,
unsigned lookup_flags)
{
- unsigned char outer[20];
+ struct object_id outer;
const char *sp;
unsigned int expected_type = 0;
struct object *o;
@@ -846,15 +846,15 @@ static int peel_onion(const char *name, int len, unsigned char *sha1,
else if (expected_type == OBJ_TREE)
lookup_flags |= GET_SHA1_TREEISH;
- if (get_sha1_1(name, sp - name - 2, outer, lookup_flags))
+ if (get_sha1_1(name, sp - name - 2, outer.hash, lookup_flags))
return -1;
- o = parse_object(outer);
+ o = parse_object(&outer);
if (!o)
return -1;
if (!expected_type) {
o = deref_tag(o, name, sp - name - 2);
- if (!o || (!o->parsed && !parse_object(o->oid.hash)))
+ if (!o || (!o->parsed && !parse_object(&o->oid)))
return -1;
hashcpy(sha1, o->oid.hash);
return 0;
@@ -981,7 +981,7 @@ static int handle_one_ref(const char *path, const struct object_id *oid,
int flag, void *cb_data)
{
struct commit_list **list = cb_data;
- struct object *object = parse_object(oid->hash);
+ struct object *object = parse_object(oid);
if (!object)
return 0;
if (object->type == OBJ_TAG) {
@@ -1027,7 +1027,7 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1,
int matches;
commit = pop_most_recent_commit(&list, ONELINE_SEEN);
- if (!parse_object(commit->object.oid.hash))
+ if (!parse_object(&commit->object.oid))
continue;
buf = get_commit_buffer(commit, NULL);
p = strstr(buf, "\n\n");
@@ -1054,7 +1054,7 @@ struct grab_nth_branch_switch_cbdata {
};
static int grab_nth_branch_switch(struct object_id *ooid, struct object_id *noid,
- const char *email, unsigned long timestamp, int tz,
+ const char *email, timestamp_t timestamp, int tz,
const char *message, void *cb_data)
{
struct grab_nth_branch_switch_cbdata *cb = cb_data;
@@ -1136,13 +1136,13 @@ int get_oid_mb(const char *name, struct object_id *oid)
}
if (st)
return st;
- one = lookup_commit_reference_gently(oid_tmp.hash, 0);
+ one = lookup_commit_reference_gently(&oid_tmp, 0);
if (!one)
return -1;
if (get_sha1_committish(dots[3] ? (dots + 3) : "HEAD", oid_tmp.hash))
return -1;
- two = lookup_commit_reference_gently(oid_tmp.hash, 0);
+ two = lookup_commit_reference_gently(&oid_tmp, 0);
if (!two)
return -1;
mbs = get_merge_bases(one, two);
@@ -1408,7 +1408,7 @@ static void diagnose_invalid_sha1_path(const char *prefix,
if (file_exists(filename))
die("Path '%s' exists on disk, but not in '%.*s'.",
filename, object_name_len, object_name);
- if (errno == ENOENT || errno == ENOTDIR) {
+ if (is_missing_file_error(errno)) {
char *fullname = xstrfmt("%s%s", prefix, filename);
if (!get_tree_entry(tree_sha1, fullname,
@@ -1473,7 +1473,7 @@ static void diagnose_invalid_index_path(int stage,
if (file_exists(filename))
die("Path '%s' exists on disk, but not in the index.", filename);
- if (errno == ENOENT || errno == ENOTDIR)
+ if (is_missing_file_error(errno))
die("Path '%s' does not exist (neither on disk nor in the index).",
filename);
@@ -1511,6 +1511,7 @@ static int get_sha1_with_context_1(const char *name,
memset(oc, 0, sizeof(*oc));
oc->mode = S_IFINVALID;
+ strbuf_init(&oc->symlink_path, 0);
ret = get_sha1_1(name, namelen, sha1, flags);
if (!ret)
return ret;
@@ -1549,7 +1550,8 @@ static int get_sha1_with_context_1(const char *name,
namelen = strlen(cp);
}
- strlcpy(oc->path, cp, sizeof(oc->path));
+ if (flags & GET_SHA1_RECORD_PATH)
+ oc->path = xstrdup(cp);
if (!active_cache)
read_cache();
@@ -1612,7 +1614,8 @@ static int get_sha1_with_context_1(const char *name,
}
}
hashcpy(oc->tree, tree_sha1);
- strlcpy(oc->path, filename, sizeof(oc->path));
+ if (flags & GET_SHA1_RECORD_PATH)
+ oc->path = xstrdup(filename);
free(new_filename);
return ret;
@@ -1638,9 +1641,9 @@ void maybe_die_on_misspelt_object_name(const char *name, const char *prefix)
get_sha1_with_context_1(name, GET_SHA1_ONLY_TO_DIE, prefix, sha1, &oc);
}
-int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *orc)
+int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *oc)
{
if (flags & GET_SHA1_FOLLOW_SYMLINKS && flags & GET_SHA1_ONLY_TO_DIE)
die("BUG: incompatible flags for get_sha1_with_context");
- return get_sha1_with_context_1(str, flags, NULL, sha1, orc);
+ return get_sha1_with_context_1(str, flags, NULL, sha1, oc);
}