All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heiko Voigt <hvoigt@hvoigt.net>
To: git@vger.kernel.org
Cc: gitster@pobox.com
Subject: [PATCH 1/2] Export crlf conversion function to libgit
Date: Wed, 6 May 2009 17:09:05 +0200	[thread overview]
Message-ID: <20090506150854.GA2974@macbook.lan> (raw)

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

                 reply	other threads:[~2009-05-06 15:09 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090506150854.GA2974@macbook.lan \
    --to=hvoigt@hvoigt.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.