9front - general discussion about 9front
 help / color / mirror / Atom feed
From: ori@eigenstate.org
To: 9front@9front.org
Subject: [9front] git/walk: track mode of files in index
Date: Sat, 04 Sep 2021 17:13:10 -0400	[thread overview]
Message-ID: <5554A092595925841982BA7338B07EE2@eigenstate.org> (raw)

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);


             reply	other threads:[~2021-09-04 21:18 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-04 21:13 ori [this message]
2021-10-01 22:16 ` me

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5554A092595925841982BA7338B07EE2@eigenstate.org \
    --to=ori@eigenstate.org \
    --cc=9front@9front.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).