{"thread":{"id":"39786","subject":"[PATCH] Git doesn't allow to apply a patch with empty filenames.","startedAt":"2015-07-06T17:16:13Z","lastAt":"2015-07-06T18:36:24Z","messageCount":3,"participants":["Evgen Druzhynin","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"265575","messageId":"1436202974-7624-1-git-send-email-evgen.druzhynin@gmail.com","threadId":"39786","inReplyTo":null,"subject":"[PATCH] Git doesn't allow to apply a patch with empty filenames.","fromName":"Evgen Druzhynin","fromEmail":"evgen.druzhynin@gmail.com","sentAt":"2015-07-06T17:16:13Z","receivedAt":"2015-07-06T17:16:13Z","isPatch":true,"sender":{"key":"evgen.druzhynin@gmail.com","avatar":null},"body":"git-apply fails if '-p' option truncate at least one filename in patch to zero size.\nThis solution tries to bring closer \"git-apply\" to standard Linux patch tool.\nStandard patch tool skip the truncated filenames and successfully applies patch.\n\nEvgen Druzhynin (1):\n  Added ability to scip patch hunk with an empty file.\n\n builtin/apply.c | 16 +++++-----------\n po/bg.po        | 15 ---------------\n po/ca.po        | 15 ---------------\n po/de.po        | 15 ---------------\n po/fr.po        | 15 ---------------\n po/git.pot      | 11 -----------\n po/it.po        | 11 -----------\n po/pt_PT.po     |  7 -------\n po/ru.po        | 12 ------------\n po/sv.po        | 16 ----------------\n po/vi.po        | 12 ------------\n po/zh_CN.po     | 11 -----------\n 12 files changed, 5 insertions(+), 151 deletions(-)\n\n-- \n1.9.1\n"},{"id":"265576","messageId":"1436202974-7624-2-git-send-email-evgen.druzhynin@gmail.com","threadId":"39786","inReplyTo":"1436202974-7624-1-git-send-email-evgen.druzhynin@gmail.com","subject":"[PATCH] Added ability to scip patch hunk with an empty filename.","fromName":"Evgen Druzhynin","fromEmail":"evgen.druzhynin@gmail.com","sentAt":"2015-07-06T17:16:14Z","receivedAt":"2015-07-06T17:16:14Z","isPatch":true,"sender":{"key":"evgen.druzhynin@gmail.com","avatar":null},"body":"---\n builtin/apply.c | 16 +++++-----------\n po/bg.po        | 15 ---------------\n po/ca.po        | 15 ---------------\n po/de.po        | 15 ---------------\n po/fr.po        | 15 ---------------\n po/git.pot      | 11 -----------\n po/it.po        | 11 -----------\n po/pt_PT.po     |  7 -------\n po/ru.po        | 12 ------------\n po/sv.po        | 16 ----------------\n po/vi.po        | 12 ------------\n po/zh_CN.po     | 11 -----------\n 12 files changed, 5 insertions(+), 151 deletions(-)\n\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex 54aba4e..e4481b4 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -1488,17 +1488,11 @@ static int find_header(const char *line, unsigned long size, int *hdrsize, struc\n \t\t\tint git_hdr_len = parse_git_header(line, len, size, patch);\n \t\t\tif (git_hdr_len <= len)\n \t\t\t\tcontinue;\n-\t\t\tif (!patch->old_name && !patch->new_name) {\n-\t\t\t\tif (!patch->def_name)\n-\t\t\t\t\tdie(Q_(\"git diff header lacks filename information when removing \"\n-\t\t\t\t\t       \"%d leading pathname component (line %d)\",\n-\t\t\t\t\t       \"git diff header lacks filename information when removing \"\n-\t\t\t\t\t       \"%d leading pathname components (line %d)\",\n-\t\t\t\t\t       p_value),\n-\t\t\t\t\t    p_value, linenr);\n-\t\t\t\tpatch->old_name = xstrdup(patch->def_name);\n-\t\t\t\tpatch->new_name = xstrdup(patch->def_name);\n-\t\t\t}\n+\n+\t\t\t/* pass this hunk if the filename length is zero */\n+\t\t\tif (!patch->old_name && !patch->new_name) \n+\t\t\t\treturn -1;\t\t\t\t\n+\t\t\t\n \t\t\tif (!patch->is_delete && !patch->new_name)\n \t\t\t\tdie(\"git diff header lacks filename information \"\n \t\t\t\t    \"(line %d)\", linenr);\ndiff --git a/po/bg.po b/po/bg.po\nindex 171f813..f2cc286 100644\n--- a/po/bg.po\n+++ b/po/bg.po\n@@ -2373,21 +2373,6 @@ msgstr \"при повторното преброяване бе получен \n msgid \"patch fragment without header at line %d: %.*s\"\n msgstr \"част от кръпка без заглавна част на ред %d: %.*s\"\n \n-#: builtin/apply.c:1493\n-#, c-format\n-msgid \"\"\n-\"git diff header lacks filename information when removing %d leading pathname \"\n-\"component (line %d)\"\n-msgid_plural \"\"\n-\"git diff header lacks filename information when removing %d leading pathname \"\n-\"components (line %d)\"\n-msgstr[0] \"\"\n-\"След съкращаването на %d-та част от компонентите на пътя, в заглавната част \"\n-\"на „git diff“ липсва информация за име на файл (ред: %d)\"\n-msgstr[1] \"\"\n-\"След съкращаването на първите %d части от компонентите на пътя, в заглавната \"\n-\"част на „git diff“ липсва информация за име на файл (ред: %d)\"\n-\n #: builtin/apply.c:1656\n msgid \"new file depends on old contents\"\n msgstr \"новият файл зависи от старото съдържание на файла\"\ndiff --git a/po/ca.po b/po/ca.po\nindex c733483..c893285 100644\n--- a/po/ca.po\n+++ b/po/ca.po\n@@ -2216,21 +2216,6 @@ msgstr \"recompte: línia inesperada: %.*s\"\n msgid \"patch fragment without header at line %d: %.*s\"\n msgstr \"fragment de pedaç sense capçalera a la línia %d: %.*s\"\n \n-#: builtin/apply.c:1493\n-#, c-format\n-msgid \"\"\n-\"git diff header lacks filename information when removing %d leading pathname \"\n-\"component (line %d)\"\n-msgid_plural \"\"\n-\"git diff header lacks filename information when removing %d leading pathname \"\n-\"components (line %d)\"\n-msgstr[0] \"\"\n-\"a la capçalera de git diff li manca informació de nom de fitxer en eliminar \"\n-\"%d component de nom de camí inicial (línia %d)\"\n-msgstr[1] \"\"\n-\"a la capçalera de git diff li manca informació de nom de fitxer en eliminar \"\n-\"%d components de nom de camí inicial (línia %d)\"\n-\n #: builtin/apply.c:1656\n msgid \"new file depends on old contents\"\n msgstr \"el fitxer nou depèn dels continguts antics\"\ndiff --git a/po/de.po b/po/de.po\nindex 7d603c2..ea6b555 100644\n--- a/po/de.po\n+++ b/po/de.po\n@@ -2257,21 +2257,6 @@ msgstr \"recount: unerwartete Zeile: %.*s\"\n msgid \"patch fragment without header at line %d: %.*s\"\n msgstr \"Patch-Fragment ohne Kopfbereich bei Zeile %d: %.*s\"\n \n-#: builtin/apply.c:1493\n-#, c-format\n-msgid \"\"\n-\"git diff header lacks filename information when removing %d leading pathname \"\n-\"component (line %d)\"\n-msgid_plural \"\"\n-\"git diff header lacks filename information when removing %d leading pathname \"\n-\"components (line %d)\"\n-msgstr[0] \"\"\n-\"Dem Kopfbereich von \\\"git diff\\\" fehlen Informationen zum Dateinamen, wenn \"\n-\"%d vorangestellter Teil des Pfades entfernt wird (Zeile %d)\"\n-msgstr[1] \"\"\n-\"Dem Kopfbereich von \\\"git diff\\\" fehlen Informationen zum Dateinamen, wenn \"\n-\"%d vorangestellte Teile des Pfades entfernt werden (Zeile %d)\"\n-\n #: builtin/apply.c:1656\n msgid \"new file depends on old contents\"\n msgstr \"neue Datei hängt von alten Inhalten ab\"\ndiff --git a/po/fr.po b/po/fr.po\nindex 00bfefd..b376631 100644\n--- a/po/fr.po\n+++ b/po/fr.po\n@@ -2301,21 +2301,6 @@ msgstr \"recomptage : ligne inattendue : %.*s\"\n msgid \"patch fragment without header at line %d: %.*s\"\n msgstr \"fragment de patch sans en-tête à la ligne %d : %.*s\"\n \n-#: builtin/apply.c:1493\n-#, c-format\n-msgid \"\"\n-\"git diff header lacks filename information when removing %d leading pathname \"\n-\"component (line %d)\"\n-msgid_plural \"\"\n-\"git diff header lacks filename information when removing %d leading pathname \"\n-\"components (line %d)\"\n-msgstr[0] \"\"\n-\"information de nom de fichier manquante dans l'en-tête de git diff lors de \"\n-\"la suppression de %d composant de préfixe de chemin (ligne %d)\"\n-msgstr[1] \"\"\n-\"information de nom de fichier manquante dans l'en-tête de git diff lors de \"\n-\"la suppression de %d composants de préfixe de chemin (ligne %d)\"\n-\n #: builtin/apply.c:1656\n msgid \"new file depends on old contents\"\n msgstr \"le nouveau fichier dépend de contenus anciens\"\ndiff --git a/po/git.pot b/po/git.pot\nindex c94a955..f1433e9 100644\n--- a/po/git.pot\n+++ b/po/git.pot\n@@ -2093,17 +2093,6 @@ msgstr \"\"\n msgid \"patch fragment without header at line %d: %.*s\"\n msgstr \"\"\n \n-#: builtin/apply.c:1493\n-#, c-format\n-msgid \"\"\n-\"git diff header lacks filename information when removing %d leading pathname \"\n-\"component (line %d)\"\n-msgid_plural \"\"\n-\"git diff header lacks filename information when removing %d leading pathname \"\n-\"components (line %d)\"\n-msgstr[0] \"\"\n-msgstr[1] \"\"\n-\n #: builtin/apply.c:1656\n msgid \"new file depends on old contents\"\n msgstr \"\"\ndiff --git a/po/it.po b/po/it.po\nindex 9080219..6314bcb 100644\n--- a/po/it.po\n+++ b/po/it.po\n@@ -1042,17 +1042,6 @@ msgstr \"recount: riga inattesa: %.*s\"\n msgid \"patch fragment without header at line %d: %.*s\"\n msgstr \"frammento di patch senza intestazione alla riga %d: %.*s\"\n \n-#: builtin/apply.c:1468\n-#, c-format\n-msgid \"\"\n-\"git diff header lacks filename information when removing %d leading pathname \"\n-\"component (line %d)\"\n-msgid_plural \"\"\n-\"git diff header lacks filename information when removing %d leading pathname \"\n-\"components (line %d)\"\n-msgstr[0] \"\"\n-msgstr[1] \"\"\n-\n #: builtin/apply.c:1628\n msgid \"new file depends on old contents\"\n msgstr \"il nuovo file dipende da contenuti precedenti\"\ndiff --git a/po/pt_PT.po b/po/pt_PT.po\nindex 689ad1b..7cfba0d 100644\n--- a/po/pt_PT.po\n+++ b/po/pt_PT.po\n@@ -1025,13 +1025,6 @@ msgstr \"\"\n msgid \"patch fragment without header at line %d: %.*s\"\n msgstr \"\"\n \n-#: builtin/apply.c:1461\n-#, c-format\n-msgid \"git diff header lacks filename information when removing %d leading pathname component (line %d)\"\n-msgid_plural \"git diff header lacks filename information when removing %d leading pathname components (line %d)\"\n-msgstr[0] \"\"\n-msgstr[1] \"\"\n-\n #: builtin/apply.c:1621\n msgid \"new file depends on old contents\"\n msgstr \"\"\ndiff --git a/po/ru.po b/po/ru.po\nindex 4356ae9..a796889 100644\n--- a/po/ru.po\n+++ b/po/ru.po\n@@ -2114,18 +2114,6 @@ msgstr \"recount: не ожидаемая строка: %.*s\"\n msgid \"patch fragment without header at line %d: %.*s\"\n msgstr \"фрагмент изменений без заголовка на строке %d: %.*s\"\n \n-#: builtin/apply.c:1493\n-#, c-format\n-msgid \"\"\n-\"git diff header lacks filename information when removing %d leading pathname\"\n-\" component (line %d)\"\n-msgid_plural \"\"\n-\"git diff header lacks filename information when removing %d leading pathname\"\n-\" components (line %d)\"\n-msgstr[0] \"заголовок git diff не нашел информацию об имени файла при удалении %d ведущего компонента пути к файлу (строка %d)\"\n-msgstr[1] \"заголовок git diff не нашел информацию об имени файла при удалении %d ведущих компонент пути к файлу (строка %d)\"\n-msgstr[2] \"заголовок git diff не нашел информацию об имени файла при удалении %d ведущих компонент пути к файлу (строка %d)\"\n-\n #: builtin/apply.c:1656\n msgid \"new file depends on old contents\"\n msgstr \"новый файл зависит от старого содержимого\"\ndiff --git a/po/sv.po b/po/sv.po\nindex e4b70d6..5b2d24d 100644\n--- a/po/sv.po\n+++ b/po/sv.po\n@@ -2184,22 +2184,6 @@ msgstr \"recount: förväntade rad: %.*s\"\n msgid \"patch fragment without header at line %d: %.*s\"\n msgstr \"patch-fragment utan huvud på rad %d: %.*s\"\n \n-#: builtin/apply.c:1493\n-#, c-format\n-msgid \"\"\n-\"git diff header lacks filename information when removing %d leading pathname \"\n-\"component (line %d)\"\n-msgid_plural \"\"\n-\"git diff header lacks filename information when removing %d leading pathname \"\n-\"components (line %d)\"\n-msgstr[0] \"\"\n-\"git-diff-huvudet saknar filnamnsinformation när %d ledande sökvägskomponent\\n\"\n-\"tas bort (rad %d)\"\n-msgstr[1] \"\"\n-\"git-diff-huvudet saknar filnamnsinformation när %d ledande \"\n-\"sökvägskomponenter\\n\"\n-\"tas bort (rad %d)\"\n-\n #: builtin/apply.c:1656\n msgid \"new file depends on old contents\"\n msgstr \"ny fil beror på gammalt innehåll\"\ndiff --git a/po/vi.po b/po/vi.po\nindex 956be5a..ba1ecf5 100644\n--- a/po/vi.po\n+++ b/po/vi.po\n@@ -2212,18 +2212,6 @@ msgstr \"chi tiết: dòng không cần: %.*s\"\n msgid \"patch fragment without header at line %d: %.*s\"\n msgstr \"miếng vá phân mảnh mà không có phần đầu tại dòng %d: %.*s\"\n \n-#: builtin/apply.c:1493\n-#, c-format\n-msgid \"\"\n-\"git diff header lacks filename information when removing %d leading pathname \"\n-\"component (line %d)\"\n-msgid_plural \"\"\n-\"git diff header lacks filename information when removing %d leading pathname \"\n-\"components (line %d)\"\n-msgstr[0] \"\"\n-\"phần đầu diff cho git  thiếu thông tin tên tập tin khi gỡ bỏ đi %d trong \"\n-\"thành phần dẫn đầu tên của đường dẫn (dòng %d)\"\n-\n #: builtin/apply.c:1656\n msgid \"new file depends on old contents\"\n msgstr \"tập tin mới phụ thuộc vào nội dung cũ\"\ndiff --git a/po/zh_CN.po b/po/zh_CN.po\nindex dd2948c..b65b97a 100644\n--- a/po/zh_CN.po\n+++ b/po/zh_CN.po\n@@ -2197,17 +2197,6 @@ msgstr \"recount：意外的行：%.*s\"\n msgid \"patch fragment without header at line %d: %.*s\"\n msgstr \"第 %d 行的补丁片段没有头信息：%.*s\"\n \n-#: builtin/apply.c:1493\n-#, c-format\n-msgid \"\"\n-\"git diff header lacks filename information when removing %d leading pathname \"\n-\"component (line %d)\"\n-msgid_plural \"\"\n-\"git diff header lacks filename information when removing %d leading pathname \"\n-\"components (line %d)\"\n-msgstr[0] \"当移除 %d 个前导路径后 git diff 头缺乏文件名信息（第 %d 行）\"\n-msgstr[1] \"当移除 %d 个前导路径后 git diff 头缺乏文件名信息（第 %d 行）\"\n-\n #: builtin/apply.c:1656\n msgid \"new file depends on old contents\"\n msgstr \"新文件依赖旧内容\"\n-- \n1.9.1\n"},{"id":"265615","messageId":"xmqqy4ityvyv.fsf@gitster.dls.corp.google.com","threadId":"39786","inReplyTo":"1436202974-7624-2-git-send-email-evgen.druzhynin@gmail.com","subject":"Re: [PATCH] Added ability to scip patch hunk with an empty filename.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-07-06T18:36:24Z","receivedAt":"2015-07-06T18:36:24Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Evgen Druzhynin <evgen.druzhynin@gmail.com> writes:\n\nThis space is for you to explain why it is a good idea to do this\nchange.  What problem does it solve, how often does that problem\nappear, what other workarounds exist if any and why they are not\nsatisfactory, etc, etc?\n\n> ---\n\nAbove this line, we would want you to sign-off your patch,\ncertifying that you read DCO (see Documentation/SubmittingPatches)\nand you wrote it or otherwise have the right to pass it on as an\nopen-source patch.\n\n>  builtin/apply.c | 16 +++++-----------\n>  po/bg.po        | 15 ---------------\n>  po/ca.po        | 15 ---------------\n>  po/de.po        | 15 ---------------\n>  po/fr.po        | 15 ---------------\n>  po/git.pot      | 11 -----------\n>  po/it.po        | 11 -----------\n>  po/pt_PT.po     |  7 -------\n>  po/ru.po        | 12 ------------\n>  po/sv.po        | 16 ----------------\n>  po/vi.po        | 12 ------------\n>  po/zh_CN.po     | 11 -----------\n\nWe do not want anybody who is not doing the i18n/l10n to touch any\npo/* files.  The i18n/l10n team will adjust their translations\naccordingly when the code changes.\n\n>  12 files changed, 5 insertions(+), 151 deletions(-)\n\n> diff --git a/builtin/apply.c b/builtin/apply.c\n> index 54aba4e..e4481b4 100644\n> --- a/builtin/apply.c\n> +++ b/builtin/apply.c\n> @@ -1488,17 +1488,11 @@ static int find_header(const char *line, unsigned long size, int *hdrsize, struc\n>  \t\t\tint git_hdr_len = parse_git_header(line, len, size, patch);\n>  \t\t\tif (git_hdr_len <= len)\n>  \t\t\t\tcontinue;\n> -\t\t\tif (!patch->old_name && !patch->new_name) {\n> -\t\t\t\tif (!patch->def_name)\n> -\t\t\t\t\tdie(Q_(\"git diff header lacks filename information when removing \"\n> -\t\t\t\t\t       \"%d leading pathname component (line %d)\",\n> -\t\t\t\t\t       \"git diff header lacks filename information when removing \"\n> -\t\t\t\t\t       \"%d leading pathname components (line %d)\",\n> -\t\t\t\t\t       p_value),\n> -\t\t\t\t\t    p_value, linenr);\n> -\t\t\t\tpatch->old_name = xstrdup(patch->def_name);\n> -\t\t\t\tpatch->new_name = xstrdup(patch->def_name);\n> -\t\t\t}\n> +\n> +\t\t\t/* pass this hunk if the filename length is zero */\n> +\t\t\tif (!patch->old_name && !patch->new_name) \n> +\t\t\t\treturn -1;\t\t\t\t\n\nPlease explain why this is a good idea.\n\nThis can happen only when (1) the user gave too large a number to\nthe -p option or (2) the original patch was corrupt.  In either\ncase, we would want to stop and give the user a chance to correct\nit, either by specifying the correct -p number, or editing the\ncorrupt patch to state the right path the patch applies to.\nSilently dropping the patch is never a good thing to do, is it?\n\nThanks.\n"}]}