@@ -7,11 +7,9 @@ public class QueryStashes : Command
7
7
{
8
8
public QueryStashes ( string repo )
9
9
{
10
- _boundary = $ "-----BOUNDARY_OF_COMMIT{ Guid . NewGuid ( ) } -----";
11
-
12
10
WorkingDirectory = repo ;
13
11
Context = repo ;
14
- Args = $ "stash list -- no-show-signature --format=\" %H%n%P%n%ct%n%gd%n%B%n { _boundary } \" ";
12
+ Args = $ "stash list -z -- no-show-signature --format=\" %H%n%P%n%ct%n%gd%n%B\" ";
15
13
}
16
14
17
15
public List < Models . Stash > Result ( )
@@ -21,66 +19,57 @@ public QueryStashes(string repo)
21
19
if ( ! rs . IsSuccess )
22
20
return outs ;
23
21
24
- var nextPartIdx = 0 ;
25
- var start = 0 ;
26
- var end = rs . StdOut . IndexOf ( '\n ' , start ) ;
27
- while ( end > 0 )
22
+ var items = rs . StdOut . Split ( '\0 ' , System . StringSplitOptions . RemoveEmptyEntries ) ;
23
+ foreach ( var item in items )
28
24
{
29
- var line = rs . StdOut . Substring ( start , end - start ) ;
25
+ var current = new Models . Stash ( ) ;
30
26
31
- switch ( nextPartIdx )
27
+ var nextPartIdx = 0 ;
28
+ var start = 0 ;
29
+ var end = item . IndexOf ( '\n ' , start ) ;
30
+ while ( end > 0 && nextPartIdx < 4 )
32
31
{
33
- case 0 :
34
- _current = new Models . Stash ( ) { SHA = line } ;
35
- outs . Add ( _current ) ;
36
- break ;
37
- case 1 :
38
- ParseParent ( line ) ;
39
- break ;
40
- case 2 :
41
- _current . Time = ulong . Parse ( line ) ;
42
- break ;
43
- case 3 :
44
- _current . Name = line ;
45
- break ;
46
- default :
47
- var boundary = rs . StdOut . IndexOf ( _boundary , end + 1 , StringComparison . Ordinal ) ;
48
- if ( boundary > end )
49
- {
50
- _current . Message = rs . StdOut . Substring ( start , boundary - start - 1 ) ;
51
- end = boundary + _boundary . Length ;
52
- }
53
- else
54
- {
55
- _current . Message = rs . StdOut . Substring ( start ) ;
56
- end = rs . StdOut . Length - 2 ;
57
- }
32
+ var line = item . Substring ( start , end - start ) ;
33
+
34
+ switch ( nextPartIdx )
35
+ {
36
+ case 0 :
37
+ current . SHA = line ;
38
+ break ;
39
+ case 1 :
40
+ ParseParent ( line , ref current ) ;
41
+ break ;
42
+ case 2 :
43
+ current . Time = ulong . Parse ( line ) ;
44
+ break ;
45
+ case 3 :
46
+ current . Name = line ;
47
+ break ;
48
+ }
58
49
59
- nextPartIdx = - 1 ;
50
+ nextPartIdx ++ ;
51
+
52
+ start = end + 1 ;
53
+ if ( start >= item . Length - 1 )
60
54
break ;
61
- }
62
55
63
- nextPartIdx ++ ;
56
+ end = item . IndexOf ( '\n ' , start ) ;
57
+ }
64
58
65
- start = end + 1 ;
66
- if ( start >= rs . StdOut . Length - 1 )
67
- break ;
59
+ if ( start < item . Length )
60
+ current . Message = item . Substring ( start ) ;
68
61
69
- end = rs . StdOut . IndexOf ( ' \n ' , start ) ;
62
+ outs . Add ( current ) ;
70
63
}
71
-
72
64
return outs ;
73
65
}
74
66
75
- private void ParseParent ( string data )
67
+ private void ParseParent ( string data , ref Models . Stash current )
76
68
{
77
69
if ( data . Length < 8 )
78
70
return ;
79
71
80
- _current . Parents . AddRange ( data . Split ( separator : ' ' , options : StringSplitOptions . RemoveEmptyEntries ) ) ;
72
+ current . Parents . AddRange ( data . Split ( separator : ' ' , options : StringSplitOptions . RemoveEmptyEntries ) ) ;
81
73
}
82
-
83
- private Models . Stash _current = null ;
84
- private readonly string _boundary ;
85
74
}
86
75
}
0 commit comments