Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 68 lines (59 sloc) 1.816 kB
baffc0e Make every builtin-*.c file #include "builtin.h"
Peter Hagervall authored
1 #include "builtin.h"
2e0afaf @dscho Add git-bundle: move objects and references by archive
dscho authored
2 #include "cache.h"
30415d5 @dscho Move bundle specific stuff into bundle.[ch]
dscho authored
3 #include "bundle.h"
2e0afaf @dscho Add git-bundle: move objects and references by archive
dscho authored
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
34baebc @heikkiorsila Start conforming code to "git subcmd" style
heikkiorsila authored
9 * bundle supporting "fetch", "pull", and "ls-remote".
2e0afaf @dscho Add git-bundle: move objects and references by archive
dscho authored
10 */
11
1f986c4 Update the usage bundle string.
Thiago Farina authored
12 static const char builtin_bundle_usage[] =
13 "git bundle create <file> <git-rev-list args>\n"
14 " or: git bundle verify <file>\n"
15 " or: git bundle list-heads <file> [refname...]\n"
16 " or: git bundle unbundle <file> [refname...]";
2e0afaf @dscho Add git-bundle: move objects and references by archive
dscho authored
17
18 int cmd_bundle(int argc, const char **argv, const char *prefix)
19 {
20 struct bundle_header header;
af05d67 @szeder Always set *nongit_ok in setup_git_directory_gently()
szeder authored
21 int nongit;
2e0afaf @dscho Add git-bundle: move objects and references by archive
dscho authored
22 const char *cmd, *bundle_file;
23 int bundle_fd = -1;
24 char buffer[PATH_MAX];
25
26 if (argc < 3)
1f986c4 Update the usage bundle string.
Thiago Farina authored
27 usage(builtin_bundle_usage);
2e0afaf @dscho Add git-bundle: move objects and references by archive
dscho authored
28
29 cmd = argv[1];
30 bundle_file = argv[2];
31 argc -= 2;
32 argv += 2;
33
34 prefix = setup_git_directory_gently(&nongit);
35 if (prefix && bundle_file[0] != '/') {
36 snprintf(buffer, sizeof(buffer), "%s/%s", prefix, bundle_file);
37 bundle_file = buffer;
38 }
39
40 memset(&header, 0, sizeof(header));
30415d5 @dscho Move bundle specific stuff into bundle.[ch]
dscho authored
41 if (strcmp(cmd, "create") && (bundle_fd =
42 read_bundle_header(bundle_file, &header)) < 0)
2e0afaf @dscho Add git-bundle: move objects and references by archive
dscho authored
43 return 1;
44
45 if (!strcmp(cmd, "verify")) {
46 close(bundle_fd);
80e25ce git-bundle: make verify a bit more chatty.
Junio C Hamano authored
47 if (verify_bundle(&header, 1))
2e0afaf @dscho Add git-bundle: move objects and references by archive
dscho authored
48 return 1;
49 fprintf(stderr, "%s is okay\n", bundle_file);
50 return 0;
51 }
52 if (!strcmp(cmd, "list-heads")) {
53 close(bundle_fd);
30415d5 @dscho Move bundle specific stuff into bundle.[ch]
dscho authored
54 return !!list_bundle_refs(&header, argc, argv);
2e0afaf @dscho Add git-bundle: move objects and references by archive
dscho authored
55 }
56 if (!strcmp(cmd, "create")) {
57 if (nongit)
58 die("Need a repository to create a bundle.");
59 return !!create_bundle(&header, bundle_file, argc, argv);
60 } else if (!strcmp(cmd, "unbundle")) {
61 if (nongit)
62 die("Need a repository to unbundle.");
30415d5 @dscho Move bundle specific stuff into bundle.[ch]
dscho authored
63 return !!unbundle(&header, bundle_fd) ||
64 list_bundle_refs(&header, argc, argv);
2e0afaf @dscho Add git-bundle: move objects and references by archive
dscho authored
65 } else
1f986c4 Update the usage bundle string.
Thiago Farina authored
66 usage(builtin_bundle_usage);
2e0afaf @dscho Add git-bundle: move objects and references by archive
dscho authored
67 }
Something went wrong with that request. Please try again.