diff --git a/sys/src/cmd/git/test/diff.rc b/sys/src/cmd/git/test/diff.rc new file mode 100755 index 000000000..aa699606d --- /dev/null +++ b/sys/src/cmd/git/test/diff.rc @@ -0,0 +1,46 @@ +#!/bin/rc + +. util.rc + +nl=' +' +rm -fr scratch +mkdir -p scratch/subdir/subdir2 +mkdir -p scratch/subdir3 + +echo @@git diff -s relative@@ +@{ + cd scratch + q git/init + echo hello > file.txt + echo hello1 > subdir/file1.txt + echo hello2 > subdir/subdir2/file2.txt + echo hello3 > subdir3/file3.txt + q git/add file.txt subdir/file1.txt subdir/subdir2/file2.txt subdir3/file3.txt + q git/commit -m initial . + echo >file.txt + echo >subdir/file1.txt + echo >subdir/subdir2/file2.txt + echo >subdir3/file3.txt + + out=`$nl{git/diff -s . | awk '{ print $2 }'} + ~ $out(1) file.txt && ~ $out(2) subdir/file1.txt && ~ $out(3) subdir/subdir2/file2.txt \ + ~ $out(4) subdir3/file3.txt || die 'base level fail' + + cd subdir + out=`$nl{git/diff -s .. | awk '{ print $2 }'} + ~ $out(1) ../file.txt && ~ $out(2) file1.txt && ~ $out(3) subdir2/file2.txt \ + ~ $out(4) ../subdir3/file3.txt || die 'subdir1 level fail' + + cd subdir2 + out=`$nl{git/diff -s ../.. | awk '{ print $2 }'} + ~ $out(1) ../../file.txt && ~ $out(2) ../file1.txt && ~ $out(3) file2.txt \ + ~ $out(4) ../../subdir3/file3.txt || die 'subdir2 level fail' + + cd ../../subdir3 + out=`$nl{git/diff -s .. | awk '{ print $2 }'} + ~ $out(1) ../file.txt && ~ $out(2) ../subdir/file1.txt && ~ $out(3) ../subdir/subdir2/file2.txt \ + ~ $out(4) file3.txt || die 'subdir3 level fail' + + ! git/diff -s ../.. >[2]/dev/null +} diff --git a/sys/src/cmd/git/test/mkfile b/sys/src/cmd/git/test/mkfile index c12e4fcfe..9e475850d 100644 --- a/sys/src/cmd/git/test/mkfile +++ b/sys/src/cmd/git/test/mkfile @@ -3,6 +3,7 @@ TEST=\ add\ basic\ + diff\ export\ ftype\ lca\ diff --git a/sys/src/cmd/git/walk.c b/sys/src/cmd/git/walk.c index 0c81aeda9..196f9b838 100644 --- a/sys/src/cmd/git/walk.c +++ b/sys/src/cmd/git/walk.c @@ -34,7 +34,6 @@ Idxed idxtab[NCACHE]; char repopath[1024]; char wdirpath[1024]; char relapath[1024]; -char slashes[1024]; int nslash; char *rstr = "R "; char *mstr = "M "; @@ -350,31 +349,33 @@ reporel(char *s) void show(Biobuf *o, int flg, char *str, char *path) { - char *pa, *pb, *suffix; - int ncommon = 0; + char *pa, *pb; + int n; dirty |= flg; if(!quiet && (printflg & flg)){ - if(nslash){ - suffix = path; + Bprint(o, str); + n = nslash; + if(n){ for(pa = relapath, pb = path; *pa && *pb; pa++, pb++){ if(*pa != *pb) break; if(*pa == '/'){ - ncommon++; - suffix = pb+1; + n--; + path = pb+1; } } - Bprint(o, "%s%.*s%s\n", str, (nslash-ncommon)*3, slashes, suffix); - } else - Bprint(o, "%s%s\n", str, path); + while(n-- > 0) + Bprint(o, "../"); + } + Bprint(o, "%s\n", path); } } void findslashes(char *path) { - char *s, *p; + char *p; p = cleanname(path); if(p[0] == '.'){ @@ -389,13 +390,9 @@ findslashes(char *path) if(*p == '/') p++; - s = slashes; - for(; *p; p++){ - if(*p != '/') - continue; - nslash++; - s = seprint(s, slashes + sizeof slashes, "../"); - } + for(; *p; p++) + if(*p == '/') + nslash++; } void