summaryrefslogtreecommitdiff
path: root/strbuf.h
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-10-28 13:17:29 -0700
committerJunio C Hamano <gitster@pobox.com>2016-01-14 15:05:55 -0800
commitc8aa9fdf5dc15e2c508acb22df03d431983569ed (patch)
tree1d905b7200f02f7ae4bdd8966ec849e8ff1c52dc /strbuf.h
parentdce80bd18cae17b2d5645e3a9c40e76f905fd643 (diff)
downloadgit-c8aa9fdf5dc15e2c508acb22df03d431983569ed.tar.gz
strbuf: make strbuf_getline_crlf() global
Often we read "text" files that are supplied by the end user (e.g. commit log message that was edited with $GIT_EDITOR upon 'git commit -e'), and in some environments lines in a text file are terminated with CRLF. Existing strbuf_getline() knows to read a single line and then strip the terminating byte from the result, but it is handy to have a version that is more tailored for a "text" input that takes both '\n' and '\r\n' as line terminator (aka <newline> in POSIX lingo) and returns the body of the line after stripping <newline>. Recently reimplemented "git am" uses such a function implemented privately; move it to strbuf.[ch] and make it available for others. Note that we do not blindly replace calls to strbuf_getline() that uses LF as the line terminator with calls to strbuf_getline_crlf() and this is very much deliberate. Some callers may want to treat an incoming line that ends with CR (and terminated with LF) to have a payload that includes the final CR, and such a blind replacement will result in misconversion when done without code audit. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'strbuf.h')
-rw-r--r--strbuf.h7
1 files changed, 7 insertions, 0 deletions
diff --git a/strbuf.h b/strbuf.h
index 7123fca7af..d84c866ab1 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -388,6 +388,13 @@ extern int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint);
*/
extern int strbuf_getline(struct strbuf *, FILE *, int);
+/*
+ * Similar to strbuf_getline(), but uses '\n' as the terminator,
+ * and additionally treats a '\r' that comes immediately before '\n'
+ * as part of the terminator.
+ */
+extern int strbuf_getline_crlf(struct strbuf *, FILE *);
+
/**
* Like `strbuf_getline`, but keeps the trailing terminator (if
* any) in the buffer.