Skip to content

Commit 6f39ea8

Browse files
authored
Merge pull request #378 from intersystems/fix-history-display
Fix history display, version when mapped
2 parents 44dd368 + 2ae9678 commit 6f39ea8

File tree

3 files changed

+291
-7
lines changed

3 files changed

+291
-7
lines changed

cls/SourceControl/Git/Util/Buffer.cls

Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
Include %callout
2+
3+
/// Encapsulates the XSLT String Buffer XDEV device. <br />
4+
/// Note that only one <class>SourceControl.Git.Util.Buffer</class> instance may be used at a time per job.
5+
Class SourceControl.Git.Util.Buffer Extends %RegisteredObject
6+
{
7+
8+
/// Size of the XSLT string buffer, in MB. <br />
9+
/// Changes will only take effect the next time <method>BeginCaptureOutput</method>() is called. <br />
10+
Property StringBufferSize As %Integer [ InitialExpression = 25 ];
11+
12+
/// Corresponds to "C" mode flag in device open. <br />
13+
/// May be changed after <method>BeginCaptureOutput</method>() is called and the XDEV device is open. <br />
14+
Property CarriageReturnMode As %Boolean [ InitialExpression = 1 ];
15+
16+
Method CarriageReturnModeSet(value As %Boolean) As %Status
17+
{
18+
Set tSC = $$$OK
19+
Set tIO = $io
20+
Try {
21+
Set tValue = ''value
22+
If ..DeviceOpen {
23+
Set tModeChange = $Select(tValue: "+", 1: "-")_"C"
24+
Use ..Device:(::tModeChange)
25+
}
26+
} Catch e {
27+
Set tSC = e.AsStatus()
28+
}
29+
Use tIO
30+
If $$$ISOK(tSC) {
31+
Set i%CarriageReturnMode = tValue
32+
}
33+
Quit tSC
34+
}
35+
36+
/// Translate Table to use - by default, UTF8 for unicode instances, RAW otherwise. <br />
37+
/// May be changed after <method>BeginCaptureOutput</method>() is called and the XDEV device is open. <br />
38+
Property TranslateTable As %String [ InitialExpression = {$select($$$IsUnicode:"UTF8",1:"RAW")} ];
39+
40+
Method TranslateTableSet(value As %String) As %Status
41+
{
42+
Set tSC = $$$OK
43+
Set tIO = $io
44+
Try {
45+
// TODO: validate that value is a valid TranslateTable, especially when ..DeviceOpen = 0
46+
If ..DeviceOpen {
47+
Use ..Device:(/IOT=value)
48+
}
49+
} Catch e {
50+
Set tSC = e.AsStatus()
51+
}
52+
Use tIO
53+
If $$$ISOK(tSC) {
54+
Set i%TranslateTable = value
55+
}
56+
Quit tSC
57+
}
58+
59+
/// Input buffer size, in bytes. <br />
60+
/// Changes will only take effect the next time <method>BeginCaptureOutput</method>() is called. <br />
61+
Property InputBufferSize As %Integer(MAXVAL = 1048576, MINVAL = 1024) [ InitialExpression = 16384 ];
62+
63+
/// Output buffer size, in bytes. <br />
64+
/// Changes will only take effect the next time <method>BeginCaptureOutput</method>() is called. <br />
65+
Property OutputBufferSize As %Integer(MAXVAL = 1048576, MINVAL = 1024) [ InitialExpression = 16384 ];
66+
67+
/// Name of XDEV device.
68+
Property Device As %String [ Internal, Private ];
69+
70+
/// Tracks whether <property>Device</property> is currently open.
71+
Property DeviceOpen As %Boolean [ InitialExpression = 0, Internal, Private ];
72+
73+
/// Keeps track of the previously opened device.
74+
Property PreviousDevice As %String [ Internal, Private ];
75+
76+
/// Keeps track of the previous state of the I/O redirection flag
77+
Property PreviousIORedirectFlag As %Boolean [ Internal, Private ];
78+
79+
/// Keeps track of the previous mnemonic routine
80+
Property PreviousMnemonicRoutine As %String [ Internal, Private ];
81+
82+
/// Initializes the device name for this object.
83+
Method %OnNew() As %Status [ Private, ServerOnly = 1 ]
84+
{
85+
// Multiple processes can use the same XDEV device name without conflict, so we can use the object reference to identify the device.
86+
Set ..Device = "|XDEV|"_(+$This)
87+
Quit $$$OK
88+
}
89+
90+
/// Begins capturing output. <br />
91+
Method BeginCaptureOutput() As %Status
92+
{
93+
Set tSC = $$$OK
94+
Try {
95+
Set tModeParams = $Select(..CarriageReturnMode: "C", 1: "")_"S"
96+
Close ..Device
97+
Open ..Device:($ZF(-6,$$$XSLTLibrary,12):..StringBufferSize:tModeParams:/HOSTNAME="XSLT":/IOT=..TranslateTable:/IBU=..InputBufferSize:/OBU=..OutputBufferSize)
98+
Set ..DeviceOpen = 1
99+
Set ..PreviousDevice = $io
100+
Set ..PreviousIORedirectFlag = ##class(%Library.Device).ReDirectIO()
101+
Set ..PreviousMnemonicRoutine = ##class(%Library.Device).GetMnemonicRoutine()
102+
Use ..Device
103+
If ..PreviousIORedirectFlag {
104+
Do ##class(%Library.Device).ReDirectIO(0)
105+
}
106+
} Catch e {
107+
Set tSC = e.AsStatus()
108+
Close ..Device
109+
Set ..DeviceOpen = 0
110+
}
111+
Quit tSC
112+
}
113+
114+
/// Reads all output from the buffer to stream <var>pStream</var>,
115+
/// which will be initialized as a <class>%Stream.TmpBinary</class> object if not provided.
116+
Method ReadToStream(ByRef pStream As %Stream.Object) As %Status
117+
{
118+
Set tSC = $$$OK
119+
Set tOldIO = $io
120+
Try {
121+
If '$IsObject($Get(pStream)) {
122+
Set pStream = ##class(%Stream.TmpBinary).%New()
123+
}
124+
125+
If '..DeviceOpen {
126+
// No-op
127+
Quit
128+
}
129+
130+
Use ..Device
131+
132+
// Flush any remaining output
133+
Write *-3
134+
135+
// Stream
136+
If pStream.%IsA("%Stream.FileCharacter") {
137+
// Force stream's file to open
138+
Set tSC = pStream.Write("")
139+
If $$$ISERR(tSC) {
140+
Quit
141+
}
142+
143+
Set tFile = pStream.Filename
144+
For {
145+
Use ..Device
146+
Set tChunk = ""
147+
Try {
148+
Read tChunk:0
149+
} Catch {}
150+
If '$Length(tChunk) {
151+
Quit
152+
}
153+
Use tFile
154+
Write tChunk
155+
}
156+
}
157+
Else {
158+
For {
159+
Use ..Device
160+
Set tChunk = ""
161+
Try {
162+
Read tChunk:0
163+
} Catch {}
164+
If '$Length(tChunk) {
165+
Quit
166+
}
167+
Do pStream.Write(tChunk)
168+
}
169+
}
170+
} Catch e {
171+
If e.Name="<ENDOFFILE>" {
172+
Set tSC = $$$OK
173+
} Else {
174+
Set tSC = e.AsStatus()
175+
}
176+
}
177+
Use tOldIO
178+
Quit tSC
179+
}
180+
181+
/// Reads all output from the buffer to <var>pString</var>.
182+
Method ReadToString(Output pString As %String) As %Status
183+
{
184+
Set tSC = $$$OK
185+
Set tOldIO = $io
186+
Set pString = $Get(pString)
187+
Try {
188+
If '..DeviceOpen {
189+
// No-op
190+
Quit
191+
}
192+
193+
Use ..Device
194+
195+
// Flush any remaining output
196+
Write *-3
197+
198+
// String
199+
For {
200+
Use ..Device
201+
Set tChunk = ""
202+
Try {
203+
Read tChunk:0
204+
} Catch {}
205+
If '$Length(tChunk) {
206+
Quit
207+
}
208+
Set pString = pString _ tChunk
209+
}
210+
} Catch e {
211+
If e.Name="<ENDOFFILE>" {
212+
Set tSC = $$$OK
213+
} Else {
214+
Set tSC = e.AsStatus()
215+
}
216+
}
217+
Use tOldIO
218+
Quit tSC
219+
}
220+
221+
/// Ends capturing output <br />
222+
/// If <var>pOutput</var> is any sort of stream, output will be written to it. <br />
223+
/// Otherwise, it will be returned as a string (initialized to "" before retrieving output from the buffer). <br />
224+
Method EndCaptureOutput(ByRef pOutput) As %Status
225+
{
226+
Set tSC = $$$OK
227+
Set tOldIO = $io
228+
Try {
229+
Set pOutput = $Get(pOutput)
230+
231+
If $IsObject(pOutput) && pOutput.%IsA("%Stream.Object") {
232+
Set tSC = ..ReadToStream(.pOutput)
233+
} Else {
234+
Set tSC = ..ReadToString(.pOutput)
235+
}
236+
} Catch e {
237+
Set tSC = e.AsStatus()
238+
}
239+
240+
// Close the XDEV device, and switch back to the original device
241+
Try {
242+
If (tOldIO = ..Device) {
243+
Do ..UsePreviousDeviceAndSettings()
244+
} Else {
245+
Use tOldIO
246+
}
247+
Close ..Device
248+
} Catch e {
249+
Set tSC = $$$ADDSC(tSC,e.AsStatus())
250+
}
251+
Quit tSC
252+
}
253+
254+
Method %OnClose() As %Status [ Private, ServerOnly = 1 ]
255+
{
256+
If (..Device '= "") {
257+
If ($io = ..Device) {
258+
// Switch back to the previous device if possible; if this fails, the subsequent
259+
// close of ..Device will switch back to the principal device.
260+
Try {
261+
Do ..UsePreviousDeviceAndSettings()
262+
} Catch e {}
263+
}
264+
Close ..Device
265+
}
266+
Set ..DeviceOpen = 0
267+
268+
Quit $$$OK
269+
}
270+
271+
Method UsePreviousDeviceAndSettings() [ Internal, Private ]
272+
{
273+
Use ..PreviousDevice
274+
If (..PreviousMnemonicRoutine '= "") {
275+
Set tOldMnemonic = "^"_..PreviousMnemonicRoutine
276+
Use ..PreviousDevice::(tOldMnemonic)
277+
}
278+
If ..PreviousIORedirectFlag {
279+
Do ##class(%Library.Device).ReDirectIO(1)
280+
}
281+
}
282+
283+
}

