{"thread":{"id":"40566","subject":"[PATCH] Use the alternates of the source repository for dissociating clone","startedAt":"2015-10-15T11:28:41Z","lastAt":"2015-10-23T01:14:54Z","messageCount":16,"participants":["Alexander Riesen","Johannes Schindelin","Junio C Hamano","Johannes Löthberg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"271728","messageId":"561F8DE9.4040703@cetitec.com","threadId":"40566","inReplyTo":null,"subject":"[PATCH] Use the alternates of the source repository for dissociating clone","fromName":"Alexander Riesen","fromEmail":"alexander.riesen@cetitec.com","sentAt":"2015-10-15T11:28:41Z","receivedAt":"2015-10-15T11:28:41Z","isPatch":true,"sender":{"key":"alexander.riesen@cetitec.com","avatar":"https://avatars.githubusercontent.com/u/24452597?v=4"},"body":"The \"--dissociate\" option required reference repositories, which sometimes\ndemanded a look into the objects/info/alternates by the user. As this\nis something which can be figured out automatically, do it in the\nclone unless there is no other reference repositories.\n\nSigned-off-by: Alex Riesen <raa.lkml@gmail.com>\n---\n\nI often (enough) did something like this (preparing for manual backup):\n\n     # Run mc (the Midnight Commander, it is a console (ncurses) file manager with\n     # two panels).\n     # Select a repository.\n     $ git clone --mirror --dissociate \\\n       $(sed -e 's|\\(.*\\)/objects|--reference \\1| -- \n%f/.git/objects/info/alternates' 2>/dev/null) \\\n       %f %D/%f\n     # (except that this is one long line in mc)\n\nThe '%f' expands to a selected directory on the current panel, %D - to the\ncurrent directory on the other panel. But as I see, the combination of the\noptions \"--dissociate\" and no given references is not used for anything but\ngiving the warning yet. So maybe it can be used as a shortcut for the above?\n\n  builtin/clone.c | 42 ++++++++++++++++++++++++++++++++++++++----\n  1 file changed, 38 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 578da85..344bf21 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -791,6 +791,38 @@ static void write_refspec_config(const char *src_ref_prefix,\n      strbuf_release(&value);\n  }\n\n+static int copy_alternates_to_references(const char *src_repo)\n+{\n+    int refcnt = -1;\n+    char *src_alternates = mkpathdup(\"%s/objects/info/alternates\", src_repo);\n+    FILE *in = fopen(src_alternates, \"r\");\n+    if (in) {\n+        struct strbuf line = STRBUF_INIT;\n+        refcnt = 0;\n+        while (strbuf_getline(&line, in, '\\n') != EOF) {\n+            struct string_list_item item;\n+            if (line.len < 8 || line.buf[0] == '#')\n+                continue;\n+            ++refcnt;\n+            if (!strcmp(line.buf + line.len - 8, \"/objects\"))\n+                line.buf[line.len - 8] = '\\0';\n+            if (is_absolute_path(line.buf)) {\n+                item.string = line.buf;\n+                add_one_reference(&item, NULL);\n+                continue;\n+            }\n+            item.string = mkpathdup(\"%s/objects/%s\", src_repo, line.buf);\n+            normalize_path_copy(item.string, item.string);\n+            add_one_reference(&item, NULL);\n+            free(item.string);\n+        }\n+        strbuf_release(&line);\n+        fclose(in);\n+    }\n+    free(src_alternates);\n+    return refcnt;\n+}\n+\n  static void dissociate_from_references(void)\n  {\n      static const char* argv[] = { \"repack\", \"-a\", \"-d\", NULL };\n@@ -947,10 +979,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n\n      if (option_reference.nr)\n          setup_reference();\n-    else if (option_dissociate) {\n-        warning(_(\"--dissociate given, but there is no --reference\"));\n-        option_dissociate = 0;\n-    }\n\n      fetch_pattern = value.buf;\n      refspec = parse_fetch_refspec(1, &fetch_pattern);\n@@ -976,6 +1004,12 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n          warning(_(\"--local is ignored\"));\n      transport->cloning = 1;\n\n+    if (!option_reference.nr && option_dissociate &&\n+        copy_alternates_to_references(path) <= 0) {\n+        warning(_(\"--dissociate given, but there is no --reference\"));\n+        option_dissociate = 0;\n+    }\n+\n      if (!transport->get_refs_list || (!is_local && !transport->fetch))\n          die(_(\"Don't know how to clone %s\"), transport->url);\n\n-- \n2.6.1.150.gb633014\n"},{"id":"271734","messageId":"alpine.DEB.1.00.1510151609280.31610@s15462909.onlinehome-server.info","threadId":"40566","inReplyTo":"561F8DE9.4040703@cetitec.com","subject":"Re: [PATCH] Use the alternates of the source repository for dissociating clone","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2015-10-15T14:11:27Z","receivedAt":"2015-10-15T14:11:27Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Alex,\n\nOn Thu, 15 Oct 2015, Alexander Riesen wrote:\n\n> The \"--dissociate\" option required reference repositories, which sometimes\n> demanded a look into the objects/info/alternates by the user. As this\n> is something which can be figured out automatically, do it in the\n> clone unless there is no other reference repositories.\n\nWould it not make sense to reuse the copy_alternates() function to simply\ncopy the alternates and let `--dissociate` run its course with the copied\n.objects/info/alternate file? That would make for less new code...\n\nCiao,\nDscho\n"},{"id":"271735","messageId":"561FBA48.3050609@cetitec.com","threadId":"40566","inReplyTo":"alpine.DEB.1.00.1510151609280.31610@s15462909.onlinehome-server.info","subject":"[PATCH] Allow \"clone --dissociate\" to dissociate from alternates","fromName":"Alexander Riesen","fromEmail":"alexander.riesen@cetitec.com","sentAt":"2015-10-15T14:38:00Z","receivedAt":"2015-10-15T14:38:00Z","isPatch":true,"sender":{"key":"alexander.riesen@cetitec.com","avatar":"https://avatars.githubusercontent.com/u/24452597?v=4"},"body":"The option requiring the explicit reference repositories is a bit of overkill:\nthe alternates in the original repository *are* reference repositories and\nwould be dissociated from should one pass any reference repository (even an\nunrelated one).\n\nSigned-off-by: Alex Riesen <raa.lkml@gmail.com>\n---\n\nOn 10/15/2015 04:11 PM, Johannes Schindelin wrote:\n> On Thu, 15 Oct 2015, Alexander  Riesen wrote:\n >\n >> The \"--dissociate\" option required reference repositories, which sometimes\n >> demanded a look into the objects/info/alternates by the user. As this\n >> is something which can be figured out automatically, do it in the\n >> clone unless there is no other reference repositories.\n >\n > Would it not make sense to reuse the copy_alternates() function to simply\n > copy the alternates and let `--dissociate` run its course with the copied\n > .objects/info/alternate file? That would make for less new code...\n\nIIUC, I should validate the alternates in the source repository...\nBut, the only thing the user looses if it is not validated, is the nice\nwarning regarding no reference repositories to dissociate from, right?\n\nSo maybe we can just remove the reset of option_dissociate and be done with\nit? I would actually suggest removing the warning as well: the alternates are\nsomething to dissociate from. And I see no harm otherwise.\n\nHow about this instead?\n\n  builtin/clone.c | 4 ----\n  1 file changed, 4 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 578da85..b33d6f9 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -947,10 +947,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n\n      if (option_reference.nr)\n          setup_reference();\n-    else if (option_dissociate) {\n-        warning(_(\"--dissociate given, but there is no --reference\"));\n-        option_dissociate = 0;\n-    }\n\n      fetch_pattern = value.buf;\n      refspec = parse_fetch_refspec(1, &fetch_pattern);\n-- \n2.6.1.151.g74e8091\n"},{"id":"271778","messageId":"xmqqbnbzhjym.fsf@gitster.mtv.corp.google.com","threadId":"40566","inReplyTo":"561F8DE9.4040703@cetitec.com","subject":"Re: [PATCH] Use the alternates of the source repository for dissociating clone","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-10-15T21:59:13Z","receivedAt":"2015-10-15T21:59:13Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexander Riesen <alexander.riesen@cetitec.com> writes:\n\n> The \"--dissociate\" option required reference repositories, which sometimes\n> demanded a look into the objects/info/alternates by the user. As this\n> is something which can be figured out automatically, do it in the\n> clone unless there is no other reference repositories.\n\nI do not quite get this.\n\nBefore \"clone\" with or without \"--dissociate\" there is no\nobjects/info/alternates (before \"clone\", there is no \".git\" to find\nthat file in the first place).\n\nAre you talking about making a clone of a repository that was\ncreated with \"clone --reference\", to borrow from the same\nthird repository the original is borrowing from?\n"},{"id":"271797","messageId":"5620A0A9.5060007@cetitec.com","threadId":"40566","inReplyTo":"xmqqbnbzhjym.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] Use the alternates of the source repository for dissociating clone","fromName":"Alexander Riesen","fromEmail":"alexander.riesen@cetitec.com","sentAt":"2015-10-16T07:00:57Z","receivedAt":"2015-10-16T07:00:57Z","isPatch":true,"sender":{"key":"alexander.riesen@cetitec.com","avatar":"https://avatars.githubusercontent.com/u/24452597?v=4"},"body":"Resend. The previous replies didn't make it to git-ml because of html part \ninserted by gmail.\n\nOn 10/15/2015 11:59 PM, Junio C Hamano wrote:\n> Are you talking about making a clone of a repository that was\n> created with \"clone --reference\", to borrow from the same\n> third repository the original is borrowing from?\nYes. Or the alternates file was created manually in the source repository.\n"},{"id":"272029","messageId":"56274922.80007@cetitec.com","threadId":"40566","inReplyTo":"561FBA48.3050609@cetitec.com","subject":"Re: [PATCH] Allow \"clone --dissociate\" to dissociate from alternates","fromName":"Alexander Riesen","fromEmail":"alexander.riesen@cetitec.com","sentAt":"2015-10-21T08:13:22Z","receivedAt":"2015-10-21T08:13:22Z","isPatch":true,"sender":{"key":"alexander.riesen@cetitec.com","avatar":"https://avatars.githubusercontent.com/u/24452597?v=4"},"body":"Reminder. Is this (or rather the one I'm replying to) patch a better option?\n\nRegards,\nAlex\n\nOn 10/15/2015 04:38 PM, Alexander Riesen wrote:\n> The option requiring the explicit reference repositories is a bit of overkill:\n> the alternates in the original repository *are* reference repositories and\n> would be dissociated from should one pass any reference repository (even an\n> unrelated one).\n>\n> Signed-off-by: Alex Riesen <raa.lkml@gmail.com>\n> ---\n>\n> On 10/15/2015 04:11 PM, Johannes Schindelin wrote:\n>> On Thu, 15 Oct 2015, Alexander  Riesen wrote:\n> >\n> >> The \"--dissociate\" option required reference repositories, which sometimes\n> >> demanded a look into the objects/info/alternates by the user. As this\n> >> is something which can be figured out automatically, do it in the\n> >> clone unless there is no other reference repositories.\n> >\n> > Would it not make sense to reuse the copy_alternates() function to simply\n> > copy the alternates and let `--dissociate` run its course with the copied\n> > .objects/info/alternate file? That would make for less new code...\n>\n> IIUC, I should validate the alternates in the source repository...\n> But, the only thing the user looses if it is not validated, is the nice\n> warning regarding no reference repositories to dissociate from, right?\n>\n> So maybe we can just remove the reset of option_dissociate and be done with\n> it? I would actually suggest removing the warning as well: the alternates are\n> something to dissociate from. And I see no harm otherwise.\n>\n> How about this instead?\n>\n"},{"id":"272045","messageId":"xmqqpp085cth.fsf@gitster.mtv.corp.google.com","threadId":"40566","inReplyTo":"56274922.80007@cetitec.com","subject":"Re: [PATCH] Allow \"clone --dissociate\" to dissociate from alternates","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-10-21T17:52:26Z","receivedAt":"2015-10-21T17:52:26Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexander Riesen <alexander.riesen@cetitec.com> writes:\n\n> Reminder. Is this (or rather the one I'm replying to) patch a better option?\n\nI suspect that the reason why you didn't get any quick response was\nbecause it was unclear from either one of these proposed log\nmessages why any change is needed in the first place.  At least that\nis what prevented me from commenting on either.\n\nThe \"clone --dissociate\" was designed to be used with \"--reference\".\nThe mindset of those who saw the need for the feature being that\n\"clone --reference\" is the only way to make the resulting\nrepository's objects incomplete, needing to borrow objects from some\nother place, which necessitates the \"--dissociate\" option.\n\nThe readers of this change need to be enlightened with a log message\nto remind them that \"--reference\" is not the only way.  Namely, if\nyou start from a repository with $GIT_DIR/objects/info/alternates,\ni.e. the original already borrows from somewhere, and bypass the\nnormal \"Git aware\" transport mechanism, i.e. \"git clone --local\",\nthen the resulting repository would also become dependent of the\nobject store that the original depended on before the clone.  In\norder to make it free-standing, you would need \"--dissociate\", but\nthere is no \"--reference\" involved in that use case.\n\nAnd once that is clarified, it becomes very clear why it is wrong to\nblindly require \"--reference\" to be there on the command line when\n\"--dissociate\" is given.\n\nAs to the patch, I think this one is much simpler and preferrable.\nIt would hurt those who make a clone without bypassing the normal\n\"Git aware\" transport mechanism and pass \"--dissociate\" without\n\"--reference\".  They will end up making a clone that does not need\nrepacking to dissociate, but with this patch they would spend extra\ncycles to run an unnecessary repack.  To avoid that, I think you can\nthrow in an check at the beginning of dissociate_from_references()\nto see if git_path(\"objects/info/alternates\") is there and make the\nfunction a no-op if there isn't.\n\nThanks.\n"},{"id":"272100","messageId":"5628EBAF.1030205@cetitec.com","threadId":"40566","inReplyTo":"xmqqpp085cth.fsf@gitster.mtv.corp.google.com","subject":"[PATCH] Consider object stores in alternates during a dissociating clone","fromName":"Alexander Riesen","fromEmail":"alexander.riesen@cetitec.com","sentAt":"2015-10-22T13:59:11Z","receivedAt":"2015-10-22T13:59:11Z","isPatch":true,"sender":{"key":"alexander.riesen@cetitec.com","avatar":"https://avatars.githubusercontent.com/u/24452597?v=4"},"body":"From: Alex Riesen <raa.lkml@gmail.com>\n\nThe \"--reference\" option is not the only way to provide a repository to borrow\nobjects from.\nFor instance, the objects/info/alternates of the origin repository lists\nobject stores which the origin repository borrowed objects from. During\nclone operations which bypass a git aware transport (i.e.  simply copy the\nthings over, like git clone --local) the file is copied into the cloned\nrepository.\nIn such a case, even if there were no reference repositories given in the\ncommand-line, there might be still something to \"dissociate\" the cloned\nrepository from, before it is really independent.\n\nSigned-off-by: Alex Riesen <raa.lkml@gmail.com>\n---\n\nOn 10/21/2015 07:52 PM, Junio C Hamano wrote:\n> The readers of this change need  to be enlightened with a log message\n > to remind them that \"--reference\" is not the only way. Namely, if\n > you start from a repository with $GIT_DIR/objects/info/alternates,\n > i.e. the original already borrows from somewhere, and bypass the\n > normal \"Git aware\" transport mechanism, i.e. \"git clone --local\",\n > then the resulting repository would also become dependent of the\n > object store that the original depended on before the clone. In\n > order to make it free-standing, you would need \"--dissociate\", but\n > there is no \"--reference\" involved in that use case.\n >\n > And once that is clarified, it becomes very clear why it is wrong to\n > blindly require \"--reference\" to be there on the command line when\n > \"--dissociate\" is given.\n\nIndeed. Log message improved.\n\n> As to the patch, I think this  one is much simpler and preferrable.\n > It would hurt those who make a clone without bypassing the normal\n > \"Git aware\" transport mechanism and pass \"--dissociate\" without\n > \"--reference\".  They will end up making a clone that does not need\n > repacking to dissociate, but with this patch they would spend extra\n > cycles to run an unnecessary repack.  To avoid that, I think you can\n > throw in an check at the beginning of dissociate_from_references()\n > to see if git_path(\"objects/info/alternates\") is there and make the\n > function a no-op if there isn't.\n\nI think I understand. How about this?\n\n  builtin/clone.c | 10 +++++-----\n  1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 9eaecd9..a7d0c07 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -801,11 +801,15 @@ static void write_refspec_config(const char *src_ref_prefix,\n  static void dissociate_from_references(void)\n  {\n      static const char* argv[] = { \"repack\", \"-a\", \"-d\", NULL };\n+    char *alts = git_pathdup(\"objects/info/alternates\");\n\n+    if (access(alts, F_OK) < 0)\n+        return;\n      if (run_command_v_opt(argv, RUN_GIT_CMD|RUN_COMMAND_NO_STDIN))\n          die(_(\"cannot repack to clean up\"));\n-    if (unlink(git_path(\"objects/info/alternates\")) && errno != ENOENT)\n+    if (unlink(alts) && errno != ENOENT)\n          die_errno(_(\"cannot unlink temporary alternates file\"));\n+    free(alts);\n  }\n\n  int cmd_clone(int argc, const char **argv, const char *prefix)\n@@ -954,10 +958,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n\n      if (option_reference.nr)\n          setup_reference();\n-    else if (option_dissociate) {\n-        warning(_(\"--dissociate given, but there is no --reference\"));\n-        option_dissociate = 0;\n-    }\n\n      fetch_pattern = value.buf;\n      refspec = parse_fetch_refspec(1, &fetch_pattern);\n-- \n2.6.1.151.ge74ab91\n"},{"id":"272107","messageId":"xmqq7fmeubkf.fsf@gitster.mtv.corp.google.com","threadId":"40566","inReplyTo":"5628EBAF.1030205@cetitec.com","subject":"Re: [PATCH] Consider object stores in alternates during a dissociating clone","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-10-22T16:12:32Z","receivedAt":"2015-10-22T16:12:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexander Riesen <alexander.riesen@cetitec.com> writes:\n\n> I think I understand. How about this?\n>\n>  builtin/clone.c | 10 +++++-----\n>  1 file changed, 5 insertions(+), 5 deletions(-)\n>\n> diff --git a/builtin/clone.c b/builtin/clone.c\n> index 9eaecd9..a7d0c07 100644\n> --- a/builtin/clone.c\n> +++ b/builtin/clone.c\n> @@ -801,11 +801,15 @@ static void write_refspec_config(const char *src_ref_prefix,\n>  static void dissociate_from_references(void)\n>  {\n>      static const char* argv[] = { \"repack\", \"-a\", \"-d\", NULL };\n> +    char *alts = git_pathdup(\"objects/info/alternates\");\n>\n> +    if (access(alts, F_OK) < 0)\n> +        return;\n\nYou leak alts here.\n\n>      if (run_command_v_opt(argv, RUN_GIT_CMD|RUN_COMMAND_NO_STDIN))\n>          die(_(\"cannot repack to clean up\"));\n> -    if (unlink(git_path(\"objects/info/alternates\")) && errno != ENOENT)\n> +    if (unlink(alts) && errno != ENOENT)\n>          die_errno(_(\"cannot unlink temporary alternates file\"));\n> +    free(alts);\n>  }\n>\n>  int cmd_clone(int argc, const char **argv, const char *prefix)\n> @@ -954,10 +958,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n>\n>      if (option_reference.nr)\n>          setup_reference();\n> -    else if (option_dissociate) {\n> -        warning(_(\"--dissociate given, but there is no --reference\"));\n> -        option_dissociate = 0;\n> -    }\n>\n>      fetch_pattern = value.buf;\n>      refspec = parse_fetch_refspec(1, &fetch_pattern);\n\nPerhaps you would want a new test somewhere that (1) prepares the\nultimate source, (2) prepares a borrowing source with \"clone\n--reference\" from the previous, (3) creates a local clone of the\nprevious with \"clone --local\" without \"--reference\" but with\n\"--dissociate\", and (4) checks the end result by ensuring the\nabsense of $GIT_DIR/objects/info/alternates and runs \"fsck\" on it.\n\nOther than these two points, the patch looks good to me.\n"},{"id":"272109","messageId":"562911AD.50004@cetitec.com","threadId":"40566","inReplyTo":"xmqq7fmeubkf.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] Consider object stores in alternates during a dissociating clone","fromName":"Alexander Riesen","fromEmail":"alexander.riesen@cetitec.com","sentAt":"2015-10-22T16:41:17Z","receivedAt":"2015-10-22T16:41:17Z","isPatch":true,"sender":{"key":"alexander.riesen@cetitec.com","avatar":"https://avatars.githubusercontent.com/u/24452597?v=4"},"body":"From: Alex Riesen <raa.lkml@gmail.com>\n\nThe \"--reference\" option is not the only way to provide a repository to borrow\nobjects from.\nFor instance, the objects/info/alternates of the origin repository lists\nobject stores which the origin repository borrowed objects from. During\nclone operations which bypass a git aware transport (i.e.  simply copy the\nthings over, like git clone --local) the file is copied into the cloned\nrepository.\nIn such a case, even if there were no reference repositories given in the\ncommand-line, there might be still something to \"dissociate\" the cloned\nrepository from, before it is really independent.\n\nSigned-off-by: Alex Riesen <raa.lkml@gmail.com>\n---\nOn 10/22/2015 06:12 PM, Junio C Hamano wrote:\n> Alexander Riesen  <alexander.riesen@cetitec.com> writes:\n >> +    if (access(alts, F_OK) < 0)\n >> +        return;\n >\n > You leak alts here.\n\nFixed.\n\n> Perhaps you would want a new  test somewhere that (1) prepares the\n > ultimate source, (2) prepares a borrowing source with \"clone\n > --reference\" from the previous, (3) creates a local clone of the\n > previous with \"clone --local\" without \"--reference\" but with\n > \"--dissociate\", and (4) checks the end result by ensuring the\n > absense of $GIT_DIR/objects/info/alternates and runs \"fsck\" on it.\n\nAdded. t5700-clone-reference seemed like a logical place for it.\n\nRegards,\nAlex\n\n---\n  builtin/clone.c            | 11 ++++++-----\n  t/t5700-clone-reference.sh | 11 +++++++++++\n  2 files changed, 17 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 9eaecd9..1e14810 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -801,11 +801,16 @@ static void write_refspec_config(const char *src_ref_prefix,\n  static void dissociate_from_references(void)\n  {\n      static const char* argv[] = { \"repack\", \"-a\", \"-d\", NULL };\n+    char *alts = git_pathdup(\"objects/info/alternates\");\n\n+    if (access(alts, F_OK) < 0)\n+        goto done;\n      if (run_command_v_opt(argv, RUN_GIT_CMD|RUN_COMMAND_NO_STDIN))\n          die(_(\"cannot repack to clean up\"));\n-    if (unlink(git_path(\"objects/info/alternates\")) && errno != ENOENT)\n+    if (unlink(alts) && errno != ENOENT)\n          die_errno(_(\"cannot unlink temporary alternates file\"));\n+done:\n+    free(alts);\n  }\n\n  int cmd_clone(int argc, const char **argv, const char *prefix)\n@@ -954,10 +959,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n\n      if (option_reference.nr)\n          setup_reference();\n-    else if (option_dissociate) {\n-        warning(_(\"--dissociate given, but there is no --reference\"));\n-        option_dissociate = 0;\n-    }\n\n      fetch_pattern = value.buf;\n      refspec = parse_fetch_refspec(1, &fetch_pattern);\ndiff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh\nindex 2250ef4..dfa1bf7 100755\n--- a/t/t5700-clone-reference.sh\n+++ b/t/t5700-clone-reference.sh\n@@ -210,4 +210,15 @@ test_expect_success 'clone, dissociate from partial \nreference and repack' '\n      test_line_count = 1 packs.txt\n  '\n\n+test_expect_success 'clone, dissociate from alternates' '\n+    rm -fr A B C &&\n+    test_create_repo A &&\n+    commit_in A file1 &&\n+    git clone --reference=A A B &&\n+    test_line_count = 1 B/.git/objects/info/alternates &&\n+    git clone --local --dissociate B C &&\n+    ! test -f C/.git/objects/info/alternates &&\n+    ( cd C && git fsck )\n+'\n+\n  test_done\n-- \n2.6.2.313.gdf7a1dc\n"},{"id":"272112","messageId":"xmqqd1w6ssg5.fsf@gitster.mtv.corp.google.com","threadId":"40566","inReplyTo":"562911AD.50004@cetitec.com","subject":"Re: [PATCH] Consider object stores in alternates during a dissociating clone","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-10-22T17:50:50Z","receivedAt":"2015-10-22T17:50:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexander Riesen <alexander.riesen@cetitec.com> writes:\n\n>> Content-Type: text/plain; charset=windows-1252; format=flowed\n\nI had to hand-munge it as the above lost all tabs and made the patch\nunusable for machines X-<.\n\nRe-reading the documentation, I realized that the use case this new\nmode of operation allows is totally outside of the original design\nspace that was described, so I added a note to teach users how the\noption can be used in a new way as well.\n\nSo here is what I tentatively queued.\n\nThanks.\n\n-- >8 --\nFrom: Alex Riesen <raa.lkml@gmail.com>\nDate: Thu, 22 Oct 2015 18:41:17 +0200\nSubject: [PATCH] clone: allow \"--dissociate\" without reference\n\nThe \"--reference\" option is not the only way to provide a repository\nto borrow objects from.  A repository that borrows from another\nrepository can be cloned with \"clone --local\" and the resulting\nrepository will borrow from the same repository, which the user\nmay want to \"--dissociate\" from.\n\nSigned-off-by: Alex Riesen <raa.lkml@gmail.com>\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Documentation/git-clone.txt |  9 +++++++--\n builtin/clone.c             | 16 ++++++++--------\n t/t5700-clone-reference.sh  | 11 +++++++++++\n 3 files changed, 26 insertions(+), 10 deletions(-)\n\ndiff --git a/Documentation/git-clone.txt b/Documentation/git-clone.txt\nindex f1f2a3f..a8c11e3 100644\n--- a/Documentation/git-clone.txt\n+++ b/Documentation/git-clone.txt\n@@ -104,8 +104,13 @@ objects from the source repository into a pack in the cloned repository.\n --dissociate::\n \tBorrow the objects from reference repositories specified\n \twith the `--reference` options only to reduce network\n-\ttransfer and stop borrowing from them after a clone is made\n-\tby making necessary local copies of borrowed objects.\n+\ttransfer, and stop borrowing from them after a clone is made\n+\tby making necessary local copies of borrowed objects.  This\n+\toption can also be used when cloning locally from a\n+\trepository that already borrows objects from another\n+\trepository---the new repository will borrow objects from the\n+\tsame repository, and this option can be used to stop the\n+\tborrowing.\n \n --quiet::\n -q::\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 9eaecd9..caae43e 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -801,11 +801,15 @@ static void write_refspec_config(const char *src_ref_prefix,\n static void dissociate_from_references(void)\n {\n \tstatic const char* argv[] = { \"repack\", \"-a\", \"-d\", NULL };\n+\tchar *alternates = git_pathdup(\"objects/info/alternates\");\n \n-\tif (run_command_v_opt(argv, RUN_GIT_CMD|RUN_COMMAND_NO_STDIN))\n-\t\tdie(_(\"cannot repack to clean up\"));\n-\tif (unlink(git_path(\"objects/info/alternates\")) && errno != ENOENT)\n-\t\tdie_errno(_(\"cannot unlink temporary alternates file\"));\n+\tif (!access(alternates, F_OK)) {\n+\t\tif (run_command_v_opt(argv, RUN_GIT_CMD|RUN_COMMAND_NO_STDIN))\n+\t\t\tdie(_(\"cannot repack to clean up\"));\n+\t\tif (unlink(alternates) && errno != ENOENT)\n+\t\t\tdie_errno(_(\"cannot unlink temporary alternates file\"));\n+\t}\n+\tfree(alternates);\n }\n \n int cmd_clone(int argc, const char **argv, const char *prefix)\n@@ -954,10 +958,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix)\n \n \tif (option_reference.nr)\n \t\tsetup_reference();\n-\telse if (option_dissociate) {\n-\t\twarning(_(\"--dissociate given, but there is no --reference\"));\n-\t\toption_dissociate = 0;\n-\t}\n \n \tfetch_pattern = value.buf;\n \trefspec = parse_fetch_refspec(1, &fetch_pattern);\ndiff --git a/t/t5700-clone-reference.sh b/t/t5700-clone-reference.sh\nindex 2250ef4..dfa1bf7 100755\n--- a/t/t5700-clone-reference.sh\n+++ b/t/t5700-clone-reference.sh\n@@ -210,4 +210,15 @@ test_expect_success 'clone, dissociate from partial reference and repack' '\n \ttest_line_count = 1 packs.txt\n '\n \n+test_expect_success 'clone, dissociate from alternates' '\n+\trm -fr A B C &&\n+\ttest_create_repo A &&\n+\tcommit_in A file1 &&\n+\tgit clone --reference=A A B &&\n+\ttest_line_count = 1 B/.git/objects/info/alternates &&\n+\tgit clone --local --dissociate B C &&\n+\t! test -f C/.git/objects/info/alternates &&\n+\t( cd C && git fsck )\n+'\n+\n test_done\n-- \n2.6.2-383-g4ea3cbc\n"},{"id":"272113","messageId":"56292612.3020609@cetitec.com","threadId":"40566","inReplyTo":"xmqqd1w6ssg5.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] Consider object stores in alternates during a dissociating clone","fromName":"Alexander Riesen","fromEmail":"alexander.riesen@cetitec.com","sentAt":"2015-10-22T18:08:18Z","receivedAt":"2015-10-22T18:08:18Z","isPatch":true,"sender":{"key":"alexander.riesen@cetitec.com","avatar":"https://avatars.githubusercontent.com/u/24452597?v=4"},"body":"On 10/22/2015 07:50 PM, Junio C Hamano wrote:\n> Alexander Riesen <alexander.riesen@cetitec.com> writes:\n>\n>>> Content-Type: text/plain; charset=windows-1252; format=flowed\n> I had to hand-munge it as the above lost all tabs and made the patch\n> unusable for machines X-<.\nI'm very sorry. I don't know why Icedove does that, nor do\nI know how to stop it mangling the text. Right now I just\nhate the damn thing.\n\nThank you very much for reformatting the patch, as it would\ntake quite some time until I configure a sane mail program\nto work here.\n\nIncidentally, what does \"---\" mean in the documentation hunk?\n\nRegards,\nAlex\n"},{"id":"272115","messageId":"xmqq4mhisqgg.fsf@gitster.mtv.corp.google.com","threadId":"40566","inReplyTo":"56292612.3020609@cetitec.com","subject":"Re: [PATCH] Consider object stores in alternates during a dissociating clone","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-10-22T18:33:51Z","receivedAt":"2015-10-22T18:33:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Alexander Riesen <alexander.riesen@cetitec.com> writes:\n\n> Incidentally, what does \"---\" mean in the documentation hunk?\n\nHeh, good eyes.  I was hoping that it would turn into an em-dash,\nbut it seems I just get three dashes instead.\n"},{"id":"272116","messageId":"xmqqzizarb7y.fsf@gitster.mtv.corp.google.com","threadId":"40566","inReplyTo":"xmqq4mhisqgg.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH] Consider object stores in alternates during a dissociating clone","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-10-22T18:48:17Z","receivedAt":"2015-10-22T18:48:17Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Alexander Riesen <alexander.riesen@cetitec.com> writes:\n>\n>> Incidentally, what does \"---\" mean in the documentation hunk?\n>\n> Heh, good eyes.  I was hoping that it would turn into an em-dash,\n> but it seems I just get three dashes instead.\n\nOutside relnotes, there seem to be a handful instances of those\nthat expresses em-dash with \"---\".\n\n$ git grep -E '[A-Za-z]{2,}---[A-Za-z]{2,}' Documentation/\ngit-bisect.txt:command not found, 126 is for command found but not executable---these\ngit-clone.txt:\trepository---the new repository will borrow objects from the\ngit-fetch.txt:  the refspecs---they specify which refs to fetch and which local refs\ngit-push.txt:be omitted---such a push will update a ref that `<src>` normally updates\ntechnical/index-format.txt:  first subtree---let's call this A---of the root level...\n\nI'll leave it for a separate topic to clean these up later.\n"},{"id":"272118","messageId":"xmqqpp06r7ea.fsf_-_@gitster.mtv.corp.google.com","threadId":"40566","inReplyTo":"xmqqzizarb7y.fsf@gitster.mtv.corp.google.com","subject":"[PATCH] Documentation: AsciiDoc spells em-dash as double-dashes, not triple","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-10-22T20:10:53Z","receivedAt":"2015-10-22T20:10:53Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Again, we do not usually process release notes with AsciiDoc, but it\nis better to be consistent.\n\nThis incidentally reveals breakages left by an ancient 5e00439f\n(Documentation: build html for all files in technical and howto,\n2012-10-23).  The index-format documentation was originally written\nto be read as straight text without formatting and when the commit\nforced everything in Documentation/ to go through AsciiDoc, it did\nnot do any adjustment--hence the double-dashes will be seen in the\nresulting text that is rendered as preformatted fixed-width without\nconverted into em-dashes.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * An follow-up to recent AsciiDoc markup fixes.\n\n Documentation/RelNotes/1.7.7.txt         | 2 +-\n Documentation/RelNotes/1.9.0.txt         | 2 +-\n Documentation/git-bisect.txt             | 2 +-\n Documentation/git-fetch.txt              | 2 +-\n Documentation/git-push.txt               | 2 +-\n Documentation/technical/index-format.txt | 2 +-\n 6 files changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/RelNotes/1.7.7.txt b/Documentation/RelNotes/1.7.7.txt\nindex 7655ccc..6eff128 100644\n--- a/Documentation/RelNotes/1.7.7.txt\n+++ b/Documentation/RelNotes/1.7.7.txt\n@@ -84,7 +84,7 @@ Updates since v1.7.6\n    logic used by \"git diff\" to determine the hunk header.\n \n  * Invoking the low-level \"git http-fetch\" without \"-a\" option (which\n-   git itself never did---normal users should not have to worry about\n+   git itself never did--normal users should not have to worry about\n    this) is now deprecated.\n \n  * The \"--decorate\" option to \"git log\" and its family learned to\ndiff --git a/Documentation/RelNotes/1.9.0.txt b/Documentation/RelNotes/1.9.0.txt\nindex 752d791..4e4b88a 100644\n--- a/Documentation/RelNotes/1.9.0.txt\n+++ b/Documentation/RelNotes/1.9.0.txt\n@@ -177,7 +177,7 @@ Performance, Internal Implementation, etc.\n  * The naming convention of the packfiles has been updated; it used to\n    be based on the enumeration of names of the objects that are\n    contained in the pack, but now it also depends on how the packed\n-   result is represented---packing the same set of objects using\n+   result is represented--packing the same set of objects using\n    different settings (or delta order) would produce a pack with\n    different name.\n \ndiff --git a/Documentation/git-bisect.txt b/Documentation/git-bisect.txt\nindex 4cb52a7..617efa0 100644\n--- a/Documentation/git-bisect.txt\n+++ b/Documentation/git-bisect.txt\n@@ -245,7 +245,7 @@ cannot be tested. If the script exits with this code, the current\n revision will be skipped (see `git bisect skip` above). 125 was chosen\n as the highest sensible value to use for this purpose, because 126 and 127\n are used by POSIX shells to signal specific error status (127 is for\n-command not found, 126 is for command found but not executable---these\n+command not found, 126 is for command found but not executable--these\n details do not matter, as they are normal errors in the script, as far as\n \"bisect run\" is concerned).\n \ndiff --git a/Documentation/git-fetch.txt b/Documentation/git-fetch.txt\nindex 8deb614..ee51c1a 100644\n--- a/Documentation/git-fetch.txt\n+++ b/Documentation/git-fetch.txt\n@@ -71,7 +71,7 @@ This configuration is used in two ways:\n * When `git fetch` is run without specifying what branches\n   and/or tags to fetch on the command line, e.g. `git fetch origin`\n   or `git fetch`, `remote.<repository>.fetch` values are used as\n-  the refspecs---they specify which refs to fetch and which local refs\n+  the refspecs--they specify which refs to fetch and which local refs\n   to update.  The example above will fetch\n   all branches that exist in the `origin` (i.e. any ref that matches\n   the left-hand side of the value, `refs/heads/*`) and update the\ndiff --git a/Documentation/git-push.txt b/Documentation/git-push.txt\nindex b17283a..3267e21 100644\n--- a/Documentation/git-push.txt\n+++ b/Documentation/git-push.txt\n@@ -61,7 +61,7 @@ be named.\n If `git push [<repository>]` without any `<refspec>` argument is set to\n update some ref at the destination with `<src>` with\n `remote.<repository>.push` configuration variable, `:<dst>` part can\n-be omitted---such a push will update a ref that `<src>` normally updates\n+be omitted--such a push will update a ref that `<src>` normally updates\n without any `<refspec>` on the command line.  Otherwise, missing\n `:<dst>` means to update the same ref as the `<src>`.\n +\ndiff --git a/Documentation/technical/index-format.txt b/Documentation/technical/index-format.txt\nindex 1250b5c..61cb55d 100644\n--- a/Documentation/technical/index-format.txt\n+++ b/Documentation/technical/index-format.txt\n@@ -170,7 +170,7 @@ Git index format\n \n   The entries are written out in the top-down, depth-first order.  The\n   first entry represents the root level of the repository, followed by the\n-  first subtree---let's call this A---of the root level (with its name\n+  first subtree--let's call this A--of the root level (with its name\n   relative to the root level), followed by the first subtree of A (with\n   its name relative to A), ...\n \n-- \n2.6.2-390-g2f019b7\n"},{"id":"272126","messageId":"20151023011454.GA21004@zorg.kyriasis.com","threadId":"40566","inReplyTo":"56292612.3020609@cetitec.com","subject":"Re: [PATCH] Consider object stores in alternates during a dissociating clone","fromName":"Johannes Löthberg","fromEmail":"johannes@kyriasis.com","sentAt":"2015-10-23T01:14:54Z","receivedAt":"2015-10-23T01:14:54Z","isPatch":true,"sender":{"key":"johannes@kyriasis.com","avatar":"https://gravatar.com/avatar/af2dea1b1759403329a1b7eaa28a07b5c5d1901e9f55723103d6324ffb7737ae?d=mp&s=160"},"body":"On 22/10, Alexander Riesen wrote:\n>On 10/22/2015 07:50 PM, Junio C Hamano wrote:\n>>Alexander Riesen <alexander.riesen@cetitec.com> writes:\n>>\n>>>>Content-Type: text/plain; charset=windows-1252; format=flowed\n>>I had to hand-munge it as the above lost all tabs and made the patch\n>>unusable for machines X-<.\n>I'm very sorry. I don't know why Icedove does that, nor do\n>I know how to stop it mangling the text. Right now I just\n>hate the damn thing.\n>\n>Thank you very much for reformatting the patch, as it would\n>take quite some time until I configure a sane mail program\n>to work here.\n>\n\nTip: Just use git-send-email instead. There's even an example \nconfiguration for gmail in the manpage.\n\n-- \nSincerely,\n  Johannes Löthberg\n  PGP Key ID: 0x50FB9B273A9D0BB5\n  https://theos.kyriasis.com/~kyrias/\n"}]}