# 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
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=:
} >> .gitmodules
test -n "$vc_ignore_files" \
- || func_insert_sorted_if_absent ".gitmodules" $vc_ignore_files
+ || func_insert_if_absent ".gitmodules" $vc_ignore_files
}
}
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=:
}
-# 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
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
}
. `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
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=:
} >> .gitmodules
test -n "$vc_ignore_files" \
- || func_insert_sorted_if_absent ".gitmodules" $vc_ignore_files
+ || func_insert_if_absent ".gitmodules" $vc_ignore_files
}
}
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=:
}
-# 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
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
}