cls/SourceControl/Git/Utils.cls

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1658,9 +1658,7 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16581658
}
16591659
do ..PrintStreams(errStream, outStream)
16601660
if syncIris {
1661-
16621661
$$$ThrowOnError(..SyncIrisWithRepo(.files))
1663-
16641662
}
16651663
quit returnCode
16661664
}
@@ -2140,16 +2138,18 @@ ClassMethod CheckInitialization()
21402138
}
21412139
}
21422140

2143-
ClassMethod GetPackageVersion() As %String
2141+
ClassMethod GetPackageVersion() As %String [ CodeMode = objectgenerator ]
21442142
{
21452143
set package = $$$NULLOREF
21462144
if $$$comClassDefined("%IPM.Storage.Module") {
21472145
set package = ##class(%IPM.Storage.Module).NameOpen("git-source-control")
21482146
} elseif $$$comClassDefined("%ZPM.PackageManager.Developer.Module") {
21492147
set package = ##class(%ZPM.PackageManager.Developer.Module).NameOpen("git-source-control")
21502148
}
2151-
quit $select($IsObject(package):package.VersionString,
2149+
set packageVersion = $select($IsObject(package):package.VersionString,
21522150
1:"unknown")
2151+
do %code.WriteLine(" quit "_$$$QUOTE(packageVersion))
2152+
quit $$$OK
21532153
}
21542154

21552155
ClassMethod GetSourceControlInclude() As %String
@@ -2348,4 +2348,3 @@ ClassMethod BaselineExport(pCommitMessage = "", pPushToRemote = "") As %Status
23482348
}
23492349

23502350
}
2351-

cls/SourceControl/Git/WebUIDriver.cls

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Class SourceControl.Git.WebUIDriver
44
ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Output handled As %Boolean = 0, Output %data As %Stream.Object)
55
{
66
do %session.Unlock()
7+
// Make sure we capture any stray output
8+
set buffer = ##class(SourceControl.Git.Util.Buffer).%New()
9+
do buffer.BeginCaptureOutput()
710
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
811
kill %data
912
#dim %response as %CSP.Response
@@ -165,8 +168,8 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
165168
set handled = 1
166169
}
167170
}
168-
169171
}
172+
do buffer.EndCaptureOutput(.throwaway)
170173
}
171174

172175
ClassMethod UserInfo() As %SystemBase
@@ -240,4 +243,3 @@ ClassMethod GetPackageVersion() As %Library.DynamicObject
240243
}
241244

242245
}
243-

0 commit comments

Comments
 (0)