All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jonas Fonseca <fonseca@diku.dk>
To: torvalds@osdl.org, pasky@ucw.cz
Cc: git@vger.kernel.org
Subject: [PATCH] Add --strict switch to diff-cache to force SHA1 checking
Date: Sun, 24 Apr 2005 05:35:54 +0200	[thread overview]
Message-ID: <20050424033554.GA23293@diku.dk> (raw)

It seems by far the easiest to let diff-cache take care of skipping
files which have not been modified. The alternative is to keep
diff-cache's lazy checking and make cogito's diff jump through hoops.
Note, although the new SHA1 signature is derived, diff-cache still
prints the special no-SHA1 for the modified file.
-

Add --strict switch to diff-cache to force it to check the SHA1
signature of modified files so files are only listed if the mode or
content changed.

Signed-off-by: Jonas Fonseca <fonseca@diku.dk>

--- 3b4a5bb703599458ce8fe504f37f8e28b77bd6ca/diff-cache.c  (mode:100644 sha1:2ec6c29ab6b79a10277a2ff9021a2032d656abf0)
+++ uncommitted/diff-cache.c  (mode:100644)
@@ -1,6 +1,7 @@
 #include "cache.h"
 
 static int cached_only = 0;
+static int strict_checking = 0;
 static int line_termination = '\n';
 
 /* A file entry went away or appeared */
@@ -10,6 +11,26 @@
 	       sha1_to_hex(ce->sha1), ce->name, line_termination);
 }
 
+static int check_modified_signature(struct cache_entry *old, struct stat *st)
+{
+	void *map;
+	int ret = -1;
+	int fd = open(old->name, O_RDONLY);
+
+	if (fd < 0)
+		return -1;
+
+	map = mmap(NULL, st->st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+	if (map != MAP_FAILED) {
+		ret = check_sha1_signature(old->sha1, map, st->st_size, "blob");
+		munmap(map, st->st_size);
+	}
+
+	close(fd);
+
+	return ret;
+}
+
 static int show_modified(struct cache_entry *old, struct cache_entry *new)
 {
 	unsigned int mode = ntohl(new->ce_mode), oldmode;
@@ -27,6 +48,12 @@
 		changed = cache_match_stat(new, &st);
 		if (changed) {
 			mode = st.st_mode;
+
+			if (strict_checking
+			    && mode == ntohl(old->ce_mode)
+			    && check_modified_signature(old, &st) == 0)
+				return 0;
+
 			sha1 = no_sha1;
 		}
 	}
@@ -85,7 +112,7 @@
 	}
 }
 
-static char *diff_cache_usage = "diff-cache [-r] [-z] [--cached] <tree sha1>";
+static char *diff_cache_usage = "diff-cache [-r] [-z] [--cached] [--strict] <tree sha1>";
 
 int main(int argc, char **argv)
 {
@@ -110,6 +137,10 @@
 			cached_only = 1;
 			continue;
 		}
+		if (!strcmp(arg, "--strict")) {
+			strict_checking = 1;
+			continue;
+		}
 		usage(diff_cache_usage);
 	}
 

-- 
Jonas Fonseca

             reply	other threads:[~2005-04-24  3:31 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-24  3:35 Jonas Fonseca [this message]
2005-04-24  3:38 ` [PATCH] Use diff-cache --strict in gitdiff.sh Jonas Fonseca
2005-04-24  3:57 ` [PATCH] Add --strict switch to diff-cache to force SHA1 checking Linus Torvalds
2005-04-24  5:55   ` [PATCH] fix segfault in fsck-cache (2nd attempt) Andreas Gal

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=20050424033554.GA23293@diku.dk \
    --to=fonseca@diku.dk \
    --cc=git@vger.kernel.org \
    --cc=pasky@ucw.cz \
    --cc=torvalds@osdl.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.