File tree Expand file tree Collapse file tree 1 file changed +15
-15
lines changed Expand file tree Collapse file tree 1 file changed +15
-15
lines changed Original file line number Diff line number Diff line change @@ -29,20 +29,15 @@ char *gitbasename (char *path)
29
29
30
30
char * gitdirname (char * path )
31
31
{
32
- char * p = path , * after_slash = NULL , c ;
32
+ static struct strbuf buf = STRBUF_INIT ;
33
+ char * p = path , * slash = NULL , c ;
33
34
int dos_drive_prefix ;
34
35
35
36
if (!p )
36
37
return "." ;
37
38
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 ;
46
41
47
42
/*
48
43
* POSIX.1-2001 says dirname("/") should return "/", and dirname("//")
@@ -51,7 +46,7 @@ char *gitdirname(char *path)
51
46
if (is_dir_sep (* p )) {
52
47
if (!p [1 ] || (is_dir_sep (p [1 ]) && !p [2 ]))
53
48
return path ;
54
- after_slash = ++ p ;
49
+ slash = ++ p ;
55
50
}
56
51
while ((c = * (p ++ )))
57
52
if (is_dir_sep (c )) {
@@ -61,11 +56,16 @@ char *gitdirname(char *path)
61
56
while (is_dir_sep (* p ))
62
57
p ++ ;
63
58
if (* p )
64
- after_slash = tentative ;
59
+ slash = tentative ;
65
60
}
66
61
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 ;
71
71
}
You can’t perform that action at this time.
0 commit comments