Export crlf conversion function to libgit
PATCH 1/2 Export crlf conversion function to libgit
This makes it possible for parsecvs to use the git heuristics to convert textfiles into a normalized form
Signed-off-by Heiko Voigt <[email protected]>
---
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(-)
cache.h +1 -0
@@ -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 */ /*
convert.c +30 -0
@@ -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) {
Signature · 1 line
1.6.2.1.423.g442d