From: Steffen Prohaska <prohaska@zib.de>
To: dpotapov@gmail.com
Cc: gitster@pobox.com, torvalds@linux-foundation.org,
git@vger.kernel.org, Steffen Prohaska <prohaska@zib.de>
Subject: [PATCH] safecrlf: Add flag to convert_to_git() to disable safecrlf check
Date: Tue, 15 Jan 2008 00:20:40 +0100 [thread overview]
Message-ID: <12003528401309-git-send-email-prohaska@zib.de> (raw)
In-Reply-To: <004D2FB5-2CEA-4DB1-AF8D-D5ADEB0F0508@zib.de>
This commit goes on top of
"[PATCH v3] safecrlf: Add mechanism to warn about irreversible crlf conversions"
I send it as a separate patch to make reviewing easier.
Eventually it should be squashed.
I looked briefly at the various places where convert_to_git() is
called. I think that only the one code path through index_fd()
actually writes data to the repsitory. Maybe someone else with
a better understanding of git's internals should confirm this.
Steffen
---- snip ---
We want to verify if an autocrlf conversion is reversible only if
the converted data is actually written to the repository. Only
in this case the file would be modified during the next checkout.
But convert_to_git() is used for some other purposes.
This commit adds a flag to convert_to_git() that controls if the
safecrlf check is enabled. The check is only enabled if
index_fd() writes the object converted. In all other cases the
check is disabled.
Signed-off-by: Steffen Prohaska <prohaska@zib.de>
---
builtin-apply.c | 2 +-
builtin-blame.c | 2 +-
cache.h | 2 +-
convert.c | 10 +++++-----
diff.c | 2 +-
sha1_file.c | 2 +-
6 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/builtin-apply.c b/builtin-apply.c
index d57bb6e..9fb6fe3 100644
--- a/builtin-apply.c
+++ b/builtin-apply.c
@@ -1430,7 +1430,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);
+ convert_to_git(path, buf->buf, buf->len, buf, 0);
return 0;
default:
return -1;
diff --git a/builtin-blame.c b/builtin-blame.c
index 9b4c02e..c361ee1 100644
--- a/builtin-blame.c
+++ b/builtin-blame.c
@@ -2073,7 +2073,7 @@ static struct commit *fake_working_tree_commit(const char *path, const char *con
if (strbuf_read(&buf, 0, 0) < 0)
die("read error %s from stdin", strerror(errno));
}
- convert_to_git(path, buf.buf, buf.len, &buf);
+ convert_to_git(path, buf.buf, buf.len, &buf, 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 4e03e3d..43e7d0e 100644
--- a/cache.h
+++ b/cache.h
@@ -640,7 +640,7 @@ 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);
+extern int convert_to_git(const char *path, const char *src, size_t len, struct strbuf *dst, int checksafe);
extern int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst);
/* add */
diff --git a/convert.c b/convert.c
index c9678ee..5adef4f 100644
--- a/convert.c
+++ b/convert.c
@@ -81,7 +81,7 @@ static int is_binary(unsigned long size, struct text_stat *stats)
}
static int crlf_to_git(const char *path, const char *src, size_t len,
- struct strbuf *buf, int action)
+ struct strbuf *buf, int action, int checksafe)
{
struct text_stat stats;
char *dst;
@@ -107,7 +107,7 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
return 0;
}
- if (safe_crlf && auto_crlf > 0 && action != CRLF_INPUT) {
+ if (safe_crlf && checksafe && auto_crlf > 0 && action != CRLF_INPUT) {
/* CRLFs would be added by checkout: check if we have "naked" LFs */
if (stats.lf != stats.crlf) {
if (safe_crlf == SAFE_CRLF_WARN)
@@ -144,7 +144,7 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
} while (--len);
}
- if (safe_crlf && (action == CRLF_INPUT || auto_crlf <= 0)) {
+ if (safe_crlf && checksafe && (action == CRLF_INPUT || auto_crlf <= 0)) {
/* CRLFs would not be restored by checkout: check if we removed CRLFs */
if (buf->len != dst - buf->buf) {
if (safe_crlf == SAFE_CRLF_WARN)
@@ -553,7 +553,7 @@ static int git_path_check_ident(const char *path, struct git_attr_check *check)
return !!ATTR_TRUE(value);
}
-int convert_to_git(const char *path, const char *src, size_t len, struct strbuf *dst)
+int convert_to_git(const char *path, const char *src, size_t len, struct strbuf *dst, int checksafe)
{
struct git_attr_check check[3];
int crlf = CRLF_GUESS;
@@ -575,7 +575,7 @@ int convert_to_git(const char *path, const char *src, size_t len, struct strbuf
src = dst->buf;
len = dst->len;
}
- ret |= crlf_to_git(path, src, len, dst, crlf);
+ ret |= crlf_to_git(path, src, len, dst, crlf, checksafe);
if (ret) {
src = dst->buf;
len = dst->len;
diff --git a/diff.c b/diff.c
index b18c140..b5ac4f9 100644
--- a/diff.c
+++ b/diff.c
@@ -1624,7 +1624,7 @@ int diff_populate_filespec(struct diff_filespec *s, int size_only)
* Convert from working tree format to canonical git format
*/
strbuf_init(&buf, 0);
- if (convert_to_git(s->path, s->data, s->size, &buf)) {
+ if (convert_to_git(s->path, s->data, s->size, &buf, 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 6583797..3b5413d 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -2342,7 +2342,7 @@ int index_fd(unsigned char *sha1, int fd, struct stat *st, int write_object,
if ((type == OBJ_BLOB) && S_ISREG(st->st_mode)) {
struct strbuf nbuf;
strbuf_init(&nbuf, 0);
- if (convert_to_git(path, buf, size, &nbuf)) {
+ if (convert_to_git(path, buf, size, &nbuf, write_object)) {
munmap(buf, size);
buf = strbuf_detach(&nbuf, &size);
re_allocated = 1;
--
1.5.4.rc2.60.g46ee
next prev parent reply other threads:[~2008-01-14 23:21 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-13 16:30 [PATCH v3] safecrlf: Add mechanism to warn about irreversible crlf conversions Steffen Prohaska
2008-01-13 22:02 ` Dmitry Potapov
2008-01-13 22:13 ` Dmitry Potapov
2008-01-13 23:46 ` [PATCH] Don't display crlf warning twice Dmitry Potapov
2008-01-14 6:17 ` Steffen Prohaska
2008-01-14 6:40 ` Dmitry Potapov
2008-01-14 6:53 ` Steffen Prohaska
2008-01-14 23:20 ` Steffen Prohaska [this message]
2008-01-14 23:58 ` [PATCH] safecrlf: Add flag to convert_to_git() to disable safecrlf check Junio C Hamano
2008-01-15 20:52 ` Steffen Prohaska
2008-01-15 21:41 ` Steffen Prohaska
2008-01-15 23:23 ` Junio C Hamano
2008-01-15 10:26 ` Dmitry Potapov
2008-01-15 20:39 ` Steffen Prohaska
2008-01-15 23:03 ` Dmitry Potapov
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=12003528401309-git-send-email-prohaska@zib.de \
--to=prohaska@zib.de \
--cc=dpotapov@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=torvalds@linux-foundation.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).