On 01/02/2013 04:02 PM, Bernhard Voelker wrote:
If insert_vc_ignore is the only place where .gitignore
is sorted, why not fix it there, i.e. use some way to
add an entry without sorting the file?
I found out that bootstrap tries to add the just-generated
file "ABOUT-NLS" to .gitignore - which is already there.
But today, insert_sorted_if_absent() changes .gitignore
not only when the given entry is missing, but even if just
the ordering would change.
The following patch changes this behavior, and now
insert_sorted_if_absent() only adds the entry - well, sorted
again - only if the line count would change.
The second patch fixes the sorting of current .gitignore
(as in my initial patch).
WDYT?
Have a nice day,
Berny
From 99c50676d4109e767926e9aa766e6e536dd3a716 Mon Sep 17 00:00:00 2001
From: Bernhard Voelker <address@hidden>
Date: Fri, 11 Jan 2013 09:12:31 +0100
Subject: [PATCH 1/2] build: avoid unnecessary sorting of .gitignore
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_sorted_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.
---
bootstrap | 9 ++++++---
1 files changed, 6 insertions(+), 3 deletions(-)
diff --git a/bootstrap b/bootstrap
index 61a9cbd..e00639b 100755
--- a/bootstrap
+++ b/bootstrap
@@ -306,10 +306,13 @@ insert_sorted_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; } \
+ linesold=$(wc -l < $file)
+ linesnew=$(echo "$str" | sort_patterns - $file | wc -l)
+ if [ $linesold != $linesnew ] ; then
+ { echo "$str" | sort_patterns - $file > $file.bak \
+ && mv $file.bak $file; } \
|| exit 1
+ fi
}
# Adjust $PATTERN for $VC_IGNORE_FILE and insert it with