2007-07-15 07:14:45 +08:00
|
|
|
#include "builtin.h"
|
2019-11-11 04:41:25 +08:00
|
|
|
#include "argv-array.h"
|
2019-11-11 04:41:24 +08:00
|
|
|
#include "parse-options.h"
|
Add git-bundle: move objects and references by archive
Some workflows require use of repositories on machines that cannot be
connected, preventing use of git-fetch / git-push to transport objects and
references between the repositories.
git-bundle provides an alternate transport mechanism, effectively allowing
git-fetch and git-pull to operate using sneakernet transport. `git-bundle
create` allows the user to create a bundle containing one or more branches
or tags, but with specified basis assumed to exist on the target
repository. At the receiving end, git-bundle acts like git-fetch-pack,
allowing the user to invoke git-fetch or git-pull using the bundle file as
the URL. git-fetch and git-ls-remote determine they have a bundle URL by
checking that the URL points to a file, but are otherwise unchanged in
operation with bundles.
The original patch was done by Mark Levedahl <mdl123@verizon.net>.
It was updated to make git-bundle a builtin, and get rid of the tar
format: now, the first line is supposed to say "# v2 git bundle", the next
lines either contain a prerequisite ("-" followed by the hash of the
needed commit), or a ref (the hash of a commit, followed by the name of
the ref), and finally the pack. As a result, the bundle argument can be
"-" now.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-22 08:59:14 +08:00
|
|
|
#include "cache.h"
|
2007-09-11 11:03:15 +08:00
|
|
|
#include "bundle.h"
|
Add git-bundle: move objects and references by archive
Some workflows require use of repositories on machines that cannot be
connected, preventing use of git-fetch / git-push to transport objects and
references between the repositories.
git-bundle provides an alternate transport mechanism, effectively allowing
git-fetch and git-pull to operate using sneakernet transport. `git-bundle
create` allows the user to create a bundle containing one or more branches
or tags, but with specified basis assumed to exist on the target
repository. At the receiving end, git-bundle acts like git-fetch-pack,
allowing the user to invoke git-fetch or git-pull using the bundle file as
the URL. git-fetch and git-ls-remote determine they have a bundle URL by
checking that the URL points to a file, but are otherwise unchanged in
operation with bundles.
The original patch was done by Mark Levedahl <mdl123@verizon.net>.
It was updated to make git-bundle a builtin, and get rid of the tar
format: now, the first line is supposed to say "# v2 git bundle", the next
lines either contain a prerequisite ("-" followed by the hash of the
needed commit), or a ref (the hash of a commit, followed by the name of
the ref), and finally the pack. As a result, the bundle argument can be
"-" now.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-22 08:59:14 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Basic handler for bundle files to connect repositories via sneakernet.
|
|
|
|
* Invocation must include action.
|
|
|
|
* This function can create a bundle or provide information on an existing
|
2008-08-30 19:12:53 +08:00
|
|
|
* bundle supporting "fetch", "pull", and "ls-remote".
|
Add git-bundle: move objects and references by archive
Some workflows require use of repositories on machines that cannot be
connected, preventing use of git-fetch / git-push to transport objects and
references between the repositories.
git-bundle provides an alternate transport mechanism, effectively allowing
git-fetch and git-pull to operate using sneakernet transport. `git-bundle
create` allows the user to create a bundle containing one or more branches
or tags, but with specified basis assumed to exist on the target
repository. At the receiving end, git-bundle acts like git-fetch-pack,
allowing the user to invoke git-fetch or git-pull using the bundle file as
the URL. git-fetch and git-ls-remote determine they have a bundle URL by
checking that the URL points to a file, but are otherwise unchanged in
operation with bundles.
The original patch was done by Mark Levedahl <mdl123@verizon.net>.
It was updated to make git-bundle a builtin, and get rid of the tar
format: now, the first line is supposed to say "# v2 git bundle", the next
lines either contain a prerequisite ("-" followed by the hash of the
needed commit), or a ref (the hash of a commit, followed by the name of
the ref), and finally the pack. As a result, the bundle argument can be
"-" now.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-22 08:59:14 +08:00
|
|
|
*/
|
|
|
|
|
2019-11-11 04:41:24 +08:00
|
|
|
static const char * const builtin_bundle_usage[] = {
|
2019-11-11 04:41:25 +08:00
|
|
|
N_("git bundle create [<options>] <file> <git-rev-list args>"),
|
2019-11-11 04:41:24 +08:00
|
|
|
N_("git bundle verify <file>"),
|
|
|
|
N_("git bundle list-heads <file> [<refname>...]"),
|
|
|
|
N_("git bundle unbundle <file> [<refname>...]"),
|
|
|
|
NULL
|
|
|
|
};
|
Add git-bundle: move objects and references by archive
Some workflows require use of repositories on machines that cannot be
connected, preventing use of git-fetch / git-push to transport objects and
references between the repositories.
git-bundle provides an alternate transport mechanism, effectively allowing
git-fetch and git-pull to operate using sneakernet transport. `git-bundle
create` allows the user to create a bundle containing one or more branches
or tags, but with specified basis assumed to exist on the target
repository. At the receiving end, git-bundle acts like git-fetch-pack,
allowing the user to invoke git-fetch or git-pull using the bundle file as
the URL. git-fetch and git-ls-remote determine they have a bundle URL by
checking that the URL points to a file, but are otherwise unchanged in
operation with bundles.
The original patch was done by Mark Levedahl <mdl123@verizon.net>.
It was updated to make git-bundle a builtin, and get rid of the tar
format: now, the first line is supposed to say "# v2 git bundle", the next
lines either contain a prerequisite ("-" followed by the hash of the
needed commit), or a ref (the hash of a commit, followed by the name of
the ref), and finally the pack. As a result, the bundle argument can be
"-" now.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-22 08:59:14 +08:00
|
|
|
|
2019-11-11 04:41:24 +08:00
|
|
|
static const char * const builtin_bundle_create_usage[] = {
|
2019-11-11 04:41:25 +08:00
|
|
|
N_("git bundle create [<options>] <file> <git-rev-list args>"),
|
2019-11-11 04:41:24 +08:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const builtin_bundle_verify_usage[] = {
|
|
|
|
N_("git bundle verify <file>"),
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const builtin_bundle_list_heads_usage[] = {
|
|
|
|
N_("git bundle list-heads <file> [<refname>...]"),
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static const char * const builtin_bundle_unbundle_usage[] = {
|
|
|
|
N_("git bundle unbundle <file> [<refname>...]"),
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
|
|
|
static int verbose;
|
|
|
|
|
|
|
|
static int parse_options_cmd_bundle(int argc,
|
|
|
|
const char **argv,
|
|
|
|
const char* prefix,
|
|
|
|
const char * const usagestr[],
|
|
|
|
const struct option options[],
|
|
|
|
const char **bundle_file) {
|
|
|
|
int newargc;
|
|
|
|
newargc = parse_options(argc, argv, NULL, options, usagestr,
|
|
|
|
PARSE_OPT_STOP_AT_NON_OPTION);
|
|
|
|
if (argc < 1)
|
|
|
|
usage_with_options(usagestr, options);
|
|
|
|
*bundle_file = prefix_filename(prefix, argv[0]);
|
|
|
|
return newargc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {
|
2019-11-11 04:41:25 +08:00
|
|
|
int all_progress_implied = 0;
|
|
|
|
int progress = isatty(STDERR_FILENO);
|
|
|
|
struct argv_array pack_opts;
|
|
|
|
|
2019-11-11 04:41:24 +08:00
|
|
|
struct option options[] = {
|
2019-11-11 04:41:25 +08:00
|
|
|
OPT_SET_INT('q', "quiet", &progress,
|
|
|
|
N_("do not show progress meter"), 0),
|
|
|
|
OPT_SET_INT(0, "progress", &progress,
|
|
|
|
N_("show progress meter"), 1),
|
|
|
|
OPT_SET_INT(0, "all-progress", &progress,
|
|
|
|
N_("show progress meter during object writing phase"), 2),
|
|
|
|
OPT_BOOL(0, "all-progress-implied",
|
|
|
|
&all_progress_implied,
|
|
|
|
N_("similar to --all-progress when progress meter is shown")),
|
2019-11-11 04:41:24 +08:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const char* bundle_file;
|
|
|
|
|
|
|
|
argc = parse_options_cmd_bundle(argc, argv, prefix,
|
|
|
|
builtin_bundle_create_usage, options, &bundle_file);
|
|
|
|
/* bundle internals use argv[1] as further parameters */
|
|
|
|
|
2019-11-11 04:41:25 +08:00
|
|
|
argv_array_init(&pack_opts);
|
|
|
|
if (progress == 0)
|
|
|
|
argv_array_push(&pack_opts, "--quiet");
|
|
|
|
else if (progress == 1)
|
|
|
|
argv_array_push(&pack_opts, "--progress");
|
|
|
|
else if (progress == 2)
|
|
|
|
argv_array_push(&pack_opts, "--all-progress");
|
|
|
|
if (progress && all_progress_implied)
|
|
|
|
argv_array_push(&pack_opts, "--all-progress-implied");
|
|
|
|
|
2019-11-11 04:41:24 +08:00
|
|
|
if (!startup_info->have_repository)
|
|
|
|
die(_("Need a repository to create a bundle."));
|
2019-11-11 04:41:25 +08:00
|
|
|
return !!create_bundle(the_repository, bundle_file, argc, argv, &pack_opts);
|
2019-11-11 04:41:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {
|
Add git-bundle: move objects and references by archive
Some workflows require use of repositories on machines that cannot be
connected, preventing use of git-fetch / git-push to transport objects and
references between the repositories.
git-bundle provides an alternate transport mechanism, effectively allowing
git-fetch and git-pull to operate using sneakernet transport. `git-bundle
create` allows the user to create a bundle containing one or more branches
or tags, but with specified basis assumed to exist on the target
repository. At the receiving end, git-bundle acts like git-fetch-pack,
allowing the user to invoke git-fetch or git-pull using the bundle file as
the URL. git-fetch and git-ls-remote determine they have a bundle URL by
checking that the URL points to a file, but are otherwise unchanged in
operation with bundles.
The original patch was done by Mark Levedahl <mdl123@verizon.net>.
It was updated to make git-bundle a builtin, and get rid of the tar
format: now, the first line is supposed to say "# v2 git bundle", the next
lines either contain a prerequisite ("-" followed by the hash of the
needed commit), or a ref (the hash of a commit, followed by the name of
the ref), and finally the pack. As a result, the bundle argument can be
"-" now.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-22 08:59:14 +08:00
|
|
|
struct bundle_header header;
|
|
|
|
int bundle_fd = -1;
|
|
|
|
|
2019-11-11 04:41:24 +08:00
|
|
|
struct option options[] = {
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const char* bundle_file;
|
Add git-bundle: move objects and references by archive
Some workflows require use of repositories on machines that cannot be
connected, preventing use of git-fetch / git-push to transport objects and
references between the repositories.
git-bundle provides an alternate transport mechanism, effectively allowing
git-fetch and git-pull to operate using sneakernet transport. `git-bundle
create` allows the user to create a bundle containing one or more branches
or tags, but with specified basis assumed to exist on the target
repository. At the receiving end, git-bundle acts like git-fetch-pack,
allowing the user to invoke git-fetch or git-pull using the bundle file as
the URL. git-fetch and git-ls-remote determine they have a bundle URL by
checking that the URL points to a file, but are otherwise unchanged in
operation with bundles.
The original patch was done by Mark Levedahl <mdl123@verizon.net>.
It was updated to make git-bundle a builtin, and get rid of the tar
format: now, the first line is supposed to say "# v2 git bundle", the next
lines either contain a prerequisite ("-" followed by the hash of the
needed commit), or a ref (the hash of a commit, followed by the name of
the ref), and finally the pack. As a result, the bundle argument can be
"-" now.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-22 08:59:14 +08:00
|
|
|
|
2019-11-11 04:41:24 +08:00
|
|
|
argc = parse_options_cmd_bundle(argc, argv, prefix,
|
|
|
|
builtin_bundle_verify_usage, options, &bundle_file);
|
|
|
|
/* bundle internals use argv[1] as further parameters */
|
Add git-bundle: move objects and references by archive
Some workflows require use of repositories on machines that cannot be
connected, preventing use of git-fetch / git-push to transport objects and
references between the repositories.
git-bundle provides an alternate transport mechanism, effectively allowing
git-fetch and git-pull to operate using sneakernet transport. `git-bundle
create` allows the user to create a bundle containing one or more branches
or tags, but with specified basis assumed to exist on the target
repository. At the receiving end, git-bundle acts like git-fetch-pack,
allowing the user to invoke git-fetch or git-pull using the bundle file as
the URL. git-fetch and git-ls-remote determine they have a bundle URL by
checking that the URL points to a file, but are otherwise unchanged in
operation with bundles.
The original patch was done by Mark Levedahl <mdl123@verizon.net>.
It was updated to make git-bundle a builtin, and get rid of the tar
format: now, the first line is supposed to say "# v2 git bundle", the next
lines either contain a prerequisite ("-" followed by the hash of the
needed commit), or a ref (the hash of a commit, followed by the name of
the ref), and finally the pack. As a result, the bundle argument can be
"-" now.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-22 08:59:14 +08:00
|
|
|
|
|
|
|
memset(&header, 0, sizeof(header));
|
2019-11-11 04:41:24 +08:00
|
|
|
if ((bundle_fd = read_bundle_header(bundle_file, &header)) < 0)
|
Add git-bundle: move objects and references by archive
Some workflows require use of repositories on machines that cannot be
connected, preventing use of git-fetch / git-push to transport objects and
references between the repositories.
git-bundle provides an alternate transport mechanism, effectively allowing
git-fetch and git-pull to operate using sneakernet transport. `git-bundle
create` allows the user to create a bundle containing one or more branches
or tags, but with specified basis assumed to exist on the target
repository. At the receiving end, git-bundle acts like git-fetch-pack,
allowing the user to invoke git-fetch or git-pull using the bundle file as
the URL. git-fetch and git-ls-remote determine they have a bundle URL by
checking that the URL points to a file, but are otherwise unchanged in
operation with bundles.
The original patch was done by Mark Levedahl <mdl123@verizon.net>.
It was updated to make git-bundle a builtin, and get rid of the tar
format: now, the first line is supposed to say "# v2 git bundle", the next
lines either contain a prerequisite ("-" followed by the hash of the
needed commit), or a ref (the hash of a commit, followed by the name of
the ref), and finally the pack. As a result, the bundle argument can be
"-" now.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-22 08:59:14 +08:00
|
|
|
return 1;
|
2019-11-11 04:41:24 +08:00
|
|
|
close(bundle_fd);
|
|
|
|
if (verify_bundle(the_repository, &header, 1))
|
|
|
|
return 1;
|
|
|
|
fprintf(stderr, _("%s is okay\n"), bundle_file);
|
|
|
|
return 0;
|
|
|
|
}
|
Add git-bundle: move objects and references by archive
Some workflows require use of repositories on machines that cannot be
connected, preventing use of git-fetch / git-push to transport objects and
references between the repositories.
git-bundle provides an alternate transport mechanism, effectively allowing
git-fetch and git-pull to operate using sneakernet transport. `git-bundle
create` allows the user to create a bundle containing one or more branches
or tags, but with specified basis assumed to exist on the target
repository. At the receiving end, git-bundle acts like git-fetch-pack,
allowing the user to invoke git-fetch or git-pull using the bundle file as
the URL. git-fetch and git-ls-remote determine they have a bundle URL by
checking that the URL points to a file, but are otherwise unchanged in
operation with bundles.
The original patch was done by Mark Levedahl <mdl123@verizon.net>.
It was updated to make git-bundle a builtin, and get rid of the tar
format: now, the first line is supposed to say "# v2 git bundle", the next
lines either contain a prerequisite ("-" followed by the hash of the
needed commit), or a ref (the hash of a commit, followed by the name of
the ref), and finally the pack. As a result, the bundle argument can be
"-" now.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-22 08:59:14 +08:00
|
|
|
|
2019-11-11 04:41:24 +08:00
|
|
|
static int cmd_bundle_list_heads(int argc, const char **argv, const char *prefix) {
|
|
|
|
struct bundle_header header;
|
|
|
|
int bundle_fd = -1;
|
|
|
|
|
|
|
|
struct option options[] = {
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const char* bundle_file;
|
|
|
|
|
|
|
|
argc = parse_options_cmd_bundle(argc, argv, prefix,
|
|
|
|
builtin_bundle_list_heads_usage, options, &bundle_file);
|
|
|
|
/* bundle internals use argv[1] as further parameters */
|
|
|
|
|
|
|
|
memset(&header, 0, sizeof(header));
|
|
|
|
if ((bundle_fd = read_bundle_header(bundle_file, &header)) < 0)
|
|
|
|
return 1;
|
|
|
|
close(bundle_fd);
|
|
|
|
return !!list_bundle_refs(&header, argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix) {
|
|
|
|
struct bundle_header header;
|
|
|
|
int bundle_fd = -1;
|
|
|
|
|
|
|
|
struct option options[] = {
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
const char* bundle_file;
|
|
|
|
|
|
|
|
argc = parse_options_cmd_bundle(argc, argv, prefix,
|
|
|
|
builtin_bundle_unbundle_usage, options, &bundle_file);
|
|
|
|
/* bundle internals use argv[1] as further parameters */
|
|
|
|
|
|
|
|
memset(&header, 0, sizeof(header));
|
|
|
|
if ((bundle_fd = read_bundle_header(bundle_file, &header)) < 0)
|
|
|
|
return 1;
|
|
|
|
if (!startup_info->have_repository)
|
|
|
|
die(_("Need a repository to unbundle."));
|
|
|
|
return !!unbundle(the_repository, &header, bundle_fd, 0) ||
|
|
|
|
list_bundle_refs(&header, argc, argv);
|
|
|
|
}
|
|
|
|
|
|
|
|
int cmd_bundle(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
|
|
|
struct option options[] = {
|
|
|
|
OPT__VERBOSE(&verbose, N_("be verbose; must be placed before a subcommand")),
|
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
int result;
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, options, builtin_bundle_usage,
|
|
|
|
PARSE_OPT_STOP_AT_NON_OPTION);
|
|
|
|
|
|
|
|
packet_trace_identity("bundle");
|
|
|
|
|
|
|
|
if (argc < 2)
|
|
|
|
usage_with_options(builtin_bundle_usage, options);
|
|
|
|
|
|
|
|
else if (!strcmp(argv[0], "create"))
|
|
|
|
result = cmd_bundle_create(argc, argv, prefix);
|
|
|
|
else if (!strcmp(argv[0], "verify"))
|
|
|
|
result = cmd_bundle_verify(argc, argv, prefix);
|
|
|
|
else if (!strcmp(argv[0], "list-heads"))
|
|
|
|
result = cmd_bundle_list_heads(argc, argv, prefix);
|
|
|
|
else if (!strcmp(argv[0], "unbundle"))
|
|
|
|
result = cmd_bundle_unbundle(argc, argv, prefix);
|
|
|
|
else {
|
|
|
|
error(_("Unknown subcommand: %s"), argv[0]);
|
|
|
|
usage_with_options(builtin_bundle_usage, options);
|
Add git-bundle: move objects and references by archive
Some workflows require use of repositories on machines that cannot be
connected, preventing use of git-fetch / git-push to transport objects and
references between the repositories.
git-bundle provides an alternate transport mechanism, effectively allowing
git-fetch and git-pull to operate using sneakernet transport. `git-bundle
create` allows the user to create a bundle containing one or more branches
or tags, but with specified basis assumed to exist on the target
repository. At the receiving end, git-bundle acts like git-fetch-pack,
allowing the user to invoke git-fetch or git-pull using the bundle file as
the URL. git-fetch and git-ls-remote determine they have a bundle URL by
checking that the URL points to a file, but are otherwise unchanged in
operation with bundles.
The original patch was done by Mark Levedahl <mdl123@verizon.net>.
It was updated to make git-bundle a builtin, and get rid of the tar
format: now, the first line is supposed to say "# v2 git bundle", the next
lines either contain a prerequisite ("-" followed by the hash of the
needed commit), or a ref (the hash of a commit, followed by the name of
the ref), and finally the pack. As a result, the bundle argument can be
"-" now.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-22 08:59:14 +08:00
|
|
|
}
|
2019-11-11 04:41:24 +08:00
|
|
|
return result ? 1 : 0;
|
Add git-bundle: move objects and references by archive
Some workflows require use of repositories on machines that cannot be
connected, preventing use of git-fetch / git-push to transport objects and
references between the repositories.
git-bundle provides an alternate transport mechanism, effectively allowing
git-fetch and git-pull to operate using sneakernet transport. `git-bundle
create` allows the user to create a bundle containing one or more branches
or tags, but with specified basis assumed to exist on the target
repository. At the receiving end, git-bundle acts like git-fetch-pack,
allowing the user to invoke git-fetch or git-pull using the bundle file as
the URL. git-fetch and git-ls-remote determine they have a bundle URL by
checking that the URL points to a file, but are otherwise unchanged in
operation with bundles.
The original patch was done by Mark Levedahl <mdl123@verizon.net>.
It was updated to make git-bundle a builtin, and get rid of the tar
format: now, the first line is supposed to say "# v2 git bundle", the next
lines either contain a prerequisite ("-" followed by the hash of the
needed commit), or a ref (the hash of a commit, followed by the name of
the ref), and finally the pack. As a result, the bundle argument can be
"-" now.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <junkio@cox.net>
2007-02-22 08:59:14 +08:00
|
|
|
}
|