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

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
brian m. carlson 2016-04-17 23:10:39 +00:00 committed by Junio C Hamano
parent 82db3d44e7
commit 7d924c9139
17 changed files with 48 additions and 48 deletions

View File

@ -438,7 +438,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
strbuf_add(base, entry.path, te_len); strbuf_add(base, entry.path, te_len);


if (S_ISREG(entry.mode)) { 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); check_attr ? base->buf + tn_len : NULL);
} }
else if (S_ISDIR(entry.mode)) { else if (S_ISDIR(entry.mode)) {
@ -447,10 +447,10 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
void *data; void *data;
unsigned long size; 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) if (!data)
die(_("unable to read tree (%s)"), die(_("unable to read tree (%s)"),
sha1_to_hex(entry.sha1)); oid_to_hex(entry.oid));


strbuf_addch(base, '/'); strbuf_addch(base, '/');
init_tree_desc(&sub, data, size); init_tree_desc(&sub, data, size);

View File

@ -150,15 +150,15 @@ static void show_result(void)
/* An empty entry never compares same, not even to another empty entry */ /* An empty entry never compares same, not even to another empty entry */
static int same_entry(struct name_entry *a, struct name_entry *b) static int same_entry(struct name_entry *a, struct name_entry *b)
{ {
return a->sha1 && return a->oid &&
b->sha1 && b->oid &&
!hashcmp(a->sha1, b->sha1) && !oidcmp(a->oid, b->oid) &&
a->mode == b->mode; a->mode == b->mode;
} }


static int both_empty(struct name_entry *a, struct name_entry *b) 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) 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; return;


path = traverse_path(info, result); path = traverse_path(info, result);
orig = create_entry(2, ours->mode, ours->sha1, path); orig = create_entry(2, ours->mode, ours->oid->hash, path);
final = create_entry(0, result->mode, result->sha1, path); final = create_entry(0, result->mode, result->oid->hash, path);


final->link = orig; final->link = orig;


