{"thread":{"id":"1507","subject":"[PATCH] Add cheap local clone '-s' flag to git-clone-script","startedAt":"2005-08-14T08:20:37Z","lastAt":"2005-08-14T08:20:37Z","messageCount":1,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"7240","messageId":"7v4q9tdj56.fsf@assigned-by-dhcp.cox.net","threadId":"1507","inReplyTo":null,"subject":"[PATCH] Add cheap local clone '-s' flag to git-clone-script","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2005-08-14T08:20:37Z","receivedAt":"2005-08-14T08:20:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Using the $GIT_OBJECT_DIRECTORY/info/alternates mechanism,\ncreate a new repository that borrows objects from the original\nrepository when --shared flag is given in addition to --local.\n\nIt is worth pointing out that the \"cloned\" repository depends on\nthe original repository, so this should be used only when you\ncan reasonably trust that the original repository would not\ndisappear without your knowing.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n\n    This depends on the \"Alternate object pool mechanism\" patch I\n    sent out earlier, with a change suggested by Pasky to use\n    \"$GIT_OBJECT_DIRECTORY/info/alternates\" as the file name\n    instead of \"info/alt\".\n\n    This approach has the same danger as symlinking .git/objects\n    directory to the original repository that cg-clone mentions\n    about its '-l' option, but it is safer and easier to use in\n    multi-user environment.  Objects newly created in the cloned\n    repository go to the primary object pool of it, not the\n    object pool of the original repository.\n\n git-clone-script |   45 ++++++++++++++++++++++++++++-----------------\n 1 files changed, 28 insertions(+), 17 deletions(-)\n\nffdb36832dd755e65b9adfb68fa6b4a137176bc5\ndiff --git a/git-clone-script b/git-clone-script\n--- a/git-clone-script\n+++ b/git-clone-script\n@@ -6,7 +6,7 @@\n # Clone a repository into a different directory that does not yet exist.\n \n usage() {\n-\techo >&2 \"* git clone [-l] [-q] [-u <upload-pack>] <repo> <dir>\"\n+\techo >&2 \"* git clone [-l [-s]] [-q] [-u <upload-pack>] <repo> <dir>\"\n \texit 1\n }\n \n@@ -16,11 +16,14 @@ get_repo_base() {\n \n quiet=\n use_local=no\n+local_shared=no\n upload_pack=\n while\n \tcase \"$#,$1\" in\n \t0,*) break ;;\n \t*,-l|*,--l|*,--lo|*,--loc|*,--loca|*,--local) use_local=yes ;;\n+        *,-s|*,--s|*,--sh|*,--sha|*,--shar|*,--share|*,--shared) \n+          local_shared=yes ;;\n \t*,-q|*,--quiet) quiet=-q ;;\n \t1,-u|1,--upload-pack) usage ;;\n \t*,-u|*,--upload-pack)\n@@ -57,22 +60,30 @@ yes,yes)\n \t\texit 1\n \t}\n \n-\t# See if we can hardlink and drop \"l\" if not.\n-\tsample_file=$(cd \"$repo\" && \\\n-\t\t      find objects -type f -print | sed -e 1q)\n-\n-\t# objects directory should not be empty since we are cloning!\n-\ttest -f \"$repo/$sample_file\" || exit\n-\n-\tl=\n-\tif ln \"$repo/$sample_file\" \"$D/.git/objects/sample\" 2>/dev/null\n-\tthen\n-\t\tl=l\n-\tfi &&\n-\trm -f \"$D/.git/objects/sample\" &&\n-\tcd \"$repo\" &&\n-\tfind objects -type f -print |\n-\tcpio -puamd$l \"$D/.git/\" || exit 1\n+\tcase \"$local_shared\" in\n+\tno)\n+\t    # See if we can hardlink and drop \"l\" if not.\n+\t    sample_file=$(cd \"$repo\" && \\\n+\t\t\t  find objects -type f -print | sed -e 1q)\n+\n+\t    # objects directory should not be empty since we are cloning!\n+\t    test -f \"$repo/$sample_file\" || exit\n+\n+\t    l=\n+\t    if ln \"$repo/$sample_file\" \"$D/.git/objects/sample\" 2>/dev/null\n+\t    then\n+\t\t    l=l\n+\t    fi &&\n+\t    rm -f \"$D/.git/objects/sample\" &&\n+\t    cd \"$repo\" &&\n+\t    find objects -type f -print |\n+\t    cpio -puamd$l \"$D/.git/\" || exit 1\n+\t    ;;\n+\tyes)\n+\t    mkdir -p \"$D/.git/objects/info\"\n+\t    echo \"$repo/objects\" >\"$D/.git/objects/info/alternates\"\n+\t    ;;\n+\tesac\n \n \t# Make a duplicate of refs and HEAD pointer\n \tHEAD=\n"}]}