From nobody Fri Feb 18 15:55:27 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id B491219C723E; Fri, 18 Feb 2022 15:55:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4K0brJ4bV6z3ld9; Fri, 18 Feb 2022 15:55:28 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645199728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IDzKMZ1K7Ly5C648/7ikQRZDGq9ebyqh1VKFrP/YanA=; b=PjSeX+Luo30cP7hCSGWJO0/0qZMc9Kx+ebSMyV/JYmG29Q2vWcWS6vtMaFM0wUjoG+LQwD QIM28tk3HljUvJ/Cog0ESLI071lRJVVWjLq2fK92SWEaC9ul0+KbkfQK1iixguVi4AELF3 0D2YIfsZOeRkcsstiDlMO0RTCY48agdghIK+8NbLEJEf8T3JYSPgmvdQLUSqJkkotc7n+b aHJ35vckD+YLyIx61EBHhqP1/TNjRfCqjzcV8aGRaZHe5x2hVlVDH+mJk3IWAQFb8eO3vN ThpXIHeqnlH7piIAsaIcQhxhh/A0FcB3q+wwlZ8WFEWUndSgJFIE+VXQ2wVtUg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id EC7E720349; Fri, 18 Feb 2022 15:55:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 21IFtRi7058923; Fri, 18 Feb 2022 15:55:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21IFtRla058922; Fri, 18 Feb 2022 15:55:27 GMT (envelope-from git) Date: Fri, 18 Feb 2022 15:55:27 GMT Message-Id: <202202181555.21IFtRla058922@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Tom Jones Subject: git: 3931c072c63d - main - diff: fix failed compare when ignoring file case List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: thj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 3931c072c63d5a51d83157009e7f7510e08da80c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1645199728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=IDzKMZ1K7Ly5C648/7ikQRZDGq9ebyqh1VKFrP/YanA=; b=FKYOIDtKPvDAffZsV0bUZiFk4+Cb5ue0y6CAqH80EH/Q1cO4g+U3/GApburFj1ALL/5M2X Z09hVs7eULhkcYEyKArQ8qAsIqcdniVX7p6H4TUR46Aw2gtQ2lvL9HA80cO0aUapQPEbeg oOUOPm7OixUzyaslXjgVKApsFQtqDHCJDa+3jruMty+6hs/8aDjRCi2unE5VxQHHsZfOIn L/hEyZU8zfjg800DafMQYDhkfdBQjSoRpfdeRZpk6ahQO64ndH767bvuxTEvzFR9v1ik3Z admXUn6ioh+RXcO6HydKwHOqvq6we3MWMLCsewT9y86HdqgTi/sFbA+KQ4QbNg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1645199728; a=rsa-sha256; cv=none; b=Sdxfibx2Do0XtIAQu+iOTMi3h/21bHtgFb9MRmabzy+9YrO3b5RtuHnNlZqsedvczyf1P6 FRXFibwy6CybizoDVuXeuDBSlzvT4LvqnepwRv3p2PEAtDRX90hWZoo1BwU1L9tSUOQq1u xXxRmian0RCYMfzBCo6SJ947PgECCLbGBZn++aWP4ki2xxhRe0A18Yu9qI1KsIohve6Tyt t3snNstykpdNILjTzvS4ODNYed7Zy2WMejet5nsWOjtcc5OxJz2cs/fvOTVnIgfBiIG48S DK762kLwje2HHGZsBgm3fyxeqlKJBYL22W9WeNubptAm7VE2x7e6ObcqKT5RHQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by thj: URL: https://cgit.FreeBSD.org/src/commit/?id=3931c072c63d5a51d83157009e7f7510e08da80c commit 3931c072c63d5a51d83157009e7f7510e08da80c Author: Tom Jones AuthorDate: 2022-02-18 15:21:23 +0000 Commit: Tom Jones CommitDate: 2022-02-18 15:51:38 +0000 diff: fix failed compare when ignoring file case With --ignore-file-name-case we need to compare files regardless of case. We need to propigate both names down to diffit so we can look up the correct file when the names differ based on case, otherwise we try to look up the file using the case from the a tree which might not be discoverable if its case is different in the b tree. Reviewed by: bapt Sponsored by: Klara Inc. Differential Revision: https://reviews.freebsd.org/D34201 --- usr.bin/diff/diffdir.c | 27 ++++++++++++++++++--------- usr.bin/diff/tests/diff_test.sh | 13 +++++++++++++ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/usr.bin/diff/diffdir.c b/usr.bin/diff/diffdir.c index 527cd31a8c30..c5a32c217c36 100644 --- a/usr.bin/diff/diffdir.c +++ b/usr.bin/diff/diffdir.c @@ -38,7 +38,8 @@ __FBSDID("$FreeBSD$"); #include "diff.h" static int selectfile(const struct dirent *); -static void diffit(struct dirent *, char *, size_t, char *, size_t, int); +static void diffit(struct dirent *, char *, size_t, struct dirent *, + char *, size_t, int); static void print_only(const char *, size_t, const char *); #define d_status d_type /* we need to store status for -l */ @@ -128,14 +129,14 @@ diffdir(char *p1, char *p2, int flags) strcmp(dent1->d_name, dent2->d_name) ; if (pos == 0) { /* file exists in both dirs, diff it */ - diffit(dent1, path1, dirlen1, path2, dirlen2, flags); + diffit(dent1, path1, dirlen1, dent2, path2, dirlen2, flags); dp1++; dp2++; } else if (pos < 0) { /* file only in first dir, only diff if -N */ if (Nflag) { - diffit(dent1, path1, dirlen1, path2, dirlen2, - flags); + diffit(dent1, path1, dirlen1, dent2, path2, + dirlen2, flags); } else { print_only(path1, dirlen1, dent1->d_name); status |= 1; @@ -144,8 +145,8 @@ diffdir(char *p1, char *p2, int flags) } else { /* file only in second dir, only diff if -N or -P */ if (Nflag || Pflag) - diffit(dent2, path1, dirlen1, path2, dirlen2, - flags); + diffit(dent2, path1, dirlen1, dent1, path2, + dirlen2, flags); else { print_only(path2, dirlen2, dent2->d_name); status |= 1; @@ -171,12 +172,20 @@ closem: * Do the actual diff by calling either diffreg() or diffdir(). */ static void -diffit(struct dirent *dp, char *path1, size_t plen1, char *path2, size_t plen2, - int flags) +diffit(struct dirent *dp, char *path1, size_t plen1, struct dirent *dp2, + char *path2, size_t plen2, int flags) { flags |= D_HEADER; strlcpy(path1 + plen1, dp->d_name, PATH_MAX - plen1); - strlcpy(path2 + plen2, dp->d_name, PATH_MAX - plen2); + + /* + * If we are ignoring file case, use dent2s name here if both names are + * the same apart from case. + */ + if (ignore_file_case && strcasecmp(dp2->d_name, dp2->d_name) == 0) + strlcpy(path2 + plen2, dp2->d_name, PATH_MAX - plen2); + else + strlcpy(path2 + plen2, dp->d_name, PATH_MAX - plen2); if (noderef) { if (lstat(path1, &stb1) != 0) { diff --git a/usr.bin/diff/tests/diff_test.sh b/usr.bin/diff/tests/diff_test.sh index 91e43b570655..fa76c7ada3eb 100755 --- a/usr.bin/diff/tests/diff_test.sh +++ b/usr.bin/diff/tests/diff_test.sh @@ -21,6 +21,7 @@ atf_test_case non_regular_file atf_test_case binary atf_test_case functionname atf_test_case noderef +atf_test_case ignorecase simple_body() { @@ -324,6 +325,17 @@ noderef_body() atf_check -o inline:"Symbolic links A/test-file and B/test-file differ\n" -s exit:1 diff -r --no-dereference A B } +ignorecase_body() +{ + atf_check mkdir A + atf_check mkdir B + + atf_check -x "echo hello > A/foo" + atf_check -x "echo hello > B/FOO" + + atf_check -o empty -s exit:0 diff -u -r --ignore-file-name-case A B +} + atf_init_test_cases() { atf_add_test_case simple @@ -347,4 +359,5 @@ atf_init_test_cases() atf_add_test_case binary atf_add_test_case functionname atf_add_test_case noderef + atf_add_test_case ignorecase }