]> git.ipfire.org Git - thirdparty/libtool.git/commitdiff
bootstrap: always auto-add .gitignore files at the top.
authorBernhard Voelker <mail@bernhard-voelker.de>
Sat, 26 Jan 2013 05:50:04 +0000 (12:50 +0700)
committerGary V. Vaughan <gary@gnu.org>
Sat, 26 Jan 2013 05:54:44 +0000 (12:54 +0700)
* gl/build-aux/bootstrap.in (func_gitignore_entries): New function.
Strip comments and blank lines.
(func_insert_sorted_if_absent): Renamed...
(func_insert_if_absent): ...to this. Adjust all callers.
Instead of comparing the sorted new file with the original,
compare the line count, being careful to diagnose duplicate
entries which would otherwise skew the count.

Co-authored-by: Gary V. Vaughan <gary@gnu.org>
Signed-off-by: Gary V. Vaughan <gary@gnu.org>
bootstrap
gl/build-aux/bootstrap.in

index 9c7c01f0ee0d6885c033302f6de2e35424d0ee9d..44bc3281263038c150dd26d002274f4bc9d0b083 100755 (executable)
--- a/bootstrap
+++ b/bootstrap
@@ -2203,7 +2203,7 @@ test extract-trace = "$progname" && func_main "$@"
 # End:
 
 # Set a version string for *this* script.
-scriptversion=2012-10-21.12; # UTC
+scriptversion=2013-01-20.16; # UTC
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -3216,7 +3216,7 @@ func_require_build_aux ()
       func_show_eval "mkdir '$build_aux'"
 
       test -n "$vc_ignore_files" \
-          || func_insert_sorted_if_absent "$build_aux" $vc_ignore_files
+          || func_insert_if_absent "$build_aux" $vc_ignore_files
     fi
 
     require_build_aux=:
@@ -3437,7 +3437,7 @@ func_require_dotgitmodules ()
         } >> .gitmodules
 
         test -n "$vc_ignore_files" \
-          || func_insert_sorted_if_absent ".gitmodules" $vc_ignore_files
+          || func_insert_if_absent ".gitmodules" $vc_ignore_files
       }
     }
 
@@ -3772,7 +3772,7 @@ func_require_macro_dir ()
       mkdir "$macro_dir" || func_permissions_error "$macro_dir"
 
       test -n "$vc_ignore_files" \
-        || func_insert_sorted_if_absent "$macro_dir" $vc_ignore_files
+        || func_insert_if_absent "$macro_dir" $vc_ignore_files
     fi
 
     require_macro_dir=:
@@ -4320,11 +4320,25 @@ func_truncate_cmd ()
 }
 
 
-# func_insert_sorted_if_absent STR FILE...
-# ----------------------------------------
-# If $STR is not already on a line by itself in $FILE, insert it,
+# func_gitignore_entries FILE...
+# ------------------------------
+# Strip blank and comment lines to leave significant entries.
+func_gitignore_entries ()
+{
+    $debug_cmd
+
+    sed -e '/^#/d' -e '/^$/d' "$@"
+}
+
+
+# func_insert_if_absent STR FILE...
+# ---------------------------------
+# 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 whilelisting exceptions after a more generic blacklist pattern.
 # sorting the new contents of the file and replacing $FILE with the result.
-func_insert_sorted_if_absent ()
+func_insert_if_absent ()
 {
     $debug_cmd
 
@@ -4335,11 +4349,18 @@ func_insert_sorted_if_absent ()
     do
       test -f "$file" || touch "$file"
 
+      duplicate_entries=`func_gitignore_entries "$file" |sort |uniq -d`
+      test -n "$duplicate_entries" \
+          && func_error "duplicate entries in $file: " $duplicate_entries
+
       func_grep_q "$str" "$file" \
           && func_verbose "inserting '$str' into '$file'"
 
-      $bs_echo "$str" |sort -u - "$file" |func_cmp_s - "$file" \
-        || $bs_echo "$str" |sort -u - "$file" -o "$file" \
+      linesold=`func_gitignore_entries "$file" |wc -l`
+      linesnew=`$bs_echo "$str" \
+                |func_gitignore_entries - "$file" |sort -u |wc -l`
+      test $linesold -eq $linesnew \
+        || sed "1i\\$nl$str$nl" "$file" \
         || func_permissions_error "$file"
     done
 }
index a376ed41fc9b0dae00f86abe8fdbefb8b7fcb7e3..d9c7c27206d31d5c864d6763df2aeb2760c8f0aa 100755 (executable)
@@ -13,7 +13,7 @@
 . `echo "$0" |${SED-sed} 's|[^/]*$||'`"extract-trace"
 
 # Set a version string for *this* script.
-scriptversion=2012-10-21.12; # UTC
+scriptversion=2013-01-20.16; # UTC
 
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -1026,7 +1026,7 @@ func_require_build_aux ()
       func_show_eval "mkdir '$build_aux'"
 
       test -n "$vc_ignore_files" \
-          || func_insert_sorted_if_absent "$build_aux" $vc_ignore_files
+          || func_insert_if_absent "$build_aux" $vc_ignore_files
     fi
 
     require_build_aux=:
@@ -1247,7 +1247,7 @@ func_require_dotgitmodules ()
         } >> .gitmodules
 
         test -n "$vc_ignore_files" \
-          || func_insert_sorted_if_absent ".gitmodules" $vc_ignore_files
+          || func_insert_if_absent ".gitmodules" $vc_ignore_files
       }
     }
 
@@ -1582,7 +1582,7 @@ func_require_macro_dir ()
       mkdir "$macro_dir" || func_permissions_error "$macro_dir"
 
       test -n "$vc_ignore_files" \
-        || func_insert_sorted_if_absent "$macro_dir" $vc_ignore_files
+        || func_insert_if_absent "$macro_dir" $vc_ignore_files
     fi
 
     require_macro_dir=:
@@ -2130,11 +2130,25 @@ func_truncate_cmd ()
 }
 
 
-# func_insert_sorted_if_absent STR FILE...
-# ----------------------------------------
-# If $STR is not already on a line by itself in $FILE, insert it,
+# func_gitignore_entries FILE...
+# ------------------------------
+# Strip blank and comment lines to leave significant entries.
+func_gitignore_entries ()
+{
+    $debug_cmd
+
+    sed -e '/^#/d' -e '/^$/d' "$@"
+}
+
+
+# func_insert_if_absent STR FILE...
+# ---------------------------------
+# 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 whilelisting exceptions after a more generic blacklist pattern.
 # sorting the new contents of the file and replacing $FILE with the result.
-func_insert_sorted_if_absent ()
+func_insert_if_absent ()
 {
     $debug_cmd
 
@@ -2145,11 +2159,18 @@ func_insert_sorted_if_absent ()
     do
       test -f "$file" || touch "$file"
 
+      duplicate_entries=`func_gitignore_entries "$file" |sort |uniq -d`
+      test -n "$duplicate_entries" \
+          && func_error "duplicate entries in $file: " $duplicate_entries
+
       func_grep_q "$str" "$file" \
           && func_verbose "inserting '$str' into '$file'"
 
-      $bs_echo "$str" |sort -u - "$file" |func_cmp_s - "$file" \
-        || $bs_echo "$str" |sort -u - "$file" -o "$file" \
+      linesold=`func_gitignore_entries "$file" |wc -l`
+      linesnew=`$bs_echo "$str" \
+                |func_gitignore_entries - "$file" |sort -u |wc -l`
+      test $linesold -eq $linesnew \
+        || sed "1i\\$nl$str$nl" "$file" \
         || func_permissions_error "$file"
     done
 }