git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Jeff Hostetler via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Jeff Hostetler <jeffhostetler@github.com>,
	Jeff Hostetler <jeffhostetler@github.com>
Subject: [PATCH] sparse-index: pass string length to index_file_exists()
Date: Fri, 02 Feb 2024 18:04:54 +0000	[thread overview]
Message-ID: <pull.1649.git.1706897095273.gitgitgadget@gmail.com> (raw)

From: Jeff Hostetler <jeffhostetler@github.com>

The call to index_file_exists() in the loop in expand_to_path() passes
the wrong string length.  Let's fix that.

The loop in expand_to_path() searches the name-hash for each
sub-directory prefix in the provided pathname. That is, by searching
for "dir1/" then "dir1/dir2/" then "dir1/dir2/dir3/" and so on until
it finds a cache-entry representing a sparse directory.

The code creates "strbuf path_mutable" to contain the working pathname
and modifies the buffer in-place by temporarily replacing the character
following each successive "/" with NUL for the duration of the call to
index_file_exists().

It does not update the strbuf.len during this substitution.

Pass the patched length of the prefix path instead.

Signed-off-by: Jeff Hostetler <jeffhostetler@github.com>
---
    sparse-index: pass string length to index_file_exists()
    
    The call to index_file_exists() in the loop in expand_to_path() passes
    the wrong string length. Let's fix that.
    
    The loop in expand_to_path() searches the name-hash for each
    sub-directory prefix in the provided pathname. That is, by searching for
    "dir1/" then "dir1/dir2/" then "dir1/dir2/dir3/" and so on until it
    finds a cache-entry representing a sparse directory.
    
    The code creates "strbuf path_mutable" to contain the working pathname
    and modifies the buffer in-place by temporarily replacing the character
    following each successive "/" with NUL for the duration of the call to
    index_file_exists().
    
    It does not update the strbuf.len during this substitution.
    
    Pass the patched length of the prefix path instead.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1649%2Fjeffhostetler%2Fsparse-index-string-length-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1649/jeffhostetler/sparse-index-string-length-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1649

 sparse-index.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sparse-index.c b/sparse-index.c
index 1fdb07a9e69..093708f6220 100644
--- a/sparse-index.c
+++ b/sparse-index.c
@@ -579,8 +579,9 @@ void expand_to_path(struct index_state *istate,
 		replace++;
 		temp = *replace;
 		*replace = '\0';
+		substr_len = replace - path_mutable.buf;
 		if (index_file_exists(istate, path_mutable.buf,
-				      path_mutable.len, icase)) {
+				      substr_len, icase)) {
 			/*
 			 * We found a parent directory in the name-hash
 			 * hashtable, because only sparse directory entries
@@ -593,7 +594,6 @@ void expand_to_path(struct index_state *istate,
 		}
 
 		*replace = temp;
-		substr_len = replace - path_mutable.buf;
 	}
 
 cleanup:

base-commit: 43c8a30d150ecede9709c1f2527c8fba92c65f40
-- 
gitgitgadget

             reply	other threads:[~2024-02-02 18:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-02 18:04 Jeff Hostetler via GitGitGadget [this message]
2024-02-02 18:24 ` [PATCH] sparse-index: pass string length to index_file_exists() Junio C Hamano
2024-02-02 19:19   ` Jeff Hostetler
2024-02-02 19:30     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.1649.git.1706897095273.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jeffhostetler@github.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).