On 01/11/2013 01:26 PM, Pádraig Brady wrote:
> 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

Thanks, that's right.
I've folded it in a more general form into the attached new
version of the patch, i.e. s/.gitignore/$file/g, together with
a "Improved-by" line:

+  duplicate_entries=$(sort $file | uniq -d)
+  if [ "$duplicate_entries" ] ; then
+    echo "Error: Duplicate entries in $file: " $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. A little merging will be necessary ... since the
introduction of warn+die in gnulib's bootstrap.

> 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.

Yes, that sounds like a cleaner solution, although the details
may be tricky, e.g. if a manual entry contradicts to an
automatically added one. Can this happen?

Have a nice day,
Berny


>From d65a0b870b0092e9e13c278e664073841f594e26 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <[email protected]>
Date: Fri, 11 Jan 2013 16:33:43 +0100
Subject: [PATCH 1/2] build: avoid unnecessary sorting of .gitignore
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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.
Before that, ensure that the given ignore file does not already
include duplicate entries. Otherwise, the above comparison would
fail.

Improved-by: Pádraig Brady
---
 bootstrap |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/bootstrap b/bootstrap
index 61a9cbd..87c001f 100755
--- a/bootstrap
+++ b/bootstrap
@@ -306,10 +306,18 @@ 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; } \
+  duplicate_entries=$(sort $file | uniq -d)
+  if [ "$duplicate_entries" ] ; then
+    echo "Error: Duplicate entries in $file: " $duplicate_entries >&2
+    exit 1
+  fi
+  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
-- 
1.7.7


>From 2cb00b980137c093560abdec34bdd9c25daf9364 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <[email protected]>
Date: Fri, 11 Jan 2013 09:14:22 +0100
Subject: [PATCH 2/2] maint: fix alphabetical order in .gitignore

Since commit v8.20-67-g0f525b6, .gitignore sometimes
showed up as changed because the entries "*.gcda" and
"*.gcno" had not been in alphabetical order.

* .gitignore: Exchange the entries "*.gcda" and "*.gcno".
---
 .gitignore |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/.gitignore b/.gitignore
index 67f428c..f0d6d87 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,8 +1,8 @@
 *.I[12]
 *.[EIOX]
 *.bak
-*.gcno
 *.gcda
+*.gcno
 *.o
 */.deps/
 *~
-- 
1.7.7

Reply via email to