git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] Git doesn't allow to apply a patch with empty filenames.
@ 2015-07-06 17:16 Evgen Druzhynin
  2015-07-06 17:16 ` [PATCH] Added ability to scip patch hunk with an empty filename Evgen Druzhynin
  0 siblings, 1 reply; 3+ messages in thread
From: Evgen Druzhynin @ 2015-07-06 17:16 UTC (permalink / raw)
  To: git; +Cc: Evgen Druzhynin

git-apply fails if '-p' option truncate at least one filename in patch to zero size.
This solution tries to bring closer "git-apply" to standard Linux patch tool.
Standard patch tool skip the truncated filenames and successfully applies patch.

Evgen Druzhynin (1):
  Added ability to scip patch hunk with an empty file.

 builtin/apply.c | 16 +++++-----------
 po/bg.po        | 15 ---------------
 po/ca.po        | 15 ---------------
 po/de.po        | 15 ---------------
 po/fr.po        | 15 ---------------
 po/git.pot      | 11 -----------
 po/it.po        | 11 -----------
 po/pt_PT.po     |  7 -------
 po/ru.po        | 12 ------------
 po/sv.po        | 16 ----------------
 po/vi.po        | 12 ------------
 po/zh_CN.po     | 11 -----------
 12 files changed, 5 insertions(+), 151 deletions(-)

-- 
1.9.1

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH] Added ability to scip patch hunk with an empty filename.
  2015-07-06 17:16 [PATCH] Git doesn't allow to apply a patch with empty filenames Evgen Druzhynin
@ 2015-07-06 17:16 ` Evgen Druzhynin
  2015-07-06 18:36   ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Evgen Druzhynin @ 2015-07-06 17:16 UTC (permalink / raw)
  To: git; +Cc: Evgen Druzhynin

---
 builtin/apply.c | 16 +++++-----------
 po/bg.po        | 15 ---------------
 po/ca.po        | 15 ---------------
 po/de.po        | 15 ---------------
 po/fr.po        | 15 ---------------
 po/git.pot      | 11 -----------
 po/it.po        | 11 -----------
 po/pt_PT.po     |  7 -------
 po/ru.po        | 12 ------------
 po/sv.po        | 16 ----------------
 po/vi.po        | 12 ------------
 po/zh_CN.po     | 11 -----------
 12 files changed, 5 insertions(+), 151 deletions(-)

