From: Marcus Comstedt <marcus@mc.pp.se>
To: git@vger.kernel.org
Cc: gitster@pobox.com
Subject: [PATCH v3 2/4] convert: fix normalization of foreign idents
Date: Mon, 23 Aug 2010 09:05:23 +0200 [thread overview]
Message-ID: <b56d7f50198f63a810b304ae77043f58a240f743.1284820251.git.marcus@mc.pp.se> (raw)
In-Reply-To: <cover.1284820251.git.marcus@mc.pp.se>
Since ident_to_worktree() does not touch $Id$ tags which contain
foreign expansions in the repository, make sure that ident_to_git()
does not either. This fixes the problem that such files show
spurious modification upon checkout.
There is however one case where we want ident_to_git() to normalize
the tag to $Id$ despite the asymmetry: When committing a modification
to a file which has a foreign ident, the foreign ident should be
replaced with a regular git ident. Thus, add a new parameter to
convert_to_git() that indicates if we want the foreign idents
normalized after all.
Signed-off-by: Marcus Comstedt <marcus@mc.pp.se>
---
builtin/apply.c | 2 +-
builtin/blame.c | 2 +-
cache.h | 8 +++++++-
combine-diff.c | 2 +-
convert.c | 23 ++++++++++++++++++-----
diff.c | 2 +-
sha1_file.c | 3 ++-
7 files changed, 31 insertions(+), 11 deletions(-)
diff --git a/builtin/apply.c b/builtin/apply.c
index 638e7be..fe8d638 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -1932,7 +1932,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, CHECKS_DISALLOWED);
+ convert_to_git(path, buf->buf, buf->len, buf, CHECKS_DISALLOWED, NORMALIZE_FOR_COMPARE);
return 0;
default:
return -1;
diff --git a/builtin/blame.c b/builtin/blame.c
index 850e165..8d8cbf3 100644
--- a/builtin/blame.c
+++ b/builtin/blame.c
@@ -2095,7 +2095,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,
if (strbuf_read(&buf, 0, 0) < 0)
die_errno("failed to read from stdin");
}
- convert_to_git(path, buf.buf, buf.len, &buf, CHECKS_DISALLOWED);
+ convert_to_git(path, buf.buf, buf.len, &buf, CHECKS_DISALLOWED, NORMALIZE_FOR_COMPARE);
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 250abc1..3010e20 100644
--- a/cache.h
+++ b/cache.h
@@ -586,6 +586,11 @@ enum allow_checks {
CHECKS_ALLOWED = 1,
};
+enum normalize_mode {
+ NORMALIZE_FOR_COMPARE = 0,
+ NORMALIZE_FOR_COMMIT = 1,
+};
+
enum branch_track {
BRANCH_TRACK_UNSPECIFIED = -1,
BRANCH_TRACK_NEVER = 0,
@@ -1064,7 +1069,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 allow_checks checksallowed);
+ struct strbuf *dst, enum allow_checks checksallowed,
+ enum normalize_mode mode);
extern int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst);
extern int renormalize_buffer(const char *path, const char *src, size_t len, struct strbuf *dst);
diff --git a/combine-diff.c b/combine-diff.c
index c7f132d..e36bf61 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, CHECKS_ALLOWED)) {
+ if (convert_to_git(elem->path, result, len, &buf, CHECKS_ALLOWED, NORMALIZE_FOR_COMPARE)) {
free(result);
result = strbuf_detach(&buf, &len);
result_size = len;
diff --git a/convert.c b/convert.c
index 8050c24..4eb28d8 100644
--- a/convert.c
+++ b/convert.c
@@ -520,9 +520,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,
+ int normalize_foreign_ident)
{
- char *dst, *dollar;
+ char *dst, *dollar, *spc;
if (!ident || !count_ident(src, len))
return 0;
@@ -549,6 +550,16 @@ static int ident_to_git(const char *path, const char *src, size_t len,
continue;
}
+ spc = memchr(src + 4, ' ', dollar - src - 4);
+ if (spc && spc < dollar-1 &&
+ !normalize_foreign_ident) {
+ /* There are spaces in unexpected places.
+ * This is probably an id from some other
+ * versioning system. Keep it for now.
+ */
+ continue;
+ }
+
memcpy(dst, "Id$", 3);
dst += 3;
len -= dollar + 1 - src;
@@ -706,7 +717,8 @@ static enum action determine_action(enum action text_attr, enum eol eol_attr)
}
int convert_to_git(const char *path, const char *src, size_t len,
- struct strbuf *dst, enum allow_checks checksallowed)
+ struct strbuf *dst, enum allow_checks checksallowed,
+ enum normalize_mode mode)
{
struct git_attr_check check[5];
enum action action = CRLF_GUESS;
@@ -739,7 +751,8 @@ 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,
+ mode == NORMALIZE_FOR_COMMIT);
}
static int convert_to_working_tree_internal(const char *path, const char *src,
@@ -797,5 +810,5 @@ int renormalize_buffer(const char *path, const char *src, size_t len, struct str
src = dst->buf;
len = dst->len;
}
- return ret | convert_to_git(path, src, len, dst, CHECKS_DISALLOWED);
+ return ret | convert_to_git(path, src, len, dst, CHECKS_DISALLOWED, NORMALIZE_FOR_COMPARE);
}
diff --git a/diff.c b/diff.c
index ed74f6b..eebe3dd 100644
--- a/diff.c
+++ b/diff.c
@@ -2375,7 +2375,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, CHECKS_ALLOWED)) {
+ if (convert_to_git(s->path, s->data, s->size, &buf, CHECKS_ALLOWED, NORMALIZE_FOR_COMPARE)) {
size_t size = 0;
munmap(s->data, s->size);
s->should_munmap = 0;
diff --git a/sha1_file.c b/sha1_file.c
index 13624a6..cbebb75 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2434,7 +2434,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 ? CHECKS_ALLOWED : CHECKS_DISALLOWED)) {
+ write_object ? CHECKS_ALLOWED : CHECKS_DISALLOWED,
+ write_object ? NORMALIZE_FOR_COMMIT : NORMALIZE_FOR_COMPARE)) {
buf = strbuf_detach(&nbuf, &size);
re_allocated = 1;
}
--
1.7.2
next prev parent reply other threads:[~2010-09-18 14:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-18 14:30 [PATCH v3 0/4] fix normalization of foreign idents Marcus Comstedt
2010-08-23 7:05 ` Marcus Comstedt [this message]
2010-09-18 21:31 ` [PATCH v3 2/4] convert: " Junio C Hamano
2010-09-18 22:38 ` Marcus Comstedt
2010-09-07 19:16 ` [PATCH v3 3/4] t0021: test checkout and commit " Marcus Comstedt
2010-09-13 22:00 ` [PATCH v3 1/4] convert: generalize checksafe parameter Marcus Comstedt
2010-09-18 13:53 ` [PATCH v3 4/4] Documentation: document foreign idents Marcus Comstedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b56d7f50198f63a810b304ae77043f58a240f743.1284820251.git.marcus@mc.pp.se \
--to=marcus@mc.pp.se \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).