From: Alexander Riesen <alexander.riesen@cetitec.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Johannes Sixt <j6t@kdbg.org>
Subject: [PATCH] Use the alternates of the source repository for dissociating clone
Date: Thu, 15 Oct 2015 13:28:41 +0200 [thread overview]
Message-ID: <561F8DE9.4040703@cetitec.com> (raw)
The "--dissociate" option required reference repositories, which sometimes
demanded a look into the objects/info/alternates by the user. As this
is something which can be figured out automatically, do it in the
clone unless there is no other reference repositories.
Signed-off-by: Alex Riesen <raa.lkml@gmail.com>
---
I often (enough) did something like this (preparing for manual backup):
# Run mc (the Midnight Commander, it is a console (ncurses) file manager with
# two panels).
# Select a repository.
$ git clone --mirror --dissociate \
$(sed -e 's|\(.*\)/objects|--reference \1| --
%f/.git/objects/info/alternates' 2>/dev/null) \
%f %D/%f
# (except that this is one long line in mc)
The '%f' expands to a selected directory on the current panel, %D - to the
current directory on the other panel. But as I see, the combination of the
options "--dissociate" and no given references is not used for anything but
giving the warning yet. So maybe it can be used as a shortcut for the above?
builtin/clone.c | 42 ++++++++++++++++++++++++++++++++++++++----
1 file changed, 38 insertions(+), 4 deletions(-)
diff --git a/builtin/clone.c b/builtin/clone.c
index 578da85..344bf21 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -791,6 +791,38 @@ static void write_refspec_config(const char *src_ref_prefix,
strbuf_release(&value);
}
+static int copy_alternates_to_references(const char *src_repo)
+{
+ int refcnt = -1;
+ char *src_alternates = mkpathdup("%s/objects/info/alternates", src_repo);
+ FILE *in = fopen(src_alternates, "r");
+ if (in) {
+ struct strbuf line = STRBUF_INIT;
+ refcnt = 0;
+ while (strbuf_getline(&line, in, '\n') != EOF) {
+ struct string_list_item item;
+ if (line.len < 8 || line.buf[0] == '#')
+ continue;
+ ++refcnt;
+ if (!strcmp(line.buf + line.len - 8, "/objects"))
+ line.buf[line.len - 8] = '\0';
+ if (is_absolute_path(line.buf)) {
+ item.string = line.buf;
+ add_one_reference(&item, NULL);
+ continue;
+ }
+ item.string = mkpathdup("%s/objects/%s", src_repo, line.buf);
+ normalize_path_copy(item.string, item.string);
+ add_one_reference(&item, NULL);
+ free(item.string);
+ }
+ strbuf_release(&line);
+ fclose(in);
+ }
+ free(src_alternates);
+ return refcnt;
+}
+
static void dissociate_from_references(void)
{
static const char* argv[] = { "repack", "-a", "-d", NULL };
@@ -947,10 +979,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
if (option_reference.nr)
setup_reference();
- else if (option_dissociate) {
- warning(_("--dissociate given, but there is no --reference"));
- option_dissociate = 0;
- }
fetch_pattern = value.buf;
refspec = parse_fetch_refspec(1, &fetch_pattern);
@@ -976,6 +1004,12 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
warning(_("--local is ignored"));
transport->cloning = 1;
+ if (!option_reference.nr && option_dissociate &&
+ copy_alternates_to_references(path) <= 0) {
+ warning(_("--dissociate given, but there is no --reference"));
+ option_dissociate = 0;
+ }
+
if (!transport->get_refs_list || (!is_local && !transport->fetch))
die(_("Don't know how to clone %s"), transport->url);
--
2.6.1.150.gb633014
next reply other threads:[~2015-10-15 11:28 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-15 11:28 Alexander Riesen [this message]
2015-10-15 14:11 ` [PATCH] Use the alternates of the source repository for dissociating clone Johannes Schindelin
2015-10-15 14:38 ` [PATCH] Allow "clone --dissociate" to dissociate from alternates Alexander Riesen
2015-10-21 8:13 ` Alexander Riesen
2015-10-21 17:52 ` Junio C Hamano
2015-10-22 13:59 ` [PATCH] Consider object stores in alternates during a dissociating clone Alexander Riesen
2015-10-22 16:12 ` Junio C Hamano
2015-10-22 16:41 ` Alexander Riesen
2015-10-22 17:50 ` Junio C Hamano
2015-10-22 18:08 ` Alexander Riesen
2015-10-22 18:33 ` Junio C Hamano
2015-10-22 18:48 ` Junio C Hamano
2015-10-22 20:10 ` [PATCH] Documentation: AsciiDoc spells em-dash as double-dashes, not triple Junio C Hamano
2015-10-23 1:14 ` [PATCH] Consider object stores in alternates during a dissociating clone Johannes Löthberg
2015-10-15 21:59 ` [PATCH] Use the alternates of the source repository for " Junio C Hamano
2015-10-16 7:00 ` Alexander Riesen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=561F8DE9.4040703@cetitec.com \
--to=alexander.riesen@cetitec.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j6t@kdbg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).