@@ -1964,7 +1964,6 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
19641964 origlen = path -> len ;
19651965 strbuf_complete (path , '/' );
19661966 strbuf_addf (path , "%02x" , subdir_nr );
1967- baselen = path -> len ;
19681967
19691968 dir = opendir (path -> buf );
19701969 if (!dir ) {
@@ -1975,15 +1974,18 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
19751974 }
19761975
19771976 oid .hash [0 ] = subdir_nr ;
1977+ strbuf_addch (path , '/' );
1978+ baselen = path -> len ;
19781979
19791980 while ((de = readdir (dir ))) {
1981+ size_t namelen ;
19801982 if (is_dot_or_dotdot (de -> d_name ))
19811983 continue ;
19821984
1985+ namelen = strlen (de -> d_name );
19831986 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 &&
19871989 !hex_to_bytes (oid .hash + 1 , de -> d_name ,
19881990 GIT_SHA1_RAWSZ - 1 )) {
19891991 if (obj_cb ) {
@@ -2002,7 +2004,7 @@ int for_each_file_in_obj_subdir(unsigned int subdir_nr,
20022004 }
20032005 closedir (dir );
20042006
2005- strbuf_setlen (path , baselen );
2007+ strbuf_setlen (path , baselen - 1 );
20062008 if (!r && subdir_cb )
20072009 r = subdir_cb (subdir_nr , path -> buf , data );
20082010
0 commit comments