Merge branch 'bc/object-id'
Move from unsigned char[20] to struct object_id continues. * bc/object-id: match-trees: convert several leaf functions to use struct object_id tree-walk: convert tree_entry_extract() to use struct object_id struct name_entry: use struct object_id instead of unsigned char sha1[20] match-trees: convert shift_tree() and shift_tree_by() to use object_id test-match-trees: convert to use struct object_id sha1-name: introduce a get_oid() function
This commit is contained in:
commit
8429f2b42d
@ -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;
|
||||
}
|
||||
|
6
cache.h
6
cache.h
@ -1154,6 +1154,8 @@ extern int get_sha1_blob(const char *str, unsigned char *sha1);
|
||||
extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
|
||||
extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *orc);
|
||||
|
||||
extern int get_oid(const char *str, struct object_id *oid);
|
||||
|
||||
typedef int each_abbrev_fn(const unsigned char *sha1, void *);
|
||||
extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
|
||||
|
||||
@ -1764,8 +1766,8 @@ int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int
|
||||
extern int diff_auto_refresh_index;
|
||||
|
||||
/* match-trees.c */
|
||||
void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, int);
|
||||
void shift_tree_by(const unsigned char *, const unsigned char *, unsigned char *, const char *);
|
||||
void shift_tree(const struct object_id *, const struct object_id *, struct object_id *, int);
|
||||
void shift_tree_by(const struct object_id *, const struct object_id *, struct object_id *, const char *);
|
||||
|
||||
/*
|
||||
* whitespace rules.
|
||||
|
10
fsck.c
10
fsck.c
@ -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);
|
||||
@ -450,11 +450,11 @@ static int fsck_tree(struct tree *item, struct fsck_options *options)
|
||||
while (desc.size) {
|
||||
unsigned mode;
|
||||
const char *name;
|
||||
const unsigned char *sha1;
|
||||
const struct object_id *oid;
|
||||
|
||||
sha1 = tree_entry_extract(&desc, &name, &mode);
|
||||
oid = tree_entry_extract(&desc, &name, &mode);
|
||||
|
||||
has_null_sha1 |= is_null_sha1(sha1);
|
||||
has_null_sha1 |= is_null_oid(oid);
|
||||
has_full_path |= !!strchr(name, '/');
|
||||
has_empty_name |= !*name;
|
||||
has_dot |= !strcmp(name, ".");
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -48,17 +48,17 @@ static int score_matches(unsigned mode1, unsigned mode2, const char *path)
|
||||
}
|
||||
|
||||
static void *fill_tree_desc_strict(struct tree_desc *desc,
|
||||
const unsigned char *hash)
|
||||
const struct object_id *hash)
|
||||
{
|
||||
void *buffer;
|
||||
enum object_type type;
|
||||
unsigned long size;
|
||||
|
||||
buffer = read_sha1_file(hash, &type, &size);
|
||||
buffer = read_sha1_file(hash->hash, &type, &size);
|
||||
if (!buffer)
|
||||
die("unable to read tree (%s)", sha1_to_hex(hash));
|
||||
die("unable to read tree (%s)", oid_to_hex(hash));
|
||||
if (type != OBJ_TREE)
|
||||
die("%s is not a tree", sha1_to_hex(hash));
|
||||
die("%s is not a tree", oid_to_hex(hash));
|
||||
init_tree_desc(desc, buffer, size);
|
||||
return buffer;
|
||||
}
|
||||
@ -73,7 +73,7 @@ static int base_name_entries_compare(const struct name_entry *a,
|
||||
/*
|
||||
* Inspect two trees, and give a score that tells how similar they are.
|
||||
*/
|
||||
static int score_trees(const unsigned char *hash1, const unsigned char *hash2)
|
||||
static int score_trees(const struct object_id *hash1, const struct object_id *hash2)
|
||||
{
|
||||
struct tree_desc one;
|
||||
struct tree_desc two;
|
||||
@ -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
|
||||
@ -119,8 +119,8 @@ static int score_trees(const unsigned char *hash1, const unsigned char *hash2)
|
||||
/*
|
||||
* Match one itself and its subtrees with two and pick the best match.
|
||||
*/
|
||||
static void match_trees(const unsigned char *hash1,
|
||||
const unsigned char *hash2,
|
||||
static void match_trees(const struct object_id *hash1,
|
||||
const struct object_id *hash2,
|
||||
int *best_score,
|
||||
char **best_match,
|
||||
const char *base,
|
||||
@ -131,7 +131,7 @@ static void match_trees(const unsigned char *hash1,
|
||||
|
||||
while (one.size) {
|
||||
const char *path;
|
||||
const unsigned char *elem;
|
||||
const struct object_id *elem;
|
||||
unsigned mode;
|
||||
int score;
|
||||
|
||||
@ -191,15 +191,15 @@ static int splice_tree(const unsigned char *hash1,
|
||||
while (desc.size) {
|
||||
const char *name;
|
||||
unsigned mode;
|
||||
const unsigned char *sha1;
|
||||
const struct object_id *oid;
|
||||
|
||||
sha1 = tree_entry_extract(&desc, &name, &mode);
|
||||
oid = tree_entry_extract(&desc, &name, &mode);
|
||||
if (strlen(name) == toplen &&
|
||||
!memcmp(name, prefix, toplen)) {
|
||||
if (!S_ISDIR(mode))
|
||||
die("entry %s in tree %s is not a tree",
|
||||
name, sha1_to_hex(hash1));
|
||||
rewrite_here = (unsigned char *) sha1;
|
||||
rewrite_here = (unsigned char *) oid->hash;
|
||||
break;
|
||||
}
|
||||
update_tree_entry(&desc);
|
||||
@ -229,9 +229,9 @@ static int splice_tree(const unsigned char *hash1,
|
||||
* other hand, it could cover tree one and we might need to pick a
|
||||
* subtree of it.
|
||||
*/
|
||||
void shift_tree(const unsigned char *hash1,
|
||||
const unsigned char *hash2,
|
||||
unsigned char *shifted,
|
||||
void shift_tree(const struct object_id *hash1,
|
||||
const struct object_id *hash2,
|
||||
struct object_id *shifted,
|
||||
int depth_limit)
|
||||
{
|
||||
char *add_prefix;
|
||||
@ -262,7 +262,7 @@ void shift_tree(const unsigned char *hash1,
|
||||
match_trees(hash2, hash1, &del_score, &del_prefix, "", depth_limit);
|
||||
|
||||
/* Assume we do not have to do any shifting */
|
||||
hashcpy(shifted, hash2);
|
||||
oidcpy(shifted, hash2);
|
||||
|
||||
if (add_score < del_score) {
|
||||
/* We need to pick a subtree of two */
|
||||
@ -271,16 +271,16 @@ void shift_tree(const unsigned char *hash1,
|
||||
if (!*del_prefix)
|
||||
return;
|
||||
|
||||
if (get_tree_entry(hash2, del_prefix, shifted, &mode))
|
||||
if (get_tree_entry(hash2->hash, del_prefix, shifted->hash, &mode))
|
||||
die("cannot find path %s in tree %s",
|
||||
del_prefix, sha1_to_hex(hash2));
|
||||
del_prefix, oid_to_hex(hash2));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!*add_prefix)
|
||||
return;
|
||||
|
||||
splice_tree(hash1, add_prefix, hash2, shifted);
|
||||
splice_tree(hash1->hash, add_prefix, hash2->hash, shifted->hash);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -288,22 +288,22 @@ void shift_tree(const unsigned char *hash1,
|
||||
* Unfortunately we cannot fundamentally tell which one to
|
||||
* be prefixed, as recursive merge can work in either direction.
|
||||
*/
|
||||
void shift_tree_by(const unsigned char *hash1,
|
||||
const unsigned char *hash2,
|
||||
unsigned char *shifted,
|
||||
void shift_tree_by(const struct object_id *hash1,
|
||||
const struct object_id *hash2,
|
||||
struct object_id *shifted,
|
||||
const char *shift_prefix)
|
||||
{
|
||||
unsigned char sub1[20], sub2[20];
|
||||
struct object_id sub1, sub2;
|
||||
unsigned mode1, mode2;
|
||||
unsigned candidate = 0;
|
||||
|
||||
/* Can hash2 be a tree at shift_prefix in tree hash1? */
|
||||
if (!get_tree_entry(hash1, shift_prefix, sub1, &mode1) &&
|
||||
if (!get_tree_entry(hash1->hash, shift_prefix, sub1.hash, &mode1) &&
|
||||
S_ISDIR(mode1))
|
||||
candidate |= 1;
|
||||
|
||||
/* Can hash1 be a tree at shift_prefix in tree hash2? */
|
||||
if (!get_tree_entry(hash2, shift_prefix, sub2, &mode2) &&
|
||||
if (!get_tree_entry(hash2->hash, shift_prefix, sub2.hash, &mode2) &&
|
||||
S_ISDIR(mode2))
|
||||
candidate |= 2;
|
||||
|
||||
@ -313,19 +313,19 @@ void shift_tree_by(const unsigned char *hash1,
|
||||
int score;
|
||||
|
||||
candidate = 0;
|
||||
score = score_trees(sub1, hash2);
|
||||
score = score_trees(&sub1, hash2);
|
||||
if (score > best_score) {
|
||||
candidate = 1;
|
||||
best_score = score;
|
||||
}
|
||||
score = score_trees(sub2, hash1);
|
||||
score = score_trees(&sub2, hash1);
|
||||
if (score > best_score)
|
||||
candidate = 2;
|
||||
}
|
||||
|
||||
if (!candidate) {
|
||||
/* Neither is plausible -- do not shift */
|
||||
hashcpy(shifted, hash2);
|
||||
oidcpy(shifted, hash2);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -334,11 +334,11 @@ void shift_tree_by(const unsigned char *hash1,
|
||||
* shift tree2 down by adding shift_prefix above it
|
||||
* to match tree1.
|
||||
*/
|
||||
splice_tree(hash1, shift_prefix, hash2, shifted);
|
||||
splice_tree(hash1->hash, shift_prefix, hash2->hash, shifted->hash);
|
||||
else
|
||||
/*
|
||||
* shift tree2 up by removing shift_prefix from it
|
||||
* to match tree1.
|
||||
*/
|
||||
hashcpy(shifted, sub2);
|
||||
oidcpy(shifted, &sub2);
|
||||
}
|
||||
|
@ -29,9 +29,9 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
|
||||
struct object_id shifted;
|
||||
|
||||
if (!*subtree_shift) {
|
||||
shift_tree(one->object.oid.hash, two->object.oid.hash, shifted.hash, 0);
|
||||
shift_tree(&one->object.oid, &two->object.oid, &shifted, 0);
|
||||
} else {
|
||||
shift_tree_by(one->object.oid.hash, two->object.oid.hash, shifted.hash,
|
||||
shift_tree_by(&one->object.oid, &two->object.oid, &shifted,
|
||||
subtree_shift);
|
||||
}
|
||||
if (!oidcmp(&two->object.oid, &shifted))
|
||||
|
4
notes.c
4
notes.c
@ -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 @@ handle_non_note:
|
||||
}
|
||||
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 */
|
||||
|
@ -1214,6 +1214,15 @@ int get_sha1(const char *name, unsigned char *sha1)
|
||||
return get_sha1_with_context(name, 0, sha1, &unused);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is like "get_sha1()", but for struct object_id.
|
||||
*/
|
||||
int get_oid(const char *name, struct object_id *oid)
|
||||
{
|
||||
return get_sha1(name, oid->hash);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Many callers know that the user meant to name a commit-ish by
|
||||
* syntactical positions where the object name appears. Calling this
|
||||
|
@ -3,24 +3,24 @@
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
unsigned char hash1[20], hash2[20], shifted[20];
|
||||
struct object_id hash1, hash2, shifted;
|
||||
struct tree *one, *two;
|
||||
|
||||
setup_git_directory();
|
||||
|
||||
if (get_sha1(av[1], hash1))
|
||||
if (get_oid(av[1], &hash1))
|
||||
die("cannot parse %s as an object name", av[1]);
|
||||
if (get_sha1(av[2], hash2))
|
||||
if (get_oid(av[2], &hash2))
|
||||
die("cannot parse %s as an object name", av[2]);
|
||||
one = parse_tree_indirect(hash1);
|
||||
one = parse_tree_indirect(hash1.hash);
|
||||
if (!one)
|
||||
die("not a tree-ish %s", av[1]);
|
||||
two = parse_tree_indirect(hash2);
|
||||
two = parse_tree_indirect(hash2.hash);
|
||||
if (!two)
|
||||
die("not a tree-ish %s", av[2]);
|
||||
|
||||
shift_tree(one->object.oid.hash, two->object.oid.hash, shifted, -1);
|
||||
printf("shifted: %s\n", sha1_to_hex(shifted));
|
||||
shift_tree(&one->object.oid, &two->object.oid, &shifted, -1);
|
||||
printf("shifted: %s\n", oid_to_hex(&shifted));
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
|
||||
|
||||
if (t) {
|
||||
/* path present in resulting tree */
|
||||
sha1 = tree_entry_extract(t, &path, &mode);
|
||||
sha1 = tree_entry_extract(t, &path, &mode)->hash;
|
||||
pathlen = tree_entry_len(&t->entry);
|
||||
isdir = S_ISDIR(mode);
|
||||
} else {
|
||||
@ -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;
|
||||
|
||||
|
16
tree-walk.c
16
tree-walk.c
@ -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;
|
||||
}
|
||||
@ -433,10 +433,10 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
|
||||
int namelen = strlen(name);
|
||||
while (t->size) {
|
||||
const char *entry;
|
||||
const unsigned char *sha1;
|
||||
const struct object_id *oid;
|
||||
int entrylen, cmp;
|
||||
|
||||
sha1 = tree_entry_extract(t, &entry, mode);
|
||||
oid = tree_entry_extract(t, &entry, mode);
|
||||
entrylen = tree_entry_len(&t->entry);
|
||||
update_tree_entry(t);
|
||||
if (entrylen > namelen)
|
||||
@ -447,7 +447,7 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
|
||||
if (cmp < 0)
|
||||
break;
|
||||
if (entrylen == namelen) {
|
||||
hashcpy(result, sha1);
|
||||
hashcpy(result, oid->hash);
|
||||
return 0;
|
||||
}
|
||||
if (name[entrylen] != '/')
|
||||
@ -455,10 +455,10 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
|
||||
if (!S_ISDIR(*mode))
|
||||
break;
|
||||
if (++entrylen == namelen) {
|
||||
hashcpy(result, sha1);
|
||||
hashcpy(result, oid->hash);
|
||||
return 0;
|
||||
}
|
||||
return get_tree_entry(sha1, name + entrylen, result, mode);
|
||||
return get_tree_entry(oid->hash, name + entrylen, result, mode);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
@ -13,16 +13,16 @@ struct tree_desc {
|
||||
unsigned int size;
|
||||
};
|
||||
|
||||
static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)
|
||||
static inline const struct object_id *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)
|
||||
{
|
||||
*pathp = desc->entry.path;
|
||||
*modep = desc->entry.mode;
|
||||
return desc->entry.sha1;
|
||||
return desc->entry.oid;
|
||||
}
|
||||
|
||||
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 *);
|
||||
|
10
tree.c
10
tree.c
@ -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;
|
||||
|
4
walker.c
4
walker.c
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user