Skip to content

Commit

Permalink
teach dry-run convert_to_git not to require a src buffer
Browse files Browse the repository at this point in the history
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Feb 24, 2012
1 parent 92ac319 commit 4c3b57b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,17 @@ static int crlf_to_git(const char *path, const char *src, size_t len,
char *dst;

if (crlf_action == CRLF_BINARY ||
(crlf_action == CRLF_GUESS && auto_crlf == AUTO_CRLF_FALSE) || !len)
(crlf_action == CRLF_GUESS && auto_crlf == AUTO_CRLF_FALSE) ||
(src && !len))
return 0;

/*
* If we are doing a dry-run and have no source buffer, there is
* nothing to analyze; we must assume we would convert.
*/
if (!buf && !src)
return 1;

gather_stats(src, len, &stats);

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

if (!ident || !count_ident(src, len))
if (!ident || (src && !count_ident(src, len)))
return 0;

if (!buf)
Expand Down

0 comments on commit 4c3b57b

Please sign in to comment.