Skip to content

Commit 724d118

Browse files
committed
wip: more work toward smart XML three-way merge
Going to abandon the general solution to focus on the things that commonly happen - rather than trying to reimplement three-way merge, just going to do the right thing with the git conflict file
1 parent ba13a10 commit 724d118

File tree

7 files changed

+139
-15
lines changed

7 files changed

+139
-15
lines changed

cls/SourceControl/Git/Extension.cls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,4 @@ Method AddToSourceControl(InternalName As %String, Description As %String = "")
398398
}
399399

400400
}
401+

cls/SourceControl/Git/Util/Buffer.cls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,3 +281,4 @@ Method UsePreviousDeviceAndSettings() [ Internal, Private ]
281281
}
282282

283283
}
284+

cls/SourceControl/Git/Util/ProductionConflictResolver.cls

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,16 @@ Method Resolve() [ Private ]
8282
$$$ThrowStatus($$$ERROR($$$GeneralError,"Unable to load base/ours/theirs for "_..productionFile))
8383
}
8484

85-
Do ..ClassToTree(base,.baseTree)
86-
Do ..ClassToTree(ours,.oursTree)
87-
Do ..ClassToTree(theirs,.theirsTree)
85+
Do ..ClassToXMLDoc(base,.baseDoc)
86+
Do ..ClassToXMLDoc(ours,.oursDoc)
87+
Do ..ClassToXMLDoc(theirs,.theirsDoc)
8888

89-
zw baseTree,oursTree,theirsTree
89+
Do ..ThreeWayMerge(baseDoc,oursDoc,theirsDoc,.resolved)
9090

91-
Do ..ThreeWayMerge(.baseTree,.theirsTree,.oursTree,.resolved)
92-
93-
Do ..TreeToClass(.resolved)
91+
Do ..XMLDocToClass(resolved)
9492
}
9593

96-
Method ClassToTree(source As %Stream.Object, Output tree)
94+
Method ClassToXMLDoc(source As %Stream.Object, Output doc As %XML.Document)
9795
{
9896
Set sc = $$$OK
9997
Kill ^||%oddDEF
@@ -111,24 +109,52 @@ Method ClassToTree(source As %Stream.Object, Output tree)
111109
For i=1:1:$Get(classDef($$$cCLASSxdata,"ProductionDefinition",$$$cXDATAdata)) {
112110
Do xmlStream.WriteLine($Get(classDef($$$cCLASSxdata,"ProductionDefinition",$$$cXDATAdata,i)))
113111
}
114-
Set handler=##class(%XML.ImportHandler).%New("IRIS.Temp",$$$IntHandler)
115-
$$$ThrowOnError(##Class(%XML.SAX.Parser).ParseStream(xmlStream,handler))
116-
117-
Merge tree = @handler.DOMName@(handler.Tree)
112+
Set reader = ##class(%XML.Reader).%New()
113+
$$$ThrowOnError(reader.OpenStream(xmlStream))
114+
Set doc = reader.Document
118115
} Catch e {
119116
Set sc = e.AsStatus()
120117
}
121118
Do source.Rewind()
122-
Kill ^||%oddDEF(..productionClassname)
119+
Kill ^||%oddDEF
123120
$$$ThrowOnError(sc)
124121
}
125122

126-
Method ThreeWayMerge(ByRef base, ByRef theirs, ByRef ours, Output resolved)
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)
127130
{
128131
}
129132

130-
Method TreeToClass(ByRef tree)
133+
ClassMethod XMLDocToStream(document As %XML.Document, ByRef outStream)
131134
{
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."))
145+
}
146+
$$$ThrowOnError(sc)
147+
$$$ThrowOnError(production.XMLExportToStream(.outStream,,"literal,indent"))
148+
}
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"),!!
132158
}
133159

134160
}

cls/SourceControl/Git/Utils.cls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2392,3 +2392,4 @@ ClassMethod BaselineExport(pCommitMessage = "", pPushToRemote = "") As %Status
23922392
}
23932393

23942394
}
2395+

cls/SourceControl/Git/WebUIDriver.cls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,4 @@ ClassMethod GetPackageVersion() As %Library.DynamicObject
243243
}
244244

245245
}
246+

cls/_zpkg/isc/sc/git/Socket.cls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,4 @@ Method SendJSON(pObject As %DynamicAbstractObject)
194194
}
195195

