{"thread":{"id":"19198","subject":"[PATCH 1/2] Export crlf conversion function to libgit","startedAt":"2009-05-06T15:09:05Z","lastAt":"2009-05-06T15:09:05Z","messageCount":1,"participants":["Heiko Voigt"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"113087","messageId":"20090506150854.GA2974@macbook.lan","threadId":"19198","inReplyTo":null,"subject":"[PATCH 1/2] Export crlf conversion function to libgit","fromName":"Heiko Voigt","fromEmail":"hvoigt@hvoigt.net","sentAt":"2009-05-06T15:09:05Z","receivedAt":"2009-05-06T15:09:05Z","isPatch":true,"sender":{"key":"hvoigt@hvoigt.net","avatar":"https://avatars.githubusercontent.com/u/184958?v=4"},"body":"This makes it possible for parsecvs to use the git heuristics to\nconvert textfiles into a normalized form\n\nSigned-off-by: Heiko Voigt <heiko.voigt@mahr.de>\n---\nThere is another patch for parsecvs which depends on this change.\n\nI first would like to know how you feel about exporting such a function?\n\n cache.h   |    1 +\n convert.c |   30 ++++++++++++++++++++++++++++++\n 2 files changed, 31 insertions(+), 0 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex f48e80b..42e9243 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -926,6 +926,7 @@ extern void trace_argv_printf(const char **argv, const char *format, ...);\n extern int convert_to_git(const char *path, const char *src, size_t len,\n                           struct strbuf *dst, enum safe_crlf checksafe);\n extern int convert_to_working_tree(const char *path, const char *src, size_t len, struct strbuf *dst);\n+extern int crlf_to_git_buf(size_t *p_len, char *p_blob);\n \n /* add */\n /*\ndiff --git a/convert.c b/convert.c\nindex 1816e97..0ced471 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -179,6 +179,36 @@ static int crlf_to_git(const char *path, const char *src, size_t len,\n \treturn 1;\n }\n \n+int crlf_to_git_buf(size_t *p_len, char *p_blob)\n+{\n+\tstruct strbuf nbuf;\n+\tstrbuf_init(&nbuf, 0);\n+\tsize_t len = *p_len;\n+\tchar *blob = p_blob;\n+\n+\t/* this is needed otherwise crlf_to_git will skip this file */\n+\tauto_crlf = 1;\n+\n+\t/* filter blob with len and store in nbuf\n+\t * if no conversion happens just return */\n+\tif (!crlf_to_git(NULL, blob, len, &nbuf, CRLF_GUESS))\n+\t\treturn 0;\n+\n+\tblob = strbuf_detach(&nbuf, &len);\n+\t/* crlf conversion should only make our buffer shorter */\n+\tif (len <= *p_len) {\n+\t\t*p_len  = len;\n+\t\tmemcpy(p_blob, blob, len);\n+\t\tfree(blob);\n+\t} else {\n+\t\t*p_len  = len;\n+\t\tfree(blob);\n+\t\treturn 0;\n+\t}\n+\n+\treturn 1;\n+}\n+\n static int crlf_to_worktree(const char *path, const char *src, size_t len,\n                             struct strbuf *buf, int action)\n {\n-- \n1.6.2.1.423.g442d\n"}]}