@@ -251,15 +251,11 @@ static void fill_sha1_path(struct strbuf *buf, const unsigned char *sha1)
251251 }
252252}
253253
254- const char * sha1_file_name (const unsigned char * sha1 )
254+ void sha1_file_name (struct strbuf * buf , const unsigned char * sha1 )
255255{
256- static struct strbuf buf = STRBUF_INIT ;
257-
258- strbuf_reset (& buf );
259- strbuf_addf (& buf , "%s/" , get_object_directory ());
256+ strbuf_addf (buf , "%s/" , get_object_directory ());
260257
261- fill_sha1_path (& buf , sha1 );
262- return buf .buf ;
258+ fill_sha1_path (buf , sha1 );
263259}
264260
265261struct strbuf * alt_scratch_buf (struct alternate_object_database * alt )
@@ -643,7 +639,12 @@ int check_and_freshen_file(const char *fn, int freshen)
643639
644640static int check_and_freshen_local (const unsigned char * sha1 , int freshen )
645641{
646- return check_and_freshen_file (sha1_file_name (sha1 ), freshen );
642+ static struct strbuf buf = STRBUF_INIT ;
643+
644+ strbuf_reset (& buf );
645+ sha1_file_name (& buf , sha1 );
646+
647+ return check_and_freshen_file (buf .buf , freshen );
647648}
648649
649650static int check_and_freshen_nonlocal (const unsigned char * sha1 , int freshen )
@@ -799,8 +800,12 @@ static int stat_sha1_file(const unsigned char *sha1, struct stat *st,
799800 const char * * path )
800801{
801802 struct alternate_object_database * alt ;
803+ static struct strbuf buf = STRBUF_INIT ;
804+
805+ strbuf_reset (& buf );
806+ sha1_file_name (& buf , sha1 );
807+ * path = buf .buf ;
802808
803- * path = sha1_file_name (sha1 );
804809 if (!lstat (* path , st ))
805810 return 0 ;
806811
@@ -824,8 +829,12 @@ static int open_sha1_file(const unsigned char *sha1, const char **path)
824829 int fd ;
825830 struct alternate_object_database * alt ;
826831 int most_interesting_errno ;
832+ static struct strbuf buf = STRBUF_INIT ;
833+
834+ strbuf_reset (& buf );
835+ sha1_file_name (& buf , sha1 );
836+ * path = buf .buf ;
827837
828- * path = sha1_file_name (sha1 );
829838 fd = git_open (* path );
830839 if (fd >= 0 )
831840 return fd ;
@@ -1487,9 +1496,12 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
14871496 git_SHA_CTX c ;
14881497 unsigned char parano_sha1 [20 ];
14891498 static struct strbuf tmp_file = STRBUF_INIT ;
1490- const char * filename = sha1_file_name (sha1 );
1499+ static struct strbuf filename = STRBUF_INIT ;
1500+
1501+ strbuf_reset (& filename );
1502+ sha1_file_name (& filename , sha1 );
14911503
1492- fd = create_tmpfile (& tmp_file , filename );
1504+ fd = create_tmpfile (& tmp_file , filename . buf );
14931505 if (fd < 0 ) {
14941506 if (errno == EACCES )
14951507 return error ("insufficient permission for adding an object to repository database %s" , get_object_directory ());
@@ -1542,7 +1554,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,
15421554 warning_errno ("failed utime() on %s" , tmp_file .buf );
15431555 }
15441556
1545- return finalize_object_file (tmp_file .buf , filename );
1557+ return finalize_object_file (tmp_file .buf , filename . buf );
15461558}
15471559
15481560static int freshen_loose_object (const unsigned char * sha1 )
0 commit comments