diff --git a/builtin/apply.c b/builtin/apply.c
index 54aba4e..e4481b4 100644
--- a/builtin/apply.c
+++ b/builtin/apply.c
@@ -1488,17 +1488,11 @@ static int find_header(const char *line, unsigned long size, int *hdrsize, struc
 			int git_hdr_len = parse_git_header(line, len, size, patch);
 			if (git_hdr_len <= len)
 				continue;
-			if (!patch->old_name && !patch->new_name) {
-				if (!patch->def_name)
-					die(Q_("git diff header lacks filename information when removing "
-					       "%d leading pathname component (line %d)",
-					       "git diff header lacks filename information when removing "
-					       "%d leading pathname components (line %d)",
-					       p_value),
-					    p_value, linenr);
-				patch->old_name = xstrdup(patch->def_name);
-				patch->new_name = xstrdup(patch->def_name);
-			}
+
+			/* pass this hunk if the filename length is zero */
+			if (!patch->old_name && !patch->new_name) 
+				return -1;				
+			
 			if (!patch->is_delete && !patch->new_name)
 				die("git diff header lacks filename information "
 				    "(line %d)", linenr);
diff --git a/po/bg.po b/po/bg.po
index 171f813..f2cc286 100644
--- a/po/bg.po
+++ b/po/bg.po
@@ -2373,21 +2373,6 @@ msgstr "при повторното преброяване бе получен 
 msgid "patch fragment without header at line %d: %.*s"
 msgstr "част от кръпка без заглавна част на ред %d: %.*s"
 
-#: builtin/apply.c:1493
-#, c-format
-msgid ""
-"git diff header lacks filename information when removing %d leading pathname "
-"component (line %d)"
-msgid_plural ""
-"git diff header lacks filename information when removing %d leading pathname "
-"components (line %d)"
-msgstr[0] ""
-"След съкращаването на %d-та част от компонентите на пътя, в заглавната част "
-"на „git diff“ липсва информация за име на файл (ред: %d)"
-msgstr[1] ""
-"След съкращаването на първите %d части от компонентите на пътя, в заглавната "
-"част на „git diff“ липсва информация за име на файл (ред: %d)"
-
 #: builtin/apply.c:1656
 msgid "new file depends on old contents"
 msgstr "новият файл зависи от старото съдържание на файла"
diff --git a/po/ca.po b/po/ca.po
index c733483..c893285 100644
--- a/po/ca.po
+++ b/po/ca.po
@@ -2216,21 +2216,6 @@ msgstr "recompte: línia inesperada: %.*s"
 msgid "patch fragment without header at line %d: %.*s"
 msgstr "fragment de pedaç sense capçalera a la línia %d: %.*s"
 
-#: builtin/apply.c:1493
-#, c-format
-msgid ""
-"git diff header lacks filename information when removing %d leading pathname "
-"component (line %d)"
-msgid_plural ""
-"git diff header lacks filename information when removing %d leading pathname "
-"components (line %d)"
-msgstr[0] ""
-"a la capçalera de git diff li manca informació de nom de fitxer en eliminar "
-"%d component de nom de camí inicial (línia %d)"
-msgstr[1] ""
-"a la capçalera de git diff li manca informació de nom de fitxer en eliminar "
-"%d components de nom de camí inicial (línia %d)"
-
 #: builtin/apply.c:1656
 msgid "new file depends on old contents"
 msgstr "el fitxer nou depèn dels continguts antics"
diff --git a/po/de.po b/po/de.po
index 7d603c2..ea6b555 100644
--- a/po/de.po
+++ b/po/de.po
@@ -2257,21 +2257,6 @@ msgstr "recount: unerwartete Zeile: %.*s"
 msgid "patch fragment without header at line %d: %.*s"
 msgstr "Patch-Fragment ohne Kopfbereich bei Zeile %d: %.*s"
 
-#: builtin/apply.c:1493
-#, c-format
-msgid ""
-"git diff header lacks filename information when removing %d leading pathname "
-"component (line %d)"
-msgid_plural ""
-"git diff header lacks filename information when removing %d leading pathname "
-"components (line %d)"
-msgstr[0] ""
-"Dem Kopfbereich von \"git diff\" fehlen Informationen zum Dateinamen, wenn "
-"%d vorangestellter Teil des Pfades entfernt wird (Zeile %d)"
-msgstr[1] ""
-"Dem Kopfbereich von \"git diff\" fehlen Informationen zum Dateinamen, wenn "
-"%d vorangestellte Teile des Pfades entfernt werden (Zeile %d)"
-
 #: builtin/apply.c:1656
 msgid "new file depends on old contents"
 msgstr "neue Datei hängt von alten Inhalten ab"
diff --git a/po/fr.po b/po/fr.po
index 00bfefd..b376631 100644
--- a/po/fr.po
+++ b/po/fr.po
@@ -2301,21 +2301,6 @@ msgstr "recomptage : ligne inattendue : %.*s"
 msgid "patch fragment without header at line %d: %.*s"
 msgstr "fragment de patch sans en-tête à la ligne %d : %.*s"
 
-#: builtin/apply.c:1493
-#, c-format
-msgid ""
-"git diff header lacks filename information when removing %d leading pathname "
-"component (line %d)"
-msgid_plural ""
-"git diff header lacks filename information when removing %d leading pathname "
-"components (line %d)"
-msgstr[0] ""
-"information de nom de fichier manquante dans l'en-tête de git diff lors de "
-"la suppression de %d composant de préfixe de chemin (ligne %d)"
-msgstr[1] ""
-"information de nom de fichier manquante dans l'en-tête de git diff lors de "
-"la suppression de %d composants de préfixe de chemin (ligne %d)"
-
 #: builtin/apply.c:1656
 msgid "new file depends on old contents"
 msgstr "le nouveau fichier dépend de contenus anciens"
diff --git a/po/git.pot b/po/git.pot
index c94a955..f1433e9 100644
--- a/po/git.pot
+++ b/po/git.pot
@@ -2093,17 +2093,6 @@ msgstr ""
 msgid "patch fragment without header at line %d: %.*s"
 msgstr ""
 
-#: builtin/apply.c:1493
-#, c-format
-msgid ""
-"git diff header lacks filename information when removing %d leading pathname "
-"component (line %d)"
-msgid_plural ""
-"git diff header lacks filename information when removing %d leading pathname "
-"components (line %d)"
-msgstr[0] ""
-msgstr[1] ""
-
 #: builtin/apply.c:1656
 msgid "new file depends on old contents"
 msgstr ""
diff --git a/po/it.po b/po/it.po
index 9080219..6314bcb 100644
--- a/po/it.po
+++ b/po/it.po
@@ -1042,17 +1042,6 @@ msgstr "recount: riga inattesa: %.*s"
 msgid "patch fragment without header at line %d: %.*s"
 msgstr "frammento di patch senza intestazione alla riga %d: %.*s"
 
-#: builtin/apply.c:1468
-#, c-format
-msgid ""
-"git diff header lacks filename information when removing %d leading pathname "
-"component (line %d)"
-msgid_plural ""
-"git diff header lacks filename information when removing %d leading pathname "
-"components (line %d)"
-msgstr[0] ""
-msgstr[1] ""
-
 #: builtin/apply.c:1628
 msgid "new file depends on old contents"
 msgstr "il nuovo file dipende da contenuti precedenti"
diff --git a/po/pt_PT.po b/po/pt_PT.po
index 689ad1b..7cfba0d 100644
--- a/po/pt_PT.po
+++ b/po/pt_PT.po
@@ -1025,13 +1025,6 @@ msgstr ""
 msgid "patch fragment without header at line %d: %.*s"
 msgstr ""
 
-#: builtin/apply.c:1461
-#, c-format
-msgid "git diff header lacks filename information when removing %d leading pathname component (line %d)"
-msgid_plural "git diff header lacks filename information when removing %d leading pathname components (line %d)"
-msgstr[0] ""
-msgstr[1] ""
-
 #: builtin/apply.c:1621
 msgid "new file depends on old contents"
 msgstr ""
diff --git a/po/ru.po b/po/ru.po
index 4356ae9..a796889 100644
--- a/po/ru.po
+++ b/po/ru.po
@@ -2114,18 +2114,6 @@ msgstr "recount: не ожидаемая строка: %.*s"
 msgid "patch fragment without header at line %d: %.*s"
 msgstr "фрагмент изменений без заголовка на строке %d: %.*s"
 
-#: builtin/apply.c:1493
-#, c-format
-msgid ""
-"git diff header lacks filename information when removing %d leading pathname"
-" component (line %d)"
-msgid_plural ""
-"git diff header lacks filename information when removing %d leading pathname"
-" components (line %d)"
-msgstr[0] "заголовок git diff не нашел информацию об имени файла при удалении %d ведущего компонента пути к файлу (строка %d)"
-msgstr[1] "заголовок git diff не нашел информацию об имени файла при удалении %d ведущих компонент пути к файлу (строка %d)"
-msgstr[2] "заголовок git diff не нашел информацию об имени файла при удалении %d ведущих компонент пути к файлу (строка %d)"
-
 #: builtin/apply.c:1656
 msgid "new file depends on old contents"
 msgstr "новый файл зависит от старого содержимого"
diff --git a/po/sv.po b/po/sv.po
index e4b70d6..5b2d24d 100644
--- a/po/sv.po
+++ b/po/sv.po
@@ -2184,22 +2184,6 @@ msgstr "recount: förväntade rad: %.*s"
 msgid "patch fragment without header at line %d: %.*s"
 msgstr "patch-fragment utan huvud på rad %d: %.*s"
 
-#: builtin/apply.c:1493
-#, c-format
-msgid ""
-"git diff header lacks filename information when removing %d leading pathname "
-"component (line %d)"
-msgid_plural ""
-"git diff header lacks filename information when removing %d leading pathname "
-"components (line %d)"
-msgstr[0] ""
-"git-diff-huvudet saknar filnamnsinformation när %d ledande sökvägskomponent\n"
-"tas bort (rad %d)"
-msgstr[1] ""
-"git-diff-huvudet saknar filnamnsinformation när %d ledande "
-"sökvägskomponenter\n"
-"tas bort (rad %d)"
-
 #: builtin/apply.c:1656
 msgid "new file depends on old contents"
 msgstr "ny fil beror på gammalt innehåll"
diff --git a/po/vi.po b/po/vi.po
index 956be5a..ba1ecf5 100644
--- a/po/vi.po
+++ b/po/vi.po
@@ -2212,18 +2212,6 @@ msgstr "chi tiết: dòng không cần: %.*s"
 msgid "patch fragment without header at line %d: %.*s"
 msgstr "miếng vá phân mảnh mà không có phần đầu tại dòng %d: %.*s"
 
-#: builtin/apply.c:1493
-#, c-format
-msgid ""
-"git diff header lacks filename information when removing %d leading pathname "
-"component (line %d)"
-msgid_plural ""
-"git diff header lacks filename information when removing %d leading pathname "
-"components (line %d)"
-msgstr[0] ""
-"phần đầu diff cho git  thiếu thông tin tên tập tin khi gỡ bỏ đi %d trong "
-"thành phần dẫn đầu tên của đường dẫn (dòng %d)"
-
 #: builtin/apply.c:1656
 msgid "new file depends on old contents"
 msgstr "tập tin mới phụ thuộc vào nội dung cũ"
diff --git a/po/zh_CN.po b/po/zh_CN.po
index dd2948c..b65b97a 100644
--- a/po/zh_CN.po
+++ b/po/zh_CN.po
@@ -2197,17 +2197,6 @@ msgstr "recount:意外的行:%.*s"
 msgid "patch fragment without header at line %d: %.*s"
 msgstr "第 %d 行的补丁片段没有头信息:%.*s"
 
-#: builtin/apply.c:1493
-#, c-format
-msgid ""
-"git diff header lacks filename information when removing %d leading pathname "
-"component (line %d)"
-msgid_plural ""
-"git diff header lacks filename information when removing %d leading pathname "
-"components (line %d)"
-msgstr[0] "当移除 %d 个前导路径后 git diff 头缺乏文件名信息(第 %d 行)"
-msgstr[1] "当移除 %d 个前导路径后 git diff 头缺乏文件名信息(第 %d 行)"
-
 #: builtin/apply.c:1656
 msgid "new file depends on old contents"
 msgstr "新文件依赖旧内容"
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Added ability to scip patch hunk with an empty filename.
  2015-07-06 17:16 ` [PATCH] Added ability to scip patch hunk with an empty filename Evgen Druzhynin
@ 2015-07-06 18:36   ` Junio C Hamano
  0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2015-07-06 18:36 UTC (permalink / raw)
  To: Evgen Druzhynin; +Cc: git

Evgen Druzhynin <evgen.druzhynin@gmail.com> writes:

This space is for you to explain why it is a good idea to do this
change.  What problem does it solve, how often does that problem
appear, what other workarounds exist if any and why they are not
satisfactory, etc, etc?

> ---

Above this line, we would want you to sign-off your patch,
certifying that you read DCO (see Documentation/SubmittingPatches)
and you wrote it or otherwise have the right to pass it on as an
open-source patch.

>  builtin/apply.c | 16 +++++-----------
>  po/bg.po        | 15 ---------------
>  po/ca.po        | 15 ---------------
>  po/de.po        | 15 ---------------
>  po/fr.po        | 15 ---------------
>  po/git.pot      | 11 -----------
>  po/it.po        | 11 -----------
>  po/pt_PT.po     |  7 -------
>  po/ru.po        | 12 ------------
>  po/sv.po        | 16 ----------------
>  po/vi.po        | 12 ------------
>  po/zh_CN.po     | 11 -----------

We do not want anybody who is not doing the i18n/l10n to touch any
po/* files.  The i18n/l10n team will adjust their translations
accordingly when the code changes.

>  12 files changed, 5 insertions(+), 151 deletions(-)

> diff --git a/builtin/apply.c b/builtin/apply.c
> index 54aba4e..e4481b4 100644
> --- a/builtin/apply.c
> +++ b/builtin/apply.c
> @@ -1488,17 +1488,11 @@ static int find_header(const char *line, unsigned long size, int *hdrsize, struc
>  			int git_hdr_len = parse_git_header(line, len, size, patch);
>  			if (git_hdr_len <= len)
>  				continue;
> -			if (!patch->old_name && !patch->new_name) {
> -				if (!patch->def_name)
> -					die(Q_("git diff header lacks filename information when removing "
> -					       "%d leading pathname component (line %d)",
> -					       "git diff header lacks filename information when removing "
> -					       "%d leading pathname components (line %d)",
> -					       p_value),
> -					    p_value, linenr);
> -				patch->old_name = xstrdup(patch->def_name);
> -				patch->new_name = xstrdup(patch->def_name);
> -			}
> +
> +			/* pass this hunk if the filename length is zero */
> +			if (!patch->old_name && !patch->new_name) 
> +				return -1;				

Please explain why this is a good idea.

This can happen only when (1) the user gave too large a number to
the -p option or (2) the original patch was corrupt.  In either
case, we would want to stop and give the user a chance to correct
it, either by specifying the correct -p number, or editing the
corrupt patch to state the right path the patch applies to.
Silently dropping the patch is never a good thing to do, is it?

Thanks.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-07-06 18:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-06 17:16 [PATCH] Git doesn't allow to apply a patch with empty filenames Evgen Druzhynin
2015-07-06 17:16 ` [PATCH] Added ability to scip patch hunk with an empty filename Evgen Druzhynin
2015-07-06 18:36   ` Junio C Hamano

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).