{"thread":{"id":"9824","subject":"[PATCH] introduce config core.binaryCheckFirstBytes for xdiff-interface","startedAt":"2007-09-07T19:14:21Z","lastAt":"2007-09-07T21:19:33Z","messageCount":2,"participants":["Gerrit Pape","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"52928","messageId":"20070907191421.5526.qmail@f74fa18bc10c8f.315fe32.mid.smarden.org","threadId":"9824","inReplyTo":null,"subject":"[PATCH] introduce config core.binaryCheckFirstBytes for xdiff-interface","fromName":"Gerrit Pape","fromEmail":"pape@smarden.org","sentAt":"2007-09-07T19:14:21Z","receivedAt":"2007-09-07T19:14:21Z","isPatch":true,"sender":{"key":"pape@smarden.org","avatar":"https://avatars.githubusercontent.com/u/143170252?v=4"},"body":"xdiff-interface uses a hardcoded value of 8000 bytes to check from\nthe top of data whether to handle it as binary content.  If a NULL\ncharacter appears after the first 8000 bytes, git won't notice,\nwhich for example breaks the git format-patch | git am pipeline in\ngit rebase, as reported by Jamey Sharp through\n http://bugs.debian.org/436182\n\nThis patch makes the hardcoded value configurable, so that users can\nadjust the behavior when tracking binary files of huge sizes, e.g.\npdf's, in a repository.\n\nSigned-off-by: Gerrit Pape <pape@smarden.org>\n---\n Documentation/config.txt |    6 ++++++\n cache.h                  |    1 +\n config.c                 |    8 ++++++++\n environment.c            |    1 +\n xdiff-interface.c        |    5 ++---\n 5 files changed, 18 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 866e053..6c450ee 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -275,6 +275,12 @@ You probably do not need to adjust this value.\n +\n Common unit suffixes of 'k', 'm', or 'g' are supported.\n \n+core.binaryCheckFirstBytes::\n+\tNumber of bytes of the top of data that should be checked to\n+\tdecide whether the data must be handled as binary content, or\n+\tcan be interpreted as text.  The default is 8000, when set to\n+\tzero, all available data is checked.\n+\n core.excludesfile::\n \tIn addition to '.gitignore' (per-directory) and\n \t'.git/info/exclude', git looks into this file for patterns\ndiff --git a/cache.h b/cache.h\nindex 70abbd5..a9ca846 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -313,6 +313,7 @@ extern size_t packed_git_window_size;\n extern size_t packed_git_limit;\n extern size_t delta_base_cache_limit;\n extern int auto_crlf;\n+extern int binary_first_bytes;\n \n #define GIT_REPO_VERSION 0\n extern int repository_format_version;\ndiff --git a/config.c b/config.c\nindex dc3148d..892b2ff 100644\n--- a/config.c\n+++ b/config.c\n@@ -395,6 +395,14 @@ int git_default_config(const char *var, const char *value)\n \t\treturn 0;\n \t}\n \n+\tif (!strcmp(var, \"core.binarycheckfirstbytes\")) {\n+\t\tint bytes = git_config_int(var, value);\n+\t\tif (bytes < 0)\n+\t\t\tdie(\"bad value for core.binaryCheckFirstBytes %d\", bytes);\n+\t\tbinary_first_bytes = bytes;\n+\t\treturn 0;\n+\t}\n+\n \tif (!strcmp(var, \"user.name\")) {\n \t\tstrlcpy(git_default_name, value, sizeof(git_default_name));\n \t\treturn 0;\ndiff --git a/environment.c b/environment.c\nindex b5a6c69..dd072b9 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -35,6 +35,7 @@ int pager_in_use;\n int pager_use_color = 1;\n char *editor_program;\n int auto_crlf = 0;\t/* 1: both ways, -1: only when adding git objects */\n+int binary_first_bytes = 8000;\n \n /* This is set by setup_git_dir_gently() and/or git_default_config() */\n char *git_work_tree_cfg;\ndiff --git a/xdiff-interface.c b/xdiff-interface.c\nindex be866d1..dba0232 100644\n--- a/xdiff-interface.c\n+++ b/xdiff-interface.c\n@@ -122,11 +122,10 @@ int read_mmfile(mmfile_t *ptr, const char *filename)\n \treturn 0;\n }\n \n-#define FIRST_FEW_BYTES 8000\n int buffer_is_binary(const char *ptr, unsigned long size)\n {\n-\tif (FIRST_FEW_BYTES < size)\n-\t\tsize = FIRST_FEW_BYTES;\n+\tif (binary_first_bytes && (binary_first_bytes < size))\n+\t\tsize = binary_first_bytes;\n \treturn !!memchr(ptr, 0, size);\n }\n \n-- \n1.5.3.1\n"},{"id":"52947","messageId":"7vodge2mxm.fsf@gitster.siamese.dyndns.org","threadId":"9824","inReplyTo":"20070907191421.5526.qmail@f74fa18bc10c8f.315fe32.mid.smarden.org","subject":"Re: [PATCH] introduce config core.binaryCheckFirstBytes for xdiff-interface","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-09-07T21:19:33Z","receivedAt":"2007-09-07T21:19:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Gerrit Pape <pape@smarden.org> writes:\n\n> xdiff-interface uses a hardcoded value of 8000 bytes to check from\n> the top of data whether to handle it as binary content.  If a NULL\n> character appears after the first 8000 bytes, git won't notice,\n\nIf the user has to set this to suit git better for a particular\nproject, I think the same effort is better spent on setting up\nthe attribute for that file so that git does not have to guess\nthe type, no?\n"}]}