From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4B0931426C for ; Wed, 13 Mar 2024 15:04:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710342259; cv=none; b=urCAaXbs2bHKENmq/UGpWgTH18iiMX8d1XxlJ4HABG3oEX1y5XhKGvtdLPi4NlxlheQ34tntbahAK9MrZKJwgKfMq+cJ33h8MKuSZqbhqCVVnbRdHsTSL6to0+1TFQqPhzurHosvRfowG27iUmGEamDLdJU2Eu631ACLSm9zGeg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710342259; c=relaxed/simple; bh=o3coeDSBloE//wjpcqJCFIJnt8QfxBCASJ0OPrRsY3Q=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=mB6/01zTC52xyYxnunsXvZSm4cTZe5ROnkYwlCGDwTa/2nwSHTT/uWxiHFb57Rq8I48pCF7KGyCS0EbHIJX1L4VeIMbY75gOEaHYzzg8wu7HWQ+QQZgrHBZ/FOAzPVomI03dyfw/pfrUjzyqsCHRWr7TJYfOLfggbDw+IMSGZ9M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=C94YOnwA; arc=none smtp.client-ip=209.85.167.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="C94YOnwA" Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-512f3e75391so5314135e87.2 for ; Wed, 13 Mar 2024 08:04:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710342255; x=1710947055; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:reply-to:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=yNWjuJwQgu7EpBXvSb727AhYfGaywNhdQ/qY2F9vTMo=; b=C94YOnwAtsdExDblwyNjhzip+lvfTK+Mbb5vpE2OGsLPWkaRz0TP4m2agLo4zoTCwS glmNaUJi/dyRxIBXYJXB3GW3ZUuxT839k0MJmBA1Is2Ww6U6gGhCv/KQ/bMAWnFeE7pI onyzjQ1ZPXpvEBlID86TfX068md2Vd/W4dHkrsDHkL7PlrjRdf99b8KzDRIz/NIl6e+f iJagctKGaEFV321Rwt1hqvaoQKTj2h+zglknf3KJvhtnTZPouM8b8qBxQeT//XirgUHB rhWrypVcfHssxVPAfv3UrWILy7BS/5CPEZoYAe5aJfGj96Lo3OADuby43kkU8213P/Eq HlQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710342255; x=1710947055; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:reply-to:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yNWjuJwQgu7EpBXvSb727AhYfGaywNhdQ/qY2F9vTMo=; b=v6YhksRY7XnyypqBvJw5s4ybi3it+R2jTtw54IQepBlGJKdwm5J055KDJkE9ZjXWJi DF4N7XIiHiv8XYABZG/eYzCjmAp5dGysZ/Lztkv9WrL0AGmXOWaO2NozbxT7Pi5sYG5u sMRlrtSvp6dCtJVEV4aSL1D3E8s1W8oGJPWX6TWa0Qhh75E7diFI2OTx1gH3pcTh8twh D+mDDi/lDGRV2OqDeFiewD6LbmsNbkfVyt2IME+IEQ7YpWS3mt+1eNPoJqI6F6DbmeVv m+Tc95uyZhMssff32bo6gFqBXcJxO1OhCsOEeTbmhx3uGT3bl+AGILgIZkJCjC4O1Q8P d3yg== X-Forwarded-Encrypted: i=1; AJvYcCUgIXxT/ERZNwAyVineNF/tuA2k3utyYaD7ReTOH9rHVlxKNgCzC2w2ettiaW1TbwyTK4CChcWvSTC9X8OxjJgbDibp X-Gm-Message-State: AOJu0YxOJgu/mmuHTaqmDmSUbqRKKKZDZ9N5K1oTmO2s8+zxi8BJ1TCH KrbUfn4ZL0D4jfLLh72V/Z7RnPyuMCR5lVOAlymwwT68BYLiGtYdWW0HLcO4 X-Google-Smtp-Source: AGHT+IHBHYg9YY8ehIqcTCCnVeVpS/MfCzQBDStQnUEplr5/kDnK1mLqRLmncrcE1FUqrSTWaN4XGA== X-Received: by 2002:ac2:5a01:0:b0:513:def:9c8a with SMTP id q1-20020ac25a01000000b005130def9c8amr3396348lfn.69.1710342255105; Wed, 13 Mar 2024 08:04:15 -0700 (PDT) Received: from ?IPV6:2a0a:ef40:6a5:fd01:2d60:4cd4:e8ec:b443? ([2a0a:ef40:6a5:fd01:2d60:4cd4:e8ec:b443]) by smtp.gmail.com with ESMTPSA id u9-20020a05600c138900b00412f2136793sm2551791wmf.44.2024.03.13.08.04.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 Mar 2024 08:04:14 -0700 (PDT) Message-ID: Date: Wed, 13 Mar 2024 15:04:14 +0000 Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Reply-To: phillip.wood@dunelm.org.uk Subject: Re: [PATCH v3] diff: add diff.srcPrefix and diff.dstPrefix configuration variables Content-Language: en-US To: Peter Hutterer , git@vger.kernel.org Cc: Junio C Hamano , David Heidelberg , Dragan Simic References: <20240312231559.GA116605@quokka> From: Phillip Wood In-Reply-To: <20240312231559.GA116605@quokka> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Hi Peter On 12/03/2024 23:15, Peter Hutterer wrote: > Allow the default prefixes "a/" and "b/" to be tweaked by the > diff.srcprefix and diff.dstprefix configuration variables. > > Signed-off-by: Peter Hutterer > --- > Changes to v2; > - doc: change to camelcase diff.srcPrefix/diff.dstPrefix for > consistency with diff.mnemonicPrefix and most other options > - git diff --default-prefix forces a/ and b/ regardless of configured > prefix, see the 'diff_opt_default_prefix' hunk in the patch below. > > The latter may be slightly controversial but: there are scripts out > there that rely on the a/ and b/ prefix (came across one last night). > With a custom prefix those scripts will break, having an option that > forces the a/ and b/ prefix helps. Plus the man page explicitly says: > Use the default source and destination prefixes ("a/" and "b/"). > So let's stick with that behaviour then. As I understand it the purpose of --default-prefix is to override all the prefix related config settings so this seems like a very sensible choice. Best Wishes Phillip > Documentation/config/diff.txt | 6 ++++++ > diff.c | 14 ++++++++++++-- > t/t4013-diff-various.sh | 35 +++++++++++++++++++++++++++++++++++ > 3 files changed, 53 insertions(+), 2 deletions(-) > > diff --git a/Documentation/config/diff.txt b/Documentation/config/diff.txt > index 6c7e09a1ef5e..afc23d7723b6 100644 > --- a/Documentation/config/diff.txt > +++ b/Documentation/config/diff.txt > @@ -111,6 +111,12 @@ diff.mnemonicPrefix:: > diff.noprefix:: > If set, 'git diff' does not show any source or destination prefix. > > +diff.srcPrefix:: > + If set, 'git diff' uses this source prefix. Defaults to 'a/'. > + > +diff.dstPrefix:: > + If set, 'git diff' uses this destination prefix. Defaults to 'b/'. > + > diff.relative:: > If set to 'true', 'git diff' does not show changes outside of the directory > and show pathnames relative to the current directory. > diff --git a/diff.c b/diff.c > index e50def45383e..108c1875775d 100644 > --- a/diff.c > +++ b/diff.c > @@ -62,6 +62,8 @@ static const char *diff_order_file_cfg; > int diff_auto_refresh_index = 1; > static int diff_mnemonic_prefix; > static int diff_no_prefix; > +static const char *diff_src_prefix = "a/"; > +static const char *diff_dst_prefix = "b/"; > static int diff_relative; > static int diff_stat_name_width; > static int diff_stat_graph_width; > @@ -408,6 +410,12 @@ int git_diff_ui_config(const char *var, const char *value, > diff_no_prefix = git_config_bool(var, value); > return 0; > } > + if (!strcmp(var, "diff.srcprefix")) { > + return git_config_string(&diff_src_prefix, var, value); > + } > + if (!strcmp(var, "diff.dstprefix")) { > + return git_config_string(&diff_dst_prefix, var, value); > + } > if (!strcmp(var, "diff.relative")) { > diff_relative = git_config_bool(var, value); > return 0; > @@ -3425,8 +3433,8 @@ void diff_set_noprefix(struct diff_options *options) > > void diff_set_default_prefix(struct diff_options *options) > { > - options->a_prefix = "a/"; > - options->b_prefix = "b/"; > + options->a_prefix = diff_src_prefix; > + options->b_prefix = diff_dst_prefix; > } > > struct userdiff_driver *get_textconv(struct repository *r, > @@ -5362,6 +5370,8 @@ static int diff_opt_default_prefix(const struct option *opt, > > BUG_ON_OPT_NEG(unset); > BUG_ON_OPT_ARG(optarg); > + diff_src_prefix = "a/"; > + diff_dst_prefix = "b/"; > diff_set_default_prefix(options); > return 0; > } > diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh > index 1e3b2dbea484..e75f9f7d4cb2 100755 > --- a/t/t4013-diff-various.sh > +++ b/t/t4013-diff-various.sh > @@ -663,6 +663,41 @@ test_expect_success 'diff --default-prefix overrides diff.mnemonicprefix' ' > check_prefix actual a/file0 b/file0 > ' > > +test_expect_success 'diff respects diff.srcprefix' ' > + git -c diff.srcprefix=x/ diff >actual && > + check_prefix actual x/file0 b/file0 > +' > + > +test_expect_success 'diff respects diff.dstprefix' ' > + git -c diff.dstprefix=y/ diff >actual && > + check_prefix actual a/file0 y/file0 > +' > + > +test_expect_success 'diff --src-prefix overrides diff.srcprefix' ' > + git -c diff.srcprefix=z/ diff --src-prefix=z/ >actual && > + check_prefix actual z/file0 b/file0 > +' > + > +test_expect_success 'diff --dst-prefix overrides diff.dstprefix' ' > + git -c diff.dstprefix=y/ diff --dst-prefix=z/ >actual && > + check_prefix actual a/file0 z/file0 > +' > + > +test_expect_success 'diff src/dstprefix ignored with diff.noprefix' ' > + git -c diff.dstprefix=y/ -c diff.srcprefix=x/ -c diff.noprefix diff >actual && > + check_prefix actual file0 file0 > +' > + > +test_expect_success 'diff src/dstprefix ignored with diff.mnemonicprefix' ' > + git -c diff.dstprefix=x/ -c diff.srcprefix=y/ -c diff.mnemonicprefix diff >actual && > + check_prefix actual i/file0 w/file0 > +' > + > +test_expect_success 'diff src/dstprefix ignored with --default-prefix' ' > + git -c diff.dstprefix=x/ -c diff.srcprefix=y/ diff --default-prefix >actual && > + check_prefix actual a/file0 b/file0 > +' > + > test_expect_success 'diff --no-renames cannot be abbreviated' ' > test_expect_code 129 git diff --no-rename >actual 2>error && > test_must_be_empty actual &&