@ -213,7 +213,7 @@ static void unresolved_directory(const struct traverse_info *info,


newbase = traverse_path(info, p); 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)); buf0 = fill_tree_descriptor(t+0, ENTRY_SHA1(n + 0));
buf1 = fill_tree_descriptor(t+1, ENTRY_SHA1(n + 1)); buf1 = fill_tree_descriptor(t+1, ENTRY_SHA1(n + 1));
buf2 = fill_tree_descriptor(t+2, ENTRY_SHA1(n + 2)); 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; path = entry->path;
else else
path = traverse_path(info, n); 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; link->link = entry;
return link; 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 (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 */ /* We did not touch, they modified -- take theirs */
resolve(info, entry+1, entry+2); resolve(info, entry+1, entry+2);
return mask; return mask;

View File

@ -1186,7 +1186,7 @@ static void add_pbase_object(struct tree_desc *tree,
if (cmp < 0) if (cmp < 0)
return; return;
if (name[cmplen] != '/') { if (name[cmplen] != '/') {
add_object_entry(entry.sha1, add_object_entry(entry.oid->hash,
object_type(entry.mode), object_type(entry.mode),
fullname, 1); fullname, 1);
return; return;
@ -1197,7 +1197,7 @@ static void add_pbase_object(struct tree_desc *tree,
const char *down = name+cmplen+1; const char *down = name+cmplen+1;
int downlen = name_cmp_len(down); int downlen = name_cmp_len(down);


tree = pbase_tree_get(entry.sha1); tree = pbase_tree_get(entry.oid->hash);
if (!tree) if (!tree)
return; return;
init_tree_desc(&sub, tree->tree_data, tree->tree_size); init_tree_desc(&sub, tree->tree_data, tree->tree_size);

View File

@ -84,8 +84,8 @@ static int tree_is_complete(const unsigned char *sha1)
init_tree_desc(&desc, tree->buffer, tree->size); init_tree_desc(&desc, tree->buffer, tree->size);
complete = 1; complete = 1;
while (tree_entry(&desc, &entry)) { while (tree_entry(&desc, &entry)) {
if (!has_sha1_file(entry.sha1) || if (!has_sha1_file(entry.oid->hash) ||
(S_ISDIR(entry.mode) && !tree_is_complete(entry.sha1))) { (S_ISDIR(entry.mode) && !tree_is_complete(entry.oid->hash))) {
tree->object.flags |= INCOMPLETE; tree->object.flags |= INCOMPLETE;
complete = 0; complete = 0;
} }

View File

@ -663,7 +663,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
cnt++; cnt++;
else { else {
struct cache_tree_sub *sub; struct cache_tree_sub *sub;
struct tree *subtree = lookup_tree(entry.sha1); struct tree *subtree = lookup_tree(entry.oid->hash);
if (!subtree->object.parsed) if (!subtree->object.parsed)
parse_tree(subtree); parse_tree(subtree);
sub = cache_tree_sub(it, entry.path); 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 = find_cache_tree_from_traversal(root, info);
it = cache_tree_find(it, ent->path); 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 it->entry_count;
return 0; return 0;
} }

4
fsck.c
View File

@ -312,9 +312,9 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
if (S_ISGITLINK(entry.mode)) if (S_ISGITLINK(entry.mode))
continue; continue;
if (S_ISDIR(entry.mode)) 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)) 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 { else {
result = error("in tree %s: entry %s has bad mode %.6o", result = error("in tree %s: entry %s has bad mode %.6o",
oid_to_hex(&tree->object.oid), entry.path, entry.mode); oid_to_hex(&tree->object.oid), entry.path, entry.mode);

View File

@ -1312,10 +1312,10 @@ static struct object_list **process_tree(struct tree *tree,
while (tree_entry(&desc, &entry)) while (tree_entry(&desc, &entry))
switch (object_type(entry.mode)) { switch (object_type(entry.mode)) {
case OBJ_TREE: case OBJ_TREE:
p = process_tree(lookup_tree(entry.sha1), p); p = process_tree(lookup_tree(entry.oid->hash), p);
break; break;
case OBJ_BLOB: case OBJ_BLOB:
p = process_blob(lookup_blob(entry.sha1), p); p = process_blob(lookup_blob(entry.oid->hash), p);
break; break;
default: default:
/* Subproject commit - not in this repository */ /* Subproject commit - not in this repository */

View File

@ -110,16 +110,16 @@ static void process_tree(struct rev_info *revs,


if (S_ISDIR(entry.mode)) if (S_ISDIR(entry.mode))
process_tree(revs, process_tree(revs,
lookup_tree(entry.sha1), lookup_tree(entry.oid->hash),
show, base, entry.path, show, base, entry.path,
cb_data); cb_data);
else if (S_ISGITLINK(entry.mode)) else if (S_ISGITLINK(entry.mode))
process_gitlink(revs, entry.sha1, process_gitlink(revs, entry.oid->hash,
show, base, entry.path, show, base, entry.path,
cb_data); cb_data);
else else
process_blob(revs, process_blob(revs,
lookup_blob(entry.sha1), lookup_blob(entry.oid->hash),
show, base, entry.path, show, base, entry.path,
cb_data); cb_data);
} }

View File

@ -104,7 +104,7 @@ static int score_trees(const unsigned char *hash1, const unsigned char *hash2)
else if (cmp > 0) else if (cmp > 0)
/* path2 does not appear in one */ /* path2 does not appear in one */
score += score_missing(e2.mode, e2.path); score += score_missing(e2.mode, e2.path);
else if (hashcmp(e1.sha1, e2.sha1)) else if (oidcmp(e1.oid, e2.oid))
/* they are different */ /* they are different */
score += score_differs(e1.mode, e2.mode, e1.path); score += score_differs(e1.mode, e2.mode, e1.path);
else else

View File

@ -446,7 +446,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
l = (struct leaf_node *) l = (struct leaf_node *)
xcalloc(1, sizeof(struct leaf_node)); xcalloc(1, sizeof(struct leaf_node));
hashcpy(l->key_sha1, object_sha1); hashcpy(l->key_sha1, object_sha1);
hashcpy(l->val_sha1, entry.sha1); hashcpy(l->val_sha1, entry.oid->hash);
if (len < 20) { if (len < 20) {
if (!S_ISDIR(entry.mode) || path_len != 2) if (!S_ISDIR(entry.mode) || path_len != 2)
goto handle_non_note; /* not subtree */ goto handle_non_note; /* not subtree */
@ -493,7 +493,7 @@ handle_non_note:
} }
strbuf_addstr(&non_note_path, entry.path); strbuf_addstr(&non_note_path, entry.path);
add_non_note(t, strbuf_detach(&non_note_path, NULL), add_non_note(t, strbuf_detach(&non_note_path, NULL),
entry.mode, entry.sha1); entry.mode, entry.oid->hash);
} }
} }
free(buf); free(buf);

View File

@ -59,10 +59,10 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
while (tree_entry(&desc, &entry)) { while (tree_entry(&desc, &entry)) {
switch (object_type(entry.mode)) { switch (object_type(entry.mode)) {
case OBJ_TREE: case OBJ_TREE:
mark_tree_uninteresting(lookup_tree(entry.sha1)); mark_tree_uninteresting(lookup_tree(entry.oid->hash));
break; break;
case OBJ_BLOB: case OBJ_BLOB:
mark_blob_uninteresting(lookup_blob(entry.sha1)); mark_blob_uninteresting(lookup_blob(entry.oid->hash));
break; break;
default: default:
/* Subproject commit - not in this repository */ /* Subproject commit - not in this repository */

View File

@ -229,7 +229,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
DIFF_STATUS_ADDED; DIFF_STATUS_ADDED;


if (tpi_valid) { if (tpi_valid) {
sha1_i = tp[i].entry.sha1; sha1_i = tp[i].entry.oid->hash;
mode_i = tp[i].entry.mode; mode_i = tp[i].entry.mode;
} }
else { else {
@ -270,7 +270,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
/* same rule as in emitthis */ /* same rule as in emitthis */
int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ); 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; : NULL;
} }


@ -482,7 +482,7 @@ static struct combine_diff_path *ll_diff_tree_paths(
continue; continue;


/* diff(t,pi) != ø */ /* 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)) (t.entry.mode != tp[i].entry.mode))
continue; continue;



View File

@ -38,7 +38,7 @@ static void decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned
/* Initialize the descriptor entry */ /* Initialize the descriptor entry */
desc->entry.path = path; desc->entry.path = path;
desc->entry.mode = canon_mode(mode); 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) 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) void update_tree_entry(struct tree_desc *desc)
{ {
const void *buf = desc->buffer; 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 size = desc->size;
unsigned long len = end - (const unsigned char *)buf; unsigned long len = end - (const unsigned char *)buf;


@ -110,7 +110,7 @@ void setup_traverse_info(struct traverse_info *info, const char *base)
pathlen--; pathlen--;
info->pathlen = pathlen ? pathlen + 1 : 0; info->pathlen = pathlen ? pathlen + 1 : 0;
info->name.path = base; info->name.path = base;
info->name.sha1 = (void *)(base + pathlen + 1); info->name.oid = (void *)(base + pathlen + 1);
if (pathlen) if (pathlen)
info->prev = &dummy; info->prev = &dummy;
} }

View File

@ -2,7 +2,7 @@
#define TREE_WALK_H #define TREE_WALK_H


struct name_entry { struct name_entry {
const unsigned char *sha1; const struct object_id *oid;
const char *path; const char *path;
unsigned int mode; unsigned int mode;
}; };
@ -17,12 +17,12 @@ static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, co
{ {
*pathp = desc->entry.path; *pathp = desc->entry.path;
*modep = desc->entry.mode; *modep = desc->entry.mode;
return desc->entry.sha1; return desc->entry.oid->hash;
} }


static inline int tree_entry_len(const struct name_entry *ne) 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 *); void update_tree_entry(struct tree_desc *);

10
tree.c
View File

@ -76,7 +76,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
continue; continue;
} }


switch (fn(entry.sha1, base, switch (fn(entry.oid->hash, base,
entry.path, entry.mode, stage, context)) { entry.path, entry.mode, stage, context)) {
case 0: case 0:
continue; continue;
@ -87,19 +87,19 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
} }


if (S_ISDIR(entry.mode)) if (S_ISDIR(entry.mode))
hashcpy(sha1, entry.sha1); hashcpy(sha1, entry.oid->hash);
else if (S_ISGITLINK(entry.mode)) { else if (S_ISGITLINK(entry.mode)) {
struct commit *commit; struct commit *commit;


commit = lookup_commit(entry.sha1); commit = lookup_commit(entry.oid->hash);
if (!commit) if (!commit)
die("Commit %s in submodule path %s%s not found", die("Commit %s in submodule path %s%s not found",
sha1_to_hex(entry.sha1), oid_to_hex(entry.oid),
base->buf, entry.path); base->buf, entry.path);


if (parse_commit(commit)) if (parse_commit(commit))
die("Invalid commit %s in submodule path %s%s", die("Invalid commit %s in submodule path %s%s",
sha1_to_hex(entry.sha1), oid_to_hex(entry.oid),
base->buf, entry.path); base->buf, entry.path);


hashcpy(sha1, commit->tree->object.oid.hash); hashcpy(sha1, commit->tree->object.oid.hash);

View File

@ -475,7 +475,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
for (i = 0; i < n; i++, dirmask >>= 1) { for (i = 0; i < n; i++, dirmask >>= 1) {
const unsigned char *sha1 = NULL; const unsigned char *sha1 = NULL;
if (dirmask & 1) if (dirmask & 1)
sha1 = names[i].sha1; sha1 = names[i].oid->hash;
buf[i] = fill_tree_descriptor(t+i, sha1); 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_mode = create_ce_mode(n->mode);
ce->ce_flags = create_ce_flags(stage); ce->ce_flags = create_ce_flags(stage);
ce->ce_namelen = len; ce->ce_namelen = len;
hashcpy(ce->sha1, n->sha1); hashcpy(ce->sha1, n->oid->hash);
make_traverse_path(ce->name, info, n); make_traverse_path(ce->name, info, n);


return ce; return ce;

View File

@ -43,12 +43,12 @@ static int process_tree(struct walker *walker, struct tree *tree)
if (S_ISGITLINK(entry.mode)) if (S_ISGITLINK(entry.mode))
continue; continue;
if (S_ISDIR(entry.mode)) { if (S_ISDIR(entry.mode)) {
struct tree *tree = lookup_tree(entry.sha1); struct tree *tree = lookup_tree(entry.oid->hash);
if (tree) if (tree)
obj = &tree->object; obj = &tree->object;
} }
else { else {
struct blob *blob = lookup_blob(entry.sha1); struct blob *blob = lookup_blob(entry.oid->hash);
if (blob) if (blob)
obj = &blob->object; obj = &blob->object;
} }