{"thread":{"id":"15284","subject":"[PATCH] git gui: show diffs with a minimum of 1 context line","startedAt":"2008-08-30T16:45:27Z","lastAt":"2008-09-01T19:47:29Z","messageCount":17,"participants":["Clemens Buchacher","Junio C Hamano","Johannes Sixt","Shawn O. Pearce"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"89219","messageId":"20080830164527.GA25370@localhost","threadId":"15284","inReplyTo":null,"subject":"[PATCH] git gui: show diffs with a minimum of 1 context line","fromName":"Clemens Buchacher","fromEmail":"drizzd@aon.at","sentAt":"2008-08-30T16:45:27Z","receivedAt":"2008-08-30T16:45:27Z","isPatch":true,"sender":{"key":"drizzd@gmx.net","avatar":"https://avatars.githubusercontent.com/u/59082?v=4"},"body":"git apply does not handle diffs without context correctly. Configuring git\ngui to show zero context lines therefore breaks staging.\n\nSigned-off-by: Clemens Buchacher <drizzd@aon.at>\n---\n\nIn reply to this patch I will send a first attempt at fixing this problem\ninstead of avoiding it. There does not seem to be a straightforward\nsolution, however, so this should hide the bug for now.\n\n git-gui/git-gui.sh     |    2 +-\n git-gui/lib/diff.tcl   |    2 +-\n git-gui/lib/option.tcl |    2 +-\n 3 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\nindex ad65aaa..86402d4 100755\n--- a/git-gui/git-gui.sh\n+++ b/git-gui/git-gui.sh\n@@ -1932,7 +1932,7 @@ proc show_more_context {} {\n \n proc show_less_context {} {\n \tglobal repo_config\n-\tif {$repo_config(gui.diffcontext) >= 1} {\n+\tif {$repo_config(gui.diffcontext) > 1} {\n \t\tincr repo_config(gui.diffcontext) -1\n \t\treshow_diff\n \t}\ndiff --git a/git-gui/lib/diff.tcl b/git-gui/lib/diff.tcl\nindex 52b79e4..4a7138b 100644\n--- a/git-gui/lib/diff.tcl\n+++ b/git-gui/lib/diff.tcl\n@@ -175,7 +175,7 @@ proc show_diff {path w {lno {}} {scroll_pos {}}} {\n \n \tlappend cmd -p\n \tlappend cmd --no-color\n-\tif {$repo_config(gui.diffcontext) >= 0} {\n+\tif {$repo_config(gui.diffcontext) >= 1} {\n \t\tlappend cmd \"-U$repo_config(gui.diffcontext)\"\n \t}\n \tif {$w eq $ui_index} {\ndiff --git a/git-gui/lib/option.tcl b/git-gui/lib/option.tcl\nindex ffb3f00..5e1346e 100644\n--- a/git-gui/lib/option.tcl\n+++ b/git-gui/lib/option.tcl\n@@ -125,7 +125,7 @@ proc do_options {} {\n \t\t{b gui.matchtrackingbranch {mc \"Match Tracking Branches\"}}\n \t\t{b gui.fastcopyblame {mc \"Blame Copy Only On Changed Files\"}}\n \t\t{i-20..200 gui.copyblamethreshold {mc \"Minimum Letters To Blame Copy On\"}}\n-\t\t{i-0..99 gui.diffcontext {mc \"Number of Diff Context Lines\"}}\n+\t\t{i-1..99 gui.diffcontext {mc \"Number of Diff Context Lines\"}}\n \t\t{i-0..99 gui.commitmsgwidth {mc \"Commit Message Text Width\"}}\n \t\t{t gui.newbranchtemplate {mc \"New Branch Name Template\"}}\n \t\t} {\n-- \n1.6.0\n"},{"id":"89220","messageId":"20080830165600.GB25370@localhost","threadId":"15284","inReplyTo":"20080830164527.GA25370@localhost","subject":"[PATCH] git gui: use apply --unidiff-zero when staging hunks without context","fromName":"Clemens Buchacher","fromEmail":"drizzd@aon.at","sentAt":"2008-08-30T16:56:00Z","receivedAt":"2008-08-30T16:56:00Z","isPatch":true,"sender":{"key":"drizzd@gmx.net","avatar":"https://avatars.githubusercontent.com/u/59082?v=4"},"body":"git apply does not work correctly with zero-context patches. It does a\nlittle better with --unidiff-zero.\n---\n\nThis appears to fix staging hunks with zero context lines in the majority of\ncases. Staging individual lines still is a problem frequently.\n\nIn any case, it's easy enough to break zero-context diff & patch like this:\n\necho a > victim\ngit add victim\necho b >> victim\ngit diff -U0 | git apply --cached --unidiff-zero\ngit diff\n\nSo before delving into this problem to deeply, I'd like to find out who\nneeds fixing exactly. Is there documentation defining how zero-context git\ndiff output should look like? Or is git apply the culprit in the bug above?\n\nOr do we even want to support applying zero-context patches? If not, we\nshould detect and fail such attempts.\n\nClemens\n\n git-gui/lib/diff.tcl |   10 ++++++++--\n 1 files changed, 8 insertions(+), 2 deletions(-)\n\ndiff --git a/git-gui/lib/diff.tcl b/git-gui/lib/diff.tcl\nindex 52b79e4..78c1b56 100644\n--- a/git-gui/lib/diff.tcl\n+++ b/git-gui/lib/diff.tcl\n@@ -302,12 +302,15 @@ proc read_diff {fd scroll_pos} {\n \n proc apply_hunk {x y} {\n \tglobal current_diff_path current_diff_header current_diff_side\n-\tglobal ui_diff ui_index file_states\n+\tglobal ui_diff ui_index file_states repo_config\n \n \tif {$current_diff_path eq {} || $current_diff_header eq {}} return\n \tif {![lock_index apply_hunk]} return\n \n \tset apply_cmd {apply --cached --whitespace=nowarn}\n+\tif {$repo_config(gui.diffcontext) eq 0} {\n+\t\tlappend apply_cmd --unidiff-zero\n+\t}\n \tset mi [lindex $file_states($current_diff_path) 0]\n \tif {$current_diff_side eq $ui_index} {\n \t\tset failed_msg [mc \"Failed to unstage selected hunk.\"]\n@@ -375,12 +378,15 @@ proc apply_hunk {x y} {\n \n proc apply_line {x y} {\n \tglobal current_diff_path current_diff_header current_diff_side\n-\tglobal ui_diff ui_index file_states\n+\tglobal ui_diff ui_index file_states repo_config\n \n \tif {$current_diff_path eq {} || $current_diff_header eq {}} return\n \tif {![lock_index apply_hunk]} return\n \n \tset apply_cmd {apply --cached --whitespace=nowarn}\n+\tif {$repo_config(gui.diffcontext) eq 0} {\n+\t\tlappend apply_cmd --unidiff-zero\n+\t}\n \tset mi [lindex $file_states($current_diff_path) 0]\n \tif {$current_diff_side eq $ui_index} {\n \t\tset failed_msg [mc \"Failed to unstage selected line.\"]\n-- \n1.6.0\n"},{"id":"89223","messageId":"7vtzd2ifot.fsf@gitster.siamese.dyndns.org","threadId":"15284","inReplyTo":"20080830164527.GA25370@localhost","subject":"Re: [PATCH] git gui: show diffs with a minimum of 1 context line","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-30T17:19:14Z","receivedAt":"2008-08-30T17:19:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Clemens Buchacher <drizzd@aon.at> writes:\n\n> git apply does not handle diffs without context correctly.\n\nNAK on this part of the proposed commit log message.\n\n\"git-apply\" is more anal than other \"patch\" implementations in that it\ntries to make sure that a hunk that touches the trailing end actually\napplies to the trailing end of the file.  If a patch is generated with\nnon-zero context, we can detect by presense of trailing context lines that\na patch is _not_ about modifying the trailing end, but with a -U0 patch,\nevery hunk will come without trailing context, so you need to disable that\nsafety by asking for --unidiff-zero option.\n\n> ... Configuring git\n> gui to show zero context lines therefore breaks staging.\n\nSo another option might be to pass --unidiff-zero iff/when it is feeding\nsuch a patch to fix this particular \"user error\" of \"git-apply\" program.\n\nHaving said that,\n\n> In reply to this patch I will send a first attempt at fixing this problem\n> instead of avoiding it.\n\nI suspect there are some things \"git-apply\" should be able to _figure out_\nthat the user is giving it a -U0 patch and automatically flip unidiff_zero\noption on.  For example, if the _first_ hunk of a patch does not begin\nwith \"@@ -0,0 +N,M @@\" nor with \"@@ -1,L +N,M @@\" (i.e. the hunk claims to\napply not at the beginning) and the hunk does not have leading context\nlines, _and_ if that first hunk does not have trailing context lines, then\nit is clearly a -U0 patch (or it could be a corrupt patch, but let's\ndiscount that possibility for now).\n\nEven if the hunk does claim to apply at the beginning, in which case we\ncannot determine if it is a -U0 patch by looking at the lack of leading\ncontext, if it has any context lines, we can tell it is _not_ a -U0 patch.\nWhen the first hunk that applies to the beginning lacks any context, we\ncannot really tell if it is -U0 or not (the other possibility is a total\nrewrite of the file from the beginning to the end).  Even in that case,\nyou could look at the next hunk --- if you have a hunk that applies to\nthe same path after looking at such a \"first\" hunk without context, then\nit clearly is a -U0 patch.\n"},{"id":"89225","messageId":"7vljyeif5g.fsf@gitster.siamese.dyndns.org","threadId":"15284","inReplyTo":"7vtzd2ifot.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] git gui: show diffs with a minimum of 1 context line","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-30T17:30:51Z","receivedAt":"2008-08-30T17:30:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> I suspect there are some things \"git-apply\" should be able to _figure out_\n\ns/able to/& do to/;\n\n> that the user is giving it a -U0 patch and automatically flip unidiff_zero\n> option on.  For example, if the _first_ hunk of a patch does not begin\n> with \"@@ -0,0 +N,M @@\" nor with \"@@ -1,L +N,M @@\" (i.e. the hunk claims to\n> apply not at the beginning) and the hunk does not have leading context\n> lines, _and_ if that first hunk does not have trailing context lines, then\n\nEh, what was I smoking.  In short, if the first hunk does not have _any_\ncontext lines and still says it is intended to apply to somewhere not at\nthe beginning, then that is a -U0 patch.\n"},{"id":"89227","messageId":"7vhc92ie44.fsf@gitster.siamese.dyndns.org","threadId":"15284","inReplyTo":"20080830165600.GB25370@localhost","subject":"Re: [PATCH] git gui: use apply --unidiff-zero when staging hunks without context","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-30T17:53:15Z","receivedAt":"2008-08-30T17:53:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Clemens Buchacher <drizzd@aon.at> writes:\n\n> echo a > victim\n> git add victim\n> echo b >> victim\n> git diff -U0 | git apply --cached --unidiff-zero\n> git diff\n\nI think \"diff -U0\" there would say \"@@ -1,0 +2 @@\", iow \"add this one line\nafter the first line\", and \"apply\" has an off-by-one in this case.\n"},{"id":"89240","messageId":"20080830190302.GA29851@localhost","threadId":"15284","inReplyTo":"7vhc92ie44.fsf@gitster.siamese.dyndns.org","subject":"[PATCH] git apply: do not match beginning in special unidiff-zero case","fromName":"Clemens Buchacher","fromEmail":"drizzd@aon.at","sentAt":"2008-08-30T19:03:02Z","receivedAt":"2008-08-30T19:03:02Z","isPatch":true,"sender":{"key":"drizzd@gmx.net","avatar":"https://avatars.githubusercontent.com/u/59082?v=4"},"body":"If a unidiff patch without any context modifies the second line, it does\nnot match the beginning, even though oldpos == 1.\n\nSigned-off-by: Clemens Buchacher <drizzd@aon.at>\n---\n\nOn Sat, Aug 30, 2008 at 10:53:15AM -0700, Junio C Hamano wrote:\n> Clemens Buchacher <drizzd@aon.at> writes:\n> \n> > echo a > victim\n> > git add victim\n> > echo b >> victim\n> > git diff -U0 | git apply --cached --unidiff-zero\n> > git diff\n> \n> I think \"diff -U0\" there would say \"@@ -1,0 +2 @@\", iow \"add this one line\n> after the first line\", and \"apply\" has an off-by-one in this case.\n\nIndeed. This appears to fix problems with staging hunks in git gui, even\nwith zero context lines. Staging individual lines still doesn't work,\nthough.\n\nClemens\n\n builtin-apply.c           |    9 ++++-----\n t/t4104-apply-boundary.sh |   15 ++++++++++++---\n 2 files changed, 16 insertions(+), 8 deletions(-)\n\ndiff --git a/builtin-apply.c b/builtin-apply.c\nindex 2216a0b..8402f9d 100644\n--- a/builtin-apply.c\n+++ b/builtin-apply.c\n@@ -1994,16 +1994,15 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,\n \ttrailing = frag->trailing;\n \n \t/*\n-\t * A hunk to change lines at the beginning would begin with\n+\t * Unless the patch was generated with unidiff without any context, a\n+\t * hunk to change lines at the beginning would begin with\n \t * @@ -1,L +N,M @@\n \t *\n \t * And a hunk to add to an empty file would begin with\n \t * @@ -0,0 +N,M @@\n-\t *\n-\t * In other words, a hunk that is (frag->oldpos <= 1) with or\n-\t * without leading context must match at the beginning.\n \t */\n-\tmatch_beginning = frag->oldpos <= 1;\n+\tmatch_beginning = frag->oldpos == 0 ||\n+\t\t(!unidiff_zero && frag->oldpos == 1);\n \n \t/*\n \t * A hunk without trailing lines must match at the end.\ndiff --git a/t/t4104-apply-boundary.sh b/t/t4104-apply-boundary.sh\nindex e7e2913..0e3ce36 100755\n--- a/t/t4104-apply-boundary.sh\n+++ b/t/t4104-apply-boundary.sh\n@@ -27,6 +27,15 @@ test_expect_success setup '\n \tgit diff victim >add-a-patch.with &&\n \tgit diff --unified=0 >add-a-patch.without &&\n \n+\t: insert at line two\n+\tfor i in b a '\"$L\"' y\n+\tdo\n+\t\techo $i\n+\tdone >victim &&\n+\tcat victim >insert-a-expect &&\n+\tgit diff victim >insert-a-patch.with &&\n+\tgit diff --unified=0 >insert-a-patch.without &&\n+\n \t: modify at the head\n \tfor i in a '\"$L\"' y\n \tdo\n@@ -55,7 +64,7 @@ test_expect_success setup '\n \tgit diff --unified=0 >add-z-patch.without &&\n \n \t: modify at the tail\n-\tfor i in a '\"$L\"' y\n+\tfor i in b '\"$L\"' z\n \tdo\n \t\techo $i\n \tdone >victim &&\n@@ -81,7 +90,7 @@ do\n \twith) u= ;;\n \twithout) u='--unidiff-zero ' ;;\n \tesac\n-\tfor kind in add-a add-z mod-a mod-z del-a del-z\n+\tfor kind in add-a add-z insert-a mod-a mod-z del-a del-z\n \tdo\n \t\ttest_expect_success \"apply $kind-patch $with context\" '\n \t\t\tcat original >victim &&\n@@ -95,7 +104,7 @@ do\n \tdone\n done\n \n-for kind in add-a add-z mod-a mod-z del-a del-z\n+for kind in add-a add-z insert-a mod-a mod-z del-a del-z\n do\n \trm -f $kind-ng.without\n \tsed\t-e \"s/^diff --git /diff /\" \\\n-- \n1.6.0\n"},{"id":"89241","messageId":"7vk5dygukv.fsf_-_@gitster.siamese.dyndns.org","threadId":"15284","inReplyTo":"7vhc92ie44.fsf@gitster.siamese.dyndns.org","subject":"[PATCH] git-apply: Loosen \"match_beginning\" logic","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-30T19:40:32Z","receivedAt":"2008-08-30T19:40:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Even after a handfle attempts, match_beginning logic still has corner\ncases:\n\n    1bf1a85 (apply: treat EOF as proper context., 2006-05-23)\n    65aadb9 (apply: force matching at the beginning., 2006-05-24)\n    4be6096 (apply --unidiff-zero: loosen sanity checks ..., 2006-09-17)\n    ee5a317 (Fix \"git apply\" to correctly enforce \"match ..., 2008-04-06)\n\nThis is a tricky piece of code.\n\nWe still incorrectly enforce \"match_beginning\" for -U0 matches.\nI noticed this while trying out an example sequence from Clemens Buchacher:\n\n    $ echo a >victim\n    $ git add victim\n    $ echo b >>victim\n    $ git diff -U0 >patch\n    $ cat patch\n    diff --git i/victim w/victim\n    index 7898192..422c2b7 100644\n    --- i/victim\n    +++ w/victim\n    @@ -1,0 +2 @@ a\n    +b\n    $ git apply --cached --unidiff-zero <patch\n    $ git show :victim\n    b\n    a\n\nThe change inserts a new line before the second line, but we insist it to\nbe applied at the beginning.  As the result, the code refuses to apply it\nat the original offset, and we end up adding the line at the beginning.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n builtin-apply.c |    5 ++++-\n 1 files changed, 4 insertions(+), 1 deletions(-)\n\ndiff --git c/builtin-apply.c w/builtin-apply.c\nindex 2216a0b..47261e1 100644\n--- c/builtin-apply.c\n+++ w/builtin-apply.c\n@@ -1996,6 +1996,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,\n \t/*\n \t * A hunk to change lines at the beginning would begin with\n \t * @@ -1,L +N,M @@\n+\t * but we need to be careful.  -U0 that inserts before the second\n+\t * line also has this pattern.\n \t *\n \t * And a hunk to add to an empty file would begin with\n \t * @@ -0,0 +N,M @@\n@@ -2003,7 +2005,8 @@ static int apply_one_fragment(struct image *img, struct fragment *frag,\n \t * In other words, a hunk that is (frag->oldpos <= 1) with or\n \t * without leading context must match at the beginning.\n \t */\n-\tmatch_beginning = frag->oldpos <= 1;\n+\tmatch_beginning = (!frag->oldpos ||\n+\t\t\t   (frag->oldpos == 1 && !unidiff_zero));\n \n \t/*\n \t * A hunk without trailing lines must match at the end.\n"},{"id":"89243","messageId":"48B9A2D7.8090801@telecom.at","threadId":"15284","inReplyTo":"20080830165600.GB25370@localhost","subject":"Re: [PATCH] git gui: use apply --unidiff-zero when staging hunks without context","fromName":"Johannes Sixt","fromEmail":"johannes.sixt@telecom.at","sentAt":"2008-08-30T19:43:19Z","receivedAt":"2008-08-30T19:43:19Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Clemens Buchacher schrieb:\n> git apply does not work correctly with zero-context patches. It does a\n> little better with --unidiff-zero.\n\nNo, NO, NOOOOO! This kills your data!\n\nhttp://thread.gmane.org/gmane.comp.version-control.git/67854/focus=68127\n\n-- Hannes\n"},{"id":"89244","messageId":"7vfxomgtxc.fsf@gitster.siamese.dyndns.org","threadId":"15284","inReplyTo":"20080830190302.GA29851@localhost","subject":"Re: [PATCH] git apply: do not match beginning in special unidiff-zero case","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-30T19:54:39Z","receivedAt":"2008-08-30T19:54:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Clemens Buchacher <drizzd@aon.at> writes:\n\n> If a unidiff patch without any context modifies the second line, it does\n> not match the beginning, even though oldpos == 1.\n\nHeh, it seems we independently reached the same patch, so I'll squash in\nyour new test.\n\nHaving did all this, I have to warn you, git-gui, and anybody who is\ntempted to use --unidiff-zero in \"add -i [e]dit\" that the -U0 format is\ninherently unreliable _unless the patch you are feeding is perfect_.\n\nBy reducing the context, especially when you have only addition without\ndeletion next to it (iow, \"modification to an existing line\"), the only\ninformation as to where that line needs to be inserted that you are\ntelling \"apply\" is the postimage offset, so you have to be absolutely sure\nthat the hunk header \"@@ -K,L +M,N @@\" you are feeding has the correct\nvalue for \"M\".\n\nFor git-gui's \"pick and apply\", you should be able to, but once you start\nallowing random manual editing of hunks, by definition the patch is _not_\nperfect (\"add -i [e]dit\" even admits that it does not know what it is\ndoing by passing --recount to \"apply\").\n\nSo try to avoid --unidiff-zero.  git-gui should have _enough_ information\nto add surrounding context back to the lines the user picked from the UI,\nand I do not see a reason other than sheer lazyness for it to be using the\noption.\n"},{"id":"89249","messageId":"20080830202706.GA13573@localhost","threadId":"15284","inReplyTo":"48B9A2D7.8090801@telecom.at","subject":"Re: [PATCH] git gui: use apply --unidiff-zero when staging hunks without context","fromName":"Clemens Buchacher","fromEmail":"drizzd@aon.at","sentAt":"2008-08-30T20:27:06Z","receivedAt":"2008-08-30T20:27:06Z","isPatch":true,"sender":{"key":"drizzd@gmx.net","avatar":"https://avatars.githubusercontent.com/u/59082?v=4"},"body":"On Sat, Aug 30, 2008 at 09:43:19PM +0200, Johannes Sixt wrote:\n> Clemens Buchacher schrieb:\n>> git apply does not work correctly with zero-context patches. It does a\n>> little better with --unidiff-zero.\n>\n> No, NO, NOOOOO! This kills your data!\n\nOkay. Since we have 'Stage Line for Commit', supporting this would be almost\npointless anyways. So let's forget about trying to fix this and simply\ndisable zero-context diff in git-gui, as per my original patch\n\n[PATCH] git gui: show diffs with a minimum of 1 context line\n\nClemens\n"},{"id":"89253","messageId":"20080830204632.GA14564@localhost","threadId":"15284","inReplyTo":"20080830164527.GA25370@localhost","subject":"[PATCH] git gui: show diffs with a minimum of 1 context line","fromName":"Clemens Buchacher","fromEmail":"drizzd@aon.at","sentAt":"2008-08-30T20:46:32Z","receivedAt":"2008-08-30T20:46:32Z","isPatch":true,"sender":{"key":"drizzd@gmx.net","avatar":"https://avatars.githubusercontent.com/u/59082?v=4"},"body":"Staging hunks without context does not work, because line number\ninformation would have to be recomputed for individual hunks.  Since it is\nalready possible to stage individual lines using 'Stage Line for Commit',\nzero context diffs are not really necessary for git gui, however.\n\nSigned-off-by: Clemens Buchacher <drizzd@aon.at>\n---\n\nSame patch, different commit message.\n\n git-gui/git-gui.sh     |    2 +-\n git-gui/lib/diff.tcl   |    2 +-\n git-gui/lib/option.tcl |    2 +-\n 3 files changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh\nindex ad65aaa..86402d4 100755\n--- a/git-gui/git-gui.sh\n+++ b/git-gui/git-gui.sh\n@@ -1932,7 +1932,7 @@ proc show_more_context {} {\n \n proc show_less_context {} {\n \tglobal repo_config\n-\tif {$repo_config(gui.diffcontext) >= 1} {\n+\tif {$repo_config(gui.diffcontext) > 1} {\n \t\tincr repo_config(gui.diffcontext) -1\n \t\treshow_diff\n \t}\ndiff --git a/git-gui/lib/diff.tcl b/git-gui/lib/diff.tcl\nindex 52b79e4..4a7138b 100644\n--- a/git-gui/lib/diff.tcl\n+++ b/git-gui/lib/diff.tcl\n@@ -175,7 +175,7 @@ proc show_diff {path w {lno {}} {scroll_pos {}}} {\n \n \tlappend cmd -p\n \tlappend cmd --no-color\n-\tif {$repo_config(gui.diffcontext) >= 0} {\n+\tif {$repo_config(gui.diffcontext) >= 1} {\n \t\tlappend cmd \"-U$repo_config(gui.diffcontext)\"\n \t}\n \tif {$w eq $ui_index} {\ndiff --git a/git-gui/lib/option.tcl b/git-gui/lib/option.tcl\nindex ffb3f00..5e1346e 100644\n--- a/git-gui/lib/option.tcl\n+++ b/git-gui/lib/option.tcl\n@@ -125,7 +125,7 @@ proc do_options {} {\n \t\t{b gui.matchtrackingbranch {mc \"Match Tracking Branches\"}}\n \t\t{b gui.fastcopyblame {mc \"Blame Copy Only On Changed Files\"}}\n \t\t{i-20..200 gui.copyblamethreshold {mc \"Minimum Letters To Blame Copy On\"}}\n-\t\t{i-0..99 gui.diffcontext {mc \"Number of Diff Context Lines\"}}\n+\t\t{i-1..99 gui.diffcontext {mc \"Number of Diff Context Lines\"}}\n \t\t{i-0..99 gui.commitmsgwidth {mc \"Commit Message Text Width\"}}\n \t\t{t gui.newbranchtemplate {mc \"New Branch Name Template\"}}\n \t\t} {\n-- \n1.6.0\n"},{"id":"89255","messageId":"7vprnqfcoo.fsf@gitster.siamese.dyndns.org","threadId":"15284","inReplyTo":"20080830202706.GA13573@localhost","subject":"Re: [PATCH] git gui: use apply --unidiff-zero when staging hunks without context","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-30T20:52:23Z","receivedAt":"2008-08-30T20:52:23Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Clemens Buchacher <drizzd@aon.at> writes:\n\n> On Sat, Aug 30, 2008 at 09:43:19PM +0200, Johannes Sixt wrote:\n>> Clemens Buchacher schrieb:\n>>> git apply does not work correctly with zero-context patches. It does a\n>>> little better with --unidiff-zero.\n>>\n>> No, NO, NOOOOO! This kills your data!\n>\n> Okay. Since we have 'Stage Line for Commit', supporting this would be almost\n> pointless anyways. So let's forget about trying to fix this and simply\n> disable zero-context diff in git-gui, as per my original patch\n>\n> [PATCH] git gui: show diffs with a minimum of 1 context line\n\nWell, showing is Ok as long as you do not try pick and apply.  Or did I\nmiss something?\n"},{"id":"89256","messageId":"20080830210007.GA15004@localhost","threadId":"15284","inReplyTo":"7vprnqfcoo.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH] git gui: use apply --unidiff-zero when staging hunks without context","fromName":"Clemens Buchacher","fromEmail":"drizzd@aon.at","sentAt":"2008-08-30T21:00:07Z","receivedAt":"2008-08-30T21:00:07Z","isPatch":true,"sender":{"key":"drizzd@gmx.net","avatar":"https://avatars.githubusercontent.com/u/59082?v=4"},"body":"On Sat, Aug 30, 2008 at 01:52:23PM -0700, Junio C Hamano wrote:\n> Well, showing is Ok as long as you do not try pick and apply.  Or did I\n> miss something?\n\nIf I understand correctly git gui bases its patches on what it shows in the\ndiff window - which makes sense, because otherwise it would be a PITA to\nfind out which hunk the user actually wanted.\n\nWe could allow diffs without context and disable staging in that case, but I\nsuspect this would only confuse the user.\n"},{"id":"89436","messageId":"20080901193359.GG7482@spearce.org","threadId":"15284","inReplyTo":"20080830164527.GA25370@localhost","subject":"Re: [PATCH] git gui: show diffs with a minimum of 1 context line","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-09-01T19:33:59Z","receivedAt":"2008-09-01T19:33:59Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Clemens Buchacher <drizzd@aon.at> wrote:\n> git apply does not handle diffs without context correctly. Configuring git\n> gui to show zero context lines therefore breaks staging.\n> \n> Signed-off-by: Clemens Buchacher <drizzd@aon.at>\n\nThanks, this is queued for 'maint'.\n \n-- \nShawn.\n"},{"id":"89437","messageId":"20080901194004.GH7482@spearce.org","threadId":"15284","inReplyTo":"20080830210007.GA15004@localhost","subject":"Re: [PATCH] git gui: use apply --unidiff-zero when staging hunks without context","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-09-01T19:40:04Z","receivedAt":"2008-09-01T19:40:04Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Clemens Buchacher <drizzd@aon.at> wrote:\n> On Sat, Aug 30, 2008 at 01:52:23PM -0700, Junio C Hamano wrote:\n> > Well, showing is Ok as long as you do not try pick and apply.  Or did I\n> > miss something?\n> \n> If I understand correctly git gui bases its patches on what it shows in the\n> diff window - which makes sense, because otherwise it would be a PITA to\n> find out which hunk the user actually wanted.\n> \n> We could allow diffs without context and disable staging in that case, but I\n> suspect this would only confuse the user.\n\nI agree.  Lets just disallow zero-context diffs.  Its far easier\nfor the user to understand the diff limit is 1.\n\n-- \nShawn.\n"},{"id":"89438","messageId":"20080901194141.GA10853@localhost","threadId":"15284","inReplyTo":"20080901193359.GG7482@spearce.org","subject":"Re: [PATCH] git gui: show diffs with a minimum of 1 context line","fromName":"Clemens Buchacher","fromEmail":"drizzd@aon.at","sentAt":"2008-09-01T19:41:41Z","receivedAt":"2008-09-01T19:41:41Z","isPatch":true,"sender":{"key":"drizzd@gmx.net","avatar":"https://avatars.githubusercontent.com/u/59082?v=4"},"body":"On Mon, Sep 01, 2008 at 12:33:59PM -0700, Shawn O. Pearce wrote:\n> Clemens Buchacher <drizzd@aon.at> wrote:\n> > git apply does not handle diffs without context correctly. Configuring git\n> > gui to show zero context lines therefore breaks staging.\n> > \n> > Signed-off-by: Clemens Buchacher <drizzd@aon.at>\n> \n> Thanks, this is queued for 'maint'.\n\nActually, if you don't mind, I changed the commit message because 'git\napply' is not really to blame here:\n\nStaging hunks without context does not work, because line number\ninformation would have to be recomputed for individual hunks.  Since it is\nalready possible to stage individual lines using 'Stage Line for Commit',\nzero context diffs are not really necessary for git gui, however.\n\nSigned-off-by: Clemens Buchacher <drizzd@aon.at>\n"},{"id":"89439","messageId":"20080901194729.GI7482@spearce.org","threadId":"15284","inReplyTo":"20080901194141.GA10853@localhost","subject":"Re: [PATCH] git gui: show diffs with a minimum of 1 context line","fromName":"Shawn O. Pearce","fromEmail":"spearce@spearce.org","sentAt":"2008-09-01T19:47:29Z","receivedAt":"2008-09-01T19:47:29Z","isPatch":true,"sender":{"key":"spearce@spearce.org","avatar":"https://avatars.githubusercontent.com/u/34844?v=4"},"body":"Clemens Buchacher <drizzd@aon.at> wrote:\n> Actually, if you don't mind, I changed the commit message because 'git\n> apply' is not really to blame here:\n> \n> Staging hunks without context does not work, because line number\n> information would have to be recomputed for individual hunks.  Since it is\n> already possible to stage individual lines using 'Stage Line for Commit',\n> zero context diffs are not really necessary for git gui, however.\n\nThanks, message updated.\n\n-- \nShawn.\n"}]}