{"thread":{"id":"6629","subject":"a slight anomaly in '--unified=0' diff output for one particular commit?","startedAt":"2007-02-02T16:19:31Z","lastAt":"2007-02-03T22:12:51Z","messageCount":3,"participants":["Ray Lehtiniemi","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"33393","messageId":"200702020919.31801.rayl@mail.com","threadId":"6629","inReplyTo":null,"subject":"a slight anomaly in '--unified=0' diff output for one particular commit?","fromName":"Ray Lehtiniemi","fromEmail":"rayl@mail.com","sentAt":"2007-02-02T16:19:31Z","receivedAt":"2007-02-02T16:19:31Z","isPatch":false,"sender":{"key":"rayl@mail.com","avatar":null},"body":"\nhi all\n\ni get the same output for both these commands in the git repository using \nv1.5.0-rc3-1-ge4b0e4a. \n\n  # git show --unified=1 9299c4f147bcff603eef187eb04fe38153571d30\n  # git show --unified=0 9299c4f147bcff603eef187eb04fe38153571d30\n\nin both cases, i get the following single line of context at the end of the \ndiff:\n\n  glossary.html : glossary.txt sort_glossary.pl\n\n\ni'm also not sure the numbers in the '@@@' line look correct for \nthe 'unified=0' case...\n\n\n\nthe context at the top of the diff behaves as expected.  i checked a few other \ncommits (merge and non-merge types), and they all behaved perfectly with both \nunified settings.  it's just this one commit that seems funny when \nusing --unified=0\n\n\ncan anyone reproduce?\n\nray\n"},{"id":"33476","messageId":"7virej3rkt.fsf@assigned-by-dhcp.cox.net","threadId":"6629","inReplyTo":"200702020919.31801.rayl@mail.com","subject":"Re: a slight anomaly in '--unified=0' diff output for one particular commit?","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-03T20:37:54Z","receivedAt":"2007-02-03T20:37:54Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ray Lehtiniemi <rayl@mail.com> writes:\n\n> i get the same output for both these commands in the git repository using \n> v1.5.0-rc3-1-ge4b0e4a. \n>\n>   # git show --unified=1 9299c4f147bcff603eef187eb04fe38153571d30\n>   # git show --unified=0 9299c4f147bcff603eef187eb04fe38153571d30\n>\n> in both cases, i get the following single line of context at the end of the \n> diff:\n>\n>   glossary.html : glossary.txt sort_glossary.pl\n>\n> i'm also not sure the numbers in the '@@@' line look correct for \n> the 'unified=0' case...\n\nThat's sick.\n\n-- >8 --\n[PATCH] combine-diff: special case --unified=0\n\nEven when --unified=0 is given, the main loop to show the\ncombined textual diff needs to handle a line that is unchanged\nbut has lines that were deleted relative to a parent before it\n(because that is where the lost lines hang).  However, such a\nline should not be emitted in the final output.\n\nSigned-off-by: Junio C Hamano <junkio@cox.net>\n---\n combine-diff.c |   34 ++++++++++++++++++++++++++++++----\n 1 files changed, 30 insertions(+), 4 deletions(-)\n\ndiff --git a/combine-diff.c b/combine-diff.c\nindex 29d0c9c..a5f2c8d 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -482,11 +482,11 @@ static int make_hunks(struct sline *sline, unsigned long cnt,\n \treturn has_interesting;\n }\n \n-static void show_parent_lno(struct sline *sline, unsigned long l0, unsigned long l1, int n)\n+static void show_parent_lno(struct sline *sline, unsigned long l0, unsigned long l1, int n, unsigned long null_context)\n {\n \tl0 = sline[l0].p_lno[n];\n \tl1 = sline[l1].p_lno[n];\n-\tprintf(\" -%lu,%lu\", l0, l1-l0);\n+\tprintf(\" -%lu,%lu\", l0, l1-l0-null_context);\n }\n \n static int hunk_comment_line(const char *bol)\n@@ -519,6 +519,7 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,\n \t\tunsigned long hunk_end;\n \t\tunsigned long rlines;\n \t\tconst char *hunk_comment = NULL;\n+\t\tunsigned long null_context = 0;\n \n \t\twhile (lno <= cnt && !(sline[lno].flag & mark)) {\n \t\t\tif (hunk_comment_line(sline[lno].bol))\n@@ -535,10 +536,28 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,\n \t\trlines = hunk_end - lno;\n \t\tif (cnt < hunk_end)\n \t\t\trlines--; /* pointing at the last delete hunk */\n+\n+\t\tif (!context) {\n+\t\t\t/*\n+\t\t\t * Even when running with --unified=0, all\n+\t\t\t * lines in the hunk needs to be processed in\n+\t\t\t * the loop below in order to show the\n+\t\t\t * deletion recorded in lost_head.  However,\n+\t\t\t * we do not want to show the resulting line\n+\t\t\t * with all blank context markers in such a\n+\t\t\t * case.  Compensate.\n+\t\t\t */\n+\t\t\tunsigned long j;\n+\t\t\tfor (j = lno; j < hunk_end; j++)\n+\t\t\t\tif (!(sline[j].flag & (mark-1)))\n+\t\t\t\t\tnull_context++;\n+\t\t\trlines -= null_context;\n+\t\t}\n+\n \t\tfputs(c_frag, stdout);\n \t\tfor (i = 0; i <= num_parent; i++) putchar(combine_marker);\n \t\tfor (i = 0; i < num_parent; i++)\n-\t\t\tshow_parent_lno(sline, lno, hunk_end, i);\n+\t\t\tshow_parent_lno(sline, lno, hunk_end, i, null_context);\n \t\tprintf(\" +%lu,%lu \", lno+1, rlines);\n \t\tfor (i = 0; i <= num_parent; i++) putchar(combine_marker);\n \n@@ -578,8 +597,15 @@ static void dump_sline(struct sline *sline, unsigned long cnt, int num_parent,\n \t\t\tif (cnt < lno)\n \t\t\t\tbreak;\n \t\t\tp_mask = 1;\n-\t\t\tif (!(sl->flag & (mark-1)))\n+\t\t\tif (!(sl->flag & (mark-1))) {\n+\t\t\t\t/*\n+\t\t\t\t * This sline was here to hang the\n+\t\t\t\t * lost lines in front of it.\n+\t\t\t\t */\n+\t\t\t\tif (!context)\n+\t\t\t\t\tcontinue;\n \t\t\t\tfputs(c_plain, stdout);\n+\t\t\t}\n \t\t\telse\n \t\t\t\tfputs(c_new, stdout);\n \t\t\tfor (j = 0; j < num_parent; j++) {\n"},{"id":"33494","messageId":"200702031512.52778.rayl@mail.com","threadId":"6629","inReplyTo":"7virej3rkt.fsf@assigned-by-dhcp.cox.net","subject":"Enhanced diff options for gitk (Re: --unified=0)","fromName":"Ray Lehtiniemi","fromEmail":"rayl@mail.com","sentAt":"2007-02-03T22:12:51Z","receivedAt":"2007-02-03T22:12:51Z","isPatch":false,"sender":{"key":"rayl@mail.com","avatar":null},"body":"On Saturday 03 February 2007 13:37, Junio C Hamano wrote:\n\n> That's sick.\n\n:-)  i actually only noticed it while testing this patch....\n\n \n-- >8 --\n[PATCH] Enhanced diff options for gitk.\n\nThe diff options box in the gitk preferences dialog\ndoesn't do much because the GIT_DIFF_OPTS environment\nvariable only honors the --unified option.\n\nAdjust the usage of $diffopts and remove GIT_DIFF_OPTS\nfrom gitk so that other diff options will be honored.\n\nSigned-off-by: Ray Lehtiniemi <rayl@mail.com>\n---\n gitk |   13 ++++++-------\n 1 files changed, 6 insertions(+), 7 deletions(-)\n\ndiff --git a/gitk b/gitk\nindex 68cfd63..7ee19b7 100755\n--- a/gitk\n+++ b/gitk\n@@ -4183,9 +4183,7 @@ proc mergediff {id l} {\n \n     set diffmergeid $id\n     set diffids $id\n-    # this doesn't seem to actually affect anything...\n-    set env(GIT_DIFF_OPTS) $diffopts\n-    set cmd [concat | git diff-tree --no-commit-id --cc $id]\n+    set cmd [concat | git diff-tree $diffopts --no-commit-id --cc $id]\n     if {[catch {set mdf [open $cmd r]} err]} {\n \terror_popup \"Error getting merge diffs: $err\"\n \treturn\n@@ -4332,8 +4330,7 @@ proc getblobdiffs {ids} {\n     global diffopts blobdifffd diffids env curdifftag curtagstart\n     global nextupdate diffinhdr treediffs\n \n-    set env(GIT_DIFF_OPTS) $diffopts\n-    set cmd [concat | git diff-tree --no-commit-id -r -p -C $ids]\n+    set cmd [concat | git diff-tree $diffopts --no-commit-id -r -p -C $ids]\n     if {[catch {set bdf [open $cmd r]} err]} {\n \tputs \"error getting diffs: $err\"\n \treturn\n@@ -5896,7 +5893,7 @@ proc prefscan {} {\n }\n \n proc prefsok {} {\n-    global maxwidth maxgraphpct\n+    global maxwidth maxgraphpct diffopts\n     global oldprefs prefstop showneartags\n \n     catch {destroy $prefstop}\n@@ -5906,6 +5903,8 @@ proc prefsok {} {\n \tredisplay\n     } elseif {$showneartags != $oldprefs(showneartags)} {\n \treselectline\n+    } elseif {$diffopts != $oldprefs(diffopts)} {\n+\treselectline\n     }\n }\n \n@@ -6188,7 +6187,7 @@ proc tcl_encoding {enc} {\n \n # defaults...\n set datemode 0\n-set diffopts \"-U 5 -p\"\n+set diffopts \"\"\n set wrcomcmd \"git diff-tree --stdin -p --pretty\"\n \n set gitencoding {}\n-- \n1.5.0.rc3.28.g8bbd\n"}]}