git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Henrik Grubbström" <grubba@grubba.org>
To: git@vger.kernel.org
Cc: "Henrik Grubbström  " <grubba@grubba.org>
Subject: [PATCH 3/4] convert: Inhibit contraction of foreign $Id$ during stats.
Date: Mon,  1 Mar 2010 17:16:57 +0100	[thread overview]
Message-ID: <1267460218-1172-3-git-send-email-grubba@grubba.org> (raw)
In-Reply-To: <1267460218-1172-2-git-send-email-grubba@grubba.org>

From: Henrik Grubbström (Grubba) <grubba@grubba.org>

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>
---
 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

  reply	other threads:[~2010-03-01 16:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-01 16:16 [PATCH 1/4] convert: Safer handling of $Id$ contraction Henrik Grubbström
2010-03-01 16:16 ` [PATCH 2/4] convert: Keep foreign $Id$ on checkout Henrik Grubbström
2010-03-01 16:16   ` Henrik Grubbström [this message]
2010-03-01 16:16     ` [PATCH 4/4] convert: Added core.refilteronadd feature Henrik Grubbström
2010-03-03  1:11   ` [PATCH 2/4] convert: Keep foreign $Id$ on checkout Junio C Hamano
2010-03-03 11:36     ` Henrik Grubbström
2010-03-03  1:10 ` [PATCH 1/4] convert: Safer handling of $Id$ contraction Junio C Hamano
2010-03-03 10:40   ` Henrik Grubbström
2010-03-09  9:22     ` Henrik Grubbström
  -- strict thread matches above, loose matches on Subject: below --
2010-03-15 15:30 [PATCH 0/4] ident attribute related patches (resend w/ testsuite) Henrik Grubbström (Grubba)
2010-03-15 15:30 ` [PATCH 1/4] convert: Safer handling of $Id$ contraction Henrik Grubbström (Grubba)
2010-03-15 15:30   ` [PATCH 2/4] convert: Keep foreign $Id$ on checkout Henrik Grubbström (Grubba)
2010-03-15 15:30     ` [PATCH 3/4] convert: Inhibit contraction of foreign $Id$ during stats Henrik Grubbström (Grubba)
2010-03-15 15:42       ` Bert Wesarg
2010-03-15 18:32         ` Henrik Grubbström

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=1267460218-1172-3-git-send-email-grubba@grubba.org \
    --to=grubba@grubba.org \
    --cc=git@vger.kernel.org \
    /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).