2009-06-16  Adam Barth  <abarth@webkit.org>

        Reviewed by Darin Alder.

        https://bugs.webkit.org/show_bug.cgi?id=26000

        Teach prepare-ChangeLog to match the line ends that are already present
        in ChangeLog files.  This helps folks whose use cygwin perl with CR LF
        line endings on Windows.

        Also, teach prepare-ChangeLog to normalize backslashes in paths.  This
        helps folks who use Windows SVN prepare correct ChangeLogs.

        * Scripts/prepare-ChangeLog:



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@44716 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebKitTools/ChangeLog b/WebKitTools/ChangeLog
index 5281123..79fc801 100644
--- a/WebKitTools/ChangeLog
+++ b/WebKitTools/ChangeLog
@@ -1 +1,16 @@
+2009-06-16  Adam Barth  <abarth@webkit.org>
+
+        Reviewed by Darin Alder.
+
+        https://bugs.webkit.org/show_bug.cgi?id=26000
+
+        Teach prepare-ChangeLog to match the line ends that are already present
+        in ChangeLog files.  This helps folks whose use cygwin perl with CR LF
+        line endings on Windows.
+
+        Also, teach prepare-ChangeLog to normalize backslashes in paths.  This
+        helps folks who use Windows SVN prepare correct ChangeLogs.
+
+        * Scripts/prepare-ChangeLog:
+
 == Rolled over to ChangeLog-2009-06-16 ==
diff --git a/WebKitTools/Scripts/prepare-ChangeLog b/WebKitTools/Scripts/prepare-ChangeLog
index 2c18643..23b01d4 100755
--- a/WebKitTools/Scripts/prepare-ChangeLog
+++ b/WebKitTools/Scripts/prepare-ChangeLog
@@ -86,6 +86,8 @@
 sub method_decl_to_selector($);
 sub processPaths(\@);
 sub reviewerAndDescriptionForGitCommit($);
+sub normalizeLineEndings($$);
+sub normalizePath($);
 
 # Project time zone for Cupertino, CA, US
 my $changeLogTimeZone = "PST8PDT";
@@ -300,28 +302,34 @@
     # to read it while we prepend to it later, but I like doing this part first.
     my @old_change_log = <OLD_CHANGE_LOG>;
     close OLD_CHANGE_LOG;
+    # We want to match the ChangeLog's line endings in case it doesn't match
+    # the native line endings for this version of perl.
+    my $endl = "\n";
+    if ($old_change_log[0] =~ /(\r?\n)/g) {
+        $endl = "$1";
+    }
     open CHANGE_LOG, "> ${changeLogPath}" or die "Could not write ${changeLogPath}\n.";
-    print CHANGE_LOG "$date  $name  <$email_address>\n\n";
+    print CHANGE_LOG normalizeLineEndings("$date  $name  <$email_address>\n\n", $endl);
 
     my ($reviewer, $description) = reviewerAndDescriptionForGitCommit($gitCommit) if $gitCommit;
     $reviewer = "NOBODY (OO" . "PS!)" if !$reviewer;
 
-    print CHANGE_LOG "        Reviewed by $reviewer.\n\n";
-    print CHANGE_LOG $description . "\n" if $description;
+    print CHANGE_LOG normalizeLineEndings("        Reviewed by $reviewer.\n\n", $endl);
+    print CHANGE_LOG normalizeLineEndings($description . "\n", $endl) if $description;
 
     if ($prefix =~ m/WebCore/ || `pwd` =~ m/WebCore/) {
         if ($didChangeRegressionTests) {
-            print CHANGE_LOG testListForChangeLog(sort @addedRegressionTests);
+            print CHANGE_LOG normalizeLineEndings(testListForChangeLog(sort @addedRegressionTests), $endl);
         } else {
-            print CHANGE_LOG "        WARNING: NO TEST CASES ADDED OR CHANGED\n\n";
+            print CHANGE_LOG normalizeLineEndings("        WARNING: NO TEST CASES ADDED OR CHANGED\n\n", $endl);
         }
     }
 
     foreach my $file (sort @{$files{$prefix}}) {
-        my $file_stem = substr $file, length $prefix;
-        print CHANGE_LOG "        * $file_stem:$function_lists{$file}\n";
+        my $file_stem = normalizePath(substr $file, length $prefix);
+        print CHANGE_LOG normalizeLineEndings("        * $file_stem:$function_lists{$file}\n", $endl);;
     }
-    print CHANGE_LOG "\n", @old_change_log;
+    print CHANGE_LOG normalizeLineEndings("\n", $endl), @old_change_log;
     close CHANGE_LOG;
 }
 
@@ -1452,3 +1460,17 @@
 
     return ($reviewer, $description);
 }
+
+sub normalizeLineEndings($$)
+{
+    my ($string, $endl) = @_;
+    $string =~ s/\r?\n/$endl/g;
+    return $string;
+}
+
+sub normalizePath($)
+{
+    my ($path) = @_;
+    $path =~ s/\\/\//g;
+    return $path;
+}