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

Re: [JGIT PATCH 1/1] Fix for Repository.stripWorkDir when using partial paths

From
Robin Rosenberg <robin.rosenberg.lists@dewire.com>
Date
Aug 12, 2009, 19:47 UTC
Message-ID
<200908122147.52530.robin.rosenberg.lists@dewire.com>
In-Reply-To
<4A821167.6030107@writeme.com>
onsdag 12 augusti 2009 02:48:39 skrev "Adam W. Hawks" <awhawks@writeme.com>:
Show 28 quoted lines
> 
> From ef993e633cdcb1dddda5e71db1b62306df7ce83f Mon Sep 17 00:00:00 2001
> Date: Tue, 11 Aug 2009 20:02:56 -0400
> 
> When you call stripWorkDir with a relative path
> you can get a string out of bounds error.
> 
> This change fixes that problem by using the absolute paths
> of the file instead of its relative name.
> 
> Signed-off-by: Adam W. Hawks <awhawks@writeme.com>
> ---
>  .../src/org/spearce/jgit/lib/Repository.java       |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
> 
> diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
> index 468cf4c..a68817b 100644
> --- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
> +++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
> @@ -1036,7 +1036,7 @@ public static boolean isValidRefName(final String refName) {
>  	 * @return normalized repository relative path
>  	 */
>  	public static String stripWorkDir(File wd, File f) {
> -		String relName = f.getPath().substring(wd.getPath().length() + 1);
> +		String relName = f.getAbsolutePath().substring(wd.getPath().length() + 1);
>  		relName = relName.replace(File.separatorChar, '/');
>  		return relName;
>  	}

Why not convert both paths? A trickier issue is that getAbsolutePath is very slow when the path is not absolute. I don't think we will always need to normalize in order to fix this. A few unit tests to show the cases solved would help.

-- robin
Previous: Shawn O. PearceNext: Jonas Fonseca
Message 3 of 4 in “Fix for Repository.stripWorkDir when using partial paths”
  1. 1/1 Fix for Repository.stripWorkDir when using partial pathsAdam W. Hawks, Aug 12, 2009
  2. Shawn O. PearceAug 12, 2009
  3. Robin RosenbergAug 12, 2009
  4. Make Repository.stripWorkDir more robustJonas Fonseca, Aug 19, 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.