]> git.ipfire.org Git - thirdparty/git.git/blame - builtin-bundle.c
Add script for importing bits-and-pieces to Git.
[thirdparty/git.git] / builtin-bundle.c
CommitLineData
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
34baebce 12static const char *bundle_usage="git bundle (create <bundle> <git rev-list args> | verify <bundle> | list-heads <bundle> [refname]... | unbundle <bundle> [refname]... )";
2e0afafe 13
2e0afafe
JS
14int cmd_bundle(int argc, const char **argv, const char *prefix)
15{
16 struct bundle_header header;
af05d679 17 int nongit;
2e0afafe
JS
18 const char *cmd, *bundle_file;
19 int bundle_fd = -1;
20 char buffer[PATH_MAX];
21
22 if (argc < 3)
23 usage(bundle_usage);
24
25 cmd = argv[1];
26 bundle_file = argv[2];
27 argc -= 2;
28 argv += 2;
29
30 prefix = setup_git_directory_gently(&nongit);
31 if (prefix && bundle_file[0] != '/') {
32 snprintf(buffer, sizeof(buffer), "%s/%s", prefix, bundle_file);
33 bundle_file = buffer;
34 }
35
36 memset(&header, 0, sizeof(header));
30415d50
JS
37 if (strcmp(cmd, "create") && (bundle_fd =
38 read_bundle_header(bundle_file, &header)) < 0)
2e0afafe
JS
39 return 1;
40
41 if (!strcmp(cmd, "verify")) {
42 close(bundle_fd);
80e25cee 43 if (verify_bundle(&header, 1))
2e0afafe
JS
44 return 1;
45 fprintf(stderr, "%s is okay\n", bundle_file);
46 return 0;
47 }
48 if (!strcmp(cmd, "list-heads")) {
49 close(bundle_fd);
30415d50 50 return !!list_bundle_refs(&header, argc, argv);
2e0afafe
JS
51 }
52 if (!strcmp(cmd, "create")) {
53 if (nongit)
54 die("Need a repository to create a bundle.");
55 return !!create_bundle(&header, bundle_file, argc, argv);
56 } else if (!strcmp(cmd, "unbundle")) {
57 if (nongit)
58 die("Need a repository to unbundle.");
30415d50
JS
59 return !!unbundle(&header, bundle_fd) ||
60 list_bundle_refs(&header, argc, argv);
2e0afafe
JS
61 } else
62 usage(bundle_usage);
63}