Skip to content

Commit d88b14b

Browse files
derrickstoleegitster
authored andcommitted
commit-graph: use string-list API for input
Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e0fd51e commit d88b14b

File tree

3 files changed

+23
-38
lines changed

3 files changed

+23
-38
lines changed

builtin/commit-graph.c

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,9 @@ static int graph_read(int argc, const char **argv)
119119

120120
static int graph_write(int argc, const char **argv)
121121
{
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;
129125

130126
static struct option builtin_commit_graph_write_options[] = {
131127
OPT_STRING(0, "object-dir", &opts.obj_dir,
@@ -149,34 +145,25 @@ static int graph_write(int argc, const char **argv)
149145
if (!opts.obj_dir)
150146
opts.obj_dir = get_object_directory();
151147

148+
string_list_init(&lines, 0);
152149
if (opts.stdin_packs || opts.stdin_commits) {
153150
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;
171159
}
172160

173161
write_commit_graph(opts.obj_dir,
174162
pack_indexes,
175-
packs_nr,
176163
commit_hex,
177-
commits_nr,
178164
opts.append);
179165

166+
string_list_clear(&lines, 0);
180167
return 0;
181168
}
182169

commit-graph.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -657,10 +657,8 @@ static void compute_generation_numbers(struct packed_commit_list* commits)
657657
}
658658

659659
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,
664662
int append)
665663
{
666664
struct packed_oid_list oids;
@@ -701,10 +699,10 @@ void write_commit_graph(const char *obj_dir,
701699
int dirlen;
702700
strbuf_addf(&packname, "%s/pack/", obj_dir);
703701
dirlen = packname.len;
704-
for (i = 0; i < nr_packs; i++) {
702+
for (i = 0; i < pack_indexes->nr; i++) {
705703
struct packed_git *p;
706704
strbuf_setlen(&packname, dirlen);
707-
strbuf_addstr(&packname, pack_indexes[i]);
705+
strbuf_addstr(&packname, pack_indexes->items[i].string);
708706
p = add_packed_git(packname.buf, packname.len, 1);
709707
if (!p)
710708
die("error adding pack %s", packname.buf);
@@ -717,12 +715,13 @@ void write_commit_graph(const char *obj_dir,
717715
}
718716

719717
if (commit_hex) {
720-
for (i = 0; i < nr_commits; i++) {
718+
for (i = 0; i < commit_hex->nr; i++) {
721719
const char *end;
722720
struct object_id oid;
723721
struct commit *result;
724722

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))
726725
continue;
727726

728727
result = lookup_commit_reference_gently(&oid, 1);

commit-graph.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include "git-compat-util.h"
55
#include "repository.h"
6+
#include "string-list.h"
67

78
char *get_commit_graph_filename(const char *obj_dir);
89

@@ -48,10 +49,8 @@ struct commit_graph {
4849
struct commit_graph *load_commit_graph_one(const char *graph_file);
4950

5051
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,
5554
int append);
5655

5756
int verify_commit_graph(struct repository *r, struct commit_graph *g);

0 commit comments

Comments
 (0)