bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] bootstrap: preserve git whitelist item sorting


From: Eric Blake
Subject: [PATCH] bootstrap: preserve git whitelist item sorting
Date: Tue, 5 Apr 2011 13:55:20 -0600

In .gitignore, it is handy to do:

/m4/*
!/m4/file.m4

to whitelist just file.m4 while ignoring all other files.  But
! sorts too early.

* build-aux/bootstrap (sort_patterns): New function.
(insert_sorted_if_absent): Use it to float ! lines to the bottom.
---
 build-aux/bootstrap |   21 ++++++++++++++++++---
 1 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/build-aux/bootstrap b/build-aux/bootstrap
index f004ad3..707b491 100755
--- a/build-aux/bootstrap
+++ b/build-aux/bootstrap
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Print a version string.
-scriptversion=2011-03-03.12; # UTC
+scriptversion=2011-04-05.18; # UTC

 # Bootstrap this package from checked-out sources.

@@ -278,14 +278,29 @@ if test -n "$checkout_only_file" && test ! -r 
"$checkout_only_file"; then
   exit 1
 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//
+  }'
+}
+
 # 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() {
   file=$1
   str=$2
   test -f $file || touch $file
-  echo "$str" | sort -u - $file | cmp - $file > /dev/null \
-    || echo "$str" | sort -u - $file -o $file \
+  echo "$str" | sort_patterns - $file | cmp - $file > /dev/null \
+    || { echo "$str" | sort_patterns - $file > $file.bak \
+      && mv $file.bak $file; } \
     || exit 1
 }

-- 
1.7.4




reply via email to

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