coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] maint: fix alphabetical order in .gitignore


From: Pádraig Brady
Subject: Re: [PATCH] maint: fix alphabetical order in .gitignore
Date: Fri, 11 Jan 2013 12:26:57 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:13.0) Gecko/20120615 Thunderbird/13.0.1

On 01/11/2013 08:47 AM, Bernhard Voelker wrote:
On 01/02/2013 04:02 PM, Bernhard Voelker wrote:
If insert_vc_ignore is the only place where .gitignore
is sorted, why not fix it there, i.e. use some way to
add an entry without sorting the file?

I found out that bootstrap tries to add the just-generated
file "ABOUT-NLS" to .gitignore - which is already there.

But today, insert_sorted_if_absent() changes .gitignore
not only when the given entry is missing, but even if just
the ordering would change.

The following patch changes this behavior, and now
insert_sorted_if_absent() only adds the entry - well, sorted
again - only if the line count would change.

The second patch fixes the sorting of current .gitignore
(as in my initial patch).

WDYT?

Have a nice day,
Berny


From 99c50676d4109e767926e9aa766e6e536dd3a716 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <address@hidden>
Date: Fri, 11 Jan 2013 09:12:31 +0100
Subject: [PATCH 1/2] build: avoid unnecessary sorting of .gitignore

During bootstrap, files may be created which are already included
in .gitignore, but the test to add such a file relied on the
sort order. Now, it just adds such a new entry and thus only
changes the file if the line count would change.

* bootstrap (insert_sorted_if_absent): Instead of comparing the
sorted new file with the original, the function compares the line
count, and only in case of a difference, the given file is changed.
---
  bootstrap |    9 ++++++---
  1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/bootstrap b/bootstrap
index 61a9cbd..e00639b 100755
--- a/bootstrap
+++ b/bootstrap
@@ -306,10 +306,13 @@ insert_sorted_if_absent() {
    file=$1
    str=$2
    test -f $file || touch $file
-  echo "$str" | sort_patterns - $file | cmp -s - $file > /dev/null \
-    || { echo "$str" | sort_patterns - $file > $file.bak \
-      && mv $file.bak $file; } \
+  linesold=$(wc -l < $file)
+  linesnew=$(echo "$str" | sort_patterns - $file | wc -l)
+  if [ $linesold != $linesnew ] ; then
+    { echo "$str" | sort_patterns - $file > $file.bak \
+    && mv $file.bak $file; } \
      || exit 1
+  fi
  }

  # Adjust $PATTERN for $VC_IGNORE_FILE and insert it with


Thanks for following this up.

One issue is if there were existing duplicate entries
in .gitignore, then the counts would be inaccurate.
That might be guarded with something like:

  duplicate_entries=$(sort .gitignore | uniq -d)
  if [ "$duplicate_entries" ] ; then
    echo "Error: Duplicate entries in .gitignore: " $duplicate_entries >&2
    exit 1
  fi

BTW changes to bootstrap go through gnulib first
and are synced from there, so when this is sorted
(no pun intended) I'll propose it to gnulib too.

thanks,
Pádraig.

p.s. While this removes the sorted requirement, it still
sorts the file on insertion. That's not a new restriction
but it does mess up/preclude the use of comments and separator
lines in .gitignore. In future it might be better to
auto generate something like this at the top of .gitignore:

## Inserted by bootstrap ##
entry1
blank_line_after_last_entry

To do that, you'd also have to remove existing
entries in .gitignore corresponding to the above section.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]