diff options
author | Tim Waugh <twaugh@redhat.com> | 2011-08-13 13:16:32 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2011-08-13 13:17:40 -0700 |
commit | 70febebfe5215674079dc1c65ad966f5e404d2a8 (patch) | |
tree | 12abac9fb168a50cdaa819f131a6504bda4fdba3 | |
parent | e3001b775aa8a3e7e30651b0f59d401ac4fe419d (diff) | |
download | diffutils-70febebfe5215674079dc1c65ad966f5e404d2a8.tar.gz |
diff: --ignore-file-name-case now applies at top level too
Derived from Tim Waugh's patch in:
http://lists.gnu.org/archive/html/bug-diffutils/2011-08/msg00034.html
* NEWS, doc/diffutils.texi (diff Options): Document this.
* src/diff.c (compare_files): Implement this, by using
find_dir_file_pathname.
* src/diff.h (find_dir_file_pathname): New decl.
* src/dir.c: Include filenamecat.h.
(find_dir_file_pathname): New function.
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | doc/diffutils.texi | 5 | ||||
-rw-r--r-- | src/diff.c | 2 | ||||
-rw-r--r-- | src/diff.h | 1 | ||||
-rw-r--r-- | src/dir.c | 46 |
5 files changed, 56 insertions, 2 deletions
@@ -2,6 +2,10 @@ GNU diffutils NEWS -*- outline -*- * Noteworthy changes in release ?.? (????-??-??) [?] +** Changes in behavior + + --ignore-file-name-case now applies at the top level too. + For example, "diff dir inIt" might compare "dir/Init" to "inIt". * Noteworthy changes in release 3.1 (2011-08-10) [stable] diff --git a/doc/diffutils.texi b/doc/diffutils.texi index ee419a1..f29e9a1 100644 --- a/doc/diffutils.texi +++ b/doc/diffutils.texi @@ -3802,7 +3802,10 @@ 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. For example, recursive +comparison of @file{d} to @file{e} might compare the contents of +@file{d/Init} and @file{e/inIt}. At the top level, @samp{diff d inIt} +might compare the contents of @file{d/Init} and @file{inIt}. @xref{Comparing Directories}. @item -l @@ -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"); @@ -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 *); @@ -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,48 @@ 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; + char const *match = file; + struct dirdata dirdata; + dirdata.names = NULL; + dirdata.data = NULL; + + if (ignore_file_name_case) + { + struct file_data filedata; + filedata.name = dir; + filedata.desc = 0; + + if (dir_read (&filedata, &dirdata)) + { + locale_specific_sorting = true; + if (setjmp (failed_locale_specific_sorting)) + match = file; /* longjmp may mess up MATCH. */ + else + { + for (char const **p = dirdata.names; *p; p++) + if (compare_names (*p, file) == 0) + { + if (file_name_cmp (*p, file) == 0) + { + match = *p; + break; + } + if (match == file) + match = *p; + } + } + } + } + + val = file_name_concat (dir, match, NULL); + free (dirdata.names); + free (dirdata.data); + return val; +} |