Skip to content

Commit 1b7ba79

Browse files
bk2204gitster
authored andcommitted
Convert sha1_array_for_each_unique and for_each_abbrev to object_id
Make sha1_array_for_each_unique take a callback using struct object_id. Since one of these callbacks is an argument to for_each_abbrev, convert those as well. Rename various functions, replacing "sha1" with "oid". Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 5d3206d commit 1b7ba79

File tree

9 files changed

+35
-37
lines changed

9 files changed

+35
-37
lines changed

builtin/cat-file.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,10 +401,10 @@ struct object_cb_data {
401401
struct expand_data *expand;
402402
};
403403

404-
static int batch_object_cb(const unsigned char sha1[20], void *vdata)
404+
static int batch_object_cb(const struct object_id *oid, void *vdata)
405405
{
406406
struct object_cb_data *data = vdata;
407-
hashcpy(data->expand->oid.hash, sha1);
407+
oidcpy(&data->expand->oid, oid);
408408
batch_object_write(NULL, data->opt, data->expand);
409409
return 0;
410410
}

builtin/receive-pack.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ static int receive_pack_config(const char *var, const char *value, void *cb)
225225
return git_default_config(var, value, cb);
226226
}
227227

228-
static void show_ref(const char *path, const unsigned char *sha1)
228+
static void show_ref(const char *path, const struct object_id *oid)
229229
{
230230
if (sent_capabilities) {
231-
packet_write_fmt(1, "%s %s\n", sha1_to_hex(sha1), path);
231+
packet_write_fmt(1, "%s %s\n", oid_to_hex(oid), path);
232232
} else {
233233
struct strbuf cap = STRBUF_INIT;
234234

@@ -244,7 +244,7 @@ static void show_ref(const char *path, const unsigned char *sha1)
244244
strbuf_addstr(&cap, " push-options");
245245
strbuf_addf(&cap, " agent=%s", git_user_agent_sanitized());
246246
packet_write_fmt(1, "%s %s%c%s\n",
247-
sha1_to_hex(sha1), path, 0, cap.buf);
247+
oid_to_hex(oid), path, 0, cap.buf);
248248
strbuf_release(&cap);
249249
sent_capabilities = 1;
250250
}
@@ -271,7 +271,7 @@ static int show_ref_cb(const char *path_full, const struct object_id *oid,
271271
} else {
272272
oidset_insert(seen, oid);
273273
}
274-
show_ref(path, oid->hash);
274+
show_ref(path, oid);
275275
return 0;
276276
}
277277

@@ -284,7 +284,7 @@ static void show_one_alternate_ref(const char *refname,
284284
if (oidset_insert(seen, oid))
285285
return;
286286

287-
show_ref(".have", oid->hash);
287+
show_ref(".have", oid);
288288
}
289289

290290
static void write_head_info(void)
@@ -295,7 +295,7 @@ static void write_head_info(void)
295295
for_each_alternate_ref(show_one_alternate_ref, &seen);
296296
oidset_clear(&seen);
297297
if (!sent_capabilities)
298-
show_ref("capabilities^{}", null_sha1);
298+
show_ref("capabilities^{}", &null_oid);
299299

300300
advertise_shallow_grafts(1);
301301

builtin/rev-parse.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ static int anti_reference(const char *refname, const struct object_id *oid, int
205205
return 0;
206206
}
207207

208-
static int show_abbrev(const unsigned char *sha1, void *cb_data)
208+
static int show_abbrev(const struct object_id *oid, void *cb_data)
209209
{
210-
show_rev(NORMAL, sha1, NULL);
210+
show_rev(NORMAL, oid->hash, NULL);
211211
return 0;
212212
}
213213

cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char
13501350

13511351
extern int get_oid(const char *str, struct object_id *oid);
13521352

1353-
typedef int each_abbrev_fn(const unsigned char *sha1, void *);
1353+
typedef int each_abbrev_fn(const struct object_id *oid, void *);
13541354
extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
13551355

13561356
extern int set_disambiguate_hint_config(const char *var, const char *value);

sha1-array.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ void sha1_array_clear(struct sha1_array *array)
4343
}
4444

