* [PATCH 0/5] ident attribute related patches (resend w/ testsuite v3) @ 2010-03-29 11:28 Henrik Grubbström (Grubba) 2010-03-29 11:28 ` [PATCH 1/5] convert: Safer handling of $Id$ contraction Henrik Grubbström (Grubba) 0 siblings, 1 reply; 14+ messages in thread From: Henrik Grubbström (Grubba) @ 2010-03-29 11:28 UTC (permalink / raw) To: git; +Cc: Henrik Grubbström These are some patches that are needed to get the support for the 'ident' attribute to a useable state. Since last time, suggestions by Bert Wesarg <bert.wesarg@googlemail.com> and René Scharfe <rene.scharfe@lsrfire.ath.cx> have been implemented. The testsuite passes on Linux/x86 and Solaris/x86. Henrik Grubbström (Grubba) (5): convert: Safer handling of $Id$ contraction. convert: Keep foreign $Id$ on checkout. convert: Use the enum constant SAFE_CRLF_FALSE. convert: Inhibit contraction of foreign $Id$ during stats. convert: Added core.refilteronadd feature. Documentation/config.txt | 6 ++++ builtin/apply.c | 3 +- builtin/blame.c | 3 +- cache.h | 9 +++++- combine-diff.c | 3 +- config.c | 5 +++ convert.c | 52 +++++++++++++++++++++++++++++---- diff.c | 3 +- environment.c | 1 + sha1_file.c | 60 +++++++++++++++++++++++++++++++++++++- t/t0021-conversion.sh | 72 ++++++++++++++++++++++++++++++++++++++++++---- 11 files changed, 199 insertions(+), 18 deletions(-) ^ permalink raw reply [flat|nested] 14+ messages in thread
* [PATCH 1/5] convert: Safer handling of $Id$ contraction. 2010-03-29 11:28 [PATCH 0/5] ident attribute related patches (resend w/ testsuite v3) Henrik Grubbström (Grubba) @ 2010-03-29 11:28 ` Henrik Grubbström (Grubba) 2010-03-29 11:28 ` [PATCH 2/5] convert: Keep foreign $Id$ on checkout Henrik Grubbström (Grubba) 2010-03-29 12:46 ` [PATCH 1/5] convert: Safer handling of $Id$ contraction Stephen R. van den Berg 0 siblings, 2 replies; 14+ messages in thread From: Henrik Grubbström (Grubba) @ 2010-03-29 11:28 UTC (permalink / raw) To: git; +Cc: Henrik Grubbström The code to contract $Id:xxxxx$ strings could eat an arbitrary amount of source text if the terminating $ was lost. It now refuses to contract $Id:xxxxx$ strings spanning multiple lines. Signed-off-by: Henrik Grubbström <grubba@grubba.org> --- The behaviour implemented by the patch is in line with what other VCSes that implement $Id$ do. Fixes quoting portability issue remarked on by Bert Wesarg <bert.wesarg@googlemail.com>. Implemented some optimizations suggested by René Scharfe <rene.scharfe@lsrfire.ath.cx>. convert.c | 12 ++++++++++++ t/t0021-conversion.sh | 16 ++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/convert.c b/convert.c index 4f8fcb7..239fa0a 100644 --- a/convert.c +++ b/convert.c @@ -425,6 +425,8 @@ static int count_ident(const char *cp, unsigned long size) cnt++; break; } + if (ch == '\n') + break; } } return cnt; @@ -455,6 +457,11 @@ static int ident_to_git(const char *path, const char *src, size_t len, dollar = memchr(src + 3, '$', len - 3); if (!dollar) break; + if (memchr(src + 3, '\n', dollar - src - 3)) { + /* Line break before the next dollar. */ + continue; + } + memcpy(dst, "Id$", 3); dst += 3; len -= dollar + 1 - src; @@ -514,6 +521,11 @@ static int ident_to_worktree(const char *path, const char *src, size_t len, break; } + if (memchr(src + 3, '\n', dollar - src - 3)) { + /* Line break before the next dollar. */ + continue; + } + len -= dollar + 1 - src; src = dollar + 1; } else { diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index 6cb8d60..29438c5 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -65,17 +65,21 @@ test_expect_success expanded_in_repo ' echo "\$Id:NoSpaceAtFront \$" echo "\$Id:NoSpaceAtEitherEnd\$" echo "\$Id: NoTerminatingSymbol" + echo "\$Id: Foreign Commit With Spaces \$" + echo "\$Id: NoTerminatingSymbolAtEOF" } > expanded-keywords && { echo "File with expanded keywords" - echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$" - echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$" - echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$" - echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$" - echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$" - echo "\$Id: 4f21723e7b15065df7de95bd46c8ba6fb1818f4c \$" + echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$" + echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$" + echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$" + echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$" + echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$" + echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$" echo "\$Id: NoTerminatingSymbol" + echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$" + echo "\$Id: NoTerminatingSymbolAtEOF" } > expected-output && git add expanded-keywords && -- 1.6.4.122.g6ffd7 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 2/5] convert: Keep foreign $Id$ on checkout. 2010-03-29 11:28 ` [PATCH 1/5] convert: Safer handling of $Id$ contraction Henrik Grubbström (Grubba) @ 2010-03-29 11:28 ` Henrik Grubbström (Grubba) 2010-03-29 11:28 ` [PATCH 3/5] convert: Use the enum constant SAFE_CRLF_FALSE Henrik Grubbström (Grubba) 2010-03-29 12:48 ` [PATCH 2/5] convert: Keep foreign $Id$ on checkout Stephen R. van den Berg 2010-03-29 12:46 ` [PATCH 1/5] convert: Safer handling of $Id$ contraction Stephen R. van den Berg 1 sibling, 2 replies; 14+ messages in thread From: Henrik Grubbström (Grubba) @ 2010-03-29 11:28 UTC (permalink / raw) To: git; +Cc: Henrik Grubbström If there are foreign $Id$ keywords in the repository, they are most likely there for a reason. Let's keep them on checkout (which is also what the documentation indicates). Foreign $Id$ keywords are now recognized by there being multiple space separated fields in $Id:xxxxx$. Signed-off-by: Henrik Grubbström <grubba@grubba.org> --- The typical use case is for repositories that have been converted from some other VCS, where it is desirable to keep the old identifiers around until there's some other reason to alter the file. convert.c | 16 ++++++++++++++-- t/t0021-conversion.sh | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/convert.c b/convert.c index 239fa0a..5a0b7fb 100644 --- a/convert.c +++ b/convert.c @@ -477,7 +477,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len, struct strbuf *buf, int ident) { unsigned char sha1[20]; - char *to_free = NULL, *dollar; + char *to_free = NULL, *dollar, *spc; int cnt; if (!ident) @@ -513,7 +513,10 @@ static int ident_to_worktree(const char *path, const char *src, size_t len, } else if (src[2] == ':') { /* * It's possible that an expanded Id has crept its way into the - * repository, we cope with that by stripping the expansion out + * repository, we cope with that by stripping the expansion out. + * This is probably not a good idea, since it will cause changes + * on checkout, which won't go away by stash, but let's keep it + * for git-style ids. */ dollar = memchr(src + 3, '$', len - 3); if (!dollar) { @@ -526,6 +529,15 @@ static int ident_to_worktree(const char *path, const char *src, size_t len, continue; } + spc = memchr(src + 4, ' ', dollar - src - 4); + if (spc && spc < dollar-1) { + /* There are spaces in unexpected places. + * This is probably an id from some other + * versioning system. Keep it for now. + */ + continue; + } + len -= dollar + 1 - src; src = dollar + 1; } else { diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index 29438c5..828e35b 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -78,7 +78,7 @@ test_expect_success expanded_in_repo ' echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$" echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$" echo "\$Id: NoTerminatingSymbol" - echo "\$Id: fd0478f5f1486f3d5177d4c3f6eb2765e8fc56b9 \$" + echo "\$Id: Foreign Commit With Spaces \$" echo "\$Id: NoTerminatingSymbolAtEOF" } > expected-output && -- 1.6.4.122.g6ffd7 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 3/5] convert: Use the enum constant SAFE_CRLF_FALSE. 2010-03-29 11:28 ` [PATCH 2/5] convert: Keep foreign $Id$ on checkout Henrik Grubbström (Grubba) @ 2010-03-29 11:28 ` Henrik Grubbström (Grubba) 2010-03-29 11:28 ` [PATCH 4/5] convert: Inhibit contraction of foreign $Id$ during stats Henrik Grubbström (Grubba) ` (2 more replies) 2010-03-29 12:48 ` [PATCH 2/5] convert: Keep foreign $Id$ on checkout Stephen R. van den Berg 1 sibling, 3 replies; 14+ messages in thread From: Henrik Grubbström (Grubba) @ 2010-03-29 11:28 UTC (permalink / raw) To: git; +Cc: Henrik Grubbström A few places used plain zeros as the last argument to convert_to_git, instead of the corresponding enum constant. Signed-off-by: Henrik Grubbström <grubba@grubba.org> --- Suggested by Bert Wesarg <bert.wesarg@googlemail.com>. builtin/apply.c | 2 +- builtin/blame.c | 2 +- sha1_file.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index 7ca9047..6dbe1d7 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -1759,7 +1759,7 @@ static int read_old_data(struct stat *st, const char *path, struct strbuf *buf) case S_IFREG: if (strbuf_read_file(buf, path, st->st_size) != st->st_size) return error("unable to open or read %s", path); - convert_to_git(path, buf->buf, buf->len, buf, 0); + convert_to_git(path, buf->buf, buf->len, buf, SAFE_CRLF_FALSE); return 0; default: return -1; diff --git a/builtin/blame.c b/builtin/blame.c index fc15863..3af045b 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -2050,7 +2050,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con if (strbuf_read(&buf, 0, 0) < 0) die_errno("failed to read from stdin"); } - convert_to_git(path, buf.buf, buf.len, &buf, 0); + convert_to_git(path, buf.buf, buf.len, &buf, SAFE_CRLF_FALSE); origin->file.ptr = buf.buf; origin->file.size = buf.len; pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1); diff --git a/sha1_file.c b/sha1_file.c index a08a9d0..96c69cc 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2417,7 +2417,7 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size, if ((type == OBJ_BLOB) && path) { struct strbuf nbuf = STRBUF_INIT; if (convert_to_git(path, buf, size, &nbuf, - write_object ? safe_crlf : 0)) { + write_object ? safe_crlf : SAFE_CRLF_FALSE)) { buf = strbuf_detach(&nbuf, &size); re_allocated = 1; } -- 1.6.4.122.g6ffd7 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 4/5] convert: Inhibit contraction of foreign $Id$ during stats. 2010-03-29 11:28 ` [PATCH 3/5] convert: Use the enum constant SAFE_CRLF_FALSE Henrik Grubbström (Grubba) @ 2010-03-29 11:28 ` Henrik Grubbström (Grubba) 2010-03-29 11:28 ` [PATCH 5/5] convert: Added core.refilteronadd feature Henrik Grubbström (Grubba) ` (2 more replies) 2010-03-29 12:49 ` [PATCH 3/5] convert: Use the enum constant SAFE_CRLF_FALSE Stephen R. van den Berg 2010-04-01 19:53 ` Junio C Hamano 2 siblings, 3 replies; 14+ messages in thread From: Henrik Grubbström (Grubba) @ 2010-03-29 11:28 UTC (permalink / raw) To: git; +Cc: Henrik Grubbström Files containing foreign $Id$'s were reported as modified directly on checkout, which ment that it was difficult to keep a clean working tree when handling commits with files containing such. convert_to_git() now takes one more mode parameter for controlling this. Signed-off-by: Henrik Grubbström <grubba@grubba.org> --- Changed from last time to use enum constant IDENT_MODE_FALSE instead of a plain zero, as suggested by Bert Wesarg <bert.wesarg@googlemail.com>. builtin/apply.c | 3 ++- builtin/blame.c | 3 ++- cache.h | 8 +++++++- combine-diff.c | 3 ++- convert.c | 24 ++++++++++++++++++++---- diff.c | 3 ++- sha1_file.c | 3 ++- t/t0021-conversion.sh | 21 +++++++++++++++++++++ 8 files changed, 58 insertions(+), 10 deletions(-) diff --git a/builtin/apply.c b/builtin/apply.c index 6dbe1d7..19fe436 100644 --- a/builtin/apply.c +++ b/builtin/apply.c @@ -1759,7 +1759,8 @@ static int read_old_data(struct stat *st, const char *path, struct strbuf *buf) case S_IFREG: if (strbuf_read_file(buf, path, st->st_size) != st->st_size) return error("unable to open or read %s", path); - convert_to_git(path, buf->buf, buf->len, buf, SAFE_CRLF_FALSE); + convert_to_git(path, buf->buf, buf->len, buf, SAFE_CRLF_FALSE, + IDENT_MODE_FALSE); return 0; default: return -1; diff --git a/builtin/blame.c b/builtin/blame.c index 3af045b..4cefaba 100644 --- a/builtin/blame.c +++ b/builtin/blame.c @@ -2050,7 +2050,8 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con if (strbuf_read(&buf, 0, 0) < 0) die_errno("failed to read from stdin"); } - convert_to_git(path, buf.buf, buf.len, &buf, SAFE_CRLF_FALSE); + convert_to_git(path, buf.buf, buf.len, &buf, SAFE_CRLF_FALSE, + IDENT_MODE_FALSE); origin->file.ptr = buf.buf; origin->file.size = buf.len; pretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1); diff --git a/cache.h b/cache.h index 6dcb100..d510a22 100644 --- a/cache.h +++ b/cache.h @@ -559,6 +559,11 @@ enum safe_crlf { SAFE_CRLF_WARN = 2, }; +enum ident_mode { + IDENT_MODE_FALSE = 0, + IDENT_MODE_KEEP_FOREIGN = 1, +}; + extern enum safe_crlf safe_crlf; enum branch_track { @@ -1014,7 +1019,8 @@ extern void trace_argv_printf(const char **argv, const char *format, ...); /* convert.c */ /* returns 1 if *dst was used */ extern int convert_to_git(const char *path, const char *src, size_t len, - struct strbuf *dst, enum safe_crlf checksafe); + struct strbuf *dst, enum safe_crlf checksafe, + enum ident_mode identmode); extern int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst); /* add */ diff --git a/combine-diff.c b/combine-diff.c index 6162691..ba37bcc 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -758,7 +758,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent, if (is_file) { struct strbuf buf = STRBUF_INIT; - if (convert_to_git(elem->path, result, len, &buf, safe_crlf)) { + if (convert_to_git(elem->path, result, len, &buf, + safe_crlf, IDENT_MODE_FALSE)) { free(result); result = strbuf_detach(&buf, &len); result_size = len; diff --git a/convert.c b/convert.c index 5a0b7fb..2726c0c 100644 --- a/convert.c +++ b/convert.c @@ -433,9 +433,10 @@ static int count_ident(const char *cp, unsigned long size) } static int ident_to_git(const char *path, const char *src, size_t len, - struct strbuf *buf, int ident) + struct strbuf *buf, int ident, + enum ident_mode identmode) { - char *dst, *dollar; + char *dst, *dollar, *spc; if (!ident || !count_ident(src, len)) return 0; @@ -462,6 +463,20 @@ static int ident_to_git(const char *path, const char *src, size_t len, continue; } + if ((identmode == IDENT_MODE_KEEP_FOREIGN) && len > 5) { + spc = memchr(src + 4, ' ', dollar - src - 4); + if (spc && spc < dollar-1) { + /* Foreign id. + * Contraction of these is inhibited + * during status operations to avoid + * all files containing such being + * marked as modified on checkout. + * cf sha1_file.c:index_mem(). + */ + continue; + } + } + memcpy(dst, "Id$", 3); dst += 3; len -= dollar + 1 - src; @@ -593,7 +608,8 @@ static int git_path_check_ident(const char *path, struct git_attr_check *check) } int convert_to_git(const char *path, const char *src, size_t len, - struct strbuf *dst, enum safe_crlf checksafe) + struct strbuf *dst, enum safe_crlf checksafe, + enum ident_mode identmode) { struct git_attr_check check[3]; int crlf = CRLF_GUESS; @@ -620,7 +636,7 @@ int convert_to_git(const char *path, const char *src, size_t len, src = dst->buf; len = dst->len; } - return ret | ident_to_git(path, src, len, dst, ident); + return ret | ident_to_git(path, src, len, dst, ident, identmode); } int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst) diff --git a/diff.c b/diff.c index f5d93e9..9ae688b 100644 --- a/diff.c +++ b/diff.c @@ -2113,7 +2113,8 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only) /* * Convert from working tree format to canonical git format */ - if (convert_to_git(s->path, s->data, s->size, &buf, safe_crlf)) { + if (convert_to_git(s->path, s->data, s->size, &buf, + safe_crlf, IDENT_MODE_FALSE)) { size_t size = 0; munmap(s->data, s->size); s->should_munmap = 0; diff --git a/sha1_file.c b/sha1_file.c index 96c69cc..b7114fc 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2417,7 +2417,8 @@ static int index_mem(unsigned char *sha1, void *buf, size_t size, if ((type == OBJ_BLOB) && path) { struct strbuf nbuf = STRBUF_INIT; if (convert_to_git(path, buf, size, &nbuf, - write_object ? safe_crlf : SAFE_CRLF_FALSE)) { + write_object ? safe_crlf : SAFE_CRLF_FALSE, + write_object ? IDENT_MODE_FALSE : IDENT_MODE_KEEP_FOREIGN)) { buf = strbuf_detach(&nbuf, &size); re_allocated = 1; } diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index 828e35b..f695581 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -93,4 +93,25 @@ test_expect_success expanded_in_repo ' cmp expanded-keywords expected-output ' +# Check that files containing keywords with proper markup aren't marked +# as modified on checkout. +test_expect_success keywords_not_modified ' + { + echo "File with foreign keywords" + echo "\$Id\$" + echo "\$Id: NoTerminatingSymbol" + echo "\$Id: Foreign Commit With Spaces $" + echo "\$Id: NoTerminatingSymbolAtEOF" + } > expanded-keywords2 && + + git add expanded-keywords2 && + git commit -m "File with keywords expanded" && + + echo "expanded-keywords2 ident" >> .gitattributes && + + rm -f expanded-keywords2 && + git checkout -- expanded-keywords2 && + test "x`git status --porcelain -- expanded-keywords2`" = x +' + test_done -- 1.6.4.122.g6ffd7 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 5/5] convert: Added core.refilteronadd feature. 2010-03-29 11:28 ` [PATCH 4/5] convert: Inhibit contraction of foreign $Id$ during stats Henrik Grubbström (Grubba) @ 2010-03-29 11:28 ` Henrik Grubbström (Grubba) 2010-03-29 12:54 ` Stephen R. van den Berg 2010-03-29 12:51 ` [PATCH 4/5] convert: Inhibit contraction of foreign $Id$ during stats Stephen R. van den Berg 2010-04-01 19:56 ` Junio C Hamano 2 siblings, 1 reply; 14+ messages in thread From: Henrik Grubbström (Grubba) @ 2010-03-29 11:28 UTC (permalink / raw) To: git; +Cc: Henrik Grubbström When having $Id$ tags in other versioning systems, it is customary to recalculate the tags in the source on commit or equvivalent. This commit adds a configuration option to git that causes source files to pass through a conversion roundtrip when added to the index. Signed-off-by: Henrik Grubbström <grubba@grubba.org> --- Documentation/config.txt | 6 +++++ cache.h | 1 + config.c | 5 ++++ environment.c | 1 + sha1_file.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++ t/t0021-conversion.sh | 35 ++++++++++++++++++++++++++++ 6 files changed, 105 insertions(+), 0 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 06b2f82..ceb0d50 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -535,6 +535,12 @@ core.sparseCheckout:: Enable "sparse checkout" feature. See section "Sparse checkout" in linkgit:git-read-tree[1] for more information. +core.refilterOnAdd:: + Enable "refilter on add" feature. This causes source files to be + behave as if they were checked out after a linkgit:git-add[1]. + This is typically usefull if eg the `ident` attribute is active, + in which case the $Id$ tags will be updated. + add.ignore-errors:: Tells 'git add' to continue adding files when some files cannot be added due to indexing errors. Equivalent to the '--ignore-errors' diff --git a/cache.h b/cache.h index d510a22..8b5b9dc 100644 --- a/cache.h +++ b/cache.h @@ -552,6 +552,7 @@ extern int read_replace_refs; extern int fsync_object_files; extern int core_preload_index; extern int core_apply_sparse_checkout; +extern int core_refilter_on_add; enum safe_crlf { SAFE_CRLF_FALSE = 0, diff --git a/config.c b/config.c index 6963fbe..b1db505 100644 --- a/config.c +++ b/config.c @@ -523,6 +523,11 @@ static int git_default_core_config(const char *var, const char *value) return 0; } + if (!strcmp(var, "core.refilteronadd")) { + core_refilter_on_add = git_config_bool(var, value); + return 0; + } + /* Add other config variables here and to Documentation/config.txt. */ return 0; } diff --git a/environment.c b/environment.c index 876c5e5..25e1e47 100644 --- a/environment.c +++ b/environment.c @@ -52,6 +52,7 @@ enum object_creation_mode object_creation_mode = OBJECT_CREATION_MODE; char *notes_ref_name; int grafts_replace_parents = 1; int core_apply_sparse_checkout; +int core_refilter_on_add; /* Parallel index stat data preload? */ int core_preload_index = 0; diff --git a/sha1_file.c b/sha1_file.c index b7114fc..e0b0178 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2467,6 +2467,54 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object, return ret; } +static int refilter_fd(int fd, struct stat *st, const char *path) +{ + int ret = -1; + size_t size = xsize_t(st->st_size); + struct strbuf gbuf = STRBUF_INIT; + + if (!S_ISREG(st->st_mode)) { + struct strbuf sbuf = STRBUF_INIT; + if (strbuf_read(&sbuf, fd, 4096) >= 0) + ret = convert_to_git(path, sbuf.buf, sbuf.len, &gbuf, safe_crlf, 0); + else + ret = -1; + strbuf_release(&sbuf); + } else if (size) { + void *buf = xmmap(NULL, size, PROT_READ, MAP_PRIVATE, fd, 0); + ret = convert_to_git(path, buf, size, &gbuf, safe_crlf, 0); + munmap(buf, size); + } else + ret = -1; + + if (ret > 0) { + /* Something happened during conversion to git. + * Now convert it back, and save the result. + */ + struct strbuf obuf = STRBUF_INIT; + + lseek(fd, 0, SEEK_SET); + + if (convert_to_working_tree(path, gbuf.buf, gbuf.len, &obuf)) { + if (write_or_whine(fd, obuf.buf, obuf.len, path)) + ftruncate(fd, obuf.len); + else + ret = -1; + } else { + if (write_or_whine(fd, gbuf.buf, gbuf.len, path)) + ftruncate(fd, gbuf.len); + else + ret = -1; + } + + strbuf_release(&obuf); + } + strbuf_release(&gbuf); + + close(fd); + return ret; +} + int index_path(unsigned char *sha1, const char *path, struct stat *st, int write_object) { int fd; @@ -2481,6 +2529,15 @@ int index_path(unsigned char *sha1, const char *path, struct stat *st, int write if (index_fd(sha1, fd, st, write_object, OBJ_BLOB, path) < 0) return error("%s: failed to insert into database", path); + if (write_object && core_refilter_on_add) { + fd = open(path, O_RDWR); + if (fd < 0) + return error("open(\"%s\"): %s", path, + strerror(errno)); + if (refilter_fd(fd, st, path) < 0) + return error("%s: failed to refilter file", + path); + } break; case S_IFLNK: if (strbuf_readlink(&sb, path, st->st_size)) { diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index f695581..97528c5 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -114,4 +114,39 @@ test_expect_success keywords_not_modified ' test "x`git status --porcelain -- expanded-keywords2`" = x ' +# Check that keywords are expanded on add when refilter is enabled. +test_expect_success expanded_on_add ' + git config --add core.refilteronadd true + + echo "expanded-keywords3 ident" >> .gitattributes && + + { + echo "File with keyword" + echo "\$Id\$" + } > expanded-keywords3 && + + { + echo "File with keyword" + echo "\$Id: 0661580d6f976fe7cc1e4512f8db3f2ddb8d93cc \$" + } > expected-output3 && + + git add expanded-keywords3 && + + cat expanded-keywords3 && + cmp expanded-keywords3 expected-output3 +' + +# Check that keywords are expanded on commit when refilter is enabled. +test_expect_success expanded_on_commit ' + { + echo "File with keyword" + echo "\$Id\$" + } > expanded-keywords3 && + + git commit -m "File with keyword" expanded-keywords3 && + + cat expanded-keywords3 && + cmp expanded-keywords3 expected-output3 +' + test_done -- 1.6.4.122.g6ffd7 ^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH 5/5] convert: Added core.refilteronadd feature. 2010-03-29 11:28 ` [PATCH 5/5] convert: Added core.refilteronadd feature Henrik Grubbström (Grubba) @ 2010-03-29 12:54 ` Stephen R. van den Berg 0 siblings, 0 replies; 14+ messages in thread From: Stephen R. van den Berg @ 2010-03-29 12:54 UTC (permalink / raw) To: Henrik Grubbstr??m (Grubba); +Cc: git Henrik Grubbstr??m (Grubba) wrote: >When having $Id$ tags in other versioning systems, it is customary >to recalculate the tags in the source on commit or equvivalent. >This commit adds a configuration option to git that causes source >files to pass through a conversion roundtrip when added to the index. >Signed-off-by: Henrik Grubbstr??m <grubba@grubba.org> Looks good as well. Acked-By: Stephen R. van den Berg <srb@cuci.nl> -- Stephen. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 4/5] convert: Inhibit contraction of foreign $Id$ during stats. 2010-03-29 11:28 ` [PATCH 4/5] convert: Inhibit contraction of foreign $Id$ during stats Henrik Grubbström (Grubba) 2010-03-29 11:28 ` [PATCH 5/5] convert: Added core.refilteronadd feature Henrik Grubbström (Grubba) @ 2010-03-29 12:51 ` Stephen R. van den Berg 2010-04-01 19:56 ` Junio C Hamano 2 siblings, 0 replies; 14+ messages in thread From: Stephen R. van den Berg @ 2010-03-29 12:51 UTC (permalink / raw) To: Henrik Grubbstr??m (Grubba); +Cc: git Henrik Grubbstr??m (Grubba) wrote: >Files containing foreign $Id$'s were reported as modified directly >on checkout, which ment that it was difficult to keep a clean working >tree when handling commits with files containing such. convert_to_git() >now takes one more mode parameter for controlling this. >Signed-off-by: Henrik Grubbstr??m <grubba@grubba.org> Looks good. Acked-By: Stephen R. van den Berg <srb@cuci.nl> -- Stephen. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 4/5] convert: Inhibit contraction of foreign $Id$ during stats. 2010-03-29 11:28 ` [PATCH 4/5] convert: Inhibit contraction of foreign $Id$ during stats Henrik Grubbström (Grubba) 2010-03-29 11:28 ` [PATCH 5/5] convert: Added core.refilteronadd feature Henrik Grubbström (Grubba) 2010-03-29 12:51 ` [PATCH 4/5] convert: Inhibit contraction of foreign $Id$ during stats Stephen R. van den Berg @ 2010-04-01 19:56 ` Junio C Hamano 2010-04-06 11:53 ` Henrik Grubbström 2 siblings, 1 reply; 14+ messages in thread From: Junio C Hamano @ 2010-04-01 19:56 UTC (permalink / raw) To: Henrik Grubbström (Grubba); +Cc: git "Henrik Grubbström (Grubba)" <grubba@grubba.org> writes: > @@ -462,6 +463,20 @@ static int ident_to_git(const char *path, const char *src, size_t len, > continue; > } > > + if ((identmode == IDENT_MODE_KEEP_FOREIGN) && len > 5) { > + spc = memchr(src + 4, ' ', dollar - src - 4); > + if (spc && spc < dollar-1) { > + /* Foreign id. > + * Contraction of these is inhibited > + * during status operations to avoid > + * all files containing such being > + * marked as modified on checkout. > + * cf sha1_file.c:index_mem(). > + */ > + continue; > + } > + } Somehow this feels to me that it is applying a band-aid to solve a problem that does not exist, only because the second patch in this series to keep the foreign one left expanded were not such a good change after all... ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 4/5] convert: Inhibit contraction of foreign $Id$ during stats. 2010-04-01 19:56 ` Junio C Hamano @ 2010-04-06 11:53 ` Henrik Grubbström 0 siblings, 0 replies; 14+ messages in thread From: Henrik Grubbström @ 2010-04-06 11:53 UTC (permalink / raw) To: Junio C Hamano; +Cc: git, Henrik Grubbström [-- Attachment #1: Type: TEXT/PLAIN, Size: 795 bytes --] On Thu, 1 Apr 2010, Junio C Hamano wrote: > "Henrik Grubbström (Grubba)" <grubba@grubba.org> writes: > >> @@ -462,6 +463,20 @@ static int ident_to_git(const char *path, const char *src, size_t len, [...] > > Somehow this feels to me that it is applying a band-aid to solve a problem > that does not exist, only because the second patch in this series to keep > the foreign one left expanded were not such a good change after all... True, this was the patch that I was least satisfied with, since it only solved a special case (albeit the special case that I was interested in). The general case is when the canonic (ie *_to_git) conversion filter for a file has changed after the file was committed. -- Henrik Grubbström grubba@grubba.org Roxen Internet Software AB grubba@roxen.com ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 3/5] convert: Use the enum constant SAFE_CRLF_FALSE. 2010-03-29 11:28 ` [PATCH 3/5] convert: Use the enum constant SAFE_CRLF_FALSE Henrik Grubbström (Grubba) 2010-03-29 11:28 ` [PATCH 4/5] convert: Inhibit contraction of foreign $Id$ during stats Henrik Grubbström (Grubba) @ 2010-03-29 12:49 ` Stephen R. van den Berg 2010-04-01 19:53 ` Junio C Hamano 2 siblings, 0 replies; 14+ messages in thread From: Stephen R. van den Berg @ 2010-03-29 12:49 UTC (permalink / raw) To: Henrik Grubbstr??m (Grubba); +Cc: git Henrik Grubbstr??m (Grubba) wrote: >A few places used plain zeros as the last argument to convert_to_git, >instead of the corresponding enum constant. >Signed-off-by: Henrik Grubbstr??m <grubba@grubba.org> Trivial. Acked-By: Stephen R. van den Berg <srb@cuci.nl> -- Stephen. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 3/5] convert: Use the enum constant SAFE_CRLF_FALSE. 2010-03-29 11:28 ` [PATCH 3/5] convert: Use the enum constant SAFE_CRLF_FALSE Henrik Grubbström (Grubba) 2010-03-29 11:28 ` [PATCH 4/5] convert: Inhibit contraction of foreign $Id$ during stats Henrik Grubbström (Grubba) 2010-03-29 12:49 ` [PATCH 3/5] convert: Use the enum constant SAFE_CRLF_FALSE Stephen R. van den Berg @ 2010-04-01 19:53 ` Junio C Hamano 2 siblings, 0 replies; 14+ messages in thread From: Junio C Hamano @ 2010-04-01 19:53 UTC (permalink / raw) To: Henrik Grubbström (Grubba); +Cc: git "Henrik Grubbström (Grubba)" <grubba@grubba.org> writes: > A few places used plain zeros as the last argument to convert_to_git, > instead of the corresponding enum constant. I have a feeling that you are fixing a wrong problem. If anything, I personally think that the original that passes 0 makes it easier to read the callers, and I suspect that the primary reason why it is so is because SAFE_CRLF_FALSE is grossly misnamed. X_FALSE makes the reader wonder "perhaps I can change it to X_TRUE and make something interesting happen?" but there of course is no SAFE_CRLF_TRUE. Look at the callee that _ought_ to use the enum constant but doesn't: static void check_safe_crlf(const char *path, int action, struct text_stat *stats, enum safe_crlf checksafe) { if (!checksafe) return; ... The "checksafe" is used to specify "what should be done if it turns out to be unsafe after inspection", and passing 0 is "won't do anything, so there is no point to even check". Both callers and the callee _know_ that 0 means "don't bother", and thus this callee doesn't bother. If the constant were renamed from SAFE_CRLF_FALSE to something a bit more sensible (perhaps SAFE_CRLF_NOWARN? SAFE_CRLF_NOOP?), then it might make sense to replace these 0 with symbolic constants and argue that such a change makes the code easier to read. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 2/5] convert: Keep foreign $Id$ on checkout. 2010-03-29 11:28 ` [PATCH 2/5] convert: Keep foreign $Id$ on checkout Henrik Grubbström (Grubba) 2010-03-29 11:28 ` [PATCH 3/5] convert: Use the enum constant SAFE_CRLF_FALSE Henrik Grubbström (Grubba) @ 2010-03-29 12:48 ` Stephen R. van den Berg 1 sibling, 0 replies; 14+ messages in thread From: Stephen R. van den Berg @ 2010-03-29 12:48 UTC (permalink / raw) To: Henrik Grubbstr??m (Grubba); +Cc: git Henrik Grubbstr??m (Grubba) wrote: >If there are foreign $Id$ keywords in the repository, they are most >likely there for a reason. Let's keep them on checkout (which is also >what the documentation indicates). Foreign $Id$ keywords are now >recognized by there being multiple space separated fields in $Id:xxxxx$. >Signed-off-by: Henrik Grubbstr??m <grubba@grubba.org> >--- >The typical use case is for repositories that have been converted >from some other VCS, where it is desirable to keep the old identifiers >around until there's some other reason to alter the file. Looks good. Acked-By: Stephen R. van den Berg <srb@cuci.nl> -- Stephen. ^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH 1/5] convert: Safer handling of $Id$ contraction. 2010-03-29 11:28 ` [PATCH 1/5] convert: Safer handling of $Id$ contraction Henrik Grubbström (Grubba) 2010-03-29 11:28 ` [PATCH 2/5] convert: Keep foreign $Id$ on checkout Henrik Grubbström (Grubba) @ 2010-03-29 12:46 ` Stephen R. van den Berg 1 sibling, 0 replies; 14+ messages in thread From: Stephen R. van den Berg @ 2010-03-29 12:46 UTC (permalink / raw) To: Henrik Grubbstr??m (Grubba); +Cc: git Henrik Grubbstr??m (Grubba) wrote: >The code to contract $Id:xxxxx$ strings could eat an arbitrary amount >of source text if the terminating $ was lost. It now refuses to >contract $Id:xxxxx$ strings spanning multiple lines. Looks good. Acked-By: Stephen R. van den Berg <srb@cuci.nl> -- Stephen. ^ permalink raw reply [flat|nested] 14+ messages in thread
end of thread, other threads:[~2010-04-06 11:53 UTC | newest] Thread overview: 14+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-03-29 11:28 [PATCH 0/5] ident attribute related patches (resend w/ testsuite v3) Henrik Grubbström (Grubba) 2010-03-29 11:28 ` [PATCH 1/5] convert: Safer handling of $Id$ contraction Henrik Grubbström (Grubba) 2010-03-29 11:28 ` [PATCH 2/5] convert: Keep foreign $Id$ on checkout Henrik Grubbström (Grubba) 2010-03-29 11:28 ` [PATCH 3/5] convert: Use the enum constant SAFE_CRLF_FALSE Henrik Grubbström (Grubba) 2010-03-29 11:28 ` [PATCH 4/5] convert: Inhibit contraction of foreign $Id$ during stats Henrik Grubbström (Grubba) 2010-03-29 11:28 ` [PATCH 5/5] convert: Added core.refilteronadd feature Henrik Grubbström (Grubba) 2010-03-29 12:54 ` Stephen R. van den Berg 2010-03-29 12:51 ` [PATCH 4/5] convert: Inhibit contraction of foreign $Id$ during stats Stephen R. van den Berg 2010-04-01 19:56 ` Junio C Hamano 2010-04-06 11:53 ` Henrik Grubbström 2010-03-29 12:49 ` [PATCH 3/5] convert: Use the enum constant SAFE_CRLF_FALSE Stephen R. van den Berg 2010-04-01 19:53 ` Junio C Hamano 2010-03-29 12:48 ` [PATCH 2/5] convert: Keep foreign $Id$ on checkout Stephen R. van den Berg 2010-03-29 12:46 ` [PATCH 1/5] convert: Safer handling of $Id$ contraction Stephen R. van den Berg
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).