{"thread":{"id":"10218","subject":"[PATCH 1/2] git add -i: Fix parsing of abbreviated hunk headers","startedAt":"2007-10-09T19:29:26Z","lastAt":"2007-10-09T19:29:26Z","messageCount":1,"participants":["Jean-Luc Herren"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"55298","messageId":"470BD696.1010305@gmx.ch","threadId":"10218","inReplyTo":null,"subject":"[PATCH 1/2] git add -i: Fix parsing of abbreviated hunk headers","fromName":"Jean-Luc Herren","fromEmail":"jlh@gmx.ch","sentAt":"2007-10-09T19:29:26Z","receivedAt":"2007-10-09T19:29:26Z","isPatch":true,"sender":{"key":"jlh@gmx.ch","avatar":null},"body":"The unified diff format allows one-line ranges to be abbreviated\nby omiting the size.  The hunk header \"@@ -10,1 +10,1 @@\" can be\nexpressed as \"@@ -10 +10 @@\", but this wasn't properly parsed in\nall cases.\n\nSuch abbreviated hunk headers are generated when a one-line change\n(add, remove or modify) appears without context; for example\nbecause the file is a one-liner itself or because GIT_DIFF_OPTS\nwas set to '-u0'.  If the user then runs 'git add -i' and enters\nthe 'patch' command for that file, perl complains about undefined\nvariables.\n\nSigned-off-by: Jean-Luc Herren <jlh@gmx.ch>\n---\n git-add--interactive.perl |   11 +++++------\n 1 files changed, 5 insertions(+), 6 deletions(-)\n\ndiff --git a/git-add--interactive.perl b/git-add--interactive.perl\nindex be68814..15b3f5b 100755\n--- a/git-add--interactive.perl\n+++ b/git-add--interactive.perl\n@@ -360,7 +360,9 @@ sub hunk_splittable {\n sub parse_hunk_header {\n \tmy ($line) = @_;\n \tmy ($o_ofs, $o_cnt, $n_ofs, $n_cnt) =\n-\t    $line =~ /^@@ -(\\d+)(?:,(\\d+)) \\+(\\d+)(?:,(\\d+)) @@/;\n+\t    $line =~ /^@@ -(\\d+)(?:,(\\d+))? \\+(\\d+)(?:,(\\d+))? @@/;\n+\t$o_cnt = 1 unless defined $o_cnt;\n+\t$n_cnt = 1 unless defined $n_cnt;\n \treturn ($o_ofs, $o_cnt, $n_ofs, $n_cnt);\n }\n \n@@ -705,9 +707,6 @@ sub patch_update_cmd {\n \t\t    parse_hunk_header($text->[0]);\n \n \t\tif (!$_->{USE}) {\n-\t\t\tif (!defined $o_cnt) { $o_cnt = 1; }\n-\t\t\tif (!defined $n_cnt) { $n_cnt = 1; }\n-\n \t\t\t# We would have added ($n_cnt - $o_cnt) lines\n \t\t\t# to the postimage if we were to use this hunk,\n \t\t\t# but we didn't.  So the line number that the next\n@@ -719,10 +718,10 @@ sub patch_update_cmd {\n \t\t\tif ($n_lofs) {\n \t\t\t\t$n_ofs += $n_lofs;\n \t\t\t\t$text->[0] = (\"@@ -$o_ofs\" .\n-\t\t\t\t\t      ((defined $o_cnt)\n+\t\t\t\t\t      (($o_cnt != 1)\n \t\t\t\t\t       ? \",$o_cnt\" : '') .\n \t\t\t\t\t      \" +$n_ofs\" .\n-\t\t\t\t\t      ((defined $n_cnt)\n+\t\t\t\t\t      (($n_cnt != 1)\n \t\t\t\t\t       ? \",$n_cnt\" : '') .\n \t\t\t\t\t      \" @@\\n\");\n \t\t\t}\n-- \n1.5.3.4\n"}]}