1
- using System . Collections . Generic ;
1
+ using System ;
2
+ using System . Collections . Generic ;
2
3
using System . Text ;
3
4
using System . Text . RegularExpressions ;
4
5
5
6
namespace SourceGit . Commands
6
7
{
7
8
public partial class QuerySubmodules : Command
8
9
{
9
- [ GeneratedRegex ( @"^[U\-\+ ][0-9a-f]+\s(.*)\s\(.*\)$" ) ]
10
- private static partial Regex REG_FORMAT1 ( ) ;
11
- [ GeneratedRegex ( @"^[U\-\+ ][0-9a-f]+\s(.*)$" ) ]
12
- private static partial Regex REG_FORMAT2 ( ) ;
13
- [ GeneratedRegex ( @"^\s?[\w\?]{1,4}\s+(.+)$" ) ]
10
+ [ GeneratedRegex ( @"^([U\-\+ ])([0-9a-f]+)\s(.*?)(\s\(.*\))?$" ) ]
14
11
private static partial Regex REG_FORMAT_STATUS ( ) ;
12
+ [ GeneratedRegex ( @"^\s?[\w\?]{1,4}\s+(.+)$" ) ]
13
+ private static partial Regex REG_FORMAT_DIRTY ( ) ;
15
14
16
15
public QuerySubmodules ( string repo )
17
16
{
@@ -25,49 +24,65 @@ public QuerySubmodules(string repo)
25
24
var submodules = new List < Models . Submodule > ( ) ;
26
25
var rs = ReadToEnd ( ) ;
27
26
28
- var builder = new StringBuilder ( ) ;
29
- var lines = rs . StdOut . Split ( [ ' \r ' , ' \n ' ] , System . StringSplitOptions . RemoveEmptyEntries ) ;
27
+ var lines = rs . StdOut . Split ( [ ' \r ' , ' \n ' ] , StringSplitOptions . RemoveEmptyEntries ) ;
28
+ var needCheckLocalChanges = new Dictionary < string , Models . Submodule > ( ) ;
30
29
foreach ( var line in lines )
31
30
{
32
- var match = REG_FORMAT1 ( ) . Match ( line ) ;
31
+ var match = REG_FORMAT_STATUS ( ) . Match ( line ) ;
33
32
if ( match . Success )
34
33
{
35
- var path = match . Groups [ 1 ] . Value ;
36
- builder . Append ( $ "\" { path } \" ") ;
37
- submodules . Add ( new Models . Submodule ( ) { Path = path } ) ;
38
- continue ;
39
- }
34
+ var stat = match . Groups [ 1 ] . Value ;
35
+ var sha = match . Groups [ 2 ] . Value ;
36
+ var path = match . Groups [ 3 ] . Value ;
40
37
41
- match = REG_FORMAT2 ( ) . Match ( line ) ;
42
- if ( match . Success )
43
- {
44
- var path = match . Groups [ 1 ] . Value ;
45
- builder . Append ( $ "\" { path } \" ") ;
46
- submodules . Add ( new Models . Submodule ( ) { Path = path } ) ;
38
+ var module = new Models . Submodule ( ) { Path = path , SHA = sha } ;
39
+ switch ( stat [ 0 ] )
40
+ {
41
+ case '-' :
42
+ module . Status = Models . SubmoduleStatus . NotInited ;
43
+ break ;
44
+ case '+' :
45
+ module . Status = Models . SubmoduleStatus . RevisionChanged ;
46
+ break ;
47
+ case 'U' :
48
+ module . Status = Models . SubmoduleStatus . Unmerged ;
49
+ break ;
50
+ default :
51
+ module . Status = Models . SubmoduleStatus . Normal ;
52
+ needCheckLocalChanges . Add ( path , module ) ;
53
+ break ;
54
+ }
55
+
56
+ submodules . Add ( module ) ;
47
57
}
48
58
}
49
59
50
- if ( submodules . Count > 0 )
60
+ if ( needCheckLocalChanges . Count > 0 )
51
61
{
62
+ var builder = new StringBuilder ( ) ;
63
+ foreach ( var kv in needCheckLocalChanges )
64
+ {
65
+ builder . Append ( '"' ) ;
66
+ builder . Append ( kv . Key ) ;
67
+ builder . Append ( "\" " ) ;
68
+ }
69
+
52
70
Args = $ "--no-optional-locks status -uno --porcelain -- { builder } ";
53
71
rs = ReadToEnd ( ) ;
54
72
if ( ! rs . IsSuccess )
55
73
return submodules ;
56
74
57
- var dirty = new HashSet < string > ( ) ;
58
- lines = rs . StdOut . Split ( [ '\r ' , '\n ' ] , System . StringSplitOptions . RemoveEmptyEntries ) ;
75
+ lines = rs . StdOut . Split ( [ '\r ' , '\n ' ] , StringSplitOptions . RemoveEmptyEntries ) ;
59
76
foreach ( var line in lines )
60
77
{
61
- var match = REG_FORMAT_STATUS ( ) . Match ( line ) ;
78
+ var match = REG_FORMAT_DIRTY ( ) . Match ( line ) ;
62
79
if ( match . Success )
63
80
{
64
81
var path = match . Groups [ 1 ] . Value ;
65
- dirty . Add ( path ) ;
82
+ if ( needCheckLocalChanges . TryGetValue ( path , out var m ) )
83
+ m . Status = Models . SubmoduleStatus . Modified ;
66
84
}
67
85
}
68
-
69
- foreach ( var submodule in submodules )
70
- submodule . IsDirty = dirty . Contains ( submodule . Path ) ;
71
86
}
72
87
73
88
return submodules ;
0 commit comments