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>maint
							parent
							
								
									e0fd51e1d7
								
							
						
					
					
						commit
						d88b14b3fd
					
				|  | @ -119,13 +119,9 @@ static int graph_read(int argc, const char **argv) | ||||||
|  |  | ||||||
| static int graph_write(int argc, const char **argv) | static int graph_write(int argc, const char **argv) | ||||||
| { | { | ||||||
| 	const char **pack_indexes = NULL; | 	struct string_list *pack_indexes = NULL; | ||||||
| 	int packs_nr = 0; | 	struct string_list *commit_hex = NULL; | ||||||
| 	const char **commit_hex = NULL; | 	struct string_list lines; | ||||||
| 	int commits_nr = 0; |  | ||||||
| 	const char **lines = NULL; |  | ||||||
| 	int lines_nr = 0; |  | ||||||
| 	int lines_alloc = 0; |  | ||||||
|  |  | ||||||
| 	static struct option builtin_commit_graph_write_options[] = { | 	static struct option builtin_commit_graph_write_options[] = { | ||||||
| 		OPT_STRING(0, "object-dir", &opts.obj_dir, | 		OPT_STRING(0, "object-dir", &opts.obj_dir, | ||||||
|  | @ -149,34 +145,25 @@ static int graph_write(int argc, const char **argv) | ||||||
| 	if (!opts.obj_dir) | 	if (!opts.obj_dir) | ||||||
| 		opts.obj_dir = get_object_directory(); | 		opts.obj_dir = get_object_directory(); | ||||||
|  |  | ||||||
|  | 	string_list_init(&lines, 0); | ||||||
| 	if (opts.stdin_packs || opts.stdin_commits) { | 	if (opts.stdin_packs || opts.stdin_commits) { | ||||||
| 		struct strbuf buf = STRBUF_INIT; | 		struct strbuf buf = STRBUF_INIT; | ||||||
| 		lines_nr = 0; |  | ||||||
| 		lines_alloc = 128; |  | ||||||
| 		ALLOC_ARRAY(lines, lines_alloc); |  | ||||||
|  |  | ||||||
| 		while (strbuf_getline(&buf, stdin) != EOF) { | 		while (strbuf_getline(&buf, stdin) != EOF) | ||||||
| 			ALLOC_GROW(lines, lines_nr + 1, lines_alloc); | 			string_list_append(&lines, strbuf_detach(&buf, NULL)); | ||||||
| 			lines[lines_nr++] = strbuf_detach(&buf, NULL); |  | ||||||
| 		} |  | ||||||
|  |  | ||||||
| 		if (opts.stdin_packs) { | 		if (opts.stdin_packs) | ||||||
| 			pack_indexes = lines; | 			pack_indexes = &lines; | ||||||
| 			packs_nr = lines_nr; | 		if (opts.stdin_commits) | ||||||
| 		} | 			commit_hex = &lines; | ||||||
| 		if (opts.stdin_commits) { |  | ||||||
| 			commit_hex = lines; |  | ||||||
| 			commits_nr = lines_nr; |  | ||||||
| 		} |  | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	write_commit_graph(opts.obj_dir, | 	write_commit_graph(opts.obj_dir, | ||||||
| 			   pack_indexes, | 			   pack_indexes, | ||||||
| 			   packs_nr, |  | ||||||
| 			   commit_hex, | 			   commit_hex, | ||||||
| 			   commits_nr, |  | ||||||
| 			   opts.append); | 			   opts.append); | ||||||
|  |  | ||||||
|  | 	string_list_clear(&lines, 0); | ||||||
| 	return 0; | 	return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
|  | @ -657,10 +657,8 @@ static void compute_generation_numbers(struct packed_commit_list* commits) | ||||||
| } | } | ||||||
|  |  | ||||||
| void write_commit_graph(const char *obj_dir, | void write_commit_graph(const char *obj_dir, | ||||||
| 			const char **pack_indexes, | 			struct string_list *pack_indexes, | ||||||
| 			int nr_packs, | 			struct string_list *commit_hex, | ||||||
| 			const char **commit_hex, |  | ||||||
| 			int nr_commits, |  | ||||||
| 			int append) | 			int append) | ||||||
| { | { | ||||||
| 	struct packed_oid_list oids; | 	struct packed_oid_list oids; | ||||||
|  | @ -701,10 +699,10 @@ void write_commit_graph(const char *obj_dir, | ||||||
| 		int dirlen; | 		int dirlen; | ||||||
| 		strbuf_addf(&packname, "%s/pack/", obj_dir); | 		strbuf_addf(&packname, "%s/pack/", obj_dir); | ||||||
| 		dirlen = packname.len; | 		dirlen = packname.len; | ||||||
| 		for (i = 0; i < nr_packs; i++) { | 		for (i = 0; i < pack_indexes->nr; i++) { | ||||||
| 			struct packed_git *p; | 			struct packed_git *p; | ||||||
| 			strbuf_setlen(&packname, dirlen); | 			strbuf_setlen(&packname, dirlen); | ||||||
| 			strbuf_addstr(&packname, pack_indexes[i]); | 			strbuf_addstr(&packname, pack_indexes->items[i].string); | ||||||
| 			p = add_packed_git(packname.buf, packname.len, 1); | 			p = add_packed_git(packname.buf, packname.len, 1); | ||||||
| 			if (!p) | 			if (!p) | ||||||
| 				die("error adding pack %s", packname.buf); | 				die("error adding pack %s", packname.buf); | ||||||
|  | @ -717,12 +715,13 @@ void write_commit_graph(const char *obj_dir, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if (commit_hex) { | 	if (commit_hex) { | ||||||
| 		for (i = 0; i < nr_commits; i++) { | 		for (i = 0; i < commit_hex->nr; i++) { | ||||||
| 			const char *end; | 			const char *end; | ||||||
| 			struct object_id oid; | 			struct object_id oid; | ||||||
| 			struct commit *result; | 			struct commit *result; | ||||||
|  |  | ||||||
| 			if (commit_hex[i] && parse_oid_hex(commit_hex[i], &oid, &end)) | 			if (commit_hex->items[i].string && | ||||||
|  | 			    parse_oid_hex(commit_hex->items[i].string, &oid, &end)) | ||||||
| 				continue; | 				continue; | ||||||
|  |  | ||||||
| 			result = lookup_commit_reference_gently(&oid, 1); | 			result = lookup_commit_reference_gently(&oid, 1); | ||||||
|  |  | ||||||
|  | @ -3,6 +3,7 @@ | ||||||
|  |  | ||||||
| #include "git-compat-util.h" | #include "git-compat-util.h" | ||||||
| #include "repository.h" | #include "repository.h" | ||||||
|  | #include "string-list.h" | ||||||
|  |  | ||||||
| char *get_commit_graph_filename(const char *obj_dir); | char *get_commit_graph_filename(const char *obj_dir); | ||||||
|  |  | ||||||
|  | @ -48,10 +49,8 @@ struct commit_graph { | ||||||
| struct commit_graph *load_commit_graph_one(const char *graph_file); | struct commit_graph *load_commit_graph_one(const char *graph_file); | ||||||
|  |  | ||||||
| void write_commit_graph(const char *obj_dir, | void write_commit_graph(const char *obj_dir, | ||||||
| 			const char **pack_indexes, | 			struct string_list *pack_indexes, | ||||||
| 			int nr_packs, | 			struct string_list *commit_hex, | ||||||
| 			const char **commit_hex, |  | ||||||
| 			int nr_commits, |  | ||||||
| 			int append); | 			int append); | ||||||
|  |  | ||||||
| int verify_commit_graph(struct repository *r, struct commit_graph *g); | int verify_commit_graph(struct repository *r, struct commit_graph *g); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Derrick Stolee
						Derrick Stolee