match-trees: convert splice_tree to object_id
Convert the definition of static recursive splice_tree function to use struct object_id and adjust single caller. Signed-off-by: Patryk Obara <patryk.obara@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
97a41a0c01
commit
3b34934dca
@ -158,22 +158,20 @@ static void match_trees(const struct object_id *hash1,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A tree "hash1" has a subdirectory at "prefix". Come up with a
|
* A tree "oid1" has a subdirectory at "prefix". Come up with a tree object by
|
||||||
* tree object by replacing it with another tree "hash2".
|
* replacing it with another tree "oid2".
|
||||||
*/
|
*/
|
||||||
static int splice_tree(const unsigned char *hash1,
|
static int splice_tree(const struct object_id *oid1, const char *prefix,
|
||||||
const char *prefix,
|
const struct object_id *oid2, struct object_id *result)
|
||||||
const unsigned char *hash2,
|
|
||||||
unsigned char *result)
|
|
||||||
{
|
{
|
||||||
char *subpath;
|
char *subpath;
|
||||||
int toplen;
|
int toplen;
|
||||||
char *buf;
|
char *buf;
|
||||||
unsigned long sz;
|
unsigned long sz;
|
||||||
struct tree_desc desc;
|
struct tree_desc desc;
|
||||||
unsigned char *rewrite_here;
|
struct object_id *rewrite_here;
|
||||||
const unsigned char *rewrite_with;
|
const struct object_id *rewrite_with;
|
||||||
unsigned char subtree[20];
|
struct object_id subtree;
|
||||||
enum object_type type;
|
enum object_type type;
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
@ -182,9 +180,9 @@ static int splice_tree(const unsigned char *hash1,
|
|||||||
if (*subpath)
|
if (*subpath)
|
||||||
subpath++;
|
subpath++;
|
||||||
|
|
||||||
buf = read_sha1_file(hash1, &type, &sz);
|
buf = read_sha1_file(oid1->hash, &type, &sz);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
die("cannot read tree %s", sha1_to_hex(hash1));
|
die("cannot read tree %s", oid_to_hex(oid1));
|
||||||
init_tree_desc(&desc, buf, sz);
|
init_tree_desc(&desc, buf, sz);
|
||||||
|
|
||||||
rewrite_here = NULL;
|
rewrite_here = NULL;
|
||||||
@ -197,26 +195,26 @@ static int splice_tree(const unsigned char *hash1,
|
|||||||
if (strlen(name) == toplen &&
|
if (strlen(name) == toplen &&
|
||||||
!memcmp(name, prefix, toplen)) {
|
!memcmp(name, prefix, toplen)) {
|
||||||
if (!S_ISDIR(mode))
|
if (!S_ISDIR(mode))
|
||||||
die("entry %s in tree %s is not a tree",
|
die("entry %s in tree %s is not a tree", name,
|
||||||
name, sha1_to_hex(hash1));
|
oid_to_hex(oid1));
|
||||||
rewrite_here = (unsigned char *) oid->hash;
|
rewrite_here = (struct object_id *)oid;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
update_tree_entry(&desc);
|
update_tree_entry(&desc);
|
||||||
}
|
}
|
||||||
if (!rewrite_here)
|
if (!rewrite_here)
|
||||||
die("entry %.*s not found in tree %s",
|
die("entry %.*s not found in tree %s", toplen, prefix,
|
||||||
toplen, prefix, sha1_to_hex(hash1));
|
oid_to_hex(oid1));
|
||||||
if (*subpath) {
|
if (*subpath) {
|
||||||
status = splice_tree(rewrite_here, subpath, hash2, subtree);
|
status = splice_tree(rewrite_here, subpath, oid2, &subtree);
|
||||||
if (status)
|
if (status)
|
||||||
return status;
|
return status;
|
||||||
rewrite_with = subtree;
|
rewrite_with = &subtree;
|
||||||
|
} else {
|
||||||
|
rewrite_with = oid2;
|
||||||
}
|
}
|
||||||
else
|
oidcpy(rewrite_here, rewrite_with);
|
||||||
rewrite_with = hash2;
|
status = write_sha1_file(buf, sz, tree_type, result->hash);
|
||||||
hashcpy(rewrite_here, rewrite_with);
|
|
||||||
status = write_sha1_file(buf, sz, tree_type, result);
|
|
||||||
free(buf);
|
free(buf);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
@ -280,7 +278,7 @@ void shift_tree(const struct object_id *hash1,
|
|||||||
if (!*add_prefix)
|
if (!*add_prefix)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
splice_tree(hash1->hash, add_prefix, hash2->hash, shifted->hash);
|
splice_tree(hash1, add_prefix, hash2, shifted);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -334,7 +332,7 @@ void shift_tree_by(const struct object_id *hash1,
|
|||||||
* shift tree2 down by adding shift_prefix above it
|
* shift tree2 down by adding shift_prefix above it
|
||||||
* to match tree1.
|
* to match tree1.
|
||||||
*/
|
*/
|
||||||
splice_tree(hash1->hash, shift_prefix, hash2->hash, shifted->hash);
|
splice_tree(hash1, shift_prefix, hash2, shifted);
|
||||||
else
|
else
|
||||||
/*
|
/*
|
||||||
* shift tree2 up by removing shift_prefix from it
|
* shift tree2 up by removing shift_prefix from it
|
||||||
|
Loading…
Reference in New Issue
Block a user