@@ -72,89 +72,84 @@ Method ConsumeStream() [ Private ]
72
72
73
73
Method Resolve () [ Private ]
74
74
{
75
- // If we got this far, ..productionClassname is a subclass of Ens.Production and ..productionFile is its file within the git root.
76
- Set code = 0
77
- Set code = code + ##class (SourceControl.Git.Utils ).RunGitCommand (" show" ,,.base ," :1:" _..productionFile )
78
- Set code = code + ##class (SourceControl.Git.Utils ).RunGitCommand (" show" ,,.ours ," :2:" _..productionFile )
79
- Set code = code + ##class (SourceControl.Git.Utils ).RunGitCommand (" show" ,,.theirs ," :3:" _..productionFile )
80
-
81
- If code > 0 {
82
- $$$ThrowStatus($$$ERROR($$$GeneralError," Unable to load base/ours/theirs for " _..productionFile ))
83
- }
75
+ Set filePath = ##class (SourceControl.Git.Utils ).TempFolder ()_..productionFile
76
+ Set file = ##class (%Stream.FileCharacter ).%OpenId (filePath ,,.sc )
77
+ $$$ThrowOnError(sc )
84
78
85
- Do ..ClassToXMLDoc (base ,.baseDoc )
86
- Do ..ClassToXMLDoc (ours ,.oursDoc )
87
- Do ..ClassToXMLDoc (theirs ,.theirsDoc )
79
+ Do ..ResolveStream (file ) // Throws exception on failure
88
80
89
- Do ..ThreeWayMerge (baseDoc ,oursDoc ,theirsDoc ,.resolved )
81
+ $$$ThrowOnError(##class (SourceControl.Git.Utils ).ImportItem (..productionClassname _" .CLS" ,1 ))
82
+ $$$ThrowOnError($System .OBJ .Compile (..productionClassname ," ck" ))
90
83
91
- Do ..XMLDocToClass (resolved )
84
+ // TODO: if we add multiple resolvers, move this to the end.
85
+ set code = ##class (SourceControl.Git.Utils ).RunGitWithArgs (.errStream , .outStream , " add" , ..productionFile )
86
+ if (code '= 0 ) {
87
+ $$$ThrowStatus($$$ERROR($$$GeneralError," git add reported failure" ))
88
+ }
89
+ set code = ##class (SourceControl.Git.Utils ).RunGitWithArgs (.errStream , .outStream , " commit" , " -m" , " Auto-resolved conflict on production class" )
90
+ if (code '= 0 ) {
91
+ $$$ThrowStatus($$$ERROR($$$GeneralError," git commit reported failure" ))
92
+ }
93
+ set code = ##class (SourceControl.Git.Utils ).RunGitWithArgs (.errStream , .outStream , " rebase" , " --continue" )
94
+ if (code '= 0 ) {
95
+ $$$ThrowStatus($$$ERROR($$$GeneralError," git rebase --continue reported failure" ))
96
+ }
97
+
98
+ Set ..resolved = 1
92
99
}
93
100
94
- Method ClassToXMLDoc (source As %Stream .Object , Output doc As %XML .Document )
101
+ /// Non-private to support unit testing
102
+ ClassMethod ResolveStream (stream As %Stream .Object )
95
103
{
96
- Set sc = $$$OK
97
- Kill ^||%oddDEF
98
- Set ^||%oddDEF (..productionClassname )=" "
99
- Try {
100
- Do source .Rewind ()
101
- While 'source .AtEnd {
102
- Set tTextArray ($Increment (tTextArray (0 ))) = source .ReadLine (,.sc )
103
- $$$ThrowOnError(sc )
104
+ // File may have:
105
+ /*
106
+ <<<<<<< HEAD
107
+ <Item Name="Demo7" Category="" ClassName="EnsLib.CloudStorage.BusinessOperation" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
108
+ =======
109
+ <Item Name="Demo5" Category="" ClassName="EnsLib.AmazonCloudWatch.MetricAlarmOperation" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
110
+ >>>>>>> 607d1f6 (modified src/HCC/Connect/Production.cls add Demo5)
111
+ </Item>
112
+ */
113
+
114
+ // If:
115
+ // * We have one such marker (<<<<<<< / ======= / >>>>>>>)
116
+ // * The line after >>>>>> is "</Item>"
117
+ // Then:
118
+ // * We can replace ======= with "</Item>"
119
+
120
+ Set copy = ##class (%Stream.TmpCharacter ).%New ()
121
+ Set markerCount = 0
122
+ Set postCloseMarker = 0
123
+ While 'stream .AtEnd {
124
+ Set line = stream .ReadLine ()
125
+ Set start = $Extract (line ,1 ,7 )
126
+ If start = " <<<<<<<" {
127
+ Set markerCount = markerCount + 1
128
+ Continue
129
+ } ElseIf (start = " >>>>>>>" ) {
130
+ Set postCloseMarker = 1
131
+ Continue
132
+ } ElseIf (start = " =======" ) {
133
+ Do copy .WriteLine (" </Item>" )
134
+ Continue
135
+ } ElseIf postCloseMarker {
136
+ If $ZStrip (line ," <>W" ) '= " </Item>" {
137
+ $$$ThrowStatus($$$ERROR($$$GeneralError," The type of conflict encountered is not handled; user must resolve manually." ))
138
+ }
139
+ Set postCloseMarker = 0
104
140
}
105
- $$$ThrowOnError(##class (%Atelier.v1.Utils.TextServices ).SetTextFromArray (.tTextArray ,,..productionClassname ," CLS" ))
106
- Merge classDef = ^||%oddDEF (..productionClassname )
107
-
108
- Set xmlStream = ##class (%Stream.TmpCharacter ).%New ()
109
- For i =1 :1 :$Get (classDef ($$$cCLASSxdata," ProductionDefinition" ,$$$cXDATAdata)) {
110
- Do xmlStream .WriteLine ($Get (classDef ($$$cCLASSxdata," ProductionDefinition" ,$$$cXDATAdata,i )))
111
- }
112
- Set reader = ##class (%XML.Reader ).%New ()
113
- $$$ThrowOnError(reader .OpenStream (xmlStream ))
114
- Set doc = reader .Document
115
- } Catch e {
116
- Set sc = e .AsStatus ()
141
+ Do copy .WriteLine (line )
117
142
}
118
- Do source .Rewind ()
119
- Kill ^||%oddDEF
120
- $$$ThrowOnError(sc )
121
- }
122
143
123
- ClassMethod ThreeWayMerge (base As %XML .Document , theirs As %XML .Document , ours As %XML .Document , Output resolved )
124
- {
125
- // TODO: actually do three-way merge
126
- Merge resolved = ours
127
- }
128
-
129
- ClassMethod BuildElementPathMap (doc As %XML .Document , Output map )
130
- {
131
- }
132
-
133
- ClassMethod XMLDocToStream (document As %XML .Document , ByRef outStream )
134
- {
135
- Set writer = ##class (%XML.Writer ).%New ()
136
- Set export = ##class (%Stream.TmpCharacter ).%New ()
137
- $$$ThrowOnError(writer .OutputToStream (export ))
138
- $$$ThrowOnError(writer .Document (document ))
139
-
140
- Set reader = ##class (%XML.Reader ).%New ()
141
- $$$ThrowOnError(reader .OpenStream (export ))
142
- Do reader .CorrelateRoot (" Ens.Config.Production" )
143
- If 'reader .Next (.production ,.sc ) {
144
- $$$ThrowStatus($$$ERROR($$$GeneralError," Could not reimport production from resolved XML." ))
144
+ If markerCount > 1 {
145
+ $$$ThrowStatus($$$ERROR($$$GeneralError," Multiple conflicts found, cannot resolve automatically." ))
146
+ } ElseIf markerCount = 0 {
147
+ $$$ThrowStatus($$$ERROR($$$GeneralError," No conflict markers found in file" ))
145
148
}
146
- $$$ThrowOnError(sc )
147
- $$$ThrowOnError(production .XMLExportToStream (.outStream ,," literal,indent" ))
148
- }
149
149
150
- Method XMLDocToClass (resolved As %XML .Document )
151
- {
152
- Set xData = ##class (%Dictionary.XDataDefinition ).IDKEYOpen (..productionClassname ," ProductionDefinition" ,,.sc )
153
- $$$ThrowOnError(sc )
154
- Do xData .Implementation .Clear ()
155
- Do ..XMLDocToStream (resolved ,xData .Implementation )
156
- Do xData .Implementation .Rewind ()
157
- Write !!,$ZConvert (xData .Implementation .Read (100000 )," O" ," HTML" ),!!
150
+ $$$ThrowOnError(stream .CopyFromAndSave (copy ))
151
+
152
+ Quit 1
158
153
}
159
154
160
155
}
0 commit comments