git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [JGIT PATCH 10/12] Match config subsection names using case sensitive search

From
CPConstantine Plotnikov <constantine.plotnikov@gmail.com>
Date
Jul 22, 2009, 11:11 UTC
Message-ID
<85647ef50907220411w356000bcuda21e9318eab094@mail.gmail.com>
In-Reply-To
<1248207570-13880-11-git-send-email-spearce@spearce.org>

This patch is incomplete. The method getRawEntry(...) and setStringList(...) should be fixed as part of this patch too. There is subsection is converted to lowercase. I was planning to submit it as separate patch.

Also I'm somewhat bothered by usage of toLowerCase() without locale specified and equalsIgnoreCase(). When turkish locale is default one there could be surprising results with the letter "I". The program:

import java.util.Locale;
public class Test {
	public static void main(String[] args) {
		Locale tr_TR = new Locale("tr", "TR");
		System.out.printf("i = U+%04x LC(I, tr_TR) = U+%04x\n", (int)'i',
(int)"I".toLowerCase(tr_TR).charAt(0));
		System.out.printf("I = U+%04x UC(i, tr_TR) = U+%04x\n", (int)'I',
(int)"i".toUpperCase(tr_TR).charAt(0));
	}
}
Gives the following output:

i = U+0069 LC(I, tr_TR) = U+0131 I = U+0049 UC(i, tr_TR) = U+0130

So I suggest to explicitly use Locale.US for all toLowerCase() invocation in Config class just in case and to replace equalsIgnoreCase() with something else. But this possibly should be some other patch series. I do not know what C git doing in case turkish locale and whether it is a bug or "feature".

Regards, Constantine

On Wed, Jul 22, 2009 at 12:19 AM, Shawn O. Pearce<spearce@spearce.org> wrote:
Show 59 quoted lines
> The subsection name is case sensitive, and should be matched as such.
>
> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
> ---
>  .../src/org/spearce/jgit/lib/Config.java           |   19 ++++++++++++++-----
>  1 files changed, 14 insertions(+), 5 deletions(-)
>
> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java
> index e379c37..974ffea 100644
> --- a/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java
> +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Config.java
> @@ -4,6 +4,7 @@
>  * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
>  * Copyright (C) 2008, Thad Hughes <thadh@thad.corp.google.com>
>  * Copyright (C) 2009, JetBrains s.r.o.
> + * Copyright (C) 2009, Google, Inc.
>  *
>  * All rights reserved.
>  *
> @@ -1024,17 +1025,25 @@ private static String readValue(final BufferedReader r, boolean quote,
>
>                boolean match(final String aSection, final String aSubsection,
>                                final String aKey) {
> -                       return eq(section, aSection) && eq(subsection, aSubsection)
> -                                       && eq(name, aKey);
> +                       return eqIgnoreCase(section, aSection)
> +                                       && eqSameCase(subsection, aSubsection)
> +                                       && eqIgnoreCase(name, aKey);
>                }
>
> -               private static boolean eq(final String a, final String b) {
> +               private static boolean eqIgnoreCase(final String a, final String b) {
>                        if (a == null && b == null)
>                                return true;
>                        if (a == null || b == null)
>                                return false;
>                        return a.equalsIgnoreCase(b);
>                }
> -       }
>
> -}
> \ No newline at end of file
> +               private static boolean eqSameCase(final String a, final String b) {
> +                       if (a == null && b == null)
> +                               return true;
> +                       if (a == null || b == null)
> +                               return false;
> +                       return a.equals(b);
> +               }
> +       }
> +}
> --
> 1.6.4.rc1.186.g60aa0c
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
Previous: Shawn O. PearceNext: Robin Rosenberg
Message 16 of 18 in “Cleanup Config class”
  1. 00/12 Cleanup Config classShawn O. Pearce, Jul 21, 2009
  2. 01/12 Use NB.readFully(File) to slurp complete file contentsShawn O. Pearce, Jul 21, 2009
  3. 02/12 Correct name of fileRead member of Config classShawn O. Pearce, Jul 21, 2009
  4. 03/12 Add setLong to ConfigShawn O. Pearce, Jul 21, 2009
  5. 04/12 Fix Config setInt(..., 0) to store "0" not "0 g"Shawn O. Pearce, Jul 21, 2009
  6. 05/12 Rename Config.unsetString to just unset()Shawn O. Pearce, Jul 21, 2009
  7. 06/12 Remove pointless null assignments in ConfigShawn O. Pearce, Jul 21, 2009
  8. 07/12 Clarify section and subsection values in Config codeShawn O. Pearce, Jul 21, 2009
  9. 08/12 Don't subclass PrintWriter when writing the ConfigShawn O. Pearce, Jul 21, 2009
  10. 09/12 Use a Java 5 style iteration over the Config entries listShawn O. Pearce, Jul 21, 2009
  11. 10/12 Match config subsection names using case sensitive searchShawn O. Pearce, Jul 21, 2009
  12. 11/12 Cleanup Config's MAGIC_EMPTY_VALUE to be more safeShawn O. Pearce, Jul 21, 2009
  13. 12/12 Remove unreferenced REMOTE_SECTION from RepositoryConfigShawn O. Pearce, Jul 21, 2009
  14. Robin RosenbergJul 21, 2009
  15. Shawn O. PearceJul 21, 2009
  16. Constantine PlotnikovJul 22, 2009
  17. Robin RosenbergJul 22, 2009
  18. Ensure Config readers handle case insensitive names correctlyShawn O. Pearce, Jul 24, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.