git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Gerrit Pape <pape@smarden.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH] introduce config core.binaryCheckFirstBytes for xdiff-interface
Date: Fri, 7 Sep 2007 19:14:21 +0000	[thread overview]
Message-ID: <20070907191421.5526.qmail@f74fa18bc10c8f.315fe32.mid.smarden.org> (raw)

xdiff-interface uses a hardcoded value of 8000 bytes to check from
the top of data whether to handle it as binary content.  If a NULL
character appears after the first 8000 bytes, git won't notice,
which for example breaks the git format-patch | git am pipeline in
git rebase, as reported by Jamey Sharp through
 http://bugs.debian.org/436182

This patch makes the hardcoded value configurable, so that users can
adjust the behavior when tracking binary files of huge sizes, e.g.
pdf's, in a repository.

Signed-off-by: Gerrit Pape <pape@smarden.org>
---
 Documentation/config.txt |    6 ++++++
 cache.h                  |    1 +
 config.c                 |    8 ++++++++
 environment.c            |    1 +
 xdiff-interface.c        |    5 ++---
 5 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/Documentation/config.txt b/Documentation/config.txt
index 866e053..6c450ee 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -275,6 +275,12 @@ You probably do not need to adjust this value.
 +
 Common unit suffixes of 'k', 'm', or 'g' are supported.
 
+core.binaryCheckFirstBytes::
+	Number of bytes of the top of data that should be checked to
+	decide whether the data must be handled as binary content, or
+	can be interpreted as text.  The default is 8000, when set to
+	zero, all available data is checked.
+
 core.excludesfile::
 	In addition to '.gitignore' (per-directory) and
 	'.git/info/exclude', git looks into this file for patterns
diff --git a/cache.h b/cache.h
index 70abbd5..a9ca846 100644
--- a/cache.h
+++ b/cache.h
@@ -313,6 +313,7 @@ extern size_t packed_git_window_size;
 extern size_t packed_git_limit;
 extern size_t delta_base_cache_limit;
 extern int auto_crlf;
+extern int binary_first_bytes;
 
 #define GIT_REPO_VERSION 0
 extern int repository_format_version;
diff --git a/config.c b/config.c
index dc3148d..892b2ff 100644
--- a/config.c
+++ b/config.c
@@ -395,6 +395,14 @@ int git_default_config(const char *var, const char *value)
 		return 0;
 	}
 
+	if (!strcmp(var, "core.binarycheckfirstbytes")) {
+		int bytes = git_config_int(var, value);
+		if (bytes < 0)
+			die("bad value for core.binaryCheckFirstBytes %d", bytes);
+		binary_first_bytes = bytes;
+		return 0;
+	}
+
 	if (!strcmp(var, "user.name")) {
 		strlcpy(git_default_name, value, sizeof(git_default_name));
 		return 0;
diff --git a/environment.c b/environment.c
index b5a6c69..dd072b9 100644
--- a/environment.c
+++ b/environment.c
@@ -35,6 +35,7 @@ int pager_in_use;
 int pager_use_color = 1;
 char *editor_program;
 int auto_crlf = 0;	/* 1: both ways, -1: only when adding git objects */
+int binary_first_bytes = 8000;
 
 /* This is set by setup_git_dir_gently() and/or git_default_config() */
 char *git_work_tree_cfg;
diff --git a/xdiff-interface.c b/xdiff-interface.c
index be866d1..dba0232 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -122,11 +122,10 @@ int read_mmfile(mmfile_t *ptr, const char *filename)
 	return 0;
 }
 
-#define FIRST_FEW_BYTES 8000
 int buffer_is_binary(const char *ptr, unsigned long size)
 {
-	if (FIRST_FEW_BYTES < size)
-		size = FIRST_FEW_BYTES;
+	if (binary_first_bytes && (binary_first_bytes < size))
+		size = binary_first_bytes;
 	return !!memchr(ptr, 0, size);
 }
 
-- 
1.5.3.1

             reply	other threads:[~2007-09-07 19:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-09-07 19:14 Gerrit Pape [this message]
2007-09-07 21:19 ` [PATCH] introduce config core.binaryCheckFirstBytes for xdiff-interface Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20070907191421.5526.qmail@f74fa18bc10c8f.315fe32.mid.smarden.org \
    --to=pape@smarden.org \
    --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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).