Skip to content

Commit b1081e4

Browse files
committed
Merge branch 'bc/object-id'
Conversion from unsigned char [40] to struct object_id continues. * bc/object-id: Documentation: update and rename api-sha1-array.txt Rename sha1_array to oid_array Convert sha1_array_for_each_unique and for_each_abbrev to object_id Convert sha1_array_lookup to take struct object_id Convert remaining callers of sha1_array_lookup to object_id Make sha1_array_append take a struct object_id * sha1-array: convert internal storage for struct sha1_array to object_id builtin/pull: convert to struct object_id submodule: convert check_for_new_submodule_commits to object_id sha1_name: convert disambiguate_hint_fn to take object_id sha1_name: convert struct disambiguate_state to object_id test-sha1-array: convert most code to struct object_id parse-options-cb: convert sha1_array_append caller to struct object_id fsck: convert init_skiplist to struct object_id builtin/receive-pack: convert portions to struct object_id builtin/pull: convert portions to struct object_id builtin/diff: convert to struct object_id Convert GIT_SHA1_RAWSZ used for allocation to GIT_MAX_RAWSZ Convert GIT_SHA1_HEXSZ used for allocation to GIT_MAX_HEXSZ Define new hash-size constants for allocating memory
2 parents c703555 + e239dab commit b1081e4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+459
-451
lines changed
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
sha1-array API
1+
oid-array API
22
==============
33

4-
The sha1-array API provides storage and manipulation of sets of SHA-1
4+
The oid-array API provides storage and manipulation of sets of object
55
identifiers. The emphasis is on storage and processing efficiency,
66
making them suitable for large lists. Note that the ordering of items is
77
not preserved over some operations.
88

99
Data Structures
1010
---------------
1111

12-
`struct sha1_array`::
12+
`struct oid_array`::
1313

14-
A single array of SHA-1 hashes. This should be initialized by
15-
assignment from `SHA1_ARRAY_INIT`. The `sha1` member contains
14+
A single array of object IDs. This should be initialized by
15+
assignment from `OID_ARRAY_INIT`. The `oid` member contains
1616
the actual data. The `nr` member contains the number of items in
1717
the set. The `alloc` and `sorted` members are used internally,
1818
and should not be needed by API callers.
1919

2020
Functions
2121
---------
2222

23-
`sha1_array_append`::
24-
Add an item to the set. The sha1 will be placed at the end of
23+
`oid_array_append`::
24+
Add an item to the set. The object ID will be placed at the end of
2525
the array (but note that some operations below may lose this
2626
ordering).
2727

28-
`sha1_array_lookup`::
29-
Perform a binary search of the array for a specific sha1.
28+
`oid_array_lookup`::
29+
Perform a binary search of the array for a specific object ID.
3030
If found, returns the offset (in number of elements) of the
31-
sha1. If not found, returns a negative integer. If the array is
32-
not sorted, this function has the side effect of sorting it.
31+
object ID. If not found, returns a negative integer. If the array
32+
is not sorted, this function has the side effect of sorting it.
3333

34-
`sha1_array_clear`::
34+
`oid_array_clear`::
3535
Free all memory associated with the array and return it to the
3636
initial, empty state.
3737

38-
`sha1_array_for_each_unique`::
38+
`oid_array_for_each_unique`::
3939
Efficiently iterate over each unique element of the list,
4040
executing the callback function for each one. If the array is
4141
not sorted, this function has the side effect of sorting it. If
@@ -47,25 +47,25 @@ Examples
4747
--------
4848

4949
-----------------------------------------
50-
int print_callback(const unsigned char sha1[20],
50+
int print_callback(const struct object_id *oid,
5151
void *data)
5252
{
53-
printf("%s\n", sha1_to_hex(sha1));
53+
printf("%s\n", oid_to_hex(oid));
5454
return 0; /* always continue */
5555
}
5656

5757
void some_func(void)
5858
{
59-
struct sha1_array hashes = SHA1_ARRAY_INIT;
60-
unsigned char sha1[20];
59+
struct sha1_array hashes = OID_ARRAY_INIT;
60+
struct object_id oid;
6161

6262
/* Read objects into our set */
63-
while (read_object_from_stdin(sha1))
64-
sha1_array_append(&hashes, sha1);
63+
while (read_object_from_stdin(oid.hash))
64+
oid_array_append(&hashes, &oid);
6565

6666
/* Check if some objects are in our set */
67-
while (read_object_from_stdin(sha1)) {
68-
if (sha1_array_lookup(&hashes, sha1) >= 0)
67+
while (read_object_from_stdin(oid.hash)) {
68+
if (oid_array_lookup(&hashes, &oid) >= 0)
6969
printf("it's in there!\n");
7070

7171
/*
@@ -75,6 +75,6 @@ void some_func(void)
7575
* Instead, this will sort once and then skip duplicates
7676
* in linear time.
7777
*/
78-
sha1_array_for_each_unique(&hashes, print_callback, NULL);
78+
oid_array_for_each_unique(&hashes, print_callback, NULL);
7979
}
8080
-----------------------------------------

bisect.c

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#include "sha1-array.h"
1313
#include "argv-array.h"
1414

15-
static struct sha1_array good_revs;
16-
static struct sha1_array skipped_revs;
15+
static struct oid_array good_revs;
16+
static struct oid_array skipped_revs;
1717

1818
static struct object_id *current_bad_oid;
1919

@@ -415,9 +415,9 @@ static int register_ref(const char *refname, const struct object_id *oid,
415415
current_bad_oid = xmalloc(sizeof(*current_bad_oid));
416416
oidcpy(current_bad_oid, oid);
417417
} else if (starts_with(refname, good_prefix.buf)) {
418-
sha1_array_append(&good_revs, oid->hash);
418+
oid_array_append(&good_revs, oid);
419419
} else if (starts_with(refname, "skip-")) {
420-
sha1_array_append(&skipped_revs, oid->hash);
420+
oid_array_append(&skipped_revs, oid);
421421
}
422422

423423
strbuf_release(&good_prefix);
@@ -453,13 +453,13 @@ static void read_bisect_paths(struct argv_array *array)
453453
fclose(fp);
454454
}
455455

456-
static char *join_sha1_array_hex(struct sha1_array *array, char delim)
456+
static char *join_sha1_array_hex(struct oid_array *array, char delim)
457457
{
458458
struct strbuf joined_hexs = STRBUF_INIT;
459459
int i;
460460

461461
for (i = 0; i < array->nr; i++) {
462-
strbuf_addstr(&joined_hexs, sha1_to_hex(array->sha1[i]));
462+
strbuf_addstr(&joined_hexs, oid_to_hex(array->oid + i));
463463
if (i + 1 < array->nr)
464464
strbuf_addch(&joined_hexs, delim);
465465
}
@@ -501,8 +501,7 @@ struct commit_list *filter_skipped(struct commit_list *list,
501501
while (list) {
502502
struct commit_list *next = list->next;
503503
list->next = NULL;
504-
if (0 <= sha1_array_lookup(&skipped_revs,
505-
list->item->object.oid.hash)) {
504+
if (0 <= oid_array_lookup(&skipped_revs, &list->item->object.oid)) {
506505
if (skipped_first && !*skipped_first)
507506
*skipped_first = 1;
508507
/* Move current to tried list */
@@ -623,7 +622,7 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
623622
argv_array_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid));
624623
for (i = 0; i < good_revs.nr; i++)
625624
argv_array_pushf(&rev_argv, good_format,
626-
sha1_to_hex(good_revs.sha1[i]));
625+
oid_to_hex(good_revs.oid + i));
627626
argv_array_push(&rev_argv, "--");
628627
if (read_paths)
629628
read_bisect_paths(&rev_argv);
@@ -684,7 +683,7 @@ static int is_expected_rev(const struct object_id *oid)
684683

685684
static int bisect_checkout(const unsigned char *bisect_rev, int no_checkout)
686685
{
687-
char bisect_rev_hex[GIT_SHA1_HEXSZ + 1];
686+
char bisect_rev_hex[GIT_MAX_HEXSZ + 1];
688687

689688
memcpy(bisect_rev_hex, sha1_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);
690689
update_ref(NULL, "BISECT_EXPECTED_REV", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);
@@ -703,11 +702,11 @@ static int bisect_checkout(const unsigned char *bisect_rev, int no_checkout)
703702
return run_command_v_opt(argv_show_branch, RUN_GIT_CMD);
704703
}
705704

706-
static struct commit *get_commit_reference(const unsigned char *sha1)
705+
static struct commit *get_commit_reference(const struct object_id *oid)
707706
{
708-
struct commit *r = lookup_commit_reference(sha1);
707+
struct commit *r = lookup_commit_reference(oid->hash);
709708
if (!r)
710-
die(_("Not a valid commit name %s"), sha1_to_hex(sha1));
709+
die(_("Not a valid commit name %s"), oid_to_hex(oid));
711710
return r;
712711
}
713712

@@ -717,9 +716,9 @@ static struct commit **get_bad_and_good_commits(int *rev_nr)
717716
int i, n = 0;
718717

719718
ALLOC_ARRAY(rev, 1 + good_revs.nr);
720-
rev[n++] = get_commit_reference(current_bad_oid->hash);
719+
rev[n++] = get_commit_reference(current_bad_oid);
721720
for (i = 0; i < good_revs.nr; i++)
722-
rev[n++] = get_commit_reference(good_revs.sha1[i]);
721+
rev[n++] = get_commit_reference(good_revs.oid + i);
723722
*rev_nr = n;
724723

725724
return rev;
@@ -756,9 +755,9 @@ static void handle_bad_merge_base(void)
756755
exit(1);
757756
}
758757

759-
static void handle_skipped_merge_base(const unsigned char *mb)
758+
static void handle_skipped_merge_base(const struct object_id *mb)
760759
{
761-
char *mb_hex = sha1_to_hex(mb);
760+
char *mb_hex = oid_to_hex(mb);
762761
char *bad_hex = oid_to_hex(current_bad_oid);
763762
char *good_hex = join_sha1_array_hex(&good_revs, ' ');
764763

@@ -789,16 +788,16 @@ static void check_merge_bases(int no_checkout)
789788
result = get_merge_bases_many(rev[0], rev_nr - 1, rev + 1);
790789

791790
for (; result; result = result->next) {
792-
const unsigned char *mb = result->item->object.oid.hash;
793-
if (!hashcmp(mb, current_bad_oid->hash)) {
791+
const struct object_id *mb = &result->item->object.oid;
792+
if (!oidcmp(mb, current_bad_oid)) {
794793
handle_bad_merge_base();
795-
} else if (0 <= sha1_array_lookup(&good_revs, mb)) {
794+
} else if (0 <= oid_array_lookup(&good_revs, mb)) {
796795
continue;
797-
} else if (0 <= sha1_array_lookup(&skipped_revs, mb)) {
796+
} else if (0 <= oid_array_lookup(&skipped_revs, mb)) {
798797
handle_skipped_merge_base(mb);
799798
} else {
800799
printf(_("Bisecting: a merge base must be tested\n"));
801-
exit(bisect_checkout(mb, no_checkout));
800+
exit(bisect_checkout(mb->hash, no_checkout));
802801
}
803802
}
804803

builtin/blame.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1890,7 +1890,7 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent,
18901890
int cnt;
18911891
const char *cp;
18921892
struct origin *suspect = ent->suspect;
1893-
char hex[GIT_SHA1_HEXSZ + 1];
1893+
char hex[GIT_MAX_HEXSZ + 1];
18941894

18951895
oid_to_hex_r(hex, &suspect->commit->object.oid);
18961896
printf("%s %d %d %d\n",
@@ -1928,7 +1928,7 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
19281928
const char *cp;
19291929
struct origin *suspect = ent->suspect;
19301930
struct commit_info ci;
1931-
char hex[GIT_SHA1_HEXSZ + 1];
1931+
char hex[GIT_MAX_HEXSZ + 1];
19321932
int show_raw_time = !!(opt & OUTPUT_RAW_TIMESTAMP);
19331933

19341934
get_commit_info(suspect->commit, &ci, 1);

builtin/cat-file.c

Lines changed: 7 additions & 7 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
}
@@ -413,7 +413,7 @@ static int batch_loose_object(const struct object_id *oid,
413413
const char *path,
414414
void *data)
415415
{
416-
sha1_array_append(data, oid->hash);
416+
oid_array_append(data, oid);
417417
return 0;
418418
}
419419

@@ -422,7 +422,7 @@ static int batch_packed_object(const struct object_id *oid,
422422
uint32_t pos,
423423
void *data)
424424
{
425-
sha1_array_append(data, oid->hash);
425+
oid_array_append(data, oid);
426426
return 0;
427427
}
428428

@@ -462,17 +462,17 @@ static int batch_objects(struct batch_options *opt)
462462
data.info.typep = &data.type;
463463

464464
if (opt->all_objects) {
465-
struct sha1_array sa = SHA1_ARRAY_INIT;
465+
struct oid_array sa = OID_ARRAY_INIT;
466466
struct object_cb_data cb;
467467

468468
for_each_loose_object(batch_loose_object, &sa, 0);
469469
for_each_packed_object(batch_packed_object, &sa, 0);
470470

471471
cb.opt = opt;
472472
cb.expand = &data;
473-
sha1_array_for_each_unique(&sa, batch_object_cb, &cb);
473+
oid_array_for_each_unique(&sa, batch_object_cb, &cb);
474474

475-
sha1_array_clear(&sa);
475+
oid_array_clear(&sa);
476476
return 0;
477477
}
478478

0 commit comments

Comments
 (0)