{"thread":{"id":"6808","subject":"How do I get git-format-patch to ignore changes that remove spaces from the end of the line?","startedAt":"2007-02-13T21:59:33Z","lastAt":"2007-02-14T17:18:15Z","messageCount":6,"participants":["Timur Tabi","Junio C Hamano","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"34469","messageId":"45D234C5.5090005@freescale.com","threadId":"6808","inReplyTo":null,"subject":"How do I get git-format-patch to ignore changes that remove spaces from the end of the line?","fromName":"Timur Tabi","fromEmail":"timur@freescale.com","sentAt":"2007-02-13T21:59:33Z","receivedAt":"2007-02-13T21:59:33Z","isPatch":false,"sender":{"key":"timur@freescale.com","avatar":null},"body":"I have configured my text editor to remove spaces at the end of each line \nwhenever it saves a file.  I do this so that I don't inadvertently add spaces to \nthe end of any line.\n\nUnfortunately, if the file *already* had spaces at the end of some lines before \nI start editing it, this spaces will also be removed.\n\nAfter I commit my changes, I use git-format-patch to make a patch.  I then get \ndeltas like this:\n\n   * Copyright (C) 1996-2005 Paul Mackerras.\n- *\n+ *\n   *  Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.\n- *    {engebret|bergner}@us.ibm.com\n+ *    {engebret|bergner}@us.ibm.com\n   *\n\nI don't want these deltas in my patch.  However, if I specify an option like \n--ignore-all-space, git-format-patch omits deltas like this one:\n\n-               memcpy(fs_enet_data.macaddr, mac_addr, 6);\n+                       memcpy(fs_enet_data.macaddr, mac_addr, 6);\n\nIn this case, I *do* want the delta, because I'm indenting a line to fix a \nformatting error.\n\nSo how do I get the output that I want, and not the output that I don't want?\n\n-- \nTimur Tabi\nLinux Kernel Developer @ Freescale\n"},{"id":"34472","messageId":"7vhctpwvam.fsf@assigned-by-dhcp.cox.net","threadId":"6808","inReplyTo":"45D234C5.5090005@freescale.com","subject":"Re: How do I get git-format-patch to ignore changes that remove spaces from the end of the line?","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2007-02-13T22:24:17Z","receivedAt":"2007-02-13T22:24:17Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Timur Tabi <timur@freescale.com> writes:\n\n> After I commit my changes, I use git-format-patch to make a patch.  I\n> then get deltas like this:\n>\n>   * Copyright (C) 1996-2005 Paul Mackerras.\n> - *\n> + *\n>   *  Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.\n> - *    {engebret|bergner}@us.ibm.com\n> + *    {engebret|bergner}@us.ibm.com\n>   *\n>\n> I don't want these deltas in my patch.\n\nYou could revert the change to the editor configuration and rely\non \"git diff\" before committing to point out the whitespace\nbreakage that you newly introduced to the file.  Then you would\nbe sending out exactly what you changed.\n"},{"id":"34474","messageId":"45D23D68.6040004@freescale.com","threadId":"6808","inReplyTo":"7vhctpwvam.fsf@assigned-by-dhcp.cox.net","subject":"Re: How do I get git-format-patch to ignore changes that remove spaces from the end of the line?","fromName":"Timur Tabi","fromEmail":"timur@freescale.com","sentAt":"2007-02-13T22:36:24Z","receivedAt":"2007-02-13T22:36:24Z","isPatch":false,"sender":{"key":"timur@freescale.com","avatar":null},"body":"Junio C Hamano wrote:\n\n> You could revert the change to the editor configuration and rely\n> on \"git diff\" before committing to point out the whitespace\n> breakage that you newly introduced to the file.  Then you would\n> be sending out exactly what you changed.\n\nThanks, but I was hoping that git would make my life easier, not more difficult.\n\n-- \nTimur Tabi\nLinux Kernel Developer @ Freescale\n"},{"id":"34483","messageId":"Pine.LNX.4.63.0702140125410.22628@wbgn013.biozentrum.uni-wuerzburg.de","threadId":"6808","inReplyTo":"45D23D68.6040004@freescale.com","subject":"[PATCH] teach diff machinery about --ignore-space-at-eol","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2007-02-14T00:30:29Z","receivedAt":"2007-02-14T00:30:29Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"\n`git diff --ignore-space-at-eol` will ignore whitespace at the\nline ends.\n\nSigned-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\n---\n\n\tOn Tue, 13 Feb 2007, Timur Tabi wrote:\n\t\n\t> Junio C Hamano wrote:\n\t> \n\t> > You could revert the change to the editor configuration and \n\t> > rely on \"git diff\" before committing to point out the \n\t> > whitespace breakage that you newly introduced to the file.  \n\t> > Then you would be sending out exactly what you changed.\n\t> \n\t> Thanks, but I was hoping that git would make my life easier, not \n\t> more difficult.\n\n\tStrictly speaking, you made life difficult on git by asking your \n\teditor to edit text it should not edit.\n\n\tHowever, this was a nice late-night exercise.\n\n diff.c         |    2 ++\n xdiff/xdiff.h  |    3 ++-\n xdiff/xutils.c |   24 ++++++++++++++++++++++++\n 3 files changed, 28 insertions(+), 1 deletions(-)\n\ndiff --git a/diff.c b/diff.c\nindex d712181..815a7a8 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -2059,6 +2059,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)\n \t\toptions->xdl_opts |= XDF_IGNORE_WHITESPACE;\n \telse if (!strcmp(arg, \"-b\") || !strcmp(arg, \"--ignore-space-change\"))\n \t\toptions->xdl_opts |= XDF_IGNORE_WHITESPACE_CHANGE;\n+\telse if (!strcmp(arg, \"--ignore-space-at-eol\"))\n+\t\toptions->xdl_opts |= XDF_IGNORE_WHITESPACE_AT_EOL;\n \telse if (!strcmp(arg, \"--color-words\"))\n \t\toptions->color_diff = options->color_diff_words = 1;\n \telse if (!strcmp(arg, \"--no-renames\"))\ndiff --git a/xdiff/xdiff.h b/xdiff/xdiff.h\nindex fa409d5..e874a7c 100644\n--- a/xdiff/xdiff.h\n+++ b/xdiff/xdiff.h\n@@ -31,7 +31,8 @@ extern \"C\" {\n #define XDF_NEED_MINIMAL (1 << 1)\n #define XDF_IGNORE_WHITESPACE (1 << 2)\n #define XDF_IGNORE_WHITESPACE_CHANGE (1 << 3)\n-#define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE)\n+#define XDF_IGNORE_WHITESPACE_AT_EOL (1 << 4)\n+#define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE | XDF_IGNORE_WHITESPACE_AT_EOL)\n \n #define XDL_PATCH_NORMAL '-'\n #define XDL_PATCH_REVERSE '+'\ndiff --git a/xdiff/xutils.c b/xdiff/xutils.c\nindex 1b899f3..3653864 100644\n--- a/xdiff/xutils.c\n+++ b/xdiff/xutils.c\n@@ -215,6 +215,21 @@ int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags)\n \t\t\t\treturn 0;\n \t\t}\n \t\treturn (i1 >= s1 && i2 >= s2);\n+\t} else if (flags & XDF_IGNORE_WHITESPACE_AT_EOL) {\n+\t\tfor (i1 = i2 = 0; i1 < s1 && i2 < s2; ) {\n+\t\t\tif (l1[i1] != l2[i2]) {\n+\t\t\t\twhile (i1 < s1 && isspace(l1[i1]))\n+\t\t\t\t\ti1++;\n+\t\t\t\twhile (i2 < s2 && isspace(l2[i2]))\n+\t\t\t\t\ti2++;\n+\t\t\t\tif (i1 < s1 || i2 < s2)\n+\t\t\t\t\treturn 0;\n+\t\t\t\treturn 1;\n+\t\t\t}\n+\t\t\ti1++;\n+\t\t\ti2++;\n+\t\t}\n+\t\treturn i1 >= s1 && i2 >= s2;\n \t} else\n \t\treturn s1 == s2 && !memcmp(l1, l2, s1);\n \n@@ -227,6 +242,7 @@ unsigned long xdl_hash_record(char const **data, char const *top, long flags) {\n \n \tfor (; ptr < top && *ptr != '\\n'; ptr++) {\n \t\tif (isspace(*ptr) && (flags & XDF_WHITESPACE_FLAGS)) {\n+\t\t\tconst char *ptr2 = ptr;\n \t\t\twhile (ptr + 1 < top && isspace(ptr[1])\n \t\t\t\t\t&& ptr[1] != '\\n')\n \t\t\t\tptr++;\n@@ -235,6 +251,14 @@ unsigned long xdl_hash_record(char const **data, char const *top, long flags) {\n \t\t\t\tha += (ha << 5);\n \t\t\t\tha ^= (unsigned long) ' ';\n \t\t\t}\n+\t\t\tif (flags & XDF_IGNORE_WHITESPACE_AT_EOL\n+\t\t\t\t\t&& ptr[1] != '\\n') {\n+\t\t\t\twhile (ptr2 != ptr + 1) {\n+\t\t\t\t\tha += (ha << 5);\n+\t\t\t\t\tha ^= (unsigned long) *ptr2;\n+\t\t\t\t\tptr2++;\n+\t\t\t\t}\n+\t\t\t}\n \t\t\tcontinue;\n \t\t}\n \t\tha += (ha << 5);\n"},{"id":"34498","messageId":"45D29DF5.8020809@freescale.com","threadId":"6808","inReplyTo":"Pine.LNX.4.63.0702140125410.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] teach diff machinery about --ignore-space-at-eol","fromName":"Timur Tabi","fromEmail":"timur@freescale.com","sentAt":"2007-02-14T05:28:21Z","receivedAt":"2007-02-14T05:28:21Z","isPatch":true,"sender":{"key":"timur@freescale.com","avatar":null},"body":"Johannes Schindelin wrote:\n\n> \tStrictly speaking, you made life difficult on git by asking your \n> \teditor to edit text it should not edit.\n\nGiven a choice between me and my computer, I think my computer should be \nthe one doing the hard work.\n\n> \tHowever, this was a nice late-night exercise.\n\nYou are truly a most awesome dude.  Thank you.\n"},{"id":"34575","messageId":"45D34457.8050207@freescale.com","threadId":"6808","inReplyTo":"Pine.LNX.4.63.0702140125410.22628@wbgn013.biozentrum.uni-wuerzburg.de","subject":"Re: [PATCH] teach diff machinery about --ignore-space-at-eol","fromName":"Timur Tabi","fromEmail":"timur@freescale.com","sentAt":"2007-02-14T17:18:15Z","receivedAt":"2007-02-14T17:18:15Z","isPatch":true,"sender":{"key":"timur@freescale.com","avatar":null},"body":"Johannes Schindelin wrote:\n> `git diff --ignore-space-at-eol` will ignore whitespace at the\n> line ends.\n> \n> Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>\n\nThis patch works great!  Oh git maintainer, please please please please apply \nthis patch to the next version of git.  My descendants will sing praises to your \nglory for a thousand years.\n\n-- \nTimur Tabi\nLinux Kernel Developer @ Freescale\n"}]}