diff options
author | Jim Meyering <meyering@redhat.com> | 2010-08-14 17:13:28 -0500 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2010-08-14 17:15:57 -0500 |
commit | 53de393ca335e77f22d3789100734c87868f12b3 (patch) | |
tree | ee89c725bed3856568395d3260d3ad33d40c5231 | |
parent | f2ad578b241713fa81d98b3573fa42397d2ea3f8 (diff) | |
download | diffutils-53de393ca335e77f22d3789100734c87868f12b3.tar.gz |
diff -r: avoid printing excess slashes in concatenated file names
* bootstrap.conf (gnulib_modules): Add filenamecat.
* src/diff.c: Include "filenamecat.h".
(compare_files): Use file_name_concat, rather than dir_file_pathname.
* src/util.c (dir_file_pathname): Remove now-unused function.
* src/diff.h: Remove its declaration.
* tests/excess-slash: New script to test for this.
* tests/Makefile.am (TESTS): Add it.
Forwarded by Santiago Vila from <bugs.debian.org/586301a>,
reported by Jari Aalto.
-rw-r--r-- | bootstrap.conf | 1 | ||||
m--------- | gnulib | 0 | ||||
-rw-r--r-- | src/diff.c | 7 | ||||
-rw-r--r-- | src/diff.h | 1 | ||||
-rw-r--r-- | src/util.c | 12 | ||||
-rw-r--r-- | tests/Makefile.am | 3 | ||||
-rw-r--r-- | tests/excess-slash | 19 |
7 files changed, 26 insertions, 17 deletions
diff --git a/bootstrap.conf b/bootstrap.conf index 2f104b3..ea1744c 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -33,6 +33,7 @@ extensions fcntl fdl file-type +filenamecat fnmatch-gnu getopt gettext diff --git a/gnulib b/gnulib -Subproject 880f2b69df57af506439d6aaf1fe185a6f960e4 +Subproject 0c6cf5ab43555377b99d94febb2d6f23fc3d2cb @@ -27,6 +27,7 @@ #include <error.h> #include <exclude.h> #include <exitfail.h> +#include <filenamecat.h> #include <file-type.h> #include <fnmatch.h> #include <getopt.h> @@ -1067,9 +1068,9 @@ compare_files (struct comparison const *parent, else { cmp.file[0].name = free0 - = dir_file_pathname (parent->file[0].name, name0); + = file_name_concat (parent->file[0].name, name0, NULL); cmp.file[1].name = free1 - = dir_file_pathname (parent->file[1].name, name1); + = file_name_concat (parent->file[1].name, name1, NULL); } /* Stat the files. */ @@ -1156,7 +1157,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 - = dir_file_pathname (dir, last_component (fnm)); + = file_name_concat (dir, last_component (fnm), NULL); if (STREQ (fnm, "-")) fatal ("cannot compare `-' to a directory"); @@ -349,7 +349,6 @@ void print_sdiff_script (struct change *); extern char const change_letter[4]; extern char const pr_program[]; char *concat (char const *, char const *, char const *); -char *dir_file_pathname (char const *, char const *); bool lines_differ (char const *, char const *); lin translate_line_number (struct file_data const *, lin); struct change *find_change (struct change *); @@ -756,18 +756,6 @@ zalloc (size_t size) memset (p, 0, size); return p; } - -/* Yield the newly malloc'd pathname - of the file in DIR whose filename is FILE. */ - -char * -dir_file_pathname (char const *dir, char const *file) -{ - char const *base = last_component (dir); - size_t baselen = base_len (base); - bool omit_slash = baselen == 0 || base[baselen - 1] == '/'; - return concat (dir, "/" + omit_slash, file); -} void debug_script (struct change *sp) diff --git a/tests/Makefile.am b/tests/Makefile.am index 242d501..190f16a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,7 +1,8 @@ -TESTS = \ +jESTS = \ basic \ binary \ colliding-file-names \ + excess-slash \ help-version \ function-line-vs-leading-space \ label-vs-func \ diff --git a/tests/excess-slash b/tests/excess-slash new file mode 100644 index 0000000..3ef34cc --- /dev/null +++ b/tests/excess-slash @@ -0,0 +1,19 @@ +#!/bin/sh +# Ensure that no excess slash appears in diff -r output. + +: ${srcdir=.} +. "$srcdir/init.sh"; path_prepend_ ../src + +mkdir -p a/f b/f/g || framework_failure_ +echo Only in b/f: g > expected-out || framework_failure_ + +fail=0 + +diff -r a b/ > out 2> err && fail=1 + +# expect no stderr +compare err /dev/null || fail=1 + +compare out expected-out || fail=1 + +Exit $fail |