Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
convert.c | 33 +++++++++++++--------------------
1 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/convert.c b/convert.c
index aa95834..2b90010 100644
--- a/convert.c
+++ b/convert.c
@@ -85,6 +85,7 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
{
struct text_stat stats;
char *dst;
+ void *tmp;
if ((action == CRLF_BINARY) || !auto_crlf || !len)
return 0;
@@ -110,9 +111,7 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
return 0;
}
- /* only grow if not in place */
- if (strbuf_avail(buf) + buf->len < len)
- strbuf_grow(buf, len - buf->len);
+ tmp = strbuf_start_filter(buf, src, len);
dst = buf->buf;
if (action == CRLF_GUESS) {
/*
@@ -133,13 +132,14 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
} while (--len);
}
strbuf_setlen(buf, dst - buf->buf);
+ strbuf_end_filter(tmp);
return 1;
}
static int crlf_to_worktree(const char *path, const char *src, size_t len,
struct strbuf *buf, int action)
{
- char *to_free = NULL;
+ void *to_free;
struct text_stat stats;
if ((action == CRLF_BINARY) || (action == CRLF_INPUT) ||
@@ -168,10 +168,7 @@ static int crlf_to_worktree(const char *path, const char *src, size_t len,
return 0;
}
- /* are we "faking" in place editing ? */
- if (src == buf->buf)
- to_free = strbuf_detach(buf, NULL);
-
+ to_free = strbuf_start_filter(buf, src, -1);
strbuf_grow(buf, len + stats.lf - stats.crlf);
for (;;) {
const char *nl = memchr(src, '\n', len);
@@ -187,8 +184,7 @@ static int crlf_to_worktree(const char *path, const char *src, size_t len,
src = nl + 1;
}
strbuf_add(buf, src, len);
-
- free(to_free);
+ strbuf_end_filter(to_free);
return 1;
}
@@ -418,14 +414,13 @@ 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)
{
+ void *tmp;
char *dst, *dollar;
if (!ident || !count_ident(src, len))
return 0;
- /* only grow if not in place */
- if (strbuf_avail(buf) + buf->len < len)
- strbuf_grow(buf, len - buf->len);
+ tmp = strbuf_start_filter(buf, src, len);
dst = buf->buf;
for (;;) {
dollar = memchr(src, '$', len);
@@ -448,6 +443,7 @@ static int ident_to_git(const char *path, const char *src, size_t len,
}
memcpy(dst, src, len);
strbuf_setlen(buf, dst + len - buf->buf);
+ strbuf_end_filter(tmp);
return 1;
}
@@ -455,7 +451,8 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
struct strbuf *buf, int ident)
{
unsigned char sha1[20];
- char *to_free = NULL, *dollar;
+ void *to_free;
+ char *dollar;
int cnt;
if (!ident)
@@ -464,12 +461,9 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
cnt = count_ident(src, len);
if (!cnt)
return 0;
-
- /* are we "faking" in place editing ? */
- if (src == buf->buf)
- to_free = strbuf_detach(buf, NULL);
hash_sha1_file(src, len, "blob", sha1);
+ to_free = strbuf_start_filter(buf, src, -1);
strbuf_grow(buf, len + cnt * 43);
for (;;) {
/* step 1: run to the next '$' */
@@ -512,8 +506,7 @@ static int ident_to_worktree(const char *path, const char *src, size_t len,
strbuf_addstr(buf, " $");
}
strbuf_add(buf, src, len);
-
- free(to_free);
+ strbuf_end_filter(to_free);
return 1;
}
--
1.5.3.4.208.gc1d91-dirty
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html