shithub: git9

Download patch

ref: 90998569dab18d59d81bc63c84f692e1f7052904
parent: f633a247589b6de4b058f66ad6b014db57bad3dd
author: Ori Bernstein <ori@eigenstate.org>
date: Wed Oct 16 01:03:51 EDT 2019

Refactor, fix various bugs in pull and query.

--- a/branch
+++ b/branch
@@ -40,34 +40,35 @@
 	echo $base
 	exit
 }
+
 if(! ~ $#* 1)
 	usage
-if(~ $new refs/heads/*)
-	trim='s@^refs/heads/@@g'
-if not if(~ $new heads/*)
-	trim='s@^heads/@@g'
+if(~ $1 refs/heads/*)
+	new=$1
+if not if(~ $1 heads/*)
+	new=refs/$1
 if not
-	trim='s@^@@g'
-new=`{echo $1 | sed $trim}
+	new=refs/heads/$1
 
-if(~ $#create 0){
-	if(! test -e .git/refs/heads/$new){
+if(! ~ $#create 0){
+	if(! test -e .git/$new){
 		echo branch $new: does not exist >[1=2]
 		exit exists
 	}
 }
 if not{
-	if(~ $#update 0 && test -e .git/refs/heads/$new){
-		echo could not create $new: already exists >[1=2]
+	if(~ $#update 0 && test -e .git/$new){
+		echo could not create $1: already exists >[1=2]
 		exit exists
 	}
 	branched=()
-	candidates=(.git/refs/$base .git/refs/heads/$base .git/refs/remotes/$base .git/refs/remotes/*/$base)
+	remotes=`$nl{cd .git/refs/remotes && ls}
+	candidates=(.git/refs/$base .git/refs/heads/$base .git/refs/remotes/$base .git/refs/remotes/$remotes/$base)
 	for(br in $candidates){
-		if(test -f $br){
-			echo 'creating new branch '$new
-			cp $br .git/refs/heads/$new
-			branched="ok"
+		if(~ $#branched 0 && test -f $br){
+			echo $base '=>' $1
+			cp $br .git/$new
+			branched=true
 		}
 	}
 	if(~ $#branched 0){
@@ -79,9 +80,10 @@
 if(! ~ $#stay 0)
 	exit
 
+echo ref: $new > .git/HEAD
+
 modified=`$nl{git/query -c HEAD $base | grep '^[+~]' | sed 's/^..//'}
 deleted=`$nl{git/query -c HEAD $base | grep '^-' | sed 's/^..//'}
-echo here-- mod $#modified del $#deleted
 if(! ~ $#modified 0 || ! ~ $#deleted 0){
 	if(! git/walk -q $modified $deleted){
 		echo remote changes would clobber local changes >[1=2]
@@ -93,8 +95,8 @@
 	# Modifications can turn a file into
 	# a directory, so we need to walk to
 	# check the blobs out correctly.
-	for(m in `{walk -f $modified}){
-		gm=/mnt/git/HEAD/tree/$m
+	for(gm in `{cd /mnt/git/HEAD/tree/ && walk -f $modified}){
+		m=`{sed s@^/mnt/git/HEAD/tree/@@}
 		d=`{basename -d $m}
 		mkdir -p $d
 		mkdir -p .git/index9/tracked/$d
--- a/fetch.c
+++ b/fetch.c
@@ -184,7 +184,6 @@
 			continue;
 		}
 		n = snprint(buf, sizeof(buf), "want %H", want[i]);
-		print("want %H\n", want[i]);
 		if(writepkt(fd, buf, n) == -1)
 			sysfatal("could not send want for %H", want[i]);
 		req = 1; 
--- a/pull
+++ b/pull
@@ -11,21 +11,23 @@
 	url=$3
 	dir=$4
 
-	fetch=`{git/fetch  -b $branch -u $upstream $url} |[2]  tr '\x0d' '\x0a'
+	fetch=`"{git/fetch  -b $branch -u $upstream $url |[2]  tr '\x0d' '\x0a'}
 	st=$status
-	if(! ~ $st '|'){
+	if(! ~ $st ''){
 		echo fetch failed: $st
 		exit $st
 	}	
-	echo $fetch | awk '
+	echo $"fetch | awk '
 	/^remote/{
 		if($2=="HEAD")
 			next
-		gsub("^refs/heads", "refs/remotes/'$upstream'", $2)
+		ref=$2
+		hash=$3
+		gsub("^refs/heads", "refs/remotes/'$upstream'", ref)
 		outfile = ".git/"ref
 		system("mkdir -p `{basename -d "outfile"}");
 		print hash > outfile;
-		print ref" => "hash > "/dev/fd/2"
+		print ref" => "hash > "/fd/2"
 		close(outfile);
 	}
 	'
@@ -89,7 +91,7 @@
 }
 # The remote repository and our HEAD have diverged: we
 # need to merge.
-if(! ~ `{git/query HEAD $remote @} `{git/query HEAD)
+if(! ~ `{git/query HEAD $remote @} `{git/query HEAD}){
 	echo git/merge $remote '# diverged' >[1=2]
 	exit merge
 }
--- a/ref.c
+++ b/ref.c
@@ -73,6 +73,12 @@
 }
 
 int
+isword(char e)
+{
+	return isalnum(e) || e == '/' || e == '-' || e == '_' || e == '.';
+}
+
+int
 word(Eval *ev, char *b, int nb)
 {
 	char *p, *e;
@@ -79,7 +85,7 @@
 	int n;
 
 	p = ev->p;
-	for(e = p; isalnum(*e) || *e == '/'; e++)
+	for(e = p; isword(*e); e++)
 		/* nothing */;
 	/* 1 for nul terminator */
 	n = e - p + 1;