Skip to content

Commit 4c3b57b

Browse files
peffgitster
authored andcommitted
teach dry-run convert_to_git not to require a src buffer
When we call convert_to_git in dry-run mode, it may still want to look at the source buffer, because some CRLF conversion modes depend on analyzing the source to determine whether it is in fact convertible CRLF text. However, the main motivation for convert_to_git's dry-run mode is that we would decide which method to use to acquire the blob's data (streaming versus in-core). Requiring this source analysis creates a chicken-and-egg problem. We are better off simply guessing that anything we can't analyze will end up needing conversion. This patch lets a caller specify a NULL src buffer when using dry-run mode (and only dry-run mode). A non-zero return value goes from "we would convert" to "we might convert"; a zero return value remains "we would definitely not convert". Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 92ac319 commit 4c3b57b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

convert.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,17 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
195195
char *dst;
196196

197197
if (crlf_action == CRLF_BINARY ||
198-
(crlf_action == CRLF_GUESS && auto_crlf == AUTO_CRLF_FALSE) || !len)
198+
(crlf_action == CRLF_GUESS && auto_crlf == AUTO_CRLF_FALSE) ||
199+
(src && !len))
199200
return 0;
200201

202+
/*
203+
* If we are doing a dry-run and have no source buffer, there is
204+
* nothing to analyze; we must assume we would convert.
205+
*/
206+
if (!buf && !src)
207+
return 1;
208+
201209
gather_stats(src, len, &stats);
202210

203211
if (crlf_action == CRLF_AUTO || crlf_action == CRLF_GUESS) {
@@ -532,7 +540,7 @@ static int ident_to_git(const char *path, const char *src, size_t len,
532540
{
533541
char *dst, *dollar;
534542

535-
if (!ident || !count_ident(src, len))
543+
if (!ident || (src && !count_ident(src, len)))
536544
return 0;
537545

538546
if (!buf)

0 commit comments

Comments
 (0)