{"thread":{"id":"23227","subject":"[PATCH 3/5] convert: Use the enum constant SAFE_CRLF_FALSE.","startedAt":"2010-03-29T11:28:54Z","lastAt":"2010-04-06T11:53:16Z","messageCount":14,"participants":["Henrik Grubbström (Grubba)","Stephen R. van den Berg","Junio C Hamano","Henrik Grubbström"],"isPatch":true,"patchVersion":1,"patchTotal":5},"messages":[{"id":"138072","messageId":"cover.1269860022.git.grubba@grubba.org","threadId":"23227","inReplyTo":null,"subject":"[PATCH 0/5] ident attribute related patches (resend w/ testsuite v3)","fromName":"Henrik Grubbström (Grubba)","fromEmail":"grubba@grubba.org","sentAt":"2010-03-29T11:28:54Z","receivedAt":"2010-03-29T11:28:54Z","isPatch":true,"sender":{"key":"grubba@grubba.org","avatar":"https://avatars.githubusercontent.com/u/1169458?v=4"},"body":"These are some patches that are needed to get the support for the\n'ident' attribute to a useable state.\n\nSince last time, suggestions by Bert Wesarg <bert.wesarg@googlemail.com>\nand RenÃ© Scharfe <rene.scharfe@lsrfire.ath.cx> have been implemented.\n\nThe testsuite passes on Linux/x86 and Solaris/x86.\n\nHenrik GrubbstrÃ¶m (Grubba) (5):\n  convert: Safer handling of $Id$ contraction.\n  convert: Keep foreign $Id$ on checkout.\n  convert: Use the enum constant SAFE_CRLF_FALSE.\n  convert: Inhibit contraction of foreign $Id$ during stats.\n  convert: Added core.refilteronadd feature.\n\n Documentation/config.txt |    6 ++++\n builtin/apply.c          |    3 +-\n builtin/blame.c          |    3 +-\n cache.h                  |    9 +++++-\n combine-diff.c           |    3 +-\n config.c                 |    5 +++\n convert.c                |   52 +++++++++++++++++++++++++++++----\n diff.c                   |    3 +-\n environment.c            |    1 +\n sha1_file.c              |   60 +++++++++++++++++++++++++++++++++++++-\n t/t0021-conversion.sh    |   72 ++++++++++++++++++++++++++++++++++++++++++----\n 11 files changed, 199 insertions(+), 18 deletions(-)\n"},{"id":"138071","messageId":"a75a46b1b6fdb9d52f608643676512e87474e16d.1269860022.git.grubba@grubba.org","threadId":"23227","inReplyTo":"cover.1269860022.git.grubba@grubba.org","subject":"[PATCH 1/5] convert: Safer handling of $Id$ contraction.","fromName":"Henrik Grubbström (Grubba)","fromEmail":"grubba@grubba.org","sentAt":"2010-03-29T11:28:55Z","receivedAt":"2010-03-29T11:28:55Z","isPatch":true,"sender":{"key":"grubba@grubba.org","avatar":"https://avatars.githubusercontent.com/u/1169458?v=4"},"body":"The code to contract $Id:xxxxx$ strings could eat an arbitrary amount\nof source text if the terminating $ was lost. It now refuses to\ncontract $Id:xxxxx$ strings spanning multiple lines.\n\nSigned-off-by: Henrik Grubbström <grubba@grubba.org>\n---\nThe behaviour implemented by the patch is in line with what other\nVCSes that implement $Id$ do.\n\nFixes quoting portability issue remarked on by Bert Wesarg\n<bert.wesarg@googlemail.com>.\nImplemented some optimizations suggested by René Scharfe\n<rene.scharfe@lsrfire.ath.cx>.\n\n convert.c             |   12 ++++++++++++\n t/t0021-conversion.sh |   16 ++++++++++------\n 2 files changed, 22 insertions(+), 6 deletions(-)\n\ndiff --git a/convert.c b/convert.c\nindex 4f8fcb7..239fa0a 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -425,6 +425,8 @@ static int count_ident(const char *cp, unsigned long size)\n \t\t\t\tcnt++;\n \t\t\t\tbreak;\n \t\t\t}\n+\t\t\tif (ch == '\\n')\n+\t\t\t\tbreak;\n \t\t}\n \t}\n \treturn cnt;\n@@ -455,6 +457,11 @@ static int ident_to_git(const char *path, const char *src, size_t len,\n \t\t\tdollar = memchr(src + 3, '$', len - 3);\n \t\t\tif (!dollar)\n \t\t\t\tbreak;\n+\t\t\tif (memchr(src + 3, '\\n', dollar - src - 3)) {\n+\t\t\t\t/* Line break before the next dollar. */\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n \t\t\tmemcpy(dst, \"Id$\", 3);\n \t\t\tdst += 3;\n \t\t\tlen -= dollar + 1 - src;\n@@ -514,6 +521,11 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,\n \t\t\t\tbreak;\n \t\t\t}\n \n+\t\t\tif (memchr(src + 3, '\\n', dollar - src - 3)) {\n+\t\t\t\t/* Line break before the next dollar. */\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n \t\t\tlen -= dollar + 1 - src;\n \t\t\tsrc  = dollar + 1;\n \t\t} else {\ndiff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh\nindex 6cb8d60..29438c5 100755\n--- a/t/t0021-conversion.sh\n+++ b/t/t0021-conversion.sh\n@@ -65,17 +65,21 @@ test_expect_success expanded_in_repo '\n \t\techo \"\\$Id:NoSpaceAtFront \\$\"\n \t\techo \"\\$Id:NoSpaceAtEitherEnd\\$\"\n \t\techo \"\\$Id: NoTerminatingSymbol\"\n+\t\techo \"\\$Id: Foreign Commit With Spaces \\$\"\n+\t\techo \"\\$Id: NoTerminatingSymbolAtEOF\"\n \t} > expanded-keywords &&\n \n \t{\n \t\techo \"File with expanded keywords\"\n-\t\techo \"\\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \\$\"\n-\t\techo \"\\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \\$\"\n-\t\techo \"\\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \\$\"\n-\t\techo \"\\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \\$\"\n-\t\techo \"\\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \\$\"\n-\t\techo \"\\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \\$\"\n+\t\techo \"\\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \\$\"\n+\t\techo \"\\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \\$\"\n+\t\techo \"\\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \\$\"\n+\t\techo \"\\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \\$\"\n+\t\techo \"\\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \\$\"\n+\t\techo \"\\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \\$\"\n \t\techo \"\\$Id: NoTerminatingSymbol\"\n+\t\techo \"\\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \\$\"\n+\t\techo \"\\$Id: NoTerminatingSymbolAtEOF\"\n \t} > expected-output &&\n \n \tgit add expanded-keywords &&\n-- \n1.6.4.122.g6ffd7\n"},{"id":"138073","messageId":"6d9d8b0eaa022f441c507b141ff0efa3f21d1988.1269860022.git.grubba@grubba.org","threadId":"23227","inReplyTo":"a75a46b1b6fdb9d52f608643676512e87474e16d.1269860022.git.grubba@grubba.org","subject":"[PATCH 2/5] convert: Keep foreign $Id$ on checkout.","fromName":"Henrik Grubbström (Grubba)","fromEmail":"grubba@grubba.org","sentAt":"2010-03-29T11:28:56Z","receivedAt":"2010-03-29T11:28:56Z","isPatch":true,"sender":{"key":"grubba@grubba.org","avatar":"https://avatars.githubusercontent.com/u/1169458?v=4"},"body":"If there are foreign $Id$ keywords in the repository, they are most\nlikely there for a reason. Let's keep them on checkout (which is also\nwhat the documentation indicates). Foreign $Id$ keywords are now\nrecognized by there being multiple space separated fields in $Id:xxxxx$.\n\nSigned-off-by: Henrik Grubbström <grubba@grubba.org>\n---\nThe typical use case is for repositories that have been converted\nfrom some other VCS, where it is desirable to keep the old identifiers\naround until there's some other reason to alter the file.\n\n convert.c             |   16 ++++++++++++++--\n t/t0021-conversion.sh |    2 +-\n 2 files changed, 15 insertions(+), 3 deletions(-)\n\ndiff --git a/convert.c b/convert.c\nindex 239fa0a..5a0b7fb 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -477,7 +477,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,\n                              struct strbuf *buf, int ident)\n {\n \tunsigned char sha1[20];\n-\tchar *to_free = NULL, *dollar;\n+\tchar *to_free = NULL, *dollar, *spc;\n \tint cnt;\n \n \tif (!ident)\n@@ -513,7 +513,10 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,\n \t\t} else if (src[2] == ':') {\n \t\t\t/*\n \t\t\t * It's possible that an expanded Id has crept its way into the\n-\t\t\t * repository, we cope with that by stripping the expansion out\n+\t\t\t * repository, we cope with that by stripping the expansion out.\n+\t\t\t * This is probably not a good idea, since it will cause changes\n+\t\t\t * on checkout, which won't go away by stash, but let's keep it\n+\t\t\t * for git-style ids.\n \t\t\t */\n \t\t\tdollar = memchr(src + 3, '$', len - 3);\n \t\t\tif (!dollar) {\n@@ -526,6 +529,15 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,\n \t\t\t\tcontinue;\n \t\t\t}\n \n+\t\t\tspc = memchr(src + 4, ' ', dollar - src - 4);\n+\t\t\tif (spc && spc < dollar-1) {\n+\t\t\t\t/* There are spaces in unexpected places.\n+\t\t\t\t * This is probably an id from some other\n+\t\t\t\t * versioning system. Keep it for now.\n+\t\t\t\t */\n+\t\t\t\tcontinue;\n+\t\t\t}\n+\n \t\t\tlen -= dollar + 1 - src;\n \t\t\tsrc  = dollar + 1;\n \t\t} else {\ndiff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh\nindex 29438c5..828e35b 100755\n--- a/t/t0021-conversion.sh\n+++ b/t/t0021-conversion.sh\n@@ -78,7 +78,7 @@ test_expect_success expanded_in_repo '\n \t\techo \"\\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \\$\"\n \t\techo \"\\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \\$\"\n \t\techo \"\\$Id: NoTerminatingSymbol\"\n-\t\techo \"\\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \\$\"\n+\t\techo \"\\$Id: Foreign Commit With Spaces \\$\"\n \t\techo \"\\$Id: NoTerminatingSymbolAtEOF\"\n \t} > expected-output &&\n \n-- \n1.6.4.122.g6ffd7\n"},{"id":"138070","messageId":"74ce7980eb1fe629a651433ca9f1662f26495ce9.1269860022.git.grubba@grubba.org","threadId":"23227","inReplyTo":"6d9d8b0eaa022f441c507b141ff0efa3f21d1988.1269860022.git.grubba@grubba.org","subject":"[PATCH 3/5] convert: Use the enum constant SAFE_CRLF_FALSE.","fromName":"Henrik Grubbström (Grubba)","fromEmail":"grubba@grubba.org","sentAt":"2010-03-29T11:28:57Z","receivedAt":"2010-03-29T11:28:57Z","isPatch":true,"sender":{"key":"grubba@grubba.org","avatar":"https://avatars.githubusercontent.com/u/1169458?v=4"},"body":"A few places used plain zeros as the last argument to convert_to_git,\ninstead of the corresponding enum constant.\n\nSigned-off-by: Henrik Grubbström <grubba@grubba.org>\n---\nSuggested by Bert Wesarg <bert.wesarg@googlemail.com>.\n\n builtin/apply.c |    2 +-\n builtin/blame.c |    2 +-\n sha1_file.c     |    2 +-\n 3 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex 7ca9047..6dbe1d7 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -1759,7 +1759,7 @@ static int read_old_data(struct stat *st, const char *path, struct strbuf *buf)\n \tcase S_IFREG:\n \t\tif (strbuf_read_file(buf, path, st->st_size) != st->st_size)\n \t\t\treturn error(\"unable to open or read %s\", path);\n-\t\tconvert_to_git(path, buf->buf, buf->len, buf, 0);\n+\t\tconvert_to_git(path, buf->buf, buf->len, buf, SAFE_CRLF_FALSE);\n \t\treturn 0;\n \tdefault:\n \t\treturn -1;\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex fc15863..3af045b 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -2050,7 +2050,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con\n \t\tif (strbuf_read(&buf, 0, 0) < 0)\n \t\t\tdie_errno(\"failed to read from stdin\");\n \t}\n-\tconvert_to_git(path, buf.buf, buf.len, &buf, 0);\n+\tconvert_to_git(path, buf.buf, buf.len, &buf, SAFE_CRLF_FALSE);\n \torigin->file.ptr = buf.buf;\n \torigin->file.size = buf.len;\n \tpretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1);\ndiff --git a/sha1_file.c b/sha1_file.c\nindex a08a9d0..96c69cc 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -2417,7 +2417,7 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size,\n \tif ((type == OBJ_BLOB) && path) {\n \t\tstruct strbuf nbuf = STRBUF_INIT;\n \t\tif (convert_to_git(path, buf, size, &nbuf,\n-\t\t                   write_object ? safe_crlf : 0)) {\n+\t\t                   write_object ? safe_crlf : SAFE_CRLF_FALSE)) {\n \t\t\tbuf = strbuf_detach(&nbuf, &size);\n \t\t\tre_allocated = 1;\n \t\t}\n-- \n1.6.4.122.g6ffd7\n"},{"id":"138075","messageId":"81e71814080d0eca72809a751e4e90026f8fe0ea.1269860022.git.grubba@grubba.org","threadId":"23227","inReplyTo":"74ce7980eb1fe629a651433ca9f1662f26495ce9.1269860022.git.grubba@grubba.org","subject":"[PATCH 4/5] convert: Inhibit contraction of foreign $Id$ during stats.","fromName":"Henrik Grubbström (Grubba)","fromEmail":"grubba@grubba.org","sentAt":"2010-03-29T11:28:58Z","receivedAt":"2010-03-29T11:28:58Z","isPatch":true,"sender":{"key":"grubba@grubba.org","avatar":"https://avatars.githubusercontent.com/u/1169458?v=4"},"body":"Files containing foreign $Id$'s were reported as modified directly\non checkout, which ment that it was difficult to keep a clean working\ntree when handling commits with files containing such. convert_to_git()\nnow takes one more mode parameter for controlling this.\n\nSigned-off-by: Henrik Grubbström <grubba@grubba.org>\n---\nChanged from last time to use enum constant IDENT_MODE_FALSE instead\nof a plain zero, as suggested by Bert Wesarg <bert.wesarg@googlemail.com>.\n\n builtin/apply.c       |    3 ++-\n builtin/blame.c       |    3 ++-\n cache.h               |    8 +++++++-\n combine-diff.c        |    3 ++-\n convert.c             |   24 ++++++++++++++++++++----\n diff.c                |    3 ++-\n sha1_file.c           |    3 ++-\n t/t0021-conversion.sh |   21 +++++++++++++++++++++\n 8 files changed, 58 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex 6dbe1d7..19fe436 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -1759,7 +1759,8 @@ static int read_old_data(struct stat *st, const char *path, struct strbuf *buf)\n \tcase S_IFREG:\n \t\tif (strbuf_read_file(buf, path, st->st_size) != st->st_size)\n \t\t\treturn error(\"unable to open or read %s\", path);\n-\t\tconvert_to_git(path, buf->buf, buf->len, buf, SAFE_CRLF_FALSE);\n+\t\tconvert_to_git(path, buf->buf, buf->len, buf, SAFE_CRLF_FALSE,\n+\t\t\t       IDENT_MODE_FALSE);\n \t\treturn 0;\n \tdefault:\n \t\treturn -1;\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 3af045b..4cefaba 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -2050,7 +2050,8 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con\n \t\tif (strbuf_read(&buf, 0, 0) < 0)\n \t\t\tdie_errno(\"failed to read from stdin\");\n \t}\n-\tconvert_to_git(path, buf.buf, buf.len, &buf, SAFE_CRLF_FALSE);\n+\tconvert_to_git(path, buf.buf, buf.len, &buf, SAFE_CRLF_FALSE,\n+\t\t       IDENT_MODE_FALSE);\n \torigin->file.ptr = buf.buf;\n \torigin->file.size = buf.len;\n \tpretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1);\ndiff --git a/cache.h b/cache.h\nindex 6dcb100..d510a22 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -559,6 +559,11 @@ enum safe_crlf {\n \tSAFE_CRLF_WARN = 2,\n };\n \n+enum ident_mode {\n+\tIDENT_MODE_FALSE = 0,\n+\tIDENT_MODE_KEEP_FOREIGN = 1,\n+};\n+\n extern enum safe_crlf safe_crlf;\n \n enum branch_track {\n@@ -1014,7 +1019,8 @@ extern void trace_argv_printf(const char **argv, const char *format, ...);\n /* convert.c */\n /* returns 1 if *dst was used */\n extern int convert_to_git(const char *path, const char *src, size_t len,\n-                          struct strbuf *dst, enum safe_crlf checksafe);\n+\t\t\t  struct strbuf *dst, enum safe_crlf checksafe,\n+\t\t\t  enum ident_mode identmode);\n extern int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst);\n \n /* add */\ndiff --git a/combine-diff.c b/combine-diff.c\nindex 6162691..ba37bcc 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -758,7 +758,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,\n \t\t\tif (is_file) {\n \t\t\t\tstruct strbuf buf = STRBUF_INIT;\n \n-\t\t\t\tif (convert_to_git(elem->path, result, len, &buf, safe_crlf)) {\n+\t\t\t\tif (convert_to_git(elem->path, result, len, &buf,\n+\t\t\t\t\t\t   safe_crlf, IDENT_MODE_FALSE)) {\n \t\t\t\t\tfree(result);\n \t\t\t\t\tresult = strbuf_detach(&buf, &len);\n \t\t\t\t\tresult_size = len;\ndiff --git a/convert.c b/convert.c\nindex 5a0b7fb..2726c0c 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -433,9 +433,10 @@ static int count_ident(const char *cp, unsigned long size)\n }\n \n static int ident_to_git(const char *path, const char *src, size_t len,\n-                        struct strbuf *buf, int ident)\n+\t\t\tstruct strbuf *buf, int ident,\n+\t\t\tenum ident_mode identmode)\n {\n-\tchar *dst, *dollar;\n+\tchar *dst, *dollar, *spc;\n \n \tif (!ident || !count_ident(src, len))\n \t\treturn 0;\n@@ -462,6 +463,20 @@ static int ident_to_git(const char *path, const char *src, size_t len,\n \t\t\t\tcontinue;\n \t\t\t}\n \n+\t\t\tif ((identmode == IDENT_MODE_KEEP_FOREIGN) && len > 5) {\n+\t\t\t\tspc = memchr(src + 4, ' ', dollar - src - 4);\n+\t\t\t\tif (spc && spc < dollar-1) {\n+\t\t\t\t\t/* Foreign id.\n+\t\t\t\t\t * Contraction of these is inhibited\n+\t\t\t\t\t * during status operations to avoid\n+\t\t\t\t\t * all files containing such being\n+\t\t\t\t\t * marked as modified on checkout.\n+\t\t\t\t\t * cf sha1_file.c:index_mem().\n+\t\t\t\t\t */\n+\t\t\t\t\tcontinue;\n+\t\t\t\t}\n+\t\t\t}\n+\n \t\t\tmemcpy(dst, \"Id$\", 3);\n \t\t\tdst += 3;\n \t\t\tlen -= dollar + 1 - src;\n@@ -593,7 +608,8 @@ static int git_path_check_ident(const char *path, struct git_attr_check *check)\n }\n \n int convert_to_git(const char *path, const char *src, size_t len,\n-                   struct strbuf *dst, enum safe_crlf checksafe)\n+\t\t   struct strbuf *dst, enum safe_crlf checksafe,\n+\t\t   enum ident_mode identmode)\n {\n \tstruct git_attr_check check[3];\n \tint crlf = CRLF_GUESS;\n@@ -620,7 +636,7 @@ int convert_to_git(const char *path, const char *src, size_t len,\n \t\tsrc = dst->buf;\n \t\tlen = dst->len;\n \t}\n-\treturn ret | ident_to_git(path, src, len, dst, ident);\n+\treturn ret | ident_to_git(path, src, len, dst, ident, identmode);\n }\n \n int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst)\ndiff --git a/diff.c b/diff.c\nindex f5d93e9..9ae688b 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -2113,7 +2113,8 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)\n \t\t/*\n \t\t * Convert from working tree format to canonical git format\n \t\t */\n-\t\tif (convert_to_git(s->path, s->data, s->size, &buf, safe_crlf)) {\n+\t\tif (convert_to_git(s->path, s->data, s->size, &buf,\n+\t\t\t\t   safe_crlf, IDENT_MODE_FALSE)) {\n \t\t\tsize_t size = 0;\n \t\t\tmunmap(s->data, s->size);\n \t\t\ts->should_munmap = 0;\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 96c69cc..b7114fc 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -2417,7 +2417,8 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size,\n \tif ((type == OBJ_BLOB) && path) {\n \t\tstruct strbuf nbuf = STRBUF_INIT;\n \t\tif (convert_to_git(path, buf, size, &nbuf,\n-\t\t                   write_object ? safe_crlf : SAFE_CRLF_FALSE)) {\n+\t\t                   write_object ? safe_crlf : SAFE_CRLF_FALSE,\n+\t\t\t\t   write_object ? IDENT_MODE_FALSE : IDENT_MODE_KEEP_FOREIGN)) {\n \t\t\tbuf = strbuf_detach(&nbuf, &size);\n \t\t\tre_allocated = 1;\n \t\t}\ndiff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh\nindex 828e35b..f695581 100755\n--- a/t/t0021-conversion.sh\n+++ b/t/t0021-conversion.sh\n@@ -93,4 +93,25 @@ test_expect_success expanded_in_repo '\n \tcmp expanded-keywords expected-output\n '\n \n+# Check that files containing keywords with proper markup aren't marked\n+# as modified on checkout.\n+test_expect_success keywords_not_modified '\n+\t{\n+\t\techo \"File with foreign keywords\"\n+\t\techo \"\\$Id\\$\"\n+\t\techo \"\\$Id: NoTerminatingSymbol\"\n+\t\techo \"\\$Id: Foreign Commit With Spaces $\"\n+\t\techo \"\\$Id: NoTerminatingSymbolAtEOF\"\n+\t} > expanded-keywords2 &&\n+\n+\tgit add expanded-keywords2 &&\n+\tgit commit -m \"File with keywords expanded\" &&\n+\n+\techo \"expanded-keywords2 ident\" >> .gitattributes &&\n+\n+\trm -f expanded-keywords2 &&\n+\tgit checkout -- expanded-keywords2 &&\n+\ttest \"x`git status --porcelain -- expanded-keywords2`\" = x\n+'\n+\n test_done\n-- \n1.6.4.122.g6ffd7\n"},{"id":"138074","messageId":"33b5ea46a0534af9dc755ae58e5dd4995525f643.1269860022.git.grubba@grubba.org","threadId":"23227","inReplyTo":"81e71814080d0eca72809a751e4e90026f8fe0ea.1269860022.git.grubba@grubba.org","subject":"[PATCH 5/5] convert: Added core.refilteronadd feature.","fromName":"Henrik Grubbström (Grubba)","fromEmail":"grubba@grubba.org","sentAt":"2010-03-29T11:28:59Z","receivedAt":"2010-03-29T11:28:59Z","isPatch":true,"sender":{"key":"grubba@grubba.org","avatar":"https://avatars.githubusercontent.com/u/1169458?v=4"},"body":"When having $Id$ tags in other versioning systems, it is customary\nto recalculate the tags in the source on commit or equvivalent.\nThis commit adds a configuration option to git that causes source\nfiles to pass through a conversion roundtrip when added to the index.\n\nSigned-off-by: Henrik Grubbström <grubba@grubba.org>\n---\n Documentation/config.txt |    6 +++++\n cache.h                  |    1 +\n config.c                 |    5 ++++\n environment.c            |    1 +\n sha1_file.c              |   57 ++++++++++++++++++++++++++++++++++++++++++++++\n t/t0021-conversion.sh    |   35 ++++++++++++++++++++++++++++\n 6 files changed, 105 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 06b2f82..ceb0d50 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -535,6 +535,12 @@ core.sparseCheckout::\n \tEnable \"sparse checkout\" feature. See section \"Sparse checkout\" in\n \tlinkgit:git-read-tree[1] for more information.\n \n+core.refilterOnAdd::\n+\tEnable \"refilter on add\" feature. This causes source files to be\n+\tbehave as if they were checked out after a linkgit:git-add[1].\n+\tThis is typically usefull if eg the `ident` attribute is active,\n+\tin which case the $Id$ tags will be updated.\n+\n add.ignore-errors::\n \tTells 'git add' to continue adding files when some files cannot be\n \tadded due to indexing errors. Equivalent to the '--ignore-errors'\ndiff --git a/cache.h b/cache.h\nindex d510a22..8b5b9dc 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -552,6 +552,7 @@ extern int read_replace_refs;\n extern int fsync_object_files;\n extern int core_preload_index;\n extern int core_apply_sparse_checkout;\n+extern int core_refilter_on_add;\n \n enum safe_crlf {\n \tSAFE_CRLF_FALSE = 0,\ndiff --git a/config.c b/config.c\nindex 6963fbe..b1db505 100644\n--- a/config.c\n+++ b/config.c\n@@ -523,6 +523,11 @@ static int git_default_core_config(const char *var, const char *value)\n \t\treturn 0;\n \t}\n \n+\tif (!strcmp(var, \"core.refilteronadd\")) {\n+\t\tcore_refilter_on_add = git_config_bool(var, value);\n+\t\treturn 0;\n+\t}\n+\n \t/* Add other config variables here and to Documentation/config.txt. */\n \treturn 0;\n }\ndiff --git a/environment.c b/environment.c\nindex 876c5e5..25e1e47 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -52,6 +52,7 @@ enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE;\n char *notes_ref_name;\n int grafts_replace_parents = 1;\n int core_apply_sparse_checkout;\n+int core_refilter_on_add;\n \n /* Parallel index stat data preload? */\n int core_preload_index = 0;\ndiff --git a/sha1_file.c b/sha1_file.c\nindex b7114fc..e0b0178 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -2467,6 +2467,54 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object,\n \treturn ret;\n }\n \n+static int refilter_fd(int fd, struct stat *st, const char *path)\n+{\n+\tint ret = -1;\n+\tsize_t size = xsize_t(st->st_size);\n+\tstruct strbuf gbuf = STRBUF_INIT;\n+\n+\tif (!S_ISREG(st->st_mode)) {\n+\t\tstruct strbuf sbuf = STRBUF_INIT;\n+\t\tif (strbuf_read(&sbuf, fd, 4096) >= 0)\n+\t\t\tret = convert_to_git(path, sbuf.buf, sbuf.len, &gbuf, safe_crlf, 0);\n+\t\telse\n+\t\t\tret = -1;\n+\t\tstrbuf_release(&sbuf);\n+\t} else if (size) {\n+\t\tvoid *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0);\n+\t\tret = convert_to_git(path, buf, size, &gbuf, safe_crlf, 0);\n+\t\tmunmap(buf, size);\n+\t} else\n+\t\tret = -1;\n+\n+\tif (ret > 0) {\n+\t\t/* Something happened during conversion to git.\n+\t\t * Now convert it back, and save the result.\n+\t\t */\n+\t\tstruct strbuf obuf = STRBUF_INIT;\n+\n+\t\tlseek(fd, 0, SEEK_SET);\n+\n+\t\tif (convert_to_working_tree(path, gbuf.buf, gbuf.len, &obuf)) {\n+\t\t\tif (write_or_whine(fd, obuf.buf, obuf.len, path))\n+\t\t\t\tftruncate(fd, obuf.len);\n+\t\t\telse\n+\t\t\t\tret = -1;\n+\t\t} else {\n+\t\t\tif (write_or_whine(fd, gbuf.buf, gbuf.len, path))\n+\t\t\t\tftruncate(fd, gbuf.len);\n+\t\t\telse\n+\t\t\t\tret = -1;\n+\t\t}\n+\n+\t\tstrbuf_release(&obuf);\n+\t}\n+\tstrbuf_release(&gbuf);\n+\n+\tclose(fd);\n+\treturn ret;\n+}\n+\n int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object)\n {\n \tint fd;\n@@ -2481,6 +2529,15 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, int write\n \t\tif (index_fd(sha1, fd, st, write_object, OBJ_BLOB, path) < 0)\n \t\t\treturn error(\"%s: failed to insert into database\",\n \t\t\t\t     path);\n+\t\tif (write_object && core_refilter_on_add) {\n+\t\t\tfd = open(path, O_RDWR);\n+\t\t\tif (fd < 0)\n+\t\t\t\treturn error(\"open(\\\"%s\\\"): %s\", path,\n+\t\t\t\t\t     strerror(errno));\n+\t\t\tif (refilter_fd(fd, st, path) < 0)\n+\t\t\t\treturn error(\"%s: failed to refilter file\",\n+\t\t\t\t\t     path);\n+\t\t}\n \t\tbreak;\n \tcase S_IFLNK:\n \t\tif (strbuf_readlink(&sb, path, st->st_size)) {\ndiff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh\nindex f695581..97528c5 100755\n--- a/t/t0021-conversion.sh\n+++ b/t/t0021-conversion.sh\n@@ -114,4 +114,39 @@ test_expect_success keywords_not_modified '\n \ttest \"x`git status --porcelain -- expanded-keywords2`\" = x\n '\n \n+# Check that keywords are expanded on add when refilter is enabled.\n+test_expect_success expanded_on_add '\n+\tgit config --add core.refilteronadd true\n+\n+\techo \"expanded-keywords3 ident\" >> .gitattributes &&\n+\n+\t{\n+\t\techo \"File with keyword\"\n+\t\techo \"\\$Id\\$\"\n+\t} > expanded-keywords3 &&\n+\n+\t{\n+\t\techo \"File with keyword\"\n+\t\techo \"\\$Id: 0661580d6f976fe7cc1e4512f8db3f2ddb8d93cc \\$\"\n+\t} > expected-output3 &&\n+\n+\tgit add expanded-keywords3 &&\n+\n+\tcat expanded-keywords3 &&\n+\tcmp expanded-keywords3 expected-output3\n+'\n+\n+# Check that keywords are expanded on commit when refilter is enabled.\n+test_expect_success expanded_on_commit '\n+\t{\n+\t\techo \"File with keyword\"\n+\t\techo \"\\$Id\\$\"\n+\t} > expanded-keywords3 &&\n+\n+\tgit commit -m \"File with keyword\" expanded-keywords3 &&\n+\n+\tcat expanded-keywords3 &&\n+\tcmp expanded-keywords3 expected-output3\n+'\n+\n test_done\n-- \n1.6.4.122.g6ffd7\n"},{"id":"138080","messageId":"20100329124623.GD22480@cuci.nl","threadId":"23227","inReplyTo":"a75a46b1b6fdb9d52f608643676512e87474e16d.1269860022.git.grubba@grubba.org","subject":"Re: [PATCH 1/5] convert: Safer handling of $Id$ contraction.","fromName":"Stephen R. van den Berg","fromEmail":"srb@cuci.nl","sentAt":"2010-03-29T12:46:23Z","receivedAt":"2010-03-29T12:46:23Z","isPatch":true,"sender":{"key":"srb@cuci.nl","avatar":"https://gravatar.com/avatar/f75389059e827634d38e9df2a9b6ecbd50028b5a454442efa1c7205b7ff29c6a?d=mp&s=160"},"body":"Henrik Grubbstr??m (Grubba) wrote:\n>The code to contract $Id:xxxxx$ strings could eat an arbitrary amount\n>of source text if the terminating $ was lost. It now refuses to\n>contract $Id:xxxxx$ strings spanning multiple lines.\n\nLooks good.\n\nAcked-By: Stephen R. van den Berg <srb@cuci.nl>\n-- \nStephen.\n"},{"id":"138079","messageId":"20100329124836.GE22480@cuci.nl","threadId":"23227","inReplyTo":"6d9d8b0eaa022f441c507b141ff0efa3f21d1988.1269860022.git.grubba@grubba.org","subject":"Re: [PATCH 2/5] convert: Keep foreign $Id$ on checkout.","fromName":"Stephen R. van den Berg","fromEmail":"srb@cuci.nl","sentAt":"2010-03-29T12:48:36Z","receivedAt":"2010-03-29T12:48:36Z","isPatch":true,"sender":{"key":"srb@cuci.nl","avatar":"https://gravatar.com/avatar/f75389059e827634d38e9df2a9b6ecbd50028b5a454442efa1c7205b7ff29c6a?d=mp&s=160"},"body":"Henrik Grubbstr??m (Grubba) wrote:\n>If there are foreign $Id$ keywords in the repository, they are most\n>likely there for a reason. Let's keep them on checkout (which is also\n>what the documentation indicates). Foreign $Id$ keywords are now\n>recognized by there being multiple space separated fields in $Id:xxxxx$.\n\n>Signed-off-by: Henrik Grubbstr??m <grubba@grubba.org>\n>---\n>The typical use case is for repositories that have been converted\n>from some other VCS, where it is desirable to keep the old identifiers\n>around until there's some other reason to alter the file.\n\nLooks good.\n\nAcked-By: Stephen R. van den Berg <srb@cuci.nl>\n-- \nStephen.\n"},{"id":"138081","messageId":"20100329124929.GF22480@cuci.nl","threadId":"23227","inReplyTo":"74ce7980eb1fe629a651433ca9f1662f26495ce9.1269860022.git.grubba@grubba.org","subject":"Re: [PATCH 3/5] convert: Use the enum constant SAFE_CRLF_FALSE.","fromName":"Stephen R. van den Berg","fromEmail":"srb@cuci.nl","sentAt":"2010-03-29T12:49:29Z","receivedAt":"2010-03-29T12:49:29Z","isPatch":true,"sender":{"key":"srb@cuci.nl","avatar":"https://gravatar.com/avatar/f75389059e827634d38e9df2a9b6ecbd50028b5a454442efa1c7205b7ff29c6a?d=mp&s=160"},"body":"Henrik Grubbstr??m (Grubba) wrote:\n>A few places used plain zeros as the last argument to convert_to_git,\n>instead of the corresponding enum constant.\n\n>Signed-off-by: Henrik Grubbstr??m <grubba@grubba.org>\n\nTrivial.\n\nAcked-By: Stephen R. van den Berg <srb@cuci.nl>\n-- \nStephen.\n"},{"id":"138082","messageId":"20100329125108.GG22480@cuci.nl","threadId":"23227","inReplyTo":"81e71814080d0eca72809a751e4e90026f8fe0ea.1269860022.git.grubba@grubba.org","subject":"Re: [PATCH 4/5] convert: Inhibit contraction of foreign $Id$ during stats.","fromName":"Stephen R. van den Berg","fromEmail":"srb@cuci.nl","sentAt":"2010-03-29T12:51:08Z","receivedAt":"2010-03-29T12:51:08Z","isPatch":true,"sender":{"key":"srb@cuci.nl","avatar":"https://gravatar.com/avatar/f75389059e827634d38e9df2a9b6ecbd50028b5a454442efa1c7205b7ff29c6a?d=mp&s=160"},"body":"Henrik Grubbstr??m (Grubba) wrote:\n>Files containing foreign $Id$'s were reported as modified directly\n>on checkout, which ment that it was difficult to keep a clean working\n>tree when handling commits with files containing such. convert_to_git()\n>now takes one more mode parameter for controlling this.\n\n>Signed-off-by: Henrik Grubbstr??m <grubba@grubba.org>\n\nLooks good.\n\nAcked-By: Stephen R. van den Berg <srb@cuci.nl>\n-- \nStephen.\n"},{"id":"138078","messageId":"20100329125426.GH22480@cuci.nl","threadId":"23227","inReplyTo":"33b5ea46a0534af9dc755ae58e5dd4995525f643.1269860022.git.grubba@grubba.org","subject":"Re: [PATCH 5/5] convert: Added core.refilteronadd feature.","fromName":"Stephen R. van den Berg","fromEmail":"srb@cuci.nl","sentAt":"2010-03-29T12:54:26Z","receivedAt":"2010-03-29T12:54:26Z","isPatch":true,"sender":{"key":"srb@cuci.nl","avatar":"https://gravatar.com/avatar/f75389059e827634d38e9df2a9b6ecbd50028b5a454442efa1c7205b7ff29c6a?d=mp&s=160"},"body":"Henrik Grubbstr??m (Grubba) wrote:\n>When having $Id$ tags in other versioning systems, it is customary\n>to recalculate the tags in the source on commit or equvivalent.\n>This commit adds a configuration option to git that causes source\n>files to pass through a conversion roundtrip when added to the index.\n\n>Signed-off-by: Henrik Grubbstr??m <grubba@grubba.org>\n\nLooks good as well.\n\nAcked-By: Stephen R. van den Berg <srb@cuci.nl>\n-- \nStephen.\n"},{"id":"138354","messageId":"7vaatnosop.fsf@alter.siamese.dyndns.org","threadId":"23227","inReplyTo":"74ce7980eb1fe629a651433ca9f1662f26495ce9.1269860022.git.grubba@grubba.org","subject":"Re: [PATCH 3/5] convert: Use the enum constant SAFE_CRLF_FALSE.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-04-01T19:53:42Z","receivedAt":"2010-04-01T19:53:42Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Henrik Grubbström (Grubba)\"  <grubba@grubba.org> writes:\n\n> A few places used plain zeros as the last argument to convert_to_git,\n> instead of the corresponding enum constant.\n\nI have a feeling that you are fixing a wrong problem.\n\nIf anything, I personally think that the original that passes 0 makes it\neasier to read the callers, and I suspect that the primary reason why it\nis so is because SAFE_CRLF_FALSE is grossly misnamed.  X_FALSE makes the\nreader wonder \"perhaps I can change it to X_TRUE and make something\ninteresting happen?\" but there of course is no SAFE_CRLF_TRUE.\n\nLook at the callee that _ought_ to use the enum constant but doesn't:\n\n    static void check_safe_crlf(const char *path, int action,\n                                struct text_stat *stats, enum safe_crlf checksafe)\n    {\n            if (!checksafe)\n                    return;\n    ...\n\nThe \"checksafe\" is used to specify \"what should be done if it turns out to\nbe unsafe after inspection\", and passing 0 is \"won't do anything, so there\nis no point to even check\".  Both callers and the callee _know_ that 0\nmeans \"don't bother\", and thus this callee doesn't bother.\n\nIf the constant were renamed from SAFE_CRLF_FALSE to something a bit more\nsensible (perhaps SAFE_CRLF_NOWARN?  SAFE_CRLF_NOOP?), then it might make\nsense to replace these 0 with symbolic constants and argue that such a\nchange makes the code easier to read.\n"},{"id":"138355","messageId":"7v634bosjg.fsf@alter.siamese.dyndns.org","threadId":"23227","inReplyTo":"81e71814080d0eca72809a751e4e90026f8fe0ea.1269860022.git.grubba@grubba.org","subject":"Re: [PATCH 4/5] convert: Inhibit contraction of foreign $Id$ during stats.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-04-01T19:56:51Z","receivedAt":"2010-04-01T19:56:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Henrik Grubbström (Grubba)\"  <grubba@grubba.org> writes:\n\n> @@ -462,6 +463,20 @@ static int ident_to_git(const char *path, const char *src, size_t len,\n>  \t\t\t\tcontinue;\n>  \t\t\t}\n>  \n> +\t\t\tif ((identmode == IDENT_MODE_KEEP_FOREIGN) && len > 5) {\n> +\t\t\t\tspc = memchr(src + 4, ' ', dollar - src - 4);\n> +\t\t\t\tif (spc && spc < dollar-1) {\n> +\t\t\t\t\t/* Foreign id.\n> +\t\t\t\t\t * Contraction of these is inhibited\n> +\t\t\t\t\t * during status operations to avoid\n> +\t\t\t\t\t * all files containing such being\n> +\t\t\t\t\t * marked as modified on checkout.\n> +\t\t\t\t\t * cf sha1_file.c:index_mem().\n> +\t\t\t\t\t */\n> +\t\t\t\t\tcontinue;\n> +\t\t\t\t}\n> +\t\t\t}\n\nSomehow this feels to me that it is applying a band-aid to solve a problem\nthat does not exist, only because the second patch in this series to keep\nthe foreign one left expanded were not such a good change after all...\n"},{"id":"138740","messageId":"Pine.GSO.4.63.1004061324530.1164@shipon.roxen.com","threadId":"23227","inReplyTo":"7v634bosjg.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH 4/5] convert: Inhibit contraction of foreign $Id$ during stats.","fromName":"Henrik Grubbström","fromEmail":"grubba@roxen.com","sentAt":"2010-04-06T11:53:16Z","receivedAt":"2010-04-06T11:53:16Z","isPatch":true,"sender":{"key":"grubba@roxen.com","avatar":null},"body":"On Thu, 1 Apr 2010, Junio C Hamano wrote:\n\n> \"Henrik Grubbström (Grubba)\"  <grubba@grubba.org> writes:\n>\n>> @@ -462,6 +463,20 @@ static int ident_to_git(const char *path, const char *src, size_t len,\n[...]\n>\n> Somehow this feels to me that it is applying a band-aid to solve a problem\n> that does not exist, only because the second patch in this series to keep\n> the foreign one left expanded were not such a good change after all...\n\nTrue, this was the patch that I was least satisfied with, since it only \nsolved a special case (albeit the special case that I was interested in).\n\nThe general case is when the canonic (ie *_to_git) conversion filter for a\nfile has changed after the file was committed.\n\n--\nHenrik Grubbström\t\t\t\t\tgrubba@grubba.org\nRoxen Internet Software AB\t\t\t\tgrubba@roxen.com"}]}