Skip to contentSkip to conversation

Heads and tags in subdirectories

PATCH In review Santi Béjar 2 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Heads and tags in subdirectories

Keep heads and tags in their respective subtirectoris named as the branch. This fixes the case where two repositoris have tags with the same name.

Add a "-a" flag to cg-pull to download all the repositories heads, so you can now do a "cg-log -r repo#branch" (cg-Xnormid repo#branch job).

The transition is automatic when you do the first "cg-pull repo".

 cg-Xnormid |   14 ++++++++++-
 cg-commit  |    7 +++++
 cg-pull    |   72 +++++++++++++++++++++++++++++++++++++------------------------
 3 files changed, 62 insertions(+), 31 deletions(-)
cg-Xnormid +12 -2
@@ -16,15 +16,25 @@
 
 id="$1"
 
+repo=$(echo $id | cut -d '#' -f 1)
+(echo $repo | egrep -qv '[^a-zA-Z0-9_.@!:-]') || \
+	die "name contains invalid characters"
+id=$(echo $id | sed 's@#@/@')
+
 if [ ! "$id" ] || [ "$id" = "this" ] || [ "$id" = "HEAD" ]; then
 	read id < "$_git/HEAD"
 
-elif [ -r "$_git/refs/tags/$id" ]; then
+elif [ -r "$_git/refs/tags/$id" ] && [ ! -d "$_git/refs/tags/$id" ]; then
 	read id < "$_git/refs/tags/$id"
 
-elif [ -r "$_git/refs/heads/$id" ]; then
+elif [ -r "$_git/refs/heads/$id" ] && [ ! -d "$_git/refs/tags/$id" ]; then
 	read id < "$_git/refs/heads/$id"
 
+elif [ -r "$_git/branches/$id" ]; then
+	repobranch=$(cat "$_git/branches/$id" | cut -d '#' -f 2 -s)
+	repobranch=${repobranch:-master}
+	read id < "$_git/refs/heads/$id/$repobranch"
+
 # Short id's must be lower case and at least 4 digits.
 elif [[ "$id" == [0-9a-z][0-9a-z][0-9a-z][0-9a-z]* ]]; then
 	idpref=${id:0:2}
cg-commit +6 -1
@@ -141,7 +141,12 @@ if [ "$merging" ]; then
 	[ "$msgs" ] && echo -n 'Merge with '
 	[ -s $_git/merging-sym ] || cp $_git/merging $_git/merging-sym
 	for sym in $(cat $_git/merging-sym); do
-		uri=$(cat $_git/branches/$sym)
+		repo=$(echo $sym | cut -d '#' -f 1)
+		branch=$(echo $sym | cut -d '#' -f 2 -s)
+		uri=$(cat $_git/branches/$repo)
+		uribranch=$(echo $uri | cut -d '#' -f 2 -s)
+		[ -z "$uribranch" ] && [ -n "$branch" ] &&
+		[ "$branch" != master ] && uri=${uri}#$branch
 		[ "$uri" ] || uri="$sym"
 		echo "$uri" >>$LOGMSG
 		[ "$msgs" ] && echo "$uri"
cg-pull +44 -28

106 lines not on this page · raw message

#1 lore raw

Teach cg-init about the origin directory.

---
 cg-init |    5 +++--
 1 files changed, 3 insertions(+), 2 deletions(-)
cg-init +3 -2
@@ -29,8 +29,9 @@ ln -s refs/heads/master $_git/HEAD
 if [ "$uri" ]; then
 	echo "$uri" >$_git/branches/origin
 	cg-pull origin || die "pull failed"
-
-	cp $_git/refs/heads/origin $_git/refs/heads/master
+	uribranch=$(echo $uri | cut -d '#' -f 2 -s)
+	uribranch=${uribranch:-master}
+	cp $_git/refs/heads/origin/$uribranch $_git/refs/heads/master
 	git-read-tree HEAD
 	git-checkout-cache -a
 	git-update-cache --refresh
#2 lore raw

Here it is un updated version, fixing some bugs.

 cg-Xnormid |   14 +++++++++-
 cg-commit  |    7 ++++-
 cg-init    |    5 ++-
 cg-pull    |   78 ++++++++++++++++++++++++++++++++++++-------------------------
 4 files changed, 68 insertions(+), 36 deletions(-)
cg-Xnormid +12 -2
@@ -16,15 +16,25 @@
 
 id="$1"
 
+repo=$(echo $id | cut -d '#' -f 1)
+(echo $repo | egrep -qv '[^a-zA-Z0-9_.@!:-]') || \
+	die "name contains invalid characters"
+id=$(echo $id | sed 's@#@/@')
+
 if [ ! "$id" ] || [ "$id" = "this" ] || [ "$id" = "HEAD" ]; then
 	read id < "$_git/HEAD"
 
-elif [ -r "$_git/refs/tags/$id" ]; then
+elif [ -r "$_git/refs/tags/$id" ] && [ ! -d "$_git/refs/tags/$id" ]; then
 	read id < "$_git/refs/tags/$id"
 
-elif [ -r "$_git/refs/heads/$id" ]; then
+elif [ -r "$_git/refs/heads/$id" ] && [ ! -d "$_git/refs/heads/$id" ]; then
 	read id < "$_git/refs/heads/$id"
 
+elif [ -r "$_git/branches/$id" ]; then
+	repobranch=$(cat "$_git/branches/$id" | cut -d '#' -f 2 -s)
+	repobranch=${repobranch:-master}
+	read id < "$_git/refs/heads/$id/$repobranch"
+
 # Short id's must be lower case and at least 4 digits.
 elif [[ "$id" == [0-9a-z][0-9a-z][0-9a-z][0-9a-z]* ]]; then
 	idpref=${id:0:2}
cg-commit +6 -1
@@ -141,7 +141,12 @@ if [ "$merging" ]; then
 	[ "$msgs" ] && echo -n 'Merge with '
 	[ -s $_git/merging-sym ] || cp $_git/merging $_git/merging-sym
 	for sym in $(cat $_git/merging-sym); do
-		uri=$(cat $_git/branches/$sym)
+		repo=$(echo $sym | cut -d '#' -f 1)
+		branch=$(echo $sym | cut -d '#' -f 2 -s)
+		uri=$(cat $_git/branches/$repo)
+		uribranch=$(echo $uri | cut -d '#' -f 2 -s)
+		[ -z "$uribranch" ] && [ -n "$branch" ] &&
+		[ "$branch" != master ] && uri=${uri}#$branch
 		[ "$uri" ] || uri="$sym"
 		echo "$uri" >>$LOGMSG
 		[ "$msgs" ] && echo "$uri"
cg-init +3 -2
@@ -29,8 +29,9 @@ ln -s refs/heads/master $_git/HEAD
 if [ "$uri" ]; then
 	echo "$uri" >$_git/branches/origin
 	cg-pull origin || die "pull failed"
-
-	cp $_git/refs/heads/origin $_git/refs/heads/master
+	uribranch=$(echo $uri | cut -d '#' -f 2 -s)
+	uribranch=${uribranch:-master}
+	cp $_git/refs/heads/origin/$uribranch $_git/refs/heads/master
 	git-read-tree HEAD
 	git-checkout-cache -a
 	git-update-cache --refresh
cg-pull +47 -31

124 lines not on this page · raw message

#3 lore raw

PATCH 1/1 fetch_local -d behaves different from other fetch_*

In reply to Santi Béjar

"fetch_local -d src dst" does not respect the dst directory name if both have different names. So

fetch_local -d /path/to/some/src /path/to/dst

copies to /path/to/src.

In fact this way it's never used in the current cogito so it's not really affected but it's needed in the case where the heads and tags are in directories.

 cg-pull |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
cg-pull +3 -3
@@ -223,15 +223,15 @@ fetch_local () {
 		shift
 	fi
 
-	cut_last=
+	dirs=
 	if [ "$1" = "-d" ]; then
-		cut_last=1
+		dirs=1
 		shift
 	fi
 
 	src="$1"
 	dest="$2"
-	[ "$cut_last" ] && dest=${dest%/*}
+	[ "$dirs" ] && src="${src%/}/."
 
 	cp $cp_flags_l "$src" "$dest"
 }