]>
Commit | Line | Data |
---|---|---|
baffc0e7 | 1 | #include "builtin.h" |
2e0afafe | 2 | #include "cache.h" |
30415d50 | 3 | #include "bundle.h" |
2e0afafe JS |
4 | |
5 | /* | |
6 | * Basic handler for bundle files to connect repositories via sneakernet. | |
7 | * Invocation must include action. | |
8 | * This function can create a bundle or provide information on an existing | |
34baebce | 9 | * bundle supporting "fetch", "pull", and "ls-remote". |
2e0afafe JS |
10 | */ |
11 | ||
1f986c4a TF |
12 | static const char builtin_bundle_usage[] = |
13 | "git bundle create <file> <git-rev-list args>\n" | |
14 | " or: git bundle verify <file>\n" | |
62b4698e ŠN |
15 | " or: git bundle list-heads <file> [<refname>...]\n" |
16 | " or: git bundle unbundle <file> [<refname>...]"; | |
2e0afafe | 17 | |
2e0afafe JS |
18 | int cmd_bundle(int argc, const char **argv, const char *prefix) |
19 | { | |
20 | struct bundle_header header; | |
2e0afafe JS |
21 | const char *cmd, *bundle_file; |
22 | int bundle_fd = -1; | |
23 | char buffer[PATH_MAX]; | |
24 | ||
25 | if (argc < 3) | |
1f986c4a | 26 | usage(builtin_bundle_usage); |
2e0afafe JS |
27 | |
28 | cmd = argv[1]; | |
29 | bundle_file = argv[2]; | |
30 | argc -= 2; | |
31 | argv += 2; | |
32 | ||
2e0afafe JS |
33 | if (prefix && bundle_file[0] != '/') { |
34 | snprintf(buffer, sizeof(buffer), "%s/%s", prefix, bundle_file); | |
35 | bundle_file = buffer; | |
36 | } | |
37 | ||
38 | memset(&header, 0, sizeof(header)); | |
30415d50 JS |
39 | if (strcmp(cmd, "create") && (bundle_fd = |
40 | read_bundle_header(bundle_file, &header)) < 0) | |
2e0afafe JS |
41 | return 1; |
42 | ||
43 | if (!strcmp(cmd, "verify")) { | |
44 | close(bundle_fd); | |
7886cfa0 PS |
45 | if (argc != 1) { |
46 | usage(builtin_bundle_usage); | |
47 | return 1; | |
48 | } | |
80e25cee | 49 | if (verify_bundle(&header, 1)) |
2e0afafe | 50 | return 1; |
c7c4efac | 51 | fprintf(stderr, _("%s is okay\n"), bundle_file); |
2e0afafe JS |
52 | return 0; |
53 | } | |
54 | if (!strcmp(cmd, "list-heads")) { | |
55 | close(bundle_fd); | |
30415d50 | 56 | return !!list_bundle_refs(&header, argc, argv); |
2e0afafe JS |
57 | } |
58 | if (!strcmp(cmd, "create")) { | |
7886cfa0 PS |
59 | if (argc < 2) { |
60 | usage(builtin_bundle_usage); | |
61 | return 1; | |
62 | } | |
2cb60093 | 63 | if (!startup_info->have_repository) |
c7c4efac | 64 | die(_("Need a repository to create a bundle.")); |
2e0afafe JS |
65 | return !!create_bundle(&header, bundle_file, argc, argv); |
66 | } else if (!strcmp(cmd, "unbundle")) { | |
2cb60093 | 67 | if (!startup_info->have_repository) |
c7c4efac | 68 | die(_("Need a repository to unbundle.")); |
be042aff | 69 | return !!unbundle(&header, bundle_fd, 0) || |
30415d50 | 70 | list_bundle_refs(&header, argc, argv); |
2e0afafe | 71 | } else |
1f986c4a | 72 | usage(builtin_bundle_usage); |
2e0afafe | 73 | } |