{"thread":{"id":"282","subject":"[PATCH] Add --strict switch to diff-cache to force SHA1 checking","startedAt":"2005-04-24T03:35:54Z","lastAt":"2005-04-24T05:55:54Z","messageCount":4,"participants":["Jonas Fonseca","Linus Torvalds","Andreas Gal"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"1472","messageId":"20050424033554.GA23293@diku.dk","threadId":"282","inReplyTo":null,"subject":"[PATCH] Add --strict switch to diff-cache to force SHA1 checking","fromName":"Jonas Fonseca","fromEmail":"fonseca@diku.dk","sentAt":"2005-04-24T03:35:54Z","receivedAt":"2005-04-24T03:35:54Z","isPatch":true,"sender":{"key":"fonseca@diku.dk","avatar":"https://gravatar.com/avatar/f82f3ad698717c51873b020c750a92438c820a24056dc39fe4d07baa10a92264?d=mp&s=160"},"body":"It seems by far the easiest to let diff-cache take care of skipping\nfiles which have not been modified. The alternative is to keep\ndiff-cache's lazy checking and make cogito's diff jump through hoops.\nNote, although the new SHA1 signature is derived, diff-cache still\nprints the special no-SHA1 for the modified file.\n-\n\nAdd --strict switch to diff-cache to force it to check the SHA1\nsignature of modified files so files are only listed if the mode or\ncontent changed.\n\nSigned-off-by: Jonas Fonseca <fonseca@diku.dk>\n\n--- 3b4a5bb703599458ce8fe504f37f8e28b77bd6ca/diff-cache.c  (mode:100644 sha1:2ec6c29ab6b79a10277a2ff9021a2032d656abf0)\n+++ uncommitted/diff-cache.c  (mode:100644)\n@@ -1,6 +1,7 @@\n #include \"cache.h\"\n \n static int cached_only = 0;\n+static int strict_checking = 0;\n static int line_termination = '\\n';\n \n /* A file entry went away or appeared */\n@@ -10,6 +11,26 @@\n \t       sha1_to_hex(ce->sha1), ce->name, line_termination);\n }\n \n+static int check_modified_signature(struct cache_entry *old, struct stat *st)\n+{\n+\tvoid *map;\n+\tint ret = -1;\n+\tint fd = open(old->name, O_RDONLY);\n+\n+\tif (fd < 0)\n+\t\treturn -1;\n+\n+\tmap = mmap(NULL, st->st_size, PROT_READ, MAP_PRIVATE, fd, 0);\n+\tif (map != MAP_FAILED) {\n+\t\tret = check_sha1_signature(old->sha1, map, st->st_size, \"blob\");\n+\t\tmunmap(map, st->st_size);\n+\t}\n+\n+\tclose(fd);\n+\n+\treturn ret;\n+}\n+\n static int show_modified(struct cache_entry *old, struct cache_entry *new)\n {\n \tunsigned int mode = ntohl(new->ce_mode), oldmode;\n@@ -27,6 +48,12 @@\n \t\tchanged = cache_match_stat(new, &st);\n \t\tif (changed) {\n \t\t\tmode = st.st_mode;\n+\n+\t\t\tif (strict_checking\n+\t\t\t    && mode == ntohl(old->ce_mode)\n+\t\t\t    && check_modified_signature(old, &st) == 0)\n+\t\t\t\treturn 0;\n+\n \t\t\tsha1 = no_sha1;\n \t\t}\n \t}\n@@ -85,7 +112,7 @@\n \t}\n }\n \n-static char *diff_cache_usage = \"diff-cache [-r] [-z] [--cached] <tree sha1>\";\n+static char *diff_cache_usage = \"diff-cache [-r] [-z] [--cached] [--strict] <tree sha1>\";\n \n int main(int argc, char **argv)\n {\n@@ -110,6 +137,10 @@\n \t\t\tcached_only = 1;\n \t\t\tcontinue;\n \t\t}\n+\t\tif (!strcmp(arg, \"--strict\")) {\n+\t\t\tstrict_checking = 1;\n+\t\t\tcontinue;\n+\t\t}\n \t\tusage(diff_cache_usage);\n \t}\n \n\n-- \nJonas Fonseca\n"},{"id":"1473","messageId":"20050424033824.GB23293@diku.dk","threadId":"282","inReplyTo":"20050424033554.GA23293@diku.dk","subject":"[PATCH] Use diff-cache --strict in gitdiff.sh","fromName":"Jonas Fonseca","fromEmail":"fonseca@diku.dk","sentAt":"2005-04-24T03:38:24Z","receivedAt":"2005-04-24T03:38:24Z","isPatch":true,"sender":{"key":"fonseca@diku.dk","avatar":"https://gravatar.com/avatar/f82f3ad698717c51873b020c750a92438c820a24056dc39fe4d07baa10a92264?d=mp&s=160"},"body":"Use diff-cache --strict invokation to only show diff of changed files.\n\nSigned-off-by: Jonas Fonseca <fonseca@diku.dk>\n\n--- 2aaf94eae20acc451553766f3c063bc46cfa75c6/gitdiff.sh  (mode:100755 sha1:1478a0cfb23a85c259eae1a36cf2a48597fbe8a2)\n+++ uncommitted/gitdiff.sh  (mode:100755)\n@@ -76,7 +76,7 @@\n \t# FIXME: Update ret based on what did we match. And take \"$@\"\n \t# to account after all.\n \tret=\n-\tdiff-cache -r -z $tree | xargs -0 gitdiff-do \"$tree\" uncommitted \"$filter\"\n+\tdiff-cache -r -z --strict $tree | xargs -0 gitdiff-do \"$tree\" uncommitted \"$filter\"\n \n \tif [ \"$id1\" != \" \" ]; then\n \t\trm $GIT_INDEX_FILE\n\n-- \nJonas Fonseca\n"},{"id":"1475","messageId":"Pine.LNX.4.58.0504232056160.2344@ppc970.osdl.org","threadId":"282","inReplyTo":"20050424033554.GA23293@diku.dk","subject":"Re: [PATCH] Add --strict switch to diff-cache to force SHA1 checking","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-04-24T03:57:56Z","receivedAt":"2005-04-24T03:57:56Z","isPatch":true,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\n\nOn Sun, 24 Apr 2005, Jonas Fonseca wrote:\n>\n> It seems by far the easiest to let diff-cache take care of skipping\n> files which have not been modified. The alternative is to keep\n> diff-cache's lazy checking and make cogito's diff jump through hoops.\n> Note, although the new SHA1 signature is derived, diff-cache still\n> prints the special no-SHA1 for the modified file.\n\nThe reason I don't want this is that if the commands keep on silently\nfixing things like this up, then performance will go down the toilet.\n\nWhat _should_ happen is that you do an \"update-cache --refresh\" before    \ndoing the diff-cache. That way you do _not_ end up having to check the    \nsha1 match over and over again if you just did a \"touch\" on the file.\n\nIn other words, you're adding bandage for a problem that shouldn't exist,\nand you're doing it in a way which means that _if_ the problem exists,    \nyou'll never fix it, but you'll just rely on your bandage all the time.\n\nSo cogito definitely does not have to jump through any hoops at all. It\nshould just make sure to keep the cache up-to-date if it ever cares (ie\ndo \"update-cache --refresh\"). \n\nSome commands obviously won't care.\n\n\t\tLinus\n"},{"id":"1499","messageId":"Pine.LNX.4.58.0504232250210.9799@sam.ics.uci.edu","threadId":"282","inReplyTo":"Pine.LNX.4.58.0504232056160.2344@ppc970.osdl.org","subject":"[PATCH] fix segfault in fsck-cache (2nd attempt)","fromName":"Andreas Gal","fromEmail":"gal@uci.edu","sentAt":"2005-04-24T05:55:54Z","receivedAt":"2005-04-24T05:55:54Z","isPatch":true,"sender":{"key":"gal@uci.edu","avatar":null},"body":"\nHere is how to trigger it:\n\necho blob 100 > .git/objects/00/ae4e8d3208e09f2cf7a38202a126f728cadb49\n\nThen run fsck-cache. It will try to unpack after the header to calculate \nthe hash, inflate returns total_out == 0 and memcpy() dies.\n\nThe patch below seems to work with ZLIB 1.1 and 1.2.\n\nSigned-off-by: Andreas Gal <gal@uci.edu>\n\n--- 97a515a073fec5870dfaaa279868ce9330853d3d/sha1_file.c\n+++ sha1_file.c\n@@ -155,6 +155,8 @@\n \n        inflateInit(&stream);\n        ret = inflate(&stream, 0);\n+       if (ret < Z_OK)\n+               return NULL;\n        if (sscanf(buffer, \"%10s %lu\", type, size) != 2)\n                return NULL;\n \nOn Sat, 23 Apr 2005, Linus Torvalds wrote:\n\n> \n> \n> On Sun, 24 Apr 2005, Jonas Fonseca wrote:\n> >\n> > It seems by far the easiest to let diff-cache take care of skipping\n> > files which have not been modified. The alternative is to keep\n> > diff-cache's lazy checking and make cogito's diff jump through hoops.\n> > Note, although the new SHA1 signature is derived, diff-cache still\n> > prints the special no-SHA1 for the modified file.\n> \n> The reason I don't want this is that if the commands keep on silently\n> fixing things like this up, then performance will go down the toilet.\n> \n> What _should_ happen is that you do an \"update-cache --refresh\" before    \n> doing the diff-cache. That way you do _not_ end up having to check the    \n> sha1 match over and over again if you just did a \"touch\" on the file.\n> \n> In other words, you're adding bandage for a problem that shouldn't exist,\n> and you're doing it in a way which means that _if_ the problem exists,    \n> you'll never fix it, but you'll just rely on your bandage all the time.\n> \n> So cogito definitely does not have to jump through any hoops at all. It\n> should just make sure to keep the cache up-to-date if it ever cares (ie\n> do \"update-cache --refresh\"). \n> \n> Some commands obviously won't care.\n> \n> \t\tLinus\n> -\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n> \n"}]}