9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] git/walk: track mode of files in index
@ 2021-09-04 21:13 ori
  0 siblings, 0 replies; only message in thread
From: ori @ 2021-09-04 21:13 UTC (permalink / raw)
  To: 9front

Currently, while we correctly handle modes when committing
files, we don't track the current mode of a file in the
index.

This means that when we change the mode of a file and
try to commit it, git thinks the file is not modified,
and will not include the file in the commit.

This change adds tracking for the mode of a file into
the index.

diff 3e7a249f146ce7fb3b7f482adc6b1e7f3aba5616 uncommitted
--- a/sys/src/cmd/git/branch
+++ b/sys/src/cmd/git/branch
@@ -100,7 +100,7 @@
 	}
 	if(~ $b file){
 		if(cp -x -- $basedir/tree/$m $m)
-			walk -eq $m > .git/index9/tracked/$m
+			walk -exq $m > .git/index9/tracked/$m
 		if not
 			echo -n > .git/index9/tracked/$m
 	}
--- a/sys/src/cmd/git/clone
+++ b/sys/src/cmd/git/clone
@@ -89,7 +89,7 @@
 		for(f in `$nl{walk -f $tree | drop $tree}){
 			idx=.git/index9/tracked/$f
 			mkdir -p `$nl{basename -d $idx}
-			walk -eq ./$f > $idx
+			walk -exq ./$f > $idx
 		}
 	}
 	if not{
--- a/sys/src/cmd/git/commit
+++ b/sys/src/cmd/git/commit
@@ -95,7 +95,7 @@
 		}
 		if not{
 			mkdir -p `{basename -d $f}
-			walk -eq $f > .git/index9/tracked/$f
+			walk -exq $f > .git/index9/tracked/$f
 		}
 	}
 }
--- a/sys/src/cmd/git/walk.c
+++ b/sys/src/cmd/git/walk.c
@@ -1,5 +1,6 @@
 #include <u.h>
 #include <libc.h>
+#include <fcall.h>
 #include "git.h"
 
 #define NCACHE 4096
@@ -153,8 +154,8 @@
 	if((p = strpbrk(indexqid, "  \t\n\r")) != nil)
 		*p = 0;
 
-	snprint(fileqid, sizeof(fileqid), "%ullx.%uld.%.2uhhx",
-		d->qid.path, d->qid.vers, d->qid.type);
+	snprint(fileqid, sizeof(fileqid), "%M%ullx.%uld.%.2uhhx",
+		d->mode, d->qid.path, d->qid.vers, d->qid.type);
 
 	if(strcmp(indexqid, fileqid) == 0)
 		return 1;
@@ -168,16 +169,17 @@
 
 	if((fd = create(qf, OWRITE, 0666)) == -1)
 		return;
-	fprint(fd, "%ullx.%uld.%.2uhhx\n",
-		d->qid.path, d->qid.vers, d->qid.type);
+	fprint(fd, "%M%ullx.%uld.%.2uhhx\n",
+		d->mode, d->qid.path, d->qid.vers, d->qid.type);
 	close(fd);
 }
 
 int
-samedata(char *pa, char *pb)
+same(char *pa, char *pb)
 {
 	char ba[32*1024], bb[32*1024];
 	int fa, fb, na, nb, same;
+	Dir *da, *db;
 
 	same = 0;
 	fa = open(pa, OREAD);
@@ -197,7 +199,12 @@
 		if(memcmp(ba, bb, na) != 0)
 			goto mismatch;
 	}
-	same = 1;
+	da = dirfstat(fa);
+	db = dirfstat(fb);
+	if(da->mode == db->mode)
+		same = 1;
+	free(da);
+	free(db);
 mismatch:
 	if(fa != -1)
 		close(fa);
@@ -246,6 +253,7 @@
 		usage();
 	}ARGEND
 
+	fmtinstall('M', dirmodefmt);
 	if(findrepo(repo, sizeof(repo)) == -1)
 		sysfatal("find root: %r");
 	if(chdir(repo) == -1)
@@ -303,7 +311,7 @@
 				dirty |= Aflg;
 				if(!quiet && (printflg & Aflg))
 					print("%s%s\n", astr, p);
-			}else if(samedata(p, bpath)){
+			}else if(same(p, bpath)){
 				if(!quiet && (printflg & Tflg))
 					print("%s%s\n", tstr, p);
 				writeqid(d, tpath);


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-04 21:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-04 21:13 [9front] git/walk: track mode of files in index ori

9front - general discussion about 9front

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.vuxu.org/9front

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 9front 9front/ https://inbox.vuxu.org/9front \
		9front@9front.org
	public-inbox-index 9front

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.9front


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git