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>

Patryk Obara committed Jan 28, 2018 at 01:13 UTC 3b34934dcaa4e643a3691ba1f10db054adf60ffb
1 file changed +22 -24
match-trees.c
+22 -24
@@ -158,22 +158,20 @@ static void match_trees(const struct object_id *hash1,
158 }
159
160 /*
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".
163 */
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)
166 {
167 char *subpath;
168 int toplen;
169 char *buf;
170 unsigned long sz;
171 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;
175 enum object_type type;
176 int status;
177
@@ -182,9 +180,9 @@ static int splice_tree(const unsigned char *hash1,
180 if (*subpath)
181 subpath++;
182
185 - buf = read_sha1_file(hash1, &type, &sz);
183 + buf = read_sha1_file(oid1->hash, &type, &sz);
184 if (!buf)
187 - die("cannot read tree %s", sha1_to_hex(hash1));
185 + die("cannot read tree %s", oid_to_hex(oid1));
186 init_tree_desc(&desc, buf, sz);
187
188 rewrite_here = NULL;
@@ -197,26 +195,26 @@ static int splice_tree(const unsigned char *hash1,
195 if (strlen(name) == toplen &&
196 !memcmp(name, prefix, toplen)) {
197 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;
201 break;
202 }
203 update_tree_entry(&desc);
204 }
205 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));
208 if (*subpath) {
211 - status = splice_tree(rewrite_here, subpath, hash2, subtree);
209 + status = splice_tree(rewrite_here, subpath, oid2, &subtree);
210 if (status)
211 return status;
214 - rewrite_with = subtree;
212 + rewrite_with = &subtree;
213 + } else {
214 + rewrite_with = oid2;
215 }
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);
218 free(buf);
219 return status;
220 }
@@ -280,7 +278,7 @@ void shift_tree(const struct object_id *hash1,
278 if (!*add_prefix)
279 return;
280
283 - splice_tree(hash1->hash, add_prefix, hash2->hash, shifted->hash);
281 + splice_tree(hash1, add_prefix, hash2, shifted);
282 }
283
284 /*
@@ -334,7 +332,7 @@ void shift_tree_by(const struct object_id *hash1,
332 * shift tree2 down by adding shift_prefix above it
333 * to match tree1.
334 */
337 - splice_tree(hash1->hash, shift_prefix, hash2->hash, shifted->hash);
335 + splice_tree(hash1, shift_prefix, hash2, shifted);
336 else
337 /*
338 * shift tree2 up by removing shift_prefix from it