walker: convert to struct object_id
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Oct 15, 2017 at 22:06 UTC
94f5a121d4816969fc00a17411a30d15d80d21e9
1 file changed
+12
-12
walker.c
+12
-12
@@ -7,7 +7,7 @@
7
#include "blob.h"
8
#include "refs.h"
9
10
-static unsigned char current_commit_sha1[20];
10
+static struct object_id current_commit_oid;
11
12
void walker_say(struct walker *walker, const char *fmt, ...)
13
{
@@ -24,9 +24,9 @@ static void report_missing(const struct object *obj)
24
fprintf(stderr, "Cannot obtain needed %s %s\n",
25
obj->type ? typename(obj->type): "object",
26
oid_to_hex(&obj->oid));
27
- if (!is_null_sha1(current_commit_sha1))
27
+ if (!is_null_oid(¤t_commit_oid))
28
fprintf(stderr, "while processing commit %s.\n",
29
- sha1_to_hex(current_commit_sha1));
29
+ oid_to_hex(¤t_commit_oid));
30
}
31
32
static int process(struct walker *walker, struct object *obj);
@@ -82,7 +82,7 @@ static int process_commit(struct walker *walker, struct commit *commit)
82
if (commit->object.flags & COMPLETE)
83
return 0;
84
85
- hashcpy(current_commit_sha1, commit->object.oid.hash);
85
+ oidcpy(¤t_commit_oid, &commit->object.oid);
86
87
walker_say(walker, "walk %s\n", oid_to_hex(&commit->object.oid));
88
@@ -187,14 +187,14 @@ static int loop(struct walker *walker)
187
return 0;
188
}
189
190
-static int interpret_target(struct walker *walker, char *target, unsigned char *sha1)
190
+static int interpret_target(struct walker *walker, char *target, struct object_id *oid)
191
{
192
- if (!get_sha1_hex(target, sha1))
192
+ if (!get_oid_hex(target, oid))
193
return 0;
194
if (!check_refname_format(target, 0)) {
195
struct ref *ref = alloc_ref(target);
196
if (!walker->fetch_ref(walker, ref)) {
197
- hashcpy(sha1, ref->old_oid.hash);
197
+ oidcpy(oid, &ref->old_oid);
198
free(ref);
199
return 0;
200
}
@@ -259,7 +259,7 @@ int walker_fetch(struct walker *walker, int targets, char **target,
259
struct strbuf refname = STRBUF_INIT;
260
struct strbuf err = STRBUF_INIT;
261
struct ref_transaction *transaction = NULL;
262
- unsigned char *sha1 = xmalloc(targets * 20);
262
+ struct object_id *oids = xmalloc(targets * sizeof(struct object_id));
263
char *msg = NULL;
264
int i, ret = -1;
265
@@ -279,11 +279,11 @@ int walker_fetch(struct walker *walker, int targets, char **target,
279
}
280
281
for (i = 0; i < targets; i++) {
282
- if (interpret_target(walker, target[i], &sha1[20 * i])) {
282
+ if (interpret_target(walker, target[i], oids + i)) {
283
error("Could not interpret response from server '%s' as something to pull", target[i]);
284
goto done;
285
}
286
- if (process(walker, lookup_unknown_object(&sha1[20 * i])))
286
+ if (process(walker, lookup_unknown_object(oids[i].hash)))
287
goto done;
288
}
289
@@ -304,7 +304,7 @@ int walker_fetch(struct walker *walker, int targets, char **target,
304
strbuf_reset(&refname);
305
strbuf_addf(&refname, "refs/%s", write_ref[i]);
306
if (ref_transaction_update(transaction, refname.buf,
307
- &sha1[20 * i], NULL, 0,
307
+ oids[i].hash, NULL, 0,
308
msg ? msg : "fetch (unknown)",
309
&err)) {
310
error("%s", err.buf);
@@ -321,7 +321,7 @@ int walker_fetch(struct walker *walker, int targets, char **target,
321
done:
322
ref_transaction_free(transaction);
323
free(msg);
324
- free(sha1);
324
+ free(oids);
325
strbuf_release(&err);
326
strbuf_release(&refname);
327
return ret;