Commit 7d924c91 authored by brian m. carlson's avatar brian m. carlson Committed by Junio C Hamano

struct name_entry: use struct object_id instead of unsigned char sha1[20]

Signed-off-by: brian m. carlson's avatarbrian m. carlson <[email protected]>
Signed-off-by: default avatarJunio C Hamano <[email protected]>
parent 82db3d44
......@@ -438,7 +438,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
strbuf_add(base, entry.path, te_len);
if (S_ISREG(entry.mode)) {
hit |= grep_sha1(opt, entry.sha1, base->buf, tn_len,
hit |= grep_sha1(opt, entry.oid->hash, base->buf, tn_len,
check_attr ? base->buf + tn_len : NULL);
}
else if (S_ISDIR(entry.mode)) {
......@@ -447,10 +447,10 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
void *data;
unsigned long size;
data = lock_and_read_sha1_file(entry.sha1, &type, &size);
data = lock_and_read_sha1_file(entry.oid->hash, &type, &size);
if (!data)
die(_("unable to read tree (%s)"),
sha1_to_hex(entry.sha1));
oid_to_hex(entry.oid));
strbuf_addch(base, '/');
init_tree_desc(&sub, data, size);
......
......@@ -150,15 +150,15 @@ static void show_result(void)
/* An empty entry never compares same, not even to another empty entry */
static int same_entry(struct name_entry *a, struct name_entry *b)
{
return a->sha1 &&
b->sha1 &&
!hashcmp(a->sha1, b->sha1) &&
return a->oid &&
b->oid &&
!oidcmp(a->oid, b->oid) &&
a->mode == b->mode;
}
static int both_empty(struct name_entry *a, struct name_entry *b)
{
return !(a->sha1 || b->sha1);
return !(a->oid || b->oid);
}
static struct merge_list *create_entry(unsigned stage, unsigned mode, const unsigned char *sha1, const char *path)
......@@ -188,8 +188,8 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s
return;
path = traverse_path(info, result);
orig = create_entry(2, ours->mode, ours->sha1, path);
final = create_entry(0, result->mode, result->sha1, path);
orig = create_entry(2, ours->mode, ours->oid->hash, path);
final = create_entry(0, result->mode, result->oid->hash, path);
final->link = orig;
......@@ -213,7 +213,7 @@ static void unresolved_directory(const struct traverse_info *info,
newbase = traverse_path(info, p);
#define ENTRY_SHA1(e) (((e)->mode && S_ISDIR((e)->mode)) ? (e)->sha1 : NULL)
#define ENTRY_SHA1(e) (((e)->mode && S_ISDIR((e)->mode)) ? (e)->oid->hash : NULL)
buf0 = fill_tree_descriptor(t+0, ENTRY_SHA1(n + 0));
buf1 = fill_tree_descriptor(t+1, ENTRY_SHA1(n + 1));
buf2 = fill_tree_descriptor(t+2, ENTRY_SHA1(n + 2));
......@@ -239,7 +239,7 @@ static struct merge_list *link_entry(unsigned stage, const struct traverse_info
path = entry->path;
else
path = traverse_path(info, n);
link = create_entry(stage, n->mode, n->sha1, path);
link = create_entry(stage, n->mode, n->oid->hash, path);
link->link = entry;
return link;
}
......@@ -314,7 +314,7 @@ static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, s
}
if (same_entry(entry+0, entry+1)) {
if (entry[2].sha1 && !S_ISDIR(entry[2].mode)) {
if (entry[2].oid && !S_ISDIR(entry[2].mode)) {
/* We did not touch, they modified -- take theirs */
resolve(info, entry+1, entry+2);
return mask;
......
......@@ -1186,7 +1186,7 @@ static void add_pbase_object(struct tree_desc *tree,
if (cmp < 0)
return;
if (name[cmplen] != '/') {
add_object_entry(entry.sha1,
add_object_entry(entry.oid->hash,
object_type(entry.mode),
fullname, 1);
return;
......@@ -1197,7 +1197,7 @@ static void add_pbase_object(struct tree_desc *tree,
const char *down = name+cmplen+1;
int downlen = name_cmp_len(down);
tree = pbase_tree_get(entry.sha1);
tree = pbase_tree_get(entry.oid->hash);
if (!tree)
return;
init_tree_desc(&sub, tree->tree_data, tree->tree_size);
......
......@@ -84,8 +84,8 @@ static int tree_is_complete(const unsigned char *sha1)
init_tree_desc(&desc, tree->buffer, tree->size);
complete = 1;
while (tree_entry(&desc, &entry)) {
if (!has_sha1_file(entry.sha1) ||
(S_ISDIR(entry.mode) && !tree_is_complete(entry.sha1))) {
if (!has_sha1_file(entry.oid->hash) ||
(S_ISDIR(entry.mode) && !tree_is_complete(entry.oid->hash))) {
tree->object.flags |= INCOMPLETE;
complete = 0;
}
......
......@@ -663,7 +663,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
cnt++;
else {
struct cache_tree_sub *sub;
struct tree *subtree = lookup_tree(entry.sha1);
struct tree *subtree = lookup_tree(entry.oid->hash);
if (!subtree->object.parsed)
parse_tree(subtree);
sub = cache_tree_sub(it, entry.path);
......@@ -710,7 +710,7 @@ int cache_tree_matches_traversal(struct cache_tree *root,
it = find_cache_tree_from_traversal(root, info);
it = cache_tree_find(it, ent->path);
if (it && it->entry_count > 0 && !hashcmp(ent->sha1, it->sha1))
if (it && it->entry_count > 0 && !hashcmp(ent->oid->hash, it->sha1))
return it->entry_count;
return 0;
}
......
......@@ -312,9 +312,9 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
if (S_ISGITLINK(entry.mode))
continue;
if (S_ISDIR(entry.mode))
result = options->walk(&lookup_tree(entry.sha1)->object, OBJ_TREE, data, options);
result = options->walk(&lookup_tree(entry.oid->hash)->object, OBJ_TREE, data, options);
else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode))
result = options->walk(&lookup_blob(entry.sha1)->object, OBJ_BLOB, data, options);
result = options->walk(&lookup_blob(entry.oid->hash)->object, OBJ_BLOB, data, options);
else {
result = error("in tree %s: entry %s has bad mode %.6o",
oid_to_hex(&tree->object.oid), entry.path, entry.mode);
......
......@@ -1312,10 +1312,10 @@ static struct object_list **process_tree(struct tree *tree,
while (tree_entry(&desc, &entry))
switch (object_type(entry.mode)) {
case OBJ_TREE:
p = process_tree(lookup_tree(entry.sha1), p);
p = process_tree(lookup_tree(entry.oid->hash), p);
break;
case OBJ_BLOB:
p = process_blob(lookup_blob(entry.sha1), p);
p = process_blob(lookup_blob(entry.oid->hash), p);
break;
default:
/* Subproject commit - not in this repository */
......
......@@ -110,16 +110,16 @@ static void process_tree(struct rev_info *revs,
if (S_ISDIR(entry.mode))
process_tree(revs,
lookup_tree(entry.sha1),
lookup_tree(entry.oid->hash),
show, base, entry.path,
cb_data);
else if (S_ISGITLINK(entry.mode))
process_gitlink(revs, entry.sha1,
process_gitlink(revs, entry.oid->hash,
show, base, entry.path,
cb_data);
else
process_blob(revs,
lookup_blob(entry.sha1),
lookup_blob(entry.oid->hash),
show, base, entry.path,
cb_data);
}
......
......@@ -104,7 +104,7 @@ static int score_trees(const unsigned char *hash1, const unsigned char *hash2)
else if (cmp > 0)
/* path2 does not appear in one */
score += score_missing(e2.mode, e2.path);
else if (hashcmp(e1.sha1, e2.sha1))
else if (oidcmp(e1.oid, e2.oid))
/* they are different */
score += score_differs(e1.mode, e2.mode, e1.path);
else
......
......@@ -446,7 +446,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
l = (struct leaf_node *)
xcalloc(1, sizeof(struct leaf_node));
hashcpy(l->key_sha1, object_sha1);
hashcpy(l->val_sha1, entry.sha1);
hashcpy(l->val_sha1, entry.oid->hash);
if (len < 20) {
if (!S_ISDIR(entry.mode) || path_len != 2)
goto handle_non_note; /* not subtree */
......@@ -493,7 +493,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
}
strbuf_addstr(&non_note_path, entry.path);
add_non_note(t, strbuf_detach(&non_note_path, NULL),
entry.mode, entry.sha1);
entry.mode, entry.oid->hash);
}
}
free(buf);
......
......@@ -59,10 +59,10 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
while (tree_entry(&desc, &entry)) {
switch (object_type(entry.mode)) {
case OBJ_TREE:
mark_tree_uninteresting(lookup_tree(entry.sha1));
mark_tree_uninteresting(lookup_tree(entry.oid->hash));
break;
case OBJ_BLOB:
mark_blob_uninteresting(lookup_blob(entry.sha1));
mark_blob_uninteresting(lookup_blob(entry.oid->hash));
break;
default:
/* Subproject commit - not in this repository */
......
......@@ -229,7 +229,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
DIFF_STATUS_ADDED;
if (tpi_valid) {
sha1_i = tp[i].entry.sha1;
sha1_i = tp[i].entry.oid->hash;
mode_i = tp[i].entry.mode;
}
else {
......@@ -270,7 +270,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
/* same rule as in emitthis */
int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ);
parents_sha1[i] = tpi_valid ? tp[i].entry.sha1
parents_sha1[i] = tpi_valid ? tp[i].entry.oid->hash
: NULL;
}
......@@ -482,7 +482,7 @@ static struct combine_diff_path *ll_diff_tree_paths(
continue;
/* diff(t,pi) != ø */
if (hashcmp(t.entry.sha1, tp[i].entry.sha1) ||
if (oidcmp(t.entry.oid, tp[i].entry.oid) ||
(t.entry.mode != tp[i].entry.mode))
continue;
......
......@@ -38,7 +38,7 @@ static void decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned
/* Initialize the descriptor entry */
desc->entry.path = path;
desc->entry.mode = canon_mode(mode);
desc->entry.sha1 = (const unsigned char *)(path + len);
desc->entry.oid = (const struct object_id *)(path + len);
}
void init_tree_desc(struct tree_desc *desc, const void *buffer, unsigned long size)
......@@ -76,7 +76,7 @@ static void entry_extract(struct tree_desc *t, struct name_entry *a)
void update_tree_entry(struct tree_desc *desc)
{
const void *buf = desc->buffer;
const unsigned char *end = desc->entry.sha1 + 20;
const unsigned char *end = desc->entry.oid->hash + 20;
unsigned long size = desc->size;
unsigned long len = end - (const unsigned char *)buf;
......@@ -110,7 +110,7 @@ void setup_traverse_info(struct traverse_info *info, const char *base)
pathlen--;
info->pathlen = pathlen ? pathlen + 1 : 0;
info->name.path = base;
info->name.sha1 = (void *)(base + pathlen + 1);
info->name.oid = (void *)(base + pathlen + 1);
if (pathlen)
info->prev = &dummy;
}
......
......@@ -2,7 +2,7 @@
#define TREE_WALK_H
struct name_entry {
const unsigned char *sha1;
const struct object_id *oid;
const char *path;
unsigned int mode;
};
......@@ -17,12 +17,12 @@ static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, co
{
*pathp = desc->entry.path;
*modep = desc->entry.mode;
return desc->entry.sha1;
return desc->entry.oid->hash;
}
static inline int tree_entry_len(const struct name_entry *ne)
{
return (const char *)ne->sha1 - ne->path - 1;
return (const char *)ne->oid - ne->path - 1;
}
void update_tree_entry(struct tree_desc *);
......
......@@ -76,7 +76,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
continue;
}
switch (fn(entry.sha1, base,
switch (fn(entry.oid->hash, base,
entry.path, entry.mode, stage, context)) {
case 0:
continue;
......@@ -87,19 +87,19 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
}
if (S_ISDIR(entry.mode))
hashcpy(sha1, entry.sha1);
hashcpy(sha1, entry.oid->hash);
else if (S_ISGITLINK(entry.mode)) {
struct commit *commit;
commit = lookup_commit(entry.sha1);
commit = lookup_commit(entry.oid->hash);
if (!commit)
die("Commit %s in submodule path %s%s not found",
sha1_to_hex(entry.sha1),
oid_to_hex(entry.oid),
base->buf, entry.path);
if (parse_commit(commit))
die("Invalid commit %s in submodule path %s%s",
sha1_to_hex(entry.sha1),
oid_to_hex(entry.oid),
base->buf, entry.path);
hashcpy(sha1, commit->tree->object.oid.hash);
......
......@@ -475,7 +475,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
for (i = 0; i < n; i++, dirmask >>= 1) {
const unsigned char *sha1 = NULL;
if (dirmask & 1)
sha1 = names[i].sha1;
sha1 = names[i].oid->hash;
buf[i] = fill_tree_descriptor(t+i, sha1);
}
......@@ -591,7 +591,7 @@ static struct cache_entry *create_ce_entry(const struct traverse_info *info, con
ce->ce_mode = create_ce_mode(n->mode);
ce->ce_flags = create_ce_flags(stage);
ce->ce_namelen = len;
hashcpy(ce->sha1, n->sha1);
hashcpy(ce->sha1, n->oid->hash);
make_traverse_path(ce->name, info, n);
return ce;
......
......@@ -43,12 +43,12 @@ static int process_tree(struct walker *walker, struct tree *tree)
if (S_ISGITLINK(entry.mode))
continue;
if (S_ISDIR(entry.mode)) {
struct tree *tree = lookup_tree(entry.sha1);
struct tree *tree = lookup_tree(entry.oid->hash);
if (tree)
obj = &tree->object;
}
else {
struct blob *blob = lookup_blob(entry.sha1);
struct blob *blob = lookup_blob(entry.oid->hash);
if (blob)
obj = &blob->object;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment