@@ -1964,7 +1964,6 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
1964
1964
origlen = path -> len ;
1965
1965
strbuf_complete (path , '/' );
1966
1966
strbuf_addf (path , "%02x" , subdir_nr );
1967
- baselen = path -> len ;
1968
1967
1969
1968
dir = opendir (path -> buf );
1970
1969
if (!dir ) {
@@ -1975,15 +1974,18 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
1975
1974
}
1976
1975
1977
1976
oid .hash [0 ] = subdir_nr ;
1977
+ strbuf_addch (path , '/' );
1978
+ baselen = path -> len ;
1978
1979
1979
1980
while ((de = readdir (dir ))) {
1981
+ size_t namelen ;
1980
1982
if (is_dot_or_dotdot (de -> d_name ))
1981
1983
continue ;
1982
1984
1985
+ namelen = strlen (de -> d_name );
1983
1986
strbuf_setlen (path , baselen );
1984
- strbuf_addf (path , "/%s" , de -> d_name );
1985
-
1986
- if (strlen (de -> d_name ) == GIT_SHA1_HEXSZ - 2 &&
1987
+ strbuf_add (path , de -> d_name , namelen );
1988
+ if (namelen == GIT_SHA1_HEXSZ - 2 &&
1987
1989
!hex_to_bytes (oid .hash + 1 , de -> d_name ,
1988
1990
GIT_SHA1_RAWSZ - 1 )) {
1989
1991
if (obj_cb ) {
@@ -2002,7 +2004,7 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
2002
2004
}
2003
2005
closedir (dir );
2004
2006
2005
- strbuf_setlen (path , baselen );
2007
+ strbuf_setlen (path , baselen - 1 );
2006
2008
if (!r && subdir_cb )
2007
2009
r = subdir_cb (subdir_nr , path -> buf , data );
2008
2010
0 commit comments