@@ -321,15 +321,11 @@ static void fill_sha1_path(struct strbuf *buf, const unsigned char *sha1)
321321 }
322322}
323323
324- const char * sha1_file_name (const unsigned char * sha1 )
324+ void sha1_file_name (struct strbuf * buf , const unsigned char * sha1 )
325325{
326- static struct strbuf buf = STRBUF_INIT ;
327-
328- strbuf_reset (& buf );
329- strbuf_addf (& buf , "%s/" , get_object_directory ());
330-
331- fill_sha1_path (& buf , sha1 );
332- return buf .buf ;
326+ strbuf_addstr (buf , get_object_directory ());
327+ strbuf_addch (buf , '/' );
328+ fill_sha1_path (buf , sha1 );
333329}
334330
335331struct strbuf * alt_scratch_buf (struct alternate_object_database * alt )
@@ -710,7 +706,12 @@ int check_and_freshen_file(const char *fn, int freshen)
710706
711707static int check_and_freshen_local (const unsigned char * sha1 , int freshen )
712708{
713- return check_and_freshen_file (sha1_file_name (sha1 ), freshen );
709+ static struct strbuf buf = STRBUF_INIT ;
710+
711+ strbuf_reset (& buf );
712+ sha1_file_name (& buf , sha1 );
713+
714+ return check_and_freshen_file (buf .buf , freshen );
714715}
715716
716717static int check_and_freshen_nonlocal (const unsigned char * sha1 , int freshen )
@@ -866,8 +867,12 @@ static int stat_sha1_file(const unsigned char *sha1, struct stat *st,
866867 const char * * path )
867868{
868869 struct alternate_object_database * alt ;
870+ static struct strbuf buf = STRBUF_INIT ;
871+
872+ strbuf_reset (& buf );
873+ sha1_file_name (& buf , sha1 );
874+ * path = buf .buf ;
869875
870- * path = sha1_file_name (sha1 );
871876 if (!lstat (* path , st ))
872877 return 0 ;
873878
@@ -891,8 +896,12 @@ static int open_sha1_file(const unsigned char *sha1, const char **path)
891896 int fd ;
892897 struct alternate_object_database * alt ;
893898 int most_interesting_errno ;
899+ static struct strbuf buf = STRBUF_INIT ;
900+
901+ strbuf_reset (& buf );
902+ sha1_file_name (& buf , sha1 );
903+ * path = buf .buf ;
894904
895- * path = sha1_file_name (sha1 );
896905 fd = git_open (* path );
897906 if (fd >= 0 )
898907 return fd ;
@@ -1572,9 +1581,12 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
15721581 git_SHA_CTX c ;
15731582 unsigned char parano_sha1 [20 ];
15741583 static struct strbuf tmp_file = STRBUF_INIT ;
1575- const char * filename = sha1_file_name (sha1 );
1584+ static struct strbuf filename = STRBUF_INIT ;
1585+
1586+ strbuf_reset (& filename );
1587+ sha1_file_name (& filename , sha1 );
15761588
1577- fd = create_tmpfile (& tmp_file , filename );
1589+ fd = create_tmpfile (& tmp_file , filename . buf );
15781590 if (fd < 0 ) {
15791591 if (errno == EACCES )
15801592 return error ("insufficient permission for adding an object to repository database %s" , get_object_directory ());
@@ -1627,7 +1639,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
16271639 warning_errno ("failed utime() on %s" , tmp_file .buf );
16281640 }
16291641
1630- return finalize_object_file (tmp_file .buf , filename );
1642+ return finalize_object_file (tmp_file .buf , filename . buf );
16311643}
16321644
16331645static int freshen_loose_object (const unsigned char * sha1 )
0 commit comments