Thanks for the feedback.  Here's a new patch against master.

Tim.
*/

From 456609a8adfc2b8335ce8233f0da2cc0d929e8a8 Mon Sep 17 00:00:00 2001
From: Tim Waugh <[email protected]>
Date: Fri, 12 Aug 2011 17:20:03 +0100
Subject: [PATCH] diff: apply --ignore-file-name-case even outside recursive
 directory traversal

* src/diff.c (find_dir_file_pathname): New function for finding a
matching filename in a directory.
* src/diff.h: Prototype for new function.
* src/dir.c: Use it.
---
 NEWS               |    4 ++++
 doc/diffutils.texi |    2 +-
 src/diff.c         |    2 +-
 src/diff.h         |    1 +
 src/dir.c          |   43 +++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 50 insertions(+), 2 deletions(-)

diff --git a/NEWS b/NEWS
index 42d9358..5a37963 100644
--- a/NEWS
+++ b/NEWS
@@ -2,6 +2,10 @@ GNU diffutils NEWS                                    -*- outline -*-
 
 * Noteworthy changes in release ?.? (????-??-??) [?]
 
+** Changes in behavior
+
+  The --ignore-file-name-case option now applies throughout and is not
+  limited to recursive directory traversal.
 
 * Noteworthy changes in release 3.1 (2011-08-10) [stable]
 
diff --git a/doc/diffutils.texi b/doc/diffutils.texi
index ee419a1..16ea6c9 100644
--- a/doc/diffutils.texi
+++ b/doc/diffutils.texi
@@ -3802,7 +3802,7 @@ Ignore changes that just insert or delete lines that match @var{regexp}.
 @xref{Specified Lines}.
 
 @item --ignore-file-name-case
-Ignore case when comparing file names during recursive comparison.
+Ignore case when comparing file names.
 @xref{Comparing Directories}.
 
 @item -l
diff --git a/src/diff.c b/src/diff.c
index 6a08f36..1e334b7 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -1170,7 +1170,7 @@ compare_files (struct comparison const *parent,
       char const *fnm = cmp.file[fnm_arg].name;
       char const *dir = cmp.file[dir_arg].name;
       char const *filename = cmp.file[dir_arg].name = free0
-	= file_name_concat (dir, last_component (fnm), NULL);
+	= find_dir_file_pathname (dir, last_component (fnm));
 
       if (STREQ (fnm, "-"))
 	fatal ("cannot compare `-' to a directory");
diff --git a/src/diff.h b/src/diff.h
index 88332a5..b1c90c7 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -327,6 +327,7 @@ extern void print_context_script (struct change *, bool);
 extern int diff_dirs (struct comparison const *,
                       int (*) (struct comparison const *,
                                char const *, char const *));
+char *find_dir_file_pathname (char const *, char const *);
 
 /* ed.c */
 extern void print_ed_script (struct change *);
diff --git a/src/dir.c b/src/dir.c
index 30bef2c..92eb8b4 100644
--- a/src/dir.c
+++ b/src/dir.c
@@ -21,6 +21,7 @@
 #include "diff.h"
 #include <error.h>
 #include <exclude.h>
+#include <filenamecat.h>
 #include <setjmp.h>
 #include <xalloc.h>
 
@@ -316,3 +317,45 @@ dir_loop (struct comparison const *cmp, int i)
       return true;
   return false;
 }
+
+/* Find a matching filename in a directory.  */
+
+char *
+find_dir_file_pathname (char const *dir, char const *file)
+{
+  char *val = NULL;
+
+  if (ignore_file_name_case)
+    {
+      bool locale_specific_sorting_saved = locale_specific_sorting;
+      struct file_data filedata;
+      struct dirdata dirdata;
+
+      filedata.name = dir;
+      filedata.desc = 0;
+      if (! dir_read (&filedata, &dirdata))
+	return NULL;
+
+      locale_specific_sorting = true;
+      if (setjmp (failed_locale_specific_sorting))
+	/* do nothing */ ;
+      else
+	for (char const **p = dirdata.names; *p; p++)
+	  if (compare_names (*p, file) == 0)
+	    {
+	      val = file_name_concat (dir, *p, NULL);
+	      break;
+	    }
+
+      locale_specific_sorting = locale_specific_sorting_saved;
+      free (dirdata.names);
+      free (dirdata.data);
+    }
+
+  if (val == NULL)
+    /* Return a filename even if there is no match so that we have
+       something to stat() and report an error about. */
+    val = file_name_concat (dir, file, NULL);
+
+  return val;
+}
-- 
1.7.6

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to