diff mbox series

[v2,2/2] pretty: find pretty formats case-insensitively

Message ID 20240325072651.947505-2-brianmlyles@gmail.com (mailing list archive)
State Accepted
Commit f999d5188b4060aa0f784a6f4cf1574ea352a1e7
Headers show
Series pretty: find pretty formats case-insensitively | expand

Commit Message

Brian Lyles March 25, 2024, 7:25 a.m. UTC
User-defined pretty formats are stored in config, which is meant to use
case-insensitive matching for names as noted in config.txt's 'Syntax'
section:

    All the other lines [...] are recognized as setting variables, in
    the form 'name = value' [...]. The variable names are
    case-insensitive, [...].

When a user specifies one of their format aliases with an uppercase in
it, however, it is not found.

    $ git config pretty.testAlias %h
    $ git config --list | grep pretty
    pretty.testalias=%h
    $ git log --format=testAlias -1
    fatal: invalid --pretty format: testAlias
    $ git log --format=testalias -1
    3c2a3fdc38

This is true whether the name in the config file uses any uppercase
characters or not.

Use case-insensitive comparisons when identifying format aliases.

Co-authored-by: Jeff King <peff@peff.net>
Signed-off-by: Brian Lyles <brianmlyles@gmail.com>
---
 pretty.c                      | 2 +-
 t/t4205-log-pretty-formats.sh | 8 ++++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

Comments

Jeff King March 25, 2024, 9:46 a.m. UTC | #1
On Mon, Mar 25, 2024 at 02:25:13AM -0500, Brian Lyles wrote:

> Use case-insensitive comparisons when identifying format aliases.
> 
> Co-authored-by: Jeff King <peff@peff.net>
> Signed-off-by: Brian Lyles <brianmlyles@gmail.com>

Unsurprisingly, this one looks good to me. I don't know if I deserve a
co-author, but I am happy either way. :)

-Peff
Brian Lyles March 25, 2024, 3:58 p.m. UTC | #2
On Mon, Mar 25, 2024 at 4:46 AM Jeff King <peff@peff.net> wrote:

> On Mon, Mar 25, 2024 at 02:25:13AM -0500, Brian Lyles wrote:
> 
>> Use case-insensitive comparisons when identifying format aliases.
>> 
>> Co-authored-by: Jeff King <peff@peff.net>
>> Signed-off-by: Brian Lyles <brianmlyles@gmail.com>
> 
> Unsurprisingly, this one looks good to me. I don't know if I deserve a
> co-author, but I am happy either way. :)

Let's see, you... *Checks notes* handed me 100% of the fix logic and all
of the non-boilerplate parts of the new test on a silver platter.
Co-authored-by seems pretty accurate to me =).

Thanks for the review!
diff mbox series

Patch

diff --git a/pretty.c b/pretty.c
index cf964b060c..8c1092c790 100644
--- a/pretty.c
+++ b/pretty.c
@@ -147,7 +147,7 @@  static struct cmt_fmt_map *find_commit_format_recursive(const char *sought,
 	for (i = 0; i < commit_formats_len; i++) {
 		size_t match_len;
 
-		if (!starts_with(commit_formats[i].name, sought))
+		if (!istarts_with(commit_formats[i].name, sought))
 			continue;
 
 		match_len = strlen(commit_formats[i].name);
diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
index 20bba76c43..749363ccb8 100755
--- a/t/t4205-log-pretty-formats.sh
+++ b/t/t4205-log-pretty-formats.sh
@@ -58,6 +58,14 @@  test_expect_success 'alias user-defined format' '
 	test_cmp expected actual
 '
 
+test_expect_success 'alias user-defined format is matched case-insensitively' '
+	git log --pretty="format:%h" >expected &&
+	test_config pretty.testone "format:%h" &&
+	test_config pretty.testtwo testOne &&
+	git log --pretty=testTwo >actual &&
+	test_cmp expected actual
+'
+
 test_expect_success 'alias user-defined tformat with %s (ISO8859-1 encoding)' '
 	test_config i18n.logOutputEncoding $test_encoding &&
 	git log --oneline >expected-s &&