@@ -7,11 +7,9 @@ public class QueryStashes : Command
77 {
88 public QueryStashes ( string repo )
99 {
10- _boundary = $ "-----BOUNDARY_OF_COMMIT{ Guid . NewGuid ( ) } -----";
11-
1210 WorkingDirectory = repo ;
1311 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\" ";
1513 }
1614
1715 public List < Models . Stash > Result ( )
@@ -21,66 +19,57 @@ public QueryStashes(string repo)
2119 if ( ! rs . IsSuccess )
2220 return outs ;
2321
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 )
2824 {
29- var line = rs . StdOut . Substring ( start , end - start ) ;
25+ var current = new Models . Stash ( ) ;
3026
31- switch ( nextPartIdx )
27+ var nextPartIdx = 0 ;
28+ var start = 0 ;
29+ var end = item . IndexOf ( '\n ' , start ) ;
30+ while ( end > 0 && nextPartIdx < 4 )
3231 {
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+ }
5849
59- nextPartIdx = - 1 ;
50+ nextPartIdx ++ ;
51+
52+ start = end + 1 ;
53+ if ( start >= item . Length - 1 )
6054 break ;
61- }
6255
63- nextPartIdx ++ ;
56+ end = item . IndexOf ( '\n ' , start ) ;
57+ }
6458
65- start = end + 1 ;
66- if ( start >= rs . StdOut . Length - 1 )
67- break ;
59+ if ( start < item . Length )
60+ current . Message = item . Substring ( start ) ;
6861
69- end = rs . StdOut . IndexOf ( ' \n ' , start ) ;
62+ outs . Add ( current ) ;
7063 }
71-
7264 return outs ;
7365 }
7466
75- private void ParseParent ( string data )
67+ private void ParseParent ( string data , ref Models . Stash current )
7668 {
7769 if ( data . Length < 8 )
7870 return ;
7971
80- _current . Parents . AddRange ( data . Split ( separator : ' ' , options : StringSplitOptions . RemoveEmptyEntries ) ) ;
72+ current . Parents . AddRange ( data . Split ( separator : ' ' , options : StringSplitOptions . RemoveEmptyEntries ) ) ;
8173 }
82-
83- private Models . Stash _current = null ;
84- private readonly string _boundary ;
8574 }
8675}
0 commit comments