196196
}
197+
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
Class UnitTest.SourceControl.Git.XMLThreeWayMerge Extends %UnitTest.TestCase
2+
{
3+
4+
Method TestMerge()
5+
{
6+
Set base = ..UtilXDataToDocument("Base")
7+
Set ours = ..UtilXDataToDocument("Ours")
8+
Set theirs = ..UtilXDataToDocument("Theirs")
9+
Set expectedResolve = ..UtilXDataToDocument("Resolved")
10+
11+
Do ##class(SourceControl.Git.Util.ProductionConflictResolver).
12+
}
13+
14+
Method UtilXDataToDocument(xDataName As %String) As %XML.Document
15+
{
16+
Set xdata = ##class(%Dictionary.XDataDefinition).IDKEYOpen($classname(),xDataName,,.sc)
17+
$$$ThrowOnError(sc)
18+
Set reader = ##class(%XML.Reader).%New()
19+
$$$ThrowOnError(reader.OpenStream(xdata.Implementation))
20+
Quit reader.Document
21+
}
22+
23+
XData Base
24+
{
25+
<Production Name="HCC.Connect.Production" LogGeneralTraceEvents="false">
26+
<Description>Health Connect Cloud Base Production</Description>
27+
<ActorPoolSize>1</ActorPoolSize>
28+
<Item Name="FeatureH" Category="" ClassName="Ens.Activity.Operation.REST" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
29+
<Setting Target="Adapter" Name="HTTPPort">12345</Setting>
30+
<Setting Target="Adapter" Name="HTTPServer">localhost</Setting>
31+
</Item>
32+
<Item Name="Baz" Category="" ClassName="EnsLib.DICOM.Duplex.TCP" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
33+
</Item>
34+
<Item Name="Demo5" Category="" ClassName="EnsLib.AmazonCloudWatch.MetricAlarmOperation" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
35+
</Item>
36+
</Production>
37+
}
38+
39+
XData Ours
40+
{
41+
<Production Name="HCC.Connect.Production" LogGeneralTraceEvents="false">
42+
<Description>Health Connect Cloud Base Production Ours</Description>
43+
<ActorPoolSize>2</ActorPoolSize>
44+
<Item Name="FeatureH" Category="" ClassName="Ens.Activity.Operation.REST" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
45+
<Setting Target="Adapter" Name="HTTPPort">12346</Setting>
46+
<Setting Target="Adapter" Name="HTTPServer">localhost</Setting>
47+
</Item>
48+
<Item Name="Baz" Category="" ClassName="EnsLib.DICOM.Duplex.TCP" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
49+
</Item>
50+
<Item Name="Demo5" Category="" ClassName="EnsLib.AmazonCloudWatch.MetricAlarmOperation" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
51+
</Item>
52+
</Production>
53+
}
54+
55+
XData Theirs
56+
{
57+
<Production Name="HCC.Connect.Production" LogGeneralTraceEvents="false">
58+
<Description>Health Connect Cloud Base Production</Description>
59+
<ActorPoolSize>2</ActorPoolSize>
60+
<Item Name="FeatureH" Category="" ClassName="Ens.Activity.Operation.REST" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
61+
<Setting Target="Adapter" Name="HTTPPort">12345</Setting>
62+
<Setting Target="Adapter" Name="HTTPServer">example.com</Setting>
63+
</Item>
64+
<Item Name="Baz" Category="" ClassName="EnsLib.DICOM.Duplex.TCP" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
65+
</Item>
66+
<Item Name="Demo7" Category="" ClassName="EnsLib.AmazonCloudWatch.MetricAlarmOperation" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
67+
</Item>
68+
<Item Name="Demo8" Category="" ClassName="EnsLib.AmazonCloudWatch.MetricAlarmOperation" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
69+
</Item>
70+
</Production>
71+
}
72+
73+
XData Resolved
74+
{
75+
<Production Name="HCC.Connect.Production" LogGeneralTraceEvents="false">
76+
<Description>Health Connect Cloud Base Production Ours</Description>
77+
<ActorPoolSize>2</ActorPoolSize>
78+
<Item Name="FeatureH" Category="" ClassName="Ens.Activity.Operation.REST" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
79+
<Setting Target="Adapter" Name="HTTPPort">12346</Setting>
80+
<Setting Target="Adapter" Name="HTTPServer">example.com</Setting>
81+
</Item>
82+
<Item Name="Baz" Category="" ClassName="EnsLib.DICOM.Duplex.TCP" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
83+
</Item>
84+
<Item Name="Demo5" Category="" ClassName="EnsLib.AmazonCloudWatch.MetricAlarmOperation" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
85+
</Item>
86+
<Item Name="Demo7" Category="" ClassName="EnsLib.AmazonCloudWatch.MetricAlarmOperation" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
87+
</Item>
88+
<Item Name="Demo8" Category="" ClassName="EnsLib.AmazonCloudWatch.MetricAlarmOperation" PoolSize="1" Enabled="false" Foreground="false" Comment="" LogTraceEvents="false" Schedule="">
89+
</Item>
90+
</Production>
91+
}
92+
93+
}

0 commit comments

Comments
 (0)