git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] Export crlf conversion function to libgit

From
Heiko Voigt <hvoigt@hvoigt.net>
Date
May 6, 2009, 15:09 UTC
Message-ID
<20090506150854.GA2974@macbook.lan>

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
Message 1 of 1 in “Export crlf conversion function to libgit”
  1. 1/2 Export crlf conversion function to libgitHeiko Voigt, May 6, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.