4545
int sha1_array_for_each_unique(struct sha1_array *array,
46-
for_each_sha1_fn fn,
46+
for_each_oid_fn fn,
4747
void *data)
4848
{
4949
int i;
@@ -55,7 +55,7 @@ int sha1_array_for_each_unique(struct sha1_array *array,
5555
int ret;
5656
if (i > 0 && !oidcmp(array->oid + i, array->oid + i - 1))
5757
continue;
58-
ret = fn(array->oid[i].hash, data);
58+
ret = fn(array->oid + i, data);
5959
if (ret)
6060
return ret;
6161
}

sha1-array.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ void sha1_array_append(struct sha1_array *array, const struct object_id *oid);
1414
int sha1_array_lookup(struct sha1_array *array, const struct object_id *oid);
1515
void sha1_array_clear(struct sha1_array *array);
1616

17-
typedef int (*for_each_sha1_fn)(const unsigned char sha1[20],
18-
void *data);
17+
typedef int (*for_each_oid_fn)(const struct object_id *oid,
18+
void *data);
1919
int sha1_array_for_each_unique(struct sha1_array *array,
20-
for_each_sha1_fn fn,
20+
for_each_oid_fn fn,
2121
void *data);
2222

2323
#endif /* SHA1_ARRAY_H */

sha1_name.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -342,34 +342,32 @@ static int init_object_disambiguation(const char *name, int len,
342342
return 0;
343343
}
344344

345-
static int show_ambiguous_object(const unsigned char *sha1, void *data)
345+
static int show_ambiguous_object(const struct object_id *oid, void *data)
346346
{
347347
const struct disambiguate_state *ds = data;
348-
struct object_id oid;
349348
struct strbuf desc = STRBUF_INIT;
350349
int type;
351350

352351

353-
hashcpy(oid.hash, sha1);
354-
if (ds->fn && !ds->fn(&oid, ds->cb_data))
352+
if (ds->fn && !ds->fn(oid, ds->cb_data))
355353
return 0;
356354

357-
type = sha1_object_info(sha1, NULL);
355+
type = sha1_object_info(oid->hash, NULL);
358356
if (type == OBJ_COMMIT) {
359-
struct commit *commit = lookup_commit(sha1);
357+
struct commit *commit = lookup_commit(oid->hash);
360358
if (commit) {
361359
struct pretty_print_context pp = {0};
362360
pp.date_mode.type = DATE_SHORT;
363361
format_commit_message(commit, " %ad - %s", &desc, &pp);
364362
}
365363
} else if (type == OBJ_TAG) {
366-
struct tag *tag = lookup_tag(sha1);
364+
struct tag *tag = lookup_tag(oid->hash);
367365
if (!parse_tag(tag) && tag->tag)
368366
strbuf_addf(&desc, " %s", tag->tag);
369367
}
370368

371369
advise(" %s %s%s",
372-
find_unique_abbrev(sha1, DEFAULT_ABBREV),
370+
find_unique_abbrev(oid->hash, DEFAULT_ABBREV),
373371
typename(type) ? typename(type) : "unknown type",
374372
desc.buf);
375373

submodule.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -551,18 +551,18 @@ static int has_remote(const char *refname, const struct object_id *oid,
551551
return 1;
552552
}
553553

554-
static int append_sha1_to_argv(const unsigned char sha1[20], void *data)
554+
static int append_oid_to_argv(const struct object_id *oid, void *data)
555555
{
556556
struct argv_array *argv = data;
557-
argv_array_push(argv, sha1_to_hex(sha1));
557+
argv_array_push(argv, oid_to_hex(oid));
558558
return 0;
559559
}
560560

561-
static int check_has_commit(const unsigned char sha1[20], void *data)
561+
static int check_has_commit(const struct object_id *oid, void *data)
562562
{
563563
int *has_commit = data;
564564

565-
if (!lookup_commit_reference(sha1))
565+
if (!lookup_commit_reference(oid->hash))
566566
*has_commit = 0;
567567

568568
return 0;
@@ -601,7 +601,7 @@ static int submodule_needs_pushing(const char *path, struct sha1_array *commits)
601601
int needs_pushing = 0;
602602

603603
argv_array_push(&cp.args, "rev-list");
604-
sha1_array_for_each_unique(commits, append_sha1_to_argv, &cp.args);
604+
sha1_array_for_each_unique(commits, append_oid_to_argv, &cp.args);
605605
argv_array_pushl(&cp.args, "--not", "--remotes", "-n", "1" , NULL);
606606

607607
prepare_submodule_repo_env(&cp.env_array);
@@ -687,7 +687,7 @@ int find_unpushed_submodules(struct sha1_array *commits,
687687

688688
/* argv.argv[0] will be ignored by setup_revisions */
689689
argv_array_push(&argv, "find_unpushed_submodules");
690-
sha1_array_for_each_unique(commits, append_sha1_to_argv, &argv);
690+
sha1_array_for_each_unique(commits, append_oid_to_argv, &argv);
691691
argv_array_push(&argv, "--not");
692692
argv_array_pushf(&argv, "--remotes=%s", remotes_name);
693693

@@ -831,9 +831,9 @@ void check_for_new_submodule_commits(struct object_id *oid)
831831
sha1_array_append(&ref_tips_after_fetch, oid);
832832
}
833833

834-
static int add_sha1_to_argv(const unsigned char sha1[20], void *data)
834+
static int add_oid_to_argv(const struct object_id *oid, void *data)
835835
{
836-
argv_array_push(data, sha1_to_hex(sha1));
836+
argv_array_push(data, oid_to_hex(oid));
837837
return 0;
838838
}
839839

@@ -850,10 +850,10 @@ static void calculate_changed_submodule_paths(void)
850850
init_revisions(&rev, NULL);
851851
argv_array_push(&argv, "--"); /* argv[0] program name */
852852
sha1_array_for_each_unique(&ref_tips_after_fetch,
853-
add_sha1_to_argv, &argv);
853+
add_oid_to_argv, &argv);
854854
argv_array_push(&argv, "--not");
855855
sha1_array_for_each_unique(&ref_tips_before_fetch,
856-
add_sha1_to_argv, &argv);
856+
add_oid_to_argv, &argv);
857857
setup_revisions(argv.argc, argv.argv, &rev, NULL);
858858
if (prepare_revision_walk(&rev))
859859
die("revision walk setup failed");

t/helper/test-sha1-array.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#include "cache.h"
22
#include "sha1-array.h"
33

4-
static int print_sha1(const unsigned char sha1[20], void *data)
4+
static int print_oid(const struct object_id *oid, void *data)
55
{
6-
puts(sha1_to_hex(sha1));
6+
puts(oid_to_hex(oid));
77
return 0;
88
}
99

@@ -27,7 +27,7 @@ int cmd_main(int argc, const char **argv)
2727
} else if (!strcmp(line.buf, "clear"))
2828
sha1_array_clear(&array);
2929
else if (!strcmp(line.buf, "for_each_unique"))
30-
sha1_array_for_each_unique(&array, print_sha1, NULL);
30+
sha1_array_for_each_unique(&array, print_oid, NULL);
3131
else
3232
die("unknown command: %s", line.buf);
3333
}

0 commit comments

Comments
 (0)