File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -29,20 +29,15 @@ char *gitbasename (char *path)
2929
3030char * gitdirname (char * path )
3131{
32- char * p = path , * after_slash = NULL , c ;
32+ static struct strbuf buf = STRBUF_INIT ;
33+ char * p = path , * slash = NULL , c ;
3334 int dos_drive_prefix ;
3435
3536 if (!p )
3637 return "." ;
3738
38- if ((dos_drive_prefix = skip_dos_drive_prefix (& p )) && !* p ) {
39- static struct strbuf buf = STRBUF_INIT ;
40-
41- dot :
42- strbuf_reset (& buf );
43- strbuf_addf (& buf , "%.*s." , dos_drive_prefix , path );
44- return buf .buf ;
45- }
39+ if ((dos_drive_prefix = skip_dos_drive_prefix (& p )) && !* p )
40+ goto dot ;
4641
4742 /*
4843 * POSIX.1-2001 says dirname("/") should return "/", and dirname("//")
@@ -51,7 +46,7 @@ char *gitdirname(char *path)
5146 if (is_dir_sep (* p )) {
5247 if (!p [1 ] || (is_dir_sep (p [1 ]) && !p [2 ]))
5348 return path ;
54- after_slash = ++ p ;
49+ slash = ++ p ;
5550 }
5651 while ((c = * (p ++ )))
5752 if (is_dir_sep (c )) {
@@ -61,11 +56,16 @@ char *gitdirname(char *path)
6156 while (is_dir_sep (* p ))
6257 p ++ ;
6358 if (* p )
64- after_slash = tentative ;
59+ slash = tentative ;
6560 }
6661
67- if (!after_slash )
68- goto dot ;
69- * after_slash = '\0' ;
70- return path ;
62+ if (slash ) {
63+ * slash = '\0' ;
64+ return path ;
65+ }
66+
67+ dot :
68+ strbuf_reset (& buf );
69+ strbuf_addf (& buf , "%.*s." , dos_drive_prefix , path );
70+ return buf .buf ;
7171}
You can’t perform that action at this time.
0 commit comments