2007-07-15 07:14:45 +08:00
|
|
|
#include "builtin.h"
|
2020-07-29 04:23:39 +08:00
|
|
|
#include "strvec.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:26 +08:00
|
|
|
N_("git bundle verify [<options>] <file>"),
|
2019-11-11 04:41:24 +08:00
|
|
|
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[] = {
|
2019-11-11 04:41:26 +08:00
|
|
|
N_("git bundle verify [<options>] <file>"),
|
2019-11-11 04:41:24 +08:00
|
|
|
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 parse_options_cmd_bundle(int argc,
|
|
|
|
const char **argv,
|
|
|
|
const char* prefix,
|
|
|
|
const char * const usagestr[],
|
|
|
|
const struct option options[],
|
2021-07-02 17:57:30 +08:00
|
|
|
char **bundle_file) {
|
2019-11-11 04:41:24 +08:00
|
|
|
int newargc;
|
|
|
|
newargc = parse_options(argc, argv, NULL, options, usagestr,
|
|
|
|
PARSE_OPT_STOP_AT_NON_OPTION);
|
bundle: don't segfault on "git bundle <subcmd>"
Since aef7d75e580 (builtin/bundle.c: let parse-options parse
subcommands, 2022-08-19) we've been segfaulting if no argument was
provided.
The fix is easy, as all of the "git bundle" subcommands require a
non-option argument we can check that we have arguments left after
calling parse-options().
This makes use of code added in 73c3253d75e (bundle: framework for
options before bundle file, 2019-11-10), before this change that code
has always been unreachable. In 73c3253d75e we'd never reach it as we
already checked "argc < 2" in cmd_bundle() itself.
Then when aef7d75e580 (whose segfault we're fixing here) migrated this
code to the subcommand API it removed that "argc < 2" check, but we
were still checking the wrong "argc" in parse_options_cmd_bundle(), we
need to check the "newargc". The "argc" will always be >= 1, as it
will necessarily contain at least the subcommand name
itself (e.g. "create").
As an aside, this could be safely squashed into this, but let's not do
that for this minimal segfault fix, as it's an unrelated refactoring:
--- a/builtin/bundle.c
+++ b/builtin/bundle.c
@@ -55,13 +55,12 @@ static int parse_options_cmd_bundle(int argc,
const char * const usagestr[],
const struct option options[],
char **bundle_file) {
- int newargc;
- newargc = parse_options(argc, argv, NULL, options, usagestr,
+ argc = parse_options(argc, argv, NULL, options, usagestr,
PARSE_OPT_STOP_AT_NON_OPTION);
- if (!newargc)
+ if (!argc)
usage_with_options(usagestr, options);
*bundle_file = prefix_filename(prefix, argv[0]);
- return newargc;
+ return argc;
}
static int cmd_bundle_create(int argc, const char **argv, const char *prefix) {
Reported-by: Hubert Jasudowicz <hubertj@stmcyber.pl>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Tested-by: Hubert Jasudowicz <hubertj@stmcyber.pl>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2022-12-20 21:40:18 +08:00
|
|
|
if (!newargc)
|
2019-11-11 04:41:24 +08:00
|
|
|
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);
|
2020-07-29 04:24:27 +08:00
|
|
|
struct strvec pack_opts;
|
2020-07-30 07:14:20 +08:00
|
|
|
int version = -1;
|
2021-07-02 17:57:30 +08:00
|
|
|
int ret;
|
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")),
|
2020-07-30 07:14:20 +08:00
|
|
|
OPT_INTEGER(0, "version", &version,
|
|
|
|
N_("specify bundle format version")),
|
2019-11-11 04:41:24 +08:00
|
|
|
OPT_END()
|
|
|
|
};
|
2021-07-02 17:57:30 +08:00
|
|
|
char *bundle_file;
|
2019-11-11 04:41:24 +08:00
|
|
|
|
|
|
|
argc = parse_options_cmd_bundle(argc, argv, prefix,
|
|
|
|
builtin_bundle_create_usage, options, &bundle_file);
|
|
|
|
/* bundle internals use argv[1] as further parameters */
|
|
|
|
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_init(&pack_opts);
|
2019-11-11 04:41:25 +08:00
|
|
|
if (progress == 0)
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_push(&pack_opts, "--quiet");
|
2019-11-11 04:41:25 +08:00
|
|
|
else if (progress == 1)
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_push(&pack_opts, "--progress");
|
2019-11-11 04:41:25 +08:00
|
|
|
else if (progress == 2)
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_push(&pack_opts, "--all-progress");
|
2019-11-11 04:41:25 +08:00
|
|
|
if (progress && all_progress_implied)
|
2020-07-29 04:24:27 +08:00
|
|
|
strvec_push(&pack_opts, "--all-progress-implied");
|
2019-11-11 04:41:25 +08:00
|
|
|
|
2019-11-11 04:41:24 +08:00
|
|
|
if (!startup_info->have_repository)
|
|
|
|
die(_("Need a repository to create a bundle."));
|
2021-07-02 17:57:30 +08:00
|
|
|
ret = !!create_bundle(the_repository, bundle_file, argc, argv, &pack_opts, version);
|
2022-03-05 02:32:09 +08:00
|
|
|
strvec_clear(&pack_opts);
|
2021-07-02 17:57:30 +08:00
|
|
|
free(bundle_file);
|
|
|
|
return ret;
|
2019-11-11 04:41:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int cmd_bundle_verify(int argc, const char **argv, const char *prefix) {
|
bundle: remove "ref_list" in favor of string-list.c API
Move away from the "struct ref_list" in bundle.c in favor of the
almost identical string-list.c API.
That API fits this use-case perfectly, but did not exist in its
current form when this code was added in 2e0afafebd (Add git-bundle:
move objects and references by archive, 2007-02-22), with hindsight we
could have used the path-list API, which later got renamed to
string-list. See 8fd2cb4069 (Extract helper bits from
c-merge-recursive work, 2006-07-25)
We need to change "name" to "string" and "oid" to "util" to make this
conversion, but other than that the APIs are pretty much identical for
what bundle.c made use of.
Let's also replace the memset(..,0,...) pattern with a more idiomatic
"INIT" macro, and finally add a *_release() function so to free the
allocated memory.
Before this the add_to_ref_list() would leak memory, now e.g. "bundle
list-heads" reports no memory leaks at all under valgrind.
In the bundle_header_init() function we're using a clever trick to
memcpy() what we'd get from the corresponding
BUNDLE_HEADER_INIT. There is a concurrent series to make use of that
pattern more generally, see [1].
1. https://lore.kernel.org/git/cover-0.5-00000000000-20210701T104855Z-avarab@gmail.com/
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-07-02 17:57:32 +08:00
|
|
|
struct bundle_header header = BUNDLE_HEADER_INIT;
|
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
|
|
|
int bundle_fd = -1;
|
2019-11-11 04:41:26 +08:00
|
|
|
int quiet = 0;
|
2021-07-02 17:57:30 +08:00
|
|
|
int ret;
|
2019-11-11 04:41:24 +08:00
|
|
|
struct option options[] = {
|
2019-11-11 04:41:26 +08:00
|
|
|
OPT_BOOL('q', "quiet", &quiet,
|
|
|
|
N_("do not show bundle details")),
|
2019-11-11 04:41:24 +08:00
|
|
|
OPT_END()
|
|
|
|
};
|
2021-07-02 17:57:30 +08:00
|
|
|
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
|
|
|
|
2021-07-02 17:57:30 +08:00
|
|
|
if ((bundle_fd = read_bundle_header(bundle_file, &header)) < 0) {
|
|
|
|
ret = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2019-11-11 04:41:24 +08:00
|
|
|
close(bundle_fd);
|
2021-07-02 17:57:30 +08:00
|
|
|
if (verify_bundle(the_repository, &header, !quiet)) {
|
|
|
|
ret = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2019-11-11 04:41:24 +08:00
|
|
|
fprintf(stderr, _("%s is okay\n"), bundle_file);
|
2021-07-02 17:57:30 +08:00
|
|
|
ret = 0;
|
|
|
|
cleanup:
|
|
|
|
free(bundle_file);
|
bundle: remove "ref_list" in favor of string-list.c API
Move away from the "struct ref_list" in bundle.c in favor of the
almost identical string-list.c API.
That API fits this use-case perfectly, but did not exist in its
current form when this code was added in 2e0afafebd (Add git-bundle:
move objects and references by archive, 2007-02-22), with hindsight we
could have used the path-list API, which later got renamed to
string-list. See 8fd2cb4069 (Extract helper bits from
c-merge-recursive work, 2006-07-25)
We need to change "name" to "string" and "oid" to "util" to make this
conversion, but other than that the APIs are pretty much identical for
what bundle.c made use of.
Let's also replace the memset(..,0,...) pattern with a more idiomatic
"INIT" macro, and finally add a *_release() function so to free the
allocated memory.
Before this the add_to_ref_list() would leak memory, now e.g. "bundle
list-heads" reports no memory leaks at all under valgrind.
In the bundle_header_init() function we're using a clever trick to
memcpy() what we'd get from the corresponding
BUNDLE_HEADER_INIT. There is a concurrent series to make use of that
pattern more generally, see [1].
1. https://lore.kernel.org/git/cover-0.5-00000000000-20210701T104855Z-avarab@gmail.com/
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-07-02 17:57:32 +08:00
|
|
|
bundle_header_release(&header);
|
2021-07-02 17:57:30 +08:00
|
|
|
return ret;
|
2019-11-11 04:41:24 +08:00
|
|
|
}
|
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) {
|
bundle: remove "ref_list" in favor of string-list.c API
Move away from the "struct ref_list" in bundle.c in favor of the
almost identical string-list.c API.
That API fits this use-case perfectly, but did not exist in its
current form when this code was added in 2e0afafebd (Add git-bundle:
move objects and references by archive, 2007-02-22), with hindsight we
could have used the path-list API, which later got renamed to
string-list. See 8fd2cb4069 (Extract helper bits from
c-merge-recursive work, 2006-07-25)
We need to change "name" to "string" and "oid" to "util" to make this
conversion, but other than that the APIs are pretty much identical for
what bundle.c made use of.
Let's also replace the memset(..,0,...) pattern with a more idiomatic
"INIT" macro, and finally add a *_release() function so to free the
allocated memory.
Before this the add_to_ref_list() would leak memory, now e.g. "bundle
list-heads" reports no memory leaks at all under valgrind.
In the bundle_header_init() function we're using a clever trick to
memcpy() what we'd get from the corresponding
BUNDLE_HEADER_INIT. There is a concurrent series to make use of that
pattern more generally, see [1].
1. https://lore.kernel.org/git/cover-0.5-00000000000-20210701T104855Z-avarab@gmail.com/
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-07-02 17:57:32 +08:00
|
|
|
struct bundle_header header = BUNDLE_HEADER_INIT;
|
2019-11-11 04:41:24 +08:00
|
|
|
int bundle_fd = -1;
|
2021-07-02 17:57:30 +08:00
|
|
|
int ret;
|
2019-11-11 04:41:24 +08:00
|
|
|
struct option options[] = {
|
|
|
|
OPT_END()
|
|
|
|
};
|
2021-07-02 17:57:30 +08:00
|
|
|
char *bundle_file;
|
2019-11-11 04:41:24 +08:00
|
|
|
|
|
|
|
argc = parse_options_cmd_bundle(argc, argv, prefix,
|
|
|
|
builtin_bundle_list_heads_usage, options, &bundle_file);
|
|
|
|
/* bundle internals use argv[1] as further parameters */
|
|
|
|
|
2021-07-02 17:57:30 +08:00
|
|
|
if ((bundle_fd = read_bundle_header(bundle_file, &header)) < 0) {
|
|
|
|
ret = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2019-11-11 04:41:24 +08:00
|
|
|
close(bundle_fd);
|
2021-07-02 17:57:30 +08:00
|
|
|
ret = !!list_bundle_refs(&header, argc, argv);
|
|
|
|
cleanup:
|
|
|
|
free(bundle_file);
|
bundle: remove "ref_list" in favor of string-list.c API
Move away from the "struct ref_list" in bundle.c in favor of the
almost identical string-list.c API.
That API fits this use-case perfectly, but did not exist in its
current form when this code was added in 2e0afafebd (Add git-bundle:
move objects and references by archive, 2007-02-22), with hindsight we
could have used the path-list API, which later got renamed to
string-list. See 8fd2cb4069 (Extract helper bits from
c-merge-recursive work, 2006-07-25)
We need to change "name" to "string" and "oid" to "util" to make this
conversion, but other than that the APIs are pretty much identical for
what bundle.c made use of.
Let's also replace the memset(..,0,...) pattern with a more idiomatic
"INIT" macro, and finally add a *_release() function so to free the
allocated memory.
Before this the add_to_ref_list() would leak memory, now e.g. "bundle
list-heads" reports no memory leaks at all under valgrind.
In the bundle_header_init() function we're using a clever trick to
memcpy() what we'd get from the corresponding
BUNDLE_HEADER_INIT. There is a concurrent series to make use of that
pattern more generally, see [1].
1. https://lore.kernel.org/git/cover-0.5-00000000000-20210701T104855Z-avarab@gmail.com/
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-07-02 17:57:32 +08:00
|
|
|
bundle_header_release(&header);
|
2021-07-02 17:57:30 +08:00
|
|
|
return ret;
|
2019-11-11 04:41:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int cmd_bundle_unbundle(int argc, const char **argv, const char *prefix) {
|
bundle: remove "ref_list" in favor of string-list.c API
Move away from the "struct ref_list" in bundle.c in favor of the
almost identical string-list.c API.
That API fits this use-case perfectly, but did not exist in its
current form when this code was added in 2e0afafebd (Add git-bundle:
move objects and references by archive, 2007-02-22), with hindsight we
could have used the path-list API, which later got renamed to
string-list. See 8fd2cb4069 (Extract helper bits from
c-merge-recursive work, 2006-07-25)
We need to change "name" to "string" and "oid" to "util" to make this
conversion, but other than that the APIs are pretty much identical for
what bundle.c made use of.
Let's also replace the memset(..,0,...) pattern with a more idiomatic
"INIT" macro, and finally add a *_release() function so to free the
allocated memory.
Before this the add_to_ref_list() would leak memory, now e.g. "bundle
list-heads" reports no memory leaks at all under valgrind.
In the bundle_header_init() function we're using a clever trick to
memcpy() what we'd get from the corresponding
BUNDLE_HEADER_INIT. There is a concurrent series to make use of that
pattern more generally, see [1].
1. https://lore.kernel.org/git/cover-0.5-00000000000-20210701T104855Z-avarab@gmail.com/
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-07-02 17:57:32 +08:00
|
|
|
struct bundle_header header = BUNDLE_HEADER_INIT;
|
2019-11-11 04:41:24 +08:00
|
|
|
int bundle_fd = -1;
|
2021-07-02 17:57:30 +08:00
|
|
|
int ret;
|
bundle: show progress on "unbundle"
The "unbundle" command added in 2e0afafebd8 (Add git-bundle: move
objects and references by archive, 2007-02-22) did not show progress
output, even though the underlying API learned how to show progress in
be042aff24c (Teach progress eye-candy to fetch_refs_from_bundle(),
2011-09-18).
Now we'll show "Unbundling objects" using the new --progress-title
option to "git index-pack", to go with its existing "Receiving
objects" and "Indexing objects" (which it shows when invoked with
"--stdin", and with a pack file, respectively).
Unlike "git bundle create" we don't handle "--quiet" here, nor
"--all-progress" and "--all-progress-implied". Those are all specific
to "create" (and "verify", in the case of "--quiet").
The structure of the existing documentation is a bit unclear, e.g. the
documentation for the "--quiet" option added in
79862b6b77c (bundle-create: progress output control, 2019-11-10) only
describes how it works for "create", and not for "verify". That and
other issues in it should be fixed, but I'd like to avoid untangling
that mess right now. Let's just support the standard "--no-progress"
implicitly here, and leave cleaning up the general behavior of "git
bundle" for a later change.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-09-05 15:34:45 +08:00
|
|
|
int progress = isatty(2);
|
|
|
|
|
2019-11-11 04:41:24 +08:00
|
|
|
struct option options[] = {
|
bundle: show progress on "unbundle"
The "unbundle" command added in 2e0afafebd8 (Add git-bundle: move
objects and references by archive, 2007-02-22) did not show progress
output, even though the underlying API learned how to show progress in
be042aff24c (Teach progress eye-candy to fetch_refs_from_bundle(),
2011-09-18).
Now we'll show "Unbundling objects" using the new --progress-title
option to "git index-pack", to go with its existing "Receiving
objects" and "Indexing objects" (which it shows when invoked with
"--stdin", and with a pack file, respectively).
Unlike "git bundle create" we don't handle "--quiet" here, nor
"--all-progress" and "--all-progress-implied". Those are all specific
to "create" (and "verify", in the case of "--quiet").
The structure of the existing documentation is a bit unclear, e.g. the
documentation for the "--quiet" option added in
79862b6b77c (bundle-create: progress output control, 2019-11-10) only
describes how it works for "create", and not for "verify". That and
other issues in it should be fixed, but I'd like to avoid untangling
that mess right now. Let's just support the standard "--no-progress"
implicitly here, and leave cleaning up the general behavior of "git
bundle" for a later change.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-09-05 15:34:45 +08:00
|
|
|
OPT_BOOL(0, "progress", &progress,
|
|
|
|
N_("show progress meter")),
|
2019-11-11 04:41:24 +08:00
|
|
|
OPT_END()
|
|
|
|
};
|
2021-07-02 17:57:30 +08:00
|
|
|
char *bundle_file;
|
2021-09-05 15:34:43 +08:00
|
|
|
struct strvec extra_index_pack_args = STRVEC_INIT;
|
2019-11-11 04:41:24 +08:00
|
|
|
|
|
|
|
argc = parse_options_cmd_bundle(argc, argv, prefix,
|
|
|
|
builtin_bundle_unbundle_usage, options, &bundle_file);
|
|
|
|
/* bundle internals use argv[1] as further parameters */
|
|
|
|
|
2021-07-02 17:57:30 +08:00
|
|
|
if ((bundle_fd = read_bundle_header(bundle_file, &header)) < 0) {
|
|
|
|
ret = 1;
|
|
|
|
goto cleanup;
|
|
|
|
}
|
2019-11-11 04:41:24 +08:00
|
|
|
if (!startup_info->have_repository)
|
|
|
|
die(_("Need a repository to unbundle."));
|
bundle: show progress on "unbundle"
The "unbundle" command added in 2e0afafebd8 (Add git-bundle: move
objects and references by archive, 2007-02-22) did not show progress
output, even though the underlying API learned how to show progress in
be042aff24c (Teach progress eye-candy to fetch_refs_from_bundle(),
2011-09-18).
Now we'll show "Unbundling objects" using the new --progress-title
option to "git index-pack", to go with its existing "Receiving
objects" and "Indexing objects" (which it shows when invoked with
"--stdin", and with a pack file, respectively).
Unlike "git bundle create" we don't handle "--quiet" here, nor
"--all-progress" and "--all-progress-implied". Those are all specific
to "create" (and "verify", in the case of "--quiet").
The structure of the existing documentation is a bit unclear, e.g. the
documentation for the "--quiet" option added in
79862b6b77c (bundle-create: progress output control, 2019-11-10) only
describes how it works for "create", and not for "verify". That and
other issues in it should be fixed, but I'd like to avoid untangling
that mess right now. Let's just support the standard "--no-progress"
implicitly here, and leave cleaning up the general behavior of "git
bundle" for a later change.
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-09-05 15:34:45 +08:00
|
|
|
if (progress)
|
|
|
|
strvec_pushl(&extra_index_pack_args, "-v", "--progress-title",
|
|
|
|
_("Unbundling objects"), NULL);
|
2021-09-05 15:34:43 +08:00
|
|
|
ret = !!unbundle(the_repository, &header, bundle_fd,
|
|
|
|
&extra_index_pack_args) ||
|
2019-11-11 04:41:24 +08:00
|
|
|
list_bundle_refs(&header, argc, argv);
|
bundle: remove "ref_list" in favor of string-list.c API
Move away from the "struct ref_list" in bundle.c in favor of the
almost identical string-list.c API.
That API fits this use-case perfectly, but did not exist in its
current form when this code was added in 2e0afafebd (Add git-bundle:
move objects and references by archive, 2007-02-22), with hindsight we
could have used the path-list API, which later got renamed to
string-list. See 8fd2cb4069 (Extract helper bits from
c-merge-recursive work, 2006-07-25)
We need to change "name" to "string" and "oid" to "util" to make this
conversion, but other than that the APIs are pretty much identical for
what bundle.c made use of.
Let's also replace the memset(..,0,...) pattern with a more idiomatic
"INIT" macro, and finally add a *_release() function so to free the
allocated memory.
Before this the add_to_ref_list() would leak memory, now e.g. "bundle
list-heads" reports no memory leaks at all under valgrind.
In the bundle_header_init() function we're using a clever trick to
memcpy() what we'd get from the corresponding
BUNDLE_HEADER_INIT. There is a concurrent series to make use of that
pattern more generally, see [1].
1. https://lore.kernel.org/git/cover-0.5-00000000000-20210701T104855Z-avarab@gmail.com/
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Acked-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-07-02 17:57:32 +08:00
|
|
|
bundle_header_release(&header);
|
2021-07-02 17:57:30 +08:00
|
|
|
cleanup:
|
|
|
|
free(bundle_file);
|
|
|
|
return ret;
|
2019-11-11 04:41:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int cmd_bundle(int argc, const char **argv, const char *prefix)
|
|
|
|
{
|
2022-08-20 00:04:01 +08:00
|
|
|
parse_opt_subcommand_fn *fn = NULL;
|
2019-11-11 04:41:24 +08:00
|
|
|
struct option options[] = {
|
2022-08-20 00:04:01 +08:00
|
|
|
OPT_SUBCOMMAND("create", &fn, cmd_bundle_create),
|
|
|
|
OPT_SUBCOMMAND("verify", &fn, cmd_bundle_verify),
|
|
|
|
OPT_SUBCOMMAND("list-heads", &fn, cmd_bundle_list_heads),
|
|
|
|
OPT_SUBCOMMAND("unbundle", &fn, cmd_bundle_unbundle),
|
2019-11-11 04:41:24 +08:00
|
|
|
OPT_END()
|
|
|
|
};
|
|
|
|
|
|
|
|
argc = parse_options(argc, argv, prefix, options, builtin_bundle_usage,
|
2022-08-20 00:04:01 +08:00
|
|
|
0);
|
2019-11-11 04:41:24 +08:00
|
|
|
|
|
|
|
packet_trace_identity("bundle");
|
|
|
|
|
2022-08-20 00:04:01 +08:00
|
|
|
return !!fn(argc, argv, 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
|
|
|
}
|