git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] Export crlf conversion function to libgit
@ 2009-05-06 15:09 Heiko Voigt
  0 siblings, 0 replies; only message in thread
From: Heiko Voigt @ 2009-05-06 15:09 UTC (permalink / raw)
  To: git; +Cc: gitster

This makes it possible for parsecvs to use the git heuristics to
convert textfiles into a normalized form

Signed-off-by: Heiko Voigt <heiko.voigt@mahr.de>
---
There is another patch for parsecvs which depends on this change.

I first would like to know how you feel about exporting such a function?

 cache.h   |    1 +
 convert.c |   30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 0 deletions(-)

diff --git a/cache.h b/cache.h
index f48e80b..42e9243 100644
--- a/cache.h
+++ b/cache.h
@@ -926,6 +926,7 @@ extern void trace_argv_printf(const char **argv, const char *format, ...);
 extern int convert_to_git(const char *path, const char *src, size_t len,
                           struct strbuf *dst, enum safe_crlf checksafe);
 extern int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst);
+extern int crlf_to_git_buf(size_t *p_len, char *p_blob);
 
 /* add */
 /*
diff --git a/convert.c b/convert.c
index 1816e97..0ced471 100644
--- a/convert.c
+++ b/convert.c
@@ -179,6 +179,36 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
 	return 1;
 }
 
+int crlf_to_git_buf(size_t *p_len, char *p_blob)
+{
+	struct strbuf nbuf;
+	strbuf_init(&nbuf, 0);
+	size_t len = *p_len;
+	char *blob = p_blob;
+
+	/* this is needed otherwise crlf_to_git will skip this file */
+	auto_crlf = 1;
+
+	/* filter blob with len and store in nbuf
+	 * if no conversion happens just return */
+	if (!crlf_to_git(NULL, blob, len, &nbuf, CRLF_GUESS))
+		return 0;
+
+	blob = strbuf_detach(&nbuf, &len);
+	/* crlf conversion should only make our buffer shorter */
+	if (len <= *p_len) {
+		*p_len  = len;
+		memcpy(p_blob, blob, len);
+		free(blob);
+	} else {
+		*p_len  = len;
+		free(blob);
+		return 0;
+	}
+
+	return 1;
+}
+
 static int crlf_to_worktree(const char *path, const char *src, size_t len,
                             struct strbuf *buf, int action)
 {
-- 
1.6.2.1.423.g442d

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2009-05-06 15:09 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-06 15:09 [PATCH 1/2] Export crlf conversion function to libgit Heiko Voigt

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