# HG changeset patch # User Eric Blake # Date 1302033200 21600 # Node ID b2ba0843de1050f8df84d3856b226d42f521382b # Parent 8e0176455a01f9b8dc7f143a54690bc5128074f3 bootstrap: preserve git whitelist item sorting 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 sink ! lines to the bottom. diff -r 8e0176455a01 -r b2ba0843de10 ChangeLog --- a/ChangeLog Tue Apr 05 22:32:17 2011 +0200 +++ b/ChangeLog Tue Apr 05 13:53:20 2011 -0600 @@ -1,3 +1,9 @@ +2011-04-05 Eric Blake + + bootstrap: preserve git whitelist item sorting + * build-aux/bootstrap (sort_patterns): New function. + (insert_sorted_if_absent): Use it to sink ! lines to the bottom. + 2011-04-05 Simon Josefsson * top/maint.mk (sc_prohibit_empty_lines_at_EOF): Don't trigger diff -r 8e0176455a01 -r b2ba0843de10 build-aux/bootstrap --- a/build-aux/bootstrap Tue Apr 05 22:32:17 2011 +0200 +++ b/build-aux/bootstrap Tue Apr 05 13:53:20 2011 -0600 @@ -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 @@ 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 }