All of lore.kernel.org
 help / color / mirror / Atom feed
* How do I get git-format-patch to ignore changes that remove spaces from the end of the line?
@ 2007-02-13 21:59 Timur Tabi
  2007-02-13 22:24 ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Timur Tabi @ 2007-02-13 21:59 UTC (permalink / raw)
  To: git

I have configured my text editor to remove spaces at the end of each line 
whenever it saves a file.  I do this so that I don't inadvertently add spaces to 
the end of any line.

Unfortunately, if the file *already* had spaces at the end of some lines before 
I start editing it, this spaces will also be removed.

After I commit my changes, I use git-format-patch to make a patch.  I then get 
deltas like this:

   * Copyright (C) 1996-2005 Paul Mackerras.
- *
+ *
   *  Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
- *    {engebret|bergner}@us.ibm.com
+ *    {engebret|bergner}@us.ibm.com
   *

I don't want these deltas in my patch.  However, if I specify an option like 
--ignore-all-space, git-format-patch omits deltas like this one:

-               memcpy(fs_enet_data.macaddr, mac_addr, 6);
+                       memcpy(fs_enet_data.macaddr, mac_addr, 6);

In this case, I *do* want the delta, because I'm indenting a line to fix a 
formatting error.

So how do I get the output that I want, and not the output that I don't want?

-- 
Timur Tabi
Linux Kernel Developer @ Freescale

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

* Re: How do I get git-format-patch to ignore changes that remove spaces from the end of the line?
  2007-02-13 21:59 How do I get git-format-patch to ignore changes that remove spaces from the end of the line? Timur Tabi
@ 2007-02-13 22:24 ` Junio C Hamano
  2007-02-13 22:36   ` Timur Tabi
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2007-02-13 22:24 UTC (permalink / raw)
  To: Timur Tabi; +Cc: git

Timur Tabi <timur@freescale.com> writes:

> After I commit my changes, I use git-format-patch to make a patch.  I
> then get deltas like this:
>
>   * Copyright (C) 1996-2005 Paul Mackerras.
> - *
> + *
>   *  Adapted for 64bit PowerPC by Dave Engebretsen and Peter Bergner.
> - *    {engebret|bergner}@us.ibm.com
> + *    {engebret|bergner}@us.ibm.com
>   *
>
> I don't want these deltas in my patch.

You could revert the change to the editor configuration and rely
on "git diff" before committing to point out the whitespace
breakage that you newly introduced to the file.  Then you would
be sending out exactly what you changed.

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

* Re: How do I get git-format-patch to ignore changes that remove spaces from the end of the line?
  2007-02-13 22:24 ` Junio C Hamano
@ 2007-02-13 22:36   ` Timur Tabi
  2007-02-14  0:30     ` [PATCH] teach diff machinery about --ignore-space-at-eol Johannes Schindelin
  0 siblings, 1 reply; 6+ messages in thread
From: Timur Tabi @ 2007-02-13 22:36 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

Junio C Hamano wrote:

> You could revert the change to the editor configuration and rely
> on "git diff" before committing to point out the whitespace
> breakage that you newly introduced to the file.  Then you would
> be sending out exactly what you changed.

Thanks, but I was hoping that git would make my life easier, not more difficult.

-- 
Timur Tabi
Linux Kernel Developer @ Freescale

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

* [PATCH] teach diff machinery about --ignore-space-at-eol
  2007-02-13 22:36   ` Timur Tabi
@ 2007-02-14  0:30     ` Johannes Schindelin
  2007-02-14  5:28       ` Timur Tabi
  2007-02-14 17:18       ` Timur Tabi
  0 siblings, 2 replies; 6+ messages in thread
From: Johannes Schindelin @ 2007-02-14  0:30 UTC (permalink / raw)
  To: Timur Tabi; +Cc: Junio C Hamano, git


`git diff --ignore-space-at-eol` will ignore whitespace at the
line ends.

Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>

---

	On Tue, 13 Feb 2007, Timur Tabi wrote:
	
	> Junio C Hamano wrote:
	> 
	> > You could revert the change to the editor configuration and 
	> > rely on "git diff" before committing to point out the 
	> > whitespace breakage that you newly introduced to the file.  
	> > Then you would be sending out exactly what you changed.
	> 
	> Thanks, but I was hoping that git would make my life easier, not 
	> more difficult.

	Strictly speaking, you made life difficult on git by asking your 
	editor to edit text it should not edit.

	However, this was a nice late-night exercise.

 diff.c         |    2 ++
 xdiff/xdiff.h  |    3 ++-
 xdiff/xutils.c |   24 ++++++++++++++++++++++++
 3 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/diff.c b/diff.c
index d712181..815a7a8 100644
--- a/diff.c
+++ b/diff.c
@@ -2059,6 +2059,8 @@ int diff_opt_parse(struct diff_options *options, const char **av, int ac)
 		options->xdl_opts |= XDF_IGNORE_WHITESPACE;
 	else if (!strcmp(arg, "-b") || !strcmp(arg, "--ignore-space-change"))
 		options->xdl_opts |= XDF_IGNORE_WHITESPACE_CHANGE;
+	else if (!strcmp(arg, "--ignore-space-at-eol"))
+		options->xdl_opts |= XDF_IGNORE_WHITESPACE_AT_EOL;
 	else if (!strcmp(arg, "--color-words"))
 		options->color_diff = options->color_diff_words = 1;
 	else if (!strcmp(arg, "--no-renames"))
diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h
index fa409d5..e874a7c 100644
--- a/xdiff/xdiff.h
+++ b/xdiff/xdiff.h
@@ -31,7 +31,8 @@ extern "C" {
 #define XDF_NEED_MINIMAL (1 << 1)
 #define XDF_IGNORE_WHITESPACE (1 << 2)
 #define XDF_IGNORE_WHITESPACE_CHANGE (1 << 3)
-#define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE)
+#define XDF_IGNORE_WHITESPACE_AT_EOL (1 << 4)
+#define XDF_WHITESPACE_FLAGS (XDF_IGNORE_WHITESPACE | XDF_IGNORE_WHITESPACE_CHANGE | XDF_IGNORE_WHITESPACE_AT_EOL)
 
 #define XDL_PATCH_NORMAL '-'
 #define XDL_PATCH_REVERSE '+'
diff --git a/xdiff/xutils.c b/xdiff/xutils.c
index 1b899f3..3653864 100644
--- a/xdiff/xutils.c
+++ b/xdiff/xutils.c
@@ -215,6 +215,21 @@ int xdl_recmatch(const char *l1, long s1, const char *l2, long s2, long flags)
 				return 0;
 		}
 		return (i1 >= s1 && i2 >= s2);
+	} else if (flags & XDF_IGNORE_WHITESPACE_AT_EOL) {
+		for (i1 = i2 = 0; i1 < s1 && i2 < s2; ) {
+			if (l1[i1] != l2[i2]) {
+				while (i1 < s1 && isspace(l1[i1]))
+					i1++;
+				while (i2 < s2 && isspace(l2[i2]))
+					i2++;
+				if (i1 < s1 || i2 < s2)
+					return 0;
+				return 1;
+			}
+			i1++;
+			i2++;
+		}
+		return i1 >= s1 && i2 >= s2;
 	} else
 		return s1 == s2 && !memcmp(l1, l2, s1);
 
@@ -227,6 +242,7 @@ unsigned long xdl_hash_record(char const **data, char const *top, long flags) {
 
 	for (; ptr < top && *ptr != '\n'; ptr++) {
 		if (isspace(*ptr) && (flags & XDF_WHITESPACE_FLAGS)) {
+			const char *ptr2 = ptr;
 			while (ptr + 1 < top && isspace(ptr[1])
 					&& ptr[1] != '\n')
 				ptr++;
@@ -235,6 +251,14 @@ unsigned long xdl_hash_record(char const **data, char const *top, long flags) {
 				ha += (ha << 5);
 				ha ^= (unsigned long) ' ';
 			}
+			if (flags & XDF_IGNORE_WHITESPACE_AT_EOL
+					&& ptr[1] != '\n') {
+				while (ptr2 != ptr + 1) {
+					ha += (ha << 5);
+					ha ^= (unsigned long) *ptr2;
+					ptr2++;
+				}
+			}
 			continue;
 		}
 		ha += (ha << 5);

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

* Re: [PATCH] teach diff machinery about --ignore-space-at-eol
  2007-02-14  0:30     ` [PATCH] teach diff machinery about --ignore-space-at-eol Johannes Schindelin
@ 2007-02-14  5:28       ` Timur Tabi
  2007-02-14 17:18       ` Timur Tabi
  1 sibling, 0 replies; 6+ messages in thread
From: Timur Tabi @ 2007-02-14  5:28 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Junio C Hamano, git

Johannes Schindelin wrote:

> 	Strictly speaking, you made life difficult on git by asking your 
> 	editor to edit text it should not edit.

Given a choice between me and my computer, I think my computer should be 
the one doing the hard work.

> 	However, this was a nice late-night exercise.

You are truly a most awesome dude.  Thank you.

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

* Re: [PATCH] teach diff machinery about --ignore-space-at-eol
  2007-02-14  0:30     ` [PATCH] teach diff machinery about --ignore-space-at-eol Johannes Schindelin
  2007-02-14  5:28       ` Timur Tabi
@ 2007-02-14 17:18       ` Timur Tabi
  1 sibling, 0 replies; 6+ messages in thread
From: Timur Tabi @ 2007-02-14 17:18 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Junio C Hamano, git

Johannes Schindelin wrote:
> `git diff --ignore-space-at-eol` will ignore whitespace at the
> line ends.
> 
> Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de>

This patch works great!  Oh git maintainer, please please please please apply 
this patch to the next version of git.  My descendants will sing praises to your 
glory for a thousand years.

-- 
Timur Tabi
Linux Kernel Developer @ Freescale

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

end of thread, other threads:[~2007-02-14 17:20 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-13 21:59 How do I get git-format-patch to ignore changes that remove spaces from the end of the line? Timur Tabi
2007-02-13 22:24 ` Junio C Hamano
2007-02-13 22:36   ` Timur Tabi
2007-02-14  0:30     ` [PATCH] teach diff machinery about --ignore-space-at-eol Johannes Schindelin
2007-02-14  5:28       ` Timur Tabi
2007-02-14 17:18       ` Timur Tabi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.