ref: 0f064279e7a15c16894fb3527d96f78b0aa0f550
parent: da809634e9cb0668ff9d0a37b297a4720ab79086
author: Ori Bernstein <[email protected]>
date: Tue Oct 22 14:04:53 EDT 2019
Switch branches correctly with git/branch.
--- a/branch
+++ b/branch
@@ -50,10 +50,15 @@
if not
new=refs/heads/$1
-if(! ~ $#create 0){
+if(! git/walk -q `{git/query -c HEAD $base | sed 's/^..//g'}){
+ echo remote changes would clobber local changes >[1=2]
+ exit dirty
+}
+
+if(~ $#create 0){
if(! test -e .git/$new){
echo branch $new: does not exist >[1=2]
- exit exists
+ exit noexist
}
}
if not{
@@ -76,31 +81,25 @@
}
}
+modified=`$nl{git/query -c $new $base | grep '^[+~]' | sed 's/^..//'}
+deleted=`$nl{git/query -c $new $base | grep '^-' | sed 's/^..//'}
+
if(! ~ $#stay 0)
exit
-
-modified=`$nl{git/query -c HEAD $base | grep '^[+~]' | sed 's/^..//'}
-deleted=`$nl{git/query -c HEAD $base | grep '^-' | sed 's/^..//'}
-
-if(! ~ $#modified 0 || ! ~ $#deleted 0){
- if(! git/walk -q $modified $deleted){
- echo remote changes would clobber local changes >[1=2]
- exit dirty
- }
-}
-
if(! ~ $#modified 0){
+ basedir=`{git/query -p $base}
# Modifications can turn a file into
# a directory, so we need to walk to
# check the blobs out correctly.
- 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
- cp $gm $m
- walk -eq $m > .git/index9/tracked/$m
+ for(m in $modified){
+ if(test -f $basedir/tree/$m){
+ d=`{basename -d $m}
+ mkdir -p $d
+ mkdir -p .git/index9/tracked/$d
+ cp $basedir/tree/$m $m
+ walk -eq $m > .git/index9/tracked/$m
+ }
}
}
if(! ~ $#deleted 0){
--- a/walk.c
+++ b/walk.c
@@ -150,10 +150,9 @@
}
int
-sameqid(char *f, char *qf)
+sameqid(Dir *d, char *qf)
{
char indexqid[64], fileqid[64], *p;
- Dir *d;
int fd, n;
if((fd = open(qf, OREAD)) == -1)
@@ -165,10 +164,9 @@
if((p = strpbrk(indexqid, " \t\n\r")) != nil)
*p = 0;
- if((d = dirstat(f)) == nil)
- return -1;
snprint(fileqid, sizeof(fileqid), "%ullx.%uld.%.2uhhx",
- d->qid.path, d->qid.vers, d->qid.type);
+ d->qid.path, d->qid.vers, d->qid.type);
+
if(strcmp(indexqid, fileqid) == 0)
return 1;
return 0;
@@ -221,6 +219,7 @@
char *p, *e;
int i, dirty;
Wres r;
+ Dir *d;
ARGBEGIN{
case 'q':
@@ -276,7 +275,10 @@
snprint(rmpath, sizeof(rmpath), RDIR"/%s", p);
snprint(tpath, sizeof(tpath), TDIR"/%s", p);
snprint(bpath, sizeof(bpath), HDIR"/%s", p);
- if(sameqid(p, tpath)){
+ d = dirstat(p);
+ if(d->mode & DMDIR)
+ goto next;
+ if(sameqid(d, tpath)){
if(!quiet && (printflg & Tflg))
print("%s%s\n", tstr, p);
}else if(access(p, AEXIST) != 0 || access(rmpath, AEXIST) == 0){
@@ -295,6 +297,8 @@
if(!quiet && (printflg & Tflg))
print("%s%s\n", tstr, p);
}
+next:
+ free(d);
}
if(!dirty)
exits(nil);