mirror of
https://https.git.savannah.gnu.org/git/diffutils.git
synced 2026-01-27 01:44:20 +00:00
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.
This commit is contained in:
parent
f2ad578b24
commit
53de393ca3
@ -33,6 +33,7 @@ extensions
|
||||
fcntl
|
||||
fdl
|
||||
file-type
|
||||
filenamecat
|
||||
fnmatch-gnu
|
||||
getopt
|
||||
gettext
|
||||
|
||||
2
gnulib
2
gnulib
@ -1 +1 @@
|
||||
Subproject commit 880f2b69df57af506439d6aaf1fe185a6f960e43
|
||||
Subproject commit 0c6cf5ab43555377b99d94febb2d6f23fc3d2cb0
|
||||
@ -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 *);
|
||||
|
||||
12
src/util.c
12
src/util.c
@ -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)
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
TESTS = \
|
||||
jESTS = \
|
||||
basic \
|
||||
binary \
|
||||
colliding-file-names \
|
||||
excess-slash \
|
||||
help-version \
|
||||
function-line-vs-leading-space \
|
||||
label-vs-func \
|
||||
|
||||
19
tests/excess-slash
Normal file
19
tests/excess-slash
Normal file
@ -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
|
||||
Loading…
x
Reference in New Issue
Block a user