From: Junio C Hamano Date: Mon, 21 Jun 2010 13:02:47 +0000 (-0700) Subject: Merge branch 'fg/autocrlf' X-Git-Tag: v1.7.2-rc0~24 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/d249515f297d47df6d79167b988eaa7db0981178?ds=inline;hp=-c Merge branch 'fg/autocrlf' * fg/autocrlf: autocrlf: Make it work also for un-normalized repositories --- d249515f297d47df6d79167b988eaa7db0981178 diff --combined convert.c index 824bd047a5,a54c5fc4a2..64dce3ff57 --- a/convert.c +++ b/convert.c @@@ -120,6 -120,43 +120,43 @@@ static void check_safe_crlf(const char } } + static int has_cr_in_index(const char *path) + { + int pos, len; + unsigned long sz; + enum object_type type; + void *data; + int has_cr; + struct index_state *istate = &the_index; + + len = strlen(path); + pos = index_name_pos(istate, path, len); + if (pos < 0) { + /* + * We might be in the middle of a merge, in which + * case we would read stage #2 (ours). + */ + int i; + for (i = -pos - 1; + (pos < 0 && i < istate->cache_nr && + !strcmp(istate->cache[i]->name, path)); + i++) + if (ce_stage(istate->cache[i]) == 2) + pos = i; + } + if (pos < 0) + return 0; + data = read_sha1_file(istate->cache[pos]->sha1, &type, &sz); + if (!data || type != OBJ_BLOB) { + free(data); + return 0; + } + + has_cr = memchr(data, '\r', sz) != NULL; + free(data); + return has_cr; + } + static int crlf_to_git(const char *path, const char *src, size_t len, struct strbuf *buf, int action, enum safe_crlf checksafe) { @@@ -145,6 -182,13 +182,13 @@@ */ if (is_binary(len, &stats)) return 0; + + /* + * If the file in the index has any CR in it, do not convert. + * This is the new safer autocrlf handling. + */ + if (has_cr_in_index(path)) + return 0; } check_safe_crlf(path, action, &stats, checksafe); @@@ -203,6 -247,11 +247,11 @@@ static int crlf_to_worktree(const char return 0; if (action == CRLF_GUESS) { + /* If we have any CR or CRLF line endings, we do not touch it */ + /* This is the new safer autocrlf-handling */ + if (stats.cr > 0 || stats.crlf > 0) + return 0; + /* If we have any bare CR characters, we're not going to touch it */ if (stats.cr != stats.crlf) return 0; @@@ -241,7 -290,7 +290,7 @@@ struct filter_params const char *cmd; }; -static int filter_buffer(int fd, void *data) +static int filter_buffer(int in, int out, void *data) { /* * Spawn cmd and feed the buffer contents through its stdin. @@@ -249,15 -298,13 +298,15 @@@ struct child_process child_process; struct filter_params *params = (struct filter_params *)data; int write_err, status; - const char *argv[] = { params->cmd, NULL }; + const char *argv[] = { NULL, NULL }; + + argv[0] = params->cmd; memset(&child_process, 0, sizeof(child_process)); child_process.argv = argv; child_process.use_shell = 1; child_process.in = -1; - child_process.out = fd; + child_process.out = out; if (start_command(&child_process)) return error("cannot fork to run external filter %s", params->cmd); @@@ -294,7 -341,6 +343,7 @@@ static int apply_filter(const char *pat memset(&async, 0, sizeof(async)); async.proc = filter_buffer; async.data = ¶ms; + async.out = -1; params.src = src; params.size = len; params.cmd = cmd; @@@ -427,8 -473,6 +476,8 @@@ static int count_ident(const char *cp, cnt++; break; } + if (ch == '\n') + break; } } return cnt; @@@ -459,11 -503,6 +508,11 @@@ static int ident_to_git(const char *pat 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; @@@ -479,7 -518,7 +528,7 @@@ static int ident_to_worktree(const cha struct strbuf *buf, int ident) { unsigned char sha1[20]; - char *to_free = NULL, *dollar; + char *to_free = NULL, *dollar, *spc; int cnt; if (!ident) @@@ -515,10 -554,7 +564,10 @@@ } 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,20 -562,6 +575,20 @@@ break; } + if (memchr(src + 3, '\n', dollar - src - 3)) { + /* Line break before the next dollar. */ + 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 {