commit-graph: use string-list API for input
Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Jun 27, 2018 at 09:24 UTC
d88b14b3fd691fc71c3cea5bc5bde9dd10b5e86c
3 files changed
+23
-38
builtin/commit-graph.c
+13
-26
@@ -119,13 +119,9 @@ static int graph_read(int argc, const char **argv)
119
120
static int graph_write(int argc, const char **argv)
121
{
122
- const char **pack_indexes = NULL;
123
- int packs_nr = 0;
124
- const char **commit_hex = NULL;
125
- int commits_nr = 0;
126
- const char **lines = NULL;
127
- int lines_nr = 0;
128
- int lines_alloc = 0;
122
+ struct string_list *pack_indexes = NULL;
123
+ struct string_list *commit_hex = NULL;
124
+ struct string_list lines;
125
126
static struct option builtin_commit_graph_write_options[] = {
127
OPT_STRING(0, "object-dir", &opts.obj_dir,
@@ -149,34 +145,25 @@ static int graph_write(int argc, const char **argv)
145
if (!opts.obj_dir)
146
opts.obj_dir = get_object_directory();
147
148
+ string_list_init(&lines, 0);
149
if (opts.stdin_packs || opts.stdin_commits) {
150
struct strbuf buf = STRBUF_INIT;
154
- lines_nr = 0;
155
- lines_alloc = 128;
156
- ALLOC_ARRAY(lines, lines_alloc);
157
-
158
- while (strbuf_getline(&buf, stdin) != EOF) {
159
- ALLOC_GROW(lines, lines_nr + 1, lines_alloc);
160
- lines[lines_nr++] = strbuf_detach(&buf, NULL);
161
- }
162
-
163
- if (opts.stdin_packs) {
164
- pack_indexes = lines;
165
- packs_nr = lines_nr;
166
- }
167
- if (opts.stdin_commits) {
168
- commit_hex = lines;
169
- commits_nr = lines_nr;
170
- }
151
+
152
+ while (strbuf_getline(&buf, stdin) != EOF)
153
+ string_list_append(&lines, strbuf_detach(&buf, NULL));
154
+
155
+ if (opts.stdin_packs)
156
+ pack_indexes = &lines;
157
+ if (opts.stdin_commits)
158
+ commit_hex = &lines;
159
}
160
161
write_commit_graph(opts.obj_dir,
162
pack_indexes,
175
- packs_nr,
163
commit_hex,
177
- commits_nr,
164
opts.append);
165
166
+ string_list_clear(&lines, 0);
167
return 0;
168
}
169
commit-graph.c
+7
-8
@@ -657,10 +657,8 @@ static void compute_generation_numbers(struct packed_commit_list* commits)
657
}
658
659
void write_commit_graph(const char *obj_dir,
660
- const char **pack_indexes,
661
- int nr_packs,
662
- const char **commit_hex,
663
- int nr_commits,
660
+ struct string_list *pack_indexes,
661
+ struct string_list *commit_hex,
662
int append)
663
{
664
struct packed_oid_list oids;
@@ -701,10 +699,10 @@ void write_commit_graph(const char *obj_dir,
699
int dirlen;
700
strbuf_addf(&packname, "%s/pack/", obj_dir);
701
dirlen = packname.len;
704
- for (i = 0; i < nr_packs; i++) {
702
+ for (i = 0; i < pack_indexes->nr; i++) {
703
struct packed_git *p;
704
strbuf_setlen(&packname, dirlen);
707
- strbuf_addstr(&packname, pack_indexes[i]);
705
+ strbuf_addstr(&packname, pack_indexes->items[i].string);
706
p = add_packed_git(packname.buf, packname.len, 1);
707
if (!p)
708
die("error adding pack %s", packname.buf);
@@ -717,12 +715,13 @@ void write_commit_graph(const char *obj_dir,
715
}
716
717
if (commit_hex) {
720
- for (i = 0; i < nr_commits; i++) {
718
+ for (i = 0; i < commit_hex->nr; i++) {
719
const char *end;
720
struct object_id oid;
721
struct commit *result;
722
725
- if (commit_hex[i] && parse_oid_hex(commit_hex[i], &oid, &end))
723
+ if (commit_hex->items[i].string &&
724
+ parse_oid_hex(commit_hex->items[i].string, &oid, &end))
725
continue;
726
727
result = lookup_commit_reference_gently(&oid, 1);
commit-graph.h
+3
-4
@@ -3,6 +3,7 @@
3
4
#include "git-compat-util.h"
5
#include "repository.h"
6
+#include "string-list.h"
7
8
char *get_commit_graph_filename(const char *obj_dir);
9
@@ -48,10 +49,8 @@ struct commit_graph {
49
struct commit_graph *load_commit_graph_one(const char *graph_file);
50
51
void write_commit_graph(const char *obj_dir,
51
- const char **pack_indexes,
52
- int nr_packs,
53
- const char **commit_hex,
54
- int nr_commits,
52
+ struct string_list *pack_indexes,
53
+ struct string_list *commit_hex,
54
int append);
55
56
int verify_commit_graph(struct repository *r, struct commit_graph *g);