From: Henrik Grubbström (Grubba) <grubba@xxxxxxxxxx> 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@xxxxxxxxxx> --- builtin-apply.c | 2 +- builtin-blame.c | 2 +- cache.h | 8 +++++++- combine-diff.c | 2 +- convert.c | 20 +++++++++++++++++--- diff.c | 2 +- sha1_file.c | 3 ++- 7 files changed, 30 insertions(+), 9 deletions(-) diff --git a/builtin-apply.c b/builtin-apply.c index 3af4ae0..25adef8 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, 0, 0); return 0; default: return -1; diff --git a/builtin-blame.c b/builtin-blame.c index 10f7eac..f21bf3d 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, 0, 0); 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 d478eff..1c9f491 100644 --- a/cache.h +++ b/cache.h @@ -547,6 +547,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 { @@ -996,7 +1001,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..8c9320a 100644 --- a/combine-diff.c +++ b/combine-diff.c @@ -758,7 +758,7 @@ 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, 0)) { free(result); result = strbuf_detach(&buf, &len); result_size = len; diff --git a/convert.c b/convert.c index 28aeea3..c053bcd 100644 --- a/convert.c +++ b/convert.c @@ -432,7 +432,8 @@ 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, *nl; @@ -462,6 +463,18 @@ static int ident_to_git(const char *path, const char *src, size_t len, continue; } + if ((identmode == IDENT_MODE_KEEP_FOREIGN) && + ((src[3] != ' ') || + (memchr(src + 4, ' ', len - 4) != 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; @@ -594,7 +607,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; @@ -621,7 +635,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 989dbc5..64726c8 100644 --- a/diff.c +++ b/diff.c @@ -2113,7 +2113,7 @@ 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, 0)) { size_t size = 0; munmap(s->data, s->size); s->should_munmap = 0; diff --git a/sha1_file.c b/sha1_file.c index 657825e..fd8c5df 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -2419,7 +2419,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 : 0)) { + write_object ? safe_crlf : 0, + write_object ? 0 : IDENT_MODE_KEEP_FOREIGN)) { buf = strbuf_detach(&nbuf, &size); re_allocated = 1; } -- 1.6.4.122.g6ffd7 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html