Skip to content

Commit 3b34934

Browse files
dreamergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 97a41a0 commit 3b34934

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

match-trees.c

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,20 @@ static void match_trees(const struct object_id *hash1,
158158
}
159159

160160
/*
161-
* A tree "hash1" has a subdirectory at "prefix". Come up with a
162-
* tree object by replacing it with another tree "hash2".
161+
* A tree "oid1" has a subdirectory at "prefix". Come up with a tree object by
162+
* replacing it with another tree "oid2".
163163
*/
164-
static int splice_tree(const unsigned char *hash1,
165-
const char *prefix,
166-
const unsigned char *hash2,
167-
unsigned char *result)
164+
static int splice_tree(const struct object_id *oid1, const char *prefix,
165+
const struct object_id *oid2, struct object_id *result)
168166
{
169167
char *subpath;
170168
int toplen;
171169
char *buf;
172170
unsigned long sz;
173171
struct tree_desc desc;
174-
unsigned char *rewrite_here;
175-
const unsigned char *rewrite_with;
176-
unsigned char subtree[20];
172+
struct object_id *rewrite_here;
173+
const struct object_id *rewrite_with;
174+
struct object_id subtree;
177175
enum object_type type;
178176
int status;
179177

@@ -182,9 +180,9 @@ static int splice_tree(const unsigned char *hash1,
182180
if (*subpath)
183181
subpath++;
184182

185-
buf = read_sha1_file(hash1, &type, &sz);
183+
buf = read_sha1_file(oid1->hash, &type, &sz);
186184
if (!buf)
187-
die("cannot read tree %s", sha1_to_hex(hash1));
185+
die("cannot read tree %s", oid_to_hex(oid1));
188186
init_tree_desc(&desc, buf, sz);
189187

190188
rewrite_here = NULL;
@@ -197,26 +195,26 @@ static int splice_tree(const unsigned char *hash1,
197195
if (strlen(name) == toplen &&
198196
!memcmp(name, prefix, toplen)) {
199197
if (!S_ISDIR(mode))
200-
die("entry %s in tree %s is not a tree",
201-
name, sha1_to_hex(hash1));
202-
rewrite_here = (unsigned char *) oid->hash;
198+
die("entry %s in tree %s is not a tree", name,
199+
oid_to_hex(oid1));
200+
rewrite_here = (struct object_id *)oid;
203201
break;
204202
}
205203
update_tree_entry(&desc);
206204
}
207205
if (!rewrite_here)
208-
die("entry %.*s not found in tree %s",
209-
toplen, prefix, sha1_to_hex(hash1));
206+
die("entry %.*s not found in tree %s", toplen, prefix,
207+
oid_to_hex(oid1));
210208
if (*subpath) {
211-
status = splice_tree(rewrite_here, subpath, hash2, subtree);
209+
status = splice_tree(rewrite_here, subpath, oid2, &subtree);
212210
if (status)
213211
return status;
214-
rewrite_with = subtree;
212+
rewrite_with = &subtree;
213+
} else {
214+
rewrite_with = oid2;
215215
}
216-
else
217-
rewrite_with = hash2;
218-
hashcpy(rewrite_here, rewrite_with);
219-
status = write_sha1_file(buf, sz, tree_type, result);
216+
oidcpy(rewrite_here, rewrite_with);
217+
status = write_sha1_file(buf, sz, tree_type, result->hash);
220218
free(buf);
221219
return status;
222220
}
@@ -280,7 +278,7 @@ void shift_tree(const struct object_id *hash1,
280278
if (!*add_prefix)
281279
return;
282280

283-
splice_tree(hash1->hash, add_prefix, hash2->hash, shifted->hash);
281+
splice_tree(hash1, add_prefix, hash2, shifted);
284282
}
285283

286284
/*
@@ -334,7 +332,7 @@ void shift_tree_by(const struct object_id *hash1,
334332
* shift tree2 down by adding shift_prefix above it
335333
* to match tree1.
336334
*/
337-
splice_tree(hash1->hash, shift_prefix, hash2->hash, shifted->hash);
335+
splice_tree(hash1, shift_prefix, hash2, shifted);
338336
else
339337
/*
340338
* shift tree2 up by removing shift_prefix from it

0 commit comments

Comments
 (0)