@matheusbsbs / matheus-bagliano / commits / 80e25ceece
Fork 0

git-bundle: make verify a bit more chatty.

Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Mar 5, 2007 at 16:17 UTC 80e25ceece17fd575735c40dc923086154402cbe
1 file changed +35 -20
builtin-bundle.c
+35 -20
@@ -160,9 +160,28 @@ static int fork_with_pipe(const char **argv, int *in, int *out)
160 return pid;
161 }
162
163 +static int list_refs(struct ref_list *r, int argc, const char **argv)
164 +{
165 + int i;
166 +
167 + for (i = 0; i < r->nr; i++) {
168 + if (argc > 1) {
169 + int j;
170 + for (j = 1; j < argc; j++)
171 + if (!strcmp(r->list[i].name, argv[j]))
172 + break;
173 + if (j == argc)
174 + continue;
175 + }
176 + printf("%s %s\n", sha1_to_hex(r->list[i].sha1),
177 + r->list[i].name);
178 + }
179 + return 0;
180 +}
181 +
182 #define PREREQ_MARK (1u<<16)
183
165 -static int verify_bundle(struct bundle_header *header)
184 +static int verify_bundle(struct bundle_header *header, int verbose)
185 {
186 /*
187 * Do fast check, then if any prereqs are missing then go line by line
@@ -218,27 +237,24 @@ static int verify_bundle(struct bundle_header *header)
237 for (i = 0; i < refs.nr; i++)
238 clear_commit_marks((struct commit *)refs.objects[i].item, -1);
239
240 + if (verbose) {
241 + struct ref_list *r;
242 +
243 + r = &header->references;
244 + printf("The bundle contains %d ref%s\n",
245 + r->nr, (1 < r->nr) ? "s" : "");
246 + list_refs(r, 0, NULL);
247 + r = &header->prerequisites;
248 + printf("The bundle requires these %d ref%s\n",
249 + r->nr, (1 < r->nr) ? "s" : "");
250 + list_refs(r, 0, NULL);
251 + }
252 return ret;
253 }
254
255 static int list_heads(struct bundle_header *header, int argc, const char **argv)
256 {
226 - int i;
227 - struct ref_list *r = &header->references;
228 -
229 - for (i = 0; i < r->nr; i++) {
230 - if (argc > 1) {
231 - int j;
232 - for (j = 1; j < argc; j++)
233 - if (!strcmp(r->list[i].name, argv[j]))
234 - break;
235 - if (j == argc)
236 - continue;
237 - }
238 - printf("%s %s\n", sha1_to_hex(r->list[i].sha1),
239 - r->list[i].name);
240 - }
241 - return 0;
257 + return list_refs(&header->references, argc, argv);
258 }
259
260 static void show_commit(struct commit *commit)
@@ -385,7 +401,7 @@ static int unbundle(struct bundle_header *header, int bundle_fd,
401 const char *argv_index_pack[] = {"index-pack", "--stdin", NULL};
402 int pid, status, dev_null;
403
388 - if (verify_bundle(header))
404 + if (verify_bundle(header, 0))
405 return -1;
406 dev_null = open("/dev/null", O_WRONLY);
407 pid = fork_with_pipe(argv_index_pack, &bundle_fd, &dev_null);
@@ -429,7 +445,7 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
445
446 if (!strcmp(cmd, "verify")) {
447 close(bundle_fd);
432 - if (verify_bundle(&header))
448 + if (verify_bundle(&header, 1))
449 return 1;
450 fprintf(stderr, "%s is okay\n", bundle_file);
451 return 0;
@@ -449,4 +465,3 @@ int cmd_bundle(int argc, const char **argv, const char *prefix)
465 } else
466 usage(bundle_usage);
467 }
452 -