bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] bootstrap: remove the need for a sorted .gitignore


From: Bernhard Voelker
Subject: [PATCH] bootstrap: remove the need for a sorted .gitignore
Date: Sun, 20 Jan 2013 19:20:58 +0000

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_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.
Also ensure that the given ignore file does not already include
duplicate entries, as otherwise, the entry count would be innacurate.
(sort_patterns): Remove this now redundant function.
(gitignore_entries): A new function to return significant entries
from .gitignore.

Improved-by: Pádraig Brady
---
 ChangeLog           |   11 +++++++++++
 build-aux/bootstrap |   45 +++++++++++++++++++++++----------------------
 2 files changed, 34 insertions(+), 22 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 8218eb3..311abce 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2013-01-20  Bernhard Voelker  <address@hidden>
+
+       bootstrap: remove the need for a sorted .gitignore file
+       * build-aux/bootstrap (insert_sorted_if_absent): Adjust and
+       rename to insert_if_absent(), so that we don't need or generate
+       a sorted .gitignore file.  We do require a .gitignore with no
+       existing duplicate entries and enforce that.
+       (sort_patterns): Remove this function as we now use the simpler
+       technigue of inserting blacklist entries at the top of the file,
+       assuming gnulib won't be inserting !whitelist entries.
+
 2013-01-16  Paul Eggert  <address@hidden>
 
        unistd: port to recent mingw
diff --git a/build-aux/bootstrap b/build-aux/bootstrap
index 012907a..888145a 100755
--- a/build-aux/bootstrap
+++ b/build-aux/bootstrap
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Print a version string.
-scriptversion=2012-12-28.10; # UTC
+scriptversion=2013-01-20.16; # UTC
 
 # Bootstrap this package from checked-out sources.
 
@@ -306,34 +306,34 @@ if test -n "$checkout_only_file" && test ! -r 
"$checkout_only_file"; then
   die "Bootstrapping from a non-checked-out distribution is risky."
 fi
 
-# Ensure that lines starting with ! sort last, per gitignore conventions
-# for whitelisting exceptions after a more generic blacklist pattern.
-sort_patterns() {
-  sort -u "$@" | sed '/^!/ {
-    H
-    d
-  }
-  $ {
-    P
-    x
-    s/^\n//
-  }' | sed '/^$/d'
+# Strip blank and comment lines to leave significant entries.
+gitignore_entries() {
+  sed '/^#/d; /^$/d' "$@"
 }
 
-# If $STR is not already on a line by itself in $FILE, insert it,
-# sorting the new contents of the file and replacing $FILE with the result.
-insert_sorted_if_absent() {
+# If $STR is not already on a line by itself in $FILE, insert it at the start.
+# Entries are inserted at the start of the ignore list to ensure existing
+# entries starting with ! are not overridden.  Such entries support
+# whitelisting exceptions after a more generic blacklist pattern.
+insert_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; } \
-    || die "insert_sorted_if_absent $file $str: failed"
+  test -r $file || die "Error: failed to read ignore file: $file"
+  duplicate_entries=$(gitignore_entries $file | sort | uniq -d)
+  if [ "$duplicate_entries" ] ; then
+    die "Error: Duplicate entries in $file: " $duplicate_entries
+  fi
+  linesold=$(gitignore_entries $file | wc -l)
+  linesnew=$(echo "$str" | gitignore_entries - $file | sort -u | wc -l)
+  if [ $linesold != $linesnew ] ; then
+    { echo "$str" | cat - $file > $file.bak && mv $file.bak $file; } \
+      || die "insert_if_absent $file $str: failed"
+  fi
 }
 
 # Adjust $PATTERN for $VC_IGNORE_FILE and insert it with
-# insert_sorted_if_absent.
+# insert_if_absent.
 insert_vc_ignore() {
   vc_ignore_file="$1"
   pattern="$2"
@@ -344,7 +344,7 @@ insert_vc_ignore() {
     # .gitignore entry.
     pattern=$(echo "$pattern" | sed s,^,/,);;
   esac
-  insert_sorted_if_absent "$vc_ignore_file" "$pattern"
+  insert_if_absent "$vc_ignore_file" "$pattern"
 }
 
 # Die if there is no AC_CONFIG_AUX_DIR($build_aux) line in configure.ac.
@@ -356,6 +356,7 @@ grep '^[     ]*AC_CONFIG_AUX_DIR('"$build_aux"')' 
configure.ac \
 test $found_aux_dir = yes \
   || die "configure.ac lacks 'AC_CONFIG_AUX_DIR([$build_aux])'; add it"
 
+
 # If $build_aux doesn't exist, create it now, otherwise some bits
 # below will malfunction.  If creating it, also mark it as ignored.
 if test ! -d $build_aux; then
-- 
1.7.6.4




reply via email to

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