{"thread":{"id":"783","subject":"[COGITO PATCH] Heads and tags in subdirectories","startedAt":"2005-05-31T22:00:35Z","lastAt":"2005-06-01T16:17:40Z","messageCount":4,"participants":["Santi Béjar"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"4325","messageId":"87is0zginw.fsf@ifae.es","threadId":"783","inReplyTo":null,"subject":"[COGITO PATCH] Heads and tags in subdirectories","fromName":"Santi Béjar","fromEmail":"sbejar@gmmail.es","sentAt":"2005-05-31T22:00:35Z","receivedAt":"2005-05-31T22:00:35Z","isPatch":true,"sender":{"key":"sbejar@gmmail.es","avatar":null},"body":"\nKeep heads and tags in their respective subtirectoris named as\nthe branch. This fixes the case where two repositoris have tags\nwith the same name.\n\nAdd a \"-a\" flag to cg-pull to download all the repositories heads,\nso you can now do a \"cg-log -r repo#branch\" (cg-Xnormid repo#branch\njob).\n\nThe transition is automatic when you do the first \"cg-pull repo\".\n\nSigned-off-by: \"Santi Béjar\" <sbejar@gmmail.es>\n\n cg-Xnormid |   14 ++++++++++-\n cg-commit  |    7 +++++\n cg-pull    |   72 +++++++++++++++++++++++++++++++++++++------------------------\n 3 files changed, 62 insertions(+), 31 deletions(-)\n\ndiff --git a/cg-Xnormid b/cg-Xnormid\n--- a/cg-Xnormid\n+++ b/cg-Xnormid\n@@ -16,15 +16,25 @@\n \n id=\"$1\"\n \n+repo=$(echo $id | cut -d '#' -f 1)\n+(echo $repo | egrep -qv '[^a-zA-Z0-9_.@!:-]') || \\\n+\tdie \"name contains invalid characters\"\n+id=$(echo $id | sed 's@#@/@')\n+\n if [ ! \"$id\" ] || [ \"$id\" = \"this\" ] || [ \"$id\" = \"HEAD\" ]; then\n \tread id < \"$_git/HEAD\"\n \n-elif [ -r \"$_git/refs/tags/$id\" ]; then\n+elif [ -r \"$_git/refs/tags/$id\" ] && [ ! -d \"$_git/refs/tags/$id\" ]; then\n \tread id < \"$_git/refs/tags/$id\"\n \n-elif [ -r \"$_git/refs/heads/$id\" ]; then\n+elif [ -r \"$_git/refs/heads/$id\" ] && [ ! -d \"$_git/refs/tags/$id\" ]; then\n \tread id < \"$_git/refs/heads/$id\"\n \n+elif [ -r \"$_git/branches/$id\" ]; then\n+\trepobranch=$(cat \"$_git/branches/$id\" | cut -d '#' -f 2 -s)\n+\trepobranch=${repobranch:-master}\n+\tread id < \"$_git/refs/heads/$id/$repobranch\"\n+\n # Short id's must be lower case and at least 4 digits.\n elif [[ \"$id\" == [0-9a-z][0-9a-z][0-9a-z][0-9a-z]* ]]; then\n \tidpref=${id:0:2}\ndiff --git a/cg-commit b/cg-commit\n--- a/cg-commit\n+++ b/cg-commit\n@@ -141,7 +141,12 @@ if [ \"$merging\" ]; then\n \t[ \"$msgs\" ] && echo -n 'Merge with '\n \t[ -s $_git/merging-sym ] || cp $_git/merging $_git/merging-sym\n \tfor sym in $(cat $_git/merging-sym); do\n-\t\turi=$(cat $_git/branches/$sym)\n+\t\trepo=$(echo $sym | cut -d '#' -f 1)\n+\t\tbranch=$(echo $sym | cut -d '#' -f 2 -s)\n+\t\turi=$(cat $_git/branches/$repo)\n+\t\turibranch=$(echo $uri | cut -d '#' -f 2 -s)\n+\t\t[ -z \"$uribranch\" ] && [ -n \"$branch\" ] &&\n+\t\t[ \"$branch\" != master ] && uri=${uri}#$branch\n \t\t[ \"$uri\" ] || uri=\"$sym\"\n \t\techo \"$uri\" >>$LOGMSG\n \t\t[ \"$msgs\" ] && echo \"$uri\"\ndiff --git a/cg-pull b/cg-pull\n--- a/cg-pull\n+++ b/cg-pull\n@@ -6,23 +6,41 @@\n # Takes the branch name as an argument, defaulting to \"origin\".\n #\n # See `cg-branch-add` for some description.\n+#\n+# OPTIONS\n+# -------\n+# -a::\n+#       Pull all the heads from repositori.\n \n-USAGE=\"cg-pull [BRANCH_NAME]\"\n+USAGE=\"cg-pull [-a] [BRANCH_NAME]\"\n \n . ${COGITO_LIB}cg-Xlib\n \n-name=$1\n-\n+[ \"$1\" == \"-a\" ] && all=yes && shift\n+name=$1 && shift\n \n [ \"$name\" ] || { [ -s $_git/refs/heads/origin ] && name=origin; }\n [ \"$name\" ] || die \"where to pull from?\"\n-uri=$(cat \"$_git/branches/$name\" 2>/dev/null) || die \"unknown branch: $name\"\n \n-rembranch=master\n+repo=$(echo $name | cut -d '#' -f 1)\n+repobranch=$(echo $name | cut -s -d '#' -f 2)\n+\n+uri=$(cat \"$_git/branches/$name\" 2>/dev/null) || die \"unknown branch: $name\"\n if echo \"$uri\" | grep -q '#'; then\n+\t[ -z \"$repobranch\" ] && repobranch=$(echo $uri | cut -d '#' -f 2)\n \trembranch=$(echo $uri | cut -d '#' -f 2)\n \turi=$(echo $uri | cut -d '#' -f 1)\n fi\n+repobranch=${repobranch:-master}\n+branch=$repo/$repobranch\n+[ \"$all\" ] && repobranch=\n+\n+# So long we have:\n+# $repo       = name of the repositori\n+# $uri        = uri of the repositori\n+# $repobranch = name of the branch in the repositori\n+#               empty if we want all the branches\n+# $branch     = name of the local branch in refs/heads/\n \n pull_progress() {\n \tpercentage=\"\"\n@@ -232,39 +250,37 @@ fi\n \n \n orig_head=\n-[ -s \"$_git/refs/heads/$name\" ] && orig_head=$(cat \"$_git/refs/heads/$name\")\n-\n+[ -s \"$_git/refs/heads/$branch\" ] && orig_head=$(cat \"$_git/refs/heads/$branch\")\n \n-mkdir -p $_git/refs/heads\n-rsyncerr=\n-$fetch -i \"$uri/refs/heads/$rembranch\" \"$_git/refs/heads/$name\" || rsyncerr=1\n-if [ \"$rsyncerr\" ]; then\n-\trsyncerr=\n-\t$fetch -s \"$uri/heads/$rembranch\" \"$_git/refs/heads/$name\" || rsyncerr=1\n-fi\n-if [ \"$rsyncerr\" ] && [ \"$rembranch\" = \"master\" ]; then\n-\trsyncerr=\n-\t$fetch -s \"$uri/HEAD\" \"$_git/refs/heads/$name\" || rsyncerr=1\n+# 2005/05 Convert old layout\n+[ -f $_git/refs/heads/$repo ] && orig_head=$(cat $_git/refs/heads/$repo) &&\n+rm -f $_git/refs/heads/$repo\n+\n+mkdir -p $_git/refs/heads/$repo\n+if [ \"$repobranch\" ] ; then\n+    $fetch -i \"$uri/refs/heads/$repobranch\" \"$_git/refs/heads/$branch\" ||\n+    $fetch -s \"$uri/heads/$repobranch\" \"$_git/refs/heads/$branch\" ||\n+    { [ \"$repobranch\" = \"master\" ] && $fetch -s \"$uri/HEAD\" \"$_git/refs/heads/$branch\"; } ||\n+    rsyncerr=1\n+else\n+    $fetch -i -d \"$uri/refs/heads\" \"$_git/refs/heads/$repo\" ||\n+    $fetch -s -d \"$uri/heads\" \"$_git/refs/heads/$repo\" ||\n+    rsyncerr=1\n fi\n-[ \"$rsyncerr\" ] && die \"unable to get the head pointer of branch $rembranch\"\n+[ \"$rsyncerr\" ] && die \"unable to get the head pointer of branch $repobranch\"\n \n [ -d $_git_objects ] || mkdir -p $_git_objects\n-$pull \"$name\" \"$uri\" || die \"objects pull failed\"\n+$pull \"$branch\" \"$uri\" || die \"objects pull failed\"\n \n-# FIXME: Warn about conflicting tag names?\n # XXX: We now throw stderr to /dev/null since not all repositories\n # may have tags/ and users were confused by the harmless errors.\n-[ -d $_git/refs/tags ] || mkdir -p $_git/refs/tags\n+[ -d $_git/refs/tags/$repo ] || mkdir -p $_git/refs/tags/$repo\n rsyncerr=\n-$fetch -i -s -u -d \"$uri/refs/tags\" \"$_git/refs/tags\" || rsyncerr=1\n-if [ \"$rsyncerr\" ]; then\n-\trsyncerr=\n-\t$fetch -i -s -u -d \"$uri/tags\" \"$_git/refs/tags\" || rsyncerr=1\n-fi\n+$fetch -i -s -u -d \"$uri/refs/tags\" \"$_git/refs/tags/$repo\" ||\n+$fetch -i -s -u -d \"$uri/tags\" \"$_git/refs/tags/$repo\" || rsyncerr=1\n [ \"$rsyncerr\" ] && echo \"unable to get tags list (non-fatal)\" >&2\n \n-\n-new_head=$(cat \"$_git/refs/heads/$name\")\n+new_head=$(cat \"$_git/refs/heads/$branch\")\n \n if [ ! \"$orig_head\" ]; then\n \techo \"New branch: $new_head\"\n\n"},{"id":"4358","messageId":"87psv6ibxb.fsf@ifae.es","threadId":"783","inReplyTo":"87is0zginw.fsf@ifae.es","subject":"[COGITO PATCH] fetch_local -d behaves different from other fetch_*","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2005-06-01T10:55:28Z","receivedAt":"2005-06-01T10:55:28Z","isPatch":true,"sender":{"key":"santi@agolina.net","avatar":null},"body":"\n\"fetch_local -d src dst\" does not respect the dst directory name \nif both have different names. So\n\nfetch_local -d /path/to/some/src /path/to/dst\n\ncopies to /path/to/src.\n\nIn fact this way it's never used in the current cogito so it's not\nreally affected but it's needed in the case where the heads and tags\nare in directories.\n\nSigned-off-by: \"Santi Béjar\" <sbejar@gmail.com>\n\n cg-pull |    6 +++---\n 1 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/cg-pull b/cg-pull\n--- a/cg-pull\n+++ b/cg-pull\n@@ -223,15 +223,15 @@ fetch_local () {\n \t\tshift\n \tfi\n \n-\tcut_last=\n+\tdirs=\n \tif [ \"$1\" = \"-d\" ]; then\n-\t\tcut_last=1\n+\t\tdirs=1\n \t\tshift\n \tfi\n \n \tsrc=\"$1\"\n \tdest=\"$2\"\n-\t[ \"$cut_last\" ] && dest=${dest%/*}\n+\t[ \"$dirs\" ] && src=\"${src%/}/.\"\n \n \tcp $cp_flags_l \"$src\" \"$dest\"\n }\n\n"},{"id":"4364","messageId":"87is0yi66t.fsf@ifae.es","threadId":"783","inReplyTo":"87is0zginw.fsf@ifae.es","subject":"Re: [COGITO PATCH] Heads and tags in subdirectories","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2005-06-01T12:59:22Z","receivedAt":"2005-06-01T12:59:22Z","isPatch":true,"sender":{"key":"santi@agolina.net","avatar":null},"body":"\nTeach cg-init about the origin directory.\n\nSigned-off-by: \"Santi Béjar\" <sbejar@gmail.com>\n---\n cg-init |    5 +++--\n 1 files changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/cg-init b/cg-init\n--- a/cg-init\n+++ b/cg-init\n@@ -29,8 +29,9 @@ ln -s refs/heads/master $_git/HEAD\n if [ \"$uri\" ]; then\n \techo \"$uri\" >$_git/branches/origin\n \tcg-pull origin || die \"pull failed\"\n-\n-\tcp $_git/refs/heads/origin $_git/refs/heads/master\n+\turibranch=$(echo $uri | cut -d '#' -f 2 -s)\n+\turibranch=${uribranch:-master}\n+\tcp $_git/refs/heads/origin/$uribranch $_git/refs/heads/master\n \tgit-read-tree HEAD\n \tgit-checkout-cache -a\n \tgit-update-cache --refresh\n\n"},{"id":"4371","messageId":"87ekbmqcez.fsf@gmail.com","threadId":"783","inReplyTo":"87is0yi66t.fsf@ifae.es","subject":"Re: [COGITO PATCH] Heads and tags in subdirectories","fromName":"Santi Béjar","fromEmail":"sbejar@gmail.com","sentAt":"2005-06-01T16:17:40Z","receivedAt":"2005-06-01T16:17:40Z","isPatch":true,"sender":{"key":"santi@agolina.net","avatar":null},"body":"\nHere it is un updated version, fixing some bugs.\n\n cg-Xnormid |   14 +++++++++-\n cg-commit  |    7 ++++-\n cg-init    |    5 ++-\n cg-pull    |   78 ++++++++++++++++++++++++++++++++++++-------------------------\n 4 files changed, 68 insertions(+), 36 deletions(-)\n\ndiff --git a/cg-Xnormid b/cg-Xnormid\n--- a/cg-Xnormid\n+++ b/cg-Xnormid\n@@ -16,15 +16,25 @@\n \n id=\"$1\"\n \n+repo=$(echo $id | cut -d '#' -f 1)\n+(echo $repo | egrep -qv '[^a-zA-Z0-9_.@!:-]') || \\\n+\tdie \"name contains invalid characters\"\n+id=$(echo $id | sed 's@#@/@')\n+\n if [ ! \"$id\" ] || [ \"$id\" = \"this\" ] || [ \"$id\" = \"HEAD\" ]; then\n \tread id < \"$_git/HEAD\"\n \n-elif [ -r \"$_git/refs/tags/$id\" ]; then\n+elif [ -r \"$_git/refs/tags/$id\" ] && [ ! -d \"$_git/refs/tags/$id\" ]; then\n \tread id < \"$_git/refs/tags/$id\"\n \n-elif [ -r \"$_git/refs/heads/$id\" ]; then\n+elif [ -r \"$_git/refs/heads/$id\" ] && [ ! -d \"$_git/refs/heads/$id\" ]; then\n \tread id < \"$_git/refs/heads/$id\"\n \n+elif [ -r \"$_git/branches/$id\" ]; then\n+\trepobranch=$(cat \"$_git/branches/$id\" | cut -d '#' -f 2 -s)\n+\trepobranch=${repobranch:-master}\n+\tread id < \"$_git/refs/heads/$id/$repobranch\"\n+\n # Short id's must be lower case and at least 4 digits.\n elif [[ \"$id\" == [0-9a-z][0-9a-z][0-9a-z][0-9a-z]* ]]; then\n \tidpref=${id:0:2}\ndiff --git a/cg-commit b/cg-commit\n--- a/cg-commit\n+++ b/cg-commit\n@@ -141,7 +141,12 @@ if [ \"$merging\" ]; then\n \t[ \"$msgs\" ] && echo -n 'Merge with '\n \t[ -s $_git/merging-sym ] || cp $_git/merging $_git/merging-sym\n \tfor sym in $(cat $_git/merging-sym); do\n-\t\turi=$(cat $_git/branches/$sym)\n+\t\trepo=$(echo $sym | cut -d '#' -f 1)\n+\t\tbranch=$(echo $sym | cut -d '#' -f 2 -s)\n+\t\turi=$(cat $_git/branches/$repo)\n+\t\turibranch=$(echo $uri | cut -d '#' -f 2 -s)\n+\t\t[ -z \"$uribranch\" ] && [ -n \"$branch\" ] &&\n+\t\t[ \"$branch\" != master ] && uri=${uri}#$branch\n \t\t[ \"$uri\" ] || uri=\"$sym\"\n \t\techo \"$uri\" >>$LOGMSG\n \t\t[ \"$msgs\" ] && echo \"$uri\"\ndiff --git a/cg-init b/cg-init\n--- a/cg-init\n+++ b/cg-init\n@@ -29,8 +29,9 @@ ln -s refs/heads/master $_git/HEAD\n if [ \"$uri\" ]; then\n \techo \"$uri\" >$_git/branches/origin\n \tcg-pull origin || die \"pull failed\"\n-\n-\tcp $_git/refs/heads/origin $_git/refs/heads/master\n+\turibranch=$(echo $uri | cut -d '#' -f 2 -s)\n+\turibranch=${uribranch:-master}\n+\tcp $_git/refs/heads/origin/$uribranch $_git/refs/heads/master\n \tgit-read-tree HEAD\n \tgit-checkout-cache -a\n \tgit-update-cache --refresh\ndiff --git a/cg-pull b/cg-pull\n--- a/cg-pull\n+++ b/cg-pull\n@@ -6,23 +6,41 @@\n # Takes the branch name as an argument, defaulting to \"origin\".\n #\n # See `cg-branch-add` for some description.\n+#\n+# OPTIONS\n+# -------\n+# -a::\n+#       Pull all the heads from repositori.\n \n-USAGE=\"cg-pull [BRANCH_NAME]\"\n+USAGE=\"cg-pull [-a] [BRANCH_NAME]\"\n \n . ${COGITO_LIB}cg-Xlib\n \n-name=$1\n-\n+[ \"$1\" == \"-a\" ] && all=yes && shift\n+name=$1 && shift\n \n [ \"$name\" ] || { [ -s $_git/refs/heads/origin ] && name=origin; }\n [ \"$name\" ] || die \"where to pull from?\"\n-uri=$(cat \"$_git/branches/$name\" 2>/dev/null) || die \"unknown branch: $name\"\n \n-rembranch=master\n+repo=$(echo $name | cut -d '#' -f 1)\n+repobranch=$(echo $name | cut -s -d '#' -f 2)\n+\n+uri=$(cat \"$_git/branches/$name\" 2>/dev/null) || die \"unknown branch: $name\"\n if echo \"$uri\" | grep -q '#'; then\n+\t[ -z \"$repobranch\" ] && repobranch=$(echo $uri | cut -d '#' -f 2)\n \trembranch=$(echo $uri | cut -d '#' -f 2)\n \turi=$(echo $uri | cut -d '#' -f 1)\n fi\n+repobranch=${repobranch:-master}\n+branch=$repo/$repobranch\n+[ \"$all\" ] && repobranch=\n+\n+# So long we have:\n+# $repo       = name of the repositori\n+# $uri        = uri of the repositori\n+# $repobranch = name of the branch in the repositori\n+#               empty if we want all the branches\n+# $branch     = name of the local branch in refs/heads/\n \n pull_progress() {\n \tpercentage=\"\"\n@@ -197,15 +215,15 @@ fetch_local () {\n \t\tshift\n \tfi\n \n-\tcut_last=\n+\tdirs=\n \tif [ \"$1\" = \"-d\" ]; then\n-\t\tcut_last=1\n+\t\tdirs=1\n \t\tshift\n \tfi\n \n \tsrc=\"$1\"\n \tdest=\"$2\"\n-\t[ \"$cut_last\" ] && dest=${dest%/*}\n+\t[ \"$dirs\" ] && src=\"${src%/}/.\"\n \n \tcp $cp_flags_l \"$src\" \"$dest\"\n }\n@@ -232,39 +250,37 @@ fi\n \n \n orig_head=\n-[ -s \"$_git/refs/heads/$name\" ] && orig_head=$(cat \"$_git/refs/heads/$name\")\n-\n+[ -s \"$_git/refs/heads/$branch\" ] && orig_head=$(cat \"$_git/refs/heads/$branch\")\n \n-mkdir -p $_git/refs/heads\n-rsyncerr=\n-$fetch -i \"$uri/refs/heads/$rembranch\" \"$_git/refs/heads/$name\" || rsyncerr=1\n-if [ \"$rsyncerr\" ]; then\n-\trsyncerr=\n-\t$fetch -s \"$uri/heads/$rembranch\" \"$_git/refs/heads/$name\" || rsyncerr=1\n-fi\n-if [ \"$rsyncerr\" ] && [ \"$rembranch\" = \"master\" ]; then\n-\trsyncerr=\n-\t$fetch -s \"$uri/HEAD\" \"$_git/refs/heads/$name\" || rsyncerr=1\n+# 2005/05 Convert old layout\n+[ -f $_git/refs/heads/$repo ] && orig_head=$(cat $_git/refs/heads/$repo) &&\n+rm -f $_git/refs/heads/$repo\n+\n+mkdir -p $_git/refs/heads/$repo\n+if [ \"$repobranch\" ] ; then\n+    $fetch -i \"$uri/refs/heads/$repobranch\" \"$_git/refs/heads/$branch\" ||\n+    $fetch -s \"$uri/heads/$repobranch\" \"$_git/refs/heads/$branch\" ||\n+    { [ \"$repobranch\" = \"master\" ] && $fetch -s \"$uri/HEAD\" \"$_git/refs/heads/$branch\"; } ||\n+    rsyncerr=1\n+else\n+    $fetch -i -d \"$uri/refs/heads\" \"$_git/refs/heads/$repo\" ||\n+    $fetch -s -d \"$uri/heads\" \"$_git/refs/heads/$repo\" ||\n+    rsyncerr=1\n fi\n-[ \"$rsyncerr\" ] && die \"unable to get the head pointer of branch $rembranch\"\n+[ \"$rsyncerr\" ] && die \"unable to get the head pointer of branch $repobranch\"\n \n [ -d $_git_objects ] || mkdir -p $_git_objects\n-$pull \"$name\" \"$uri\" || die \"objects pull failed\"\n+$pull \"$branch\" \"$uri\" || die \"objects pull failed\"\n \n-# FIXME: Warn about conflicting tag names?\n # XXX: We now throw stderr to /dev/null since not all repositories\n # may have tags/ and users were confused by the harmless errors.\n-[ -d $_git/refs/tags ] || mkdir -p $_git/refs/tags\n+[ -d $_git/refs/tags/$repo ] || mkdir -p $_git/refs/tags/$repo\n rsyncerr=\n-$fetch -i -s -u -d \"$uri/refs/tags\" \"$_git/refs/tags\" || rsyncerr=1\n-if [ \"$rsyncerr\" ]; then\n-\trsyncerr=\n-\t$fetch -i -s -u -d \"$uri/tags\" \"$_git/refs/tags\" || rsyncerr=1\n-fi\n+$fetch -i -s -u -d \"$uri/refs/tags\" \"$_git/refs/tags/$repo\" ||\n+$fetch -i -s -u -d \"$uri/tags\" \"$_git/refs/tags/$repo\" || rsyncerr=1\n [ \"$rsyncerr\" ] && echo \"unable to get tags list (non-fatal)\" >&2\n \n-\n-new_head=$(cat \"$_git/refs/heads/$name\")\n+new_head=$(cat \"$_git/refs/heads/$branch\")\n \n if [ ! \"$orig_head\" ]; then\n \techo \"New branch: $new_head\"\n\n"}]}