Skip to content

Commit 8f69b52

Browse files
authored
Merge pull request #649 from intersystems/issue-617
Fix $ZF MAX STRINGLENGTH issue
2 parents fadbaab + dbbd81c commit 8f69b52

File tree

5 files changed

+378
-151
lines changed

5 files changed

+378
-151
lines changed

CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Fixed errors on production page when item settings need to be XML escaped (#667)
1515
- Fixed push button not appearing after commit (#654)
1616
- Fixed merge conflict resolution on stash popping (#531)
17-
17+
- Fix "Max $ZF String" error when committing lots of files (#617)
18+
1819
## [2.8.0] - 2024-12-06
1920

2021
### Added

cls/SourceControl/Git/Utils.cls

+97-2
Original file line numberDiff line numberDiff line change
@@ -3033,8 +3033,7 @@ ClassMethod SetConfiguredRemote(url) As %String
30333033
quit output
30343034
}
30353035

3036-
// Returns true if the current branch is the default merge branch and we are in basic mode
3037-
3036+
/// Returns true if the current branch is the default merge branch and we are in basic mode
30383037
ClassMethod InDefaultBranchBasicMode() As %Boolean
30393038
{
30403039
set basicMode = ..BasicMode()
@@ -3077,4 +3076,100 @@ ClassMethod RunGitAndHandleMerge(command As %String, inFile As %String, Output r
30773076
return $$$ERROR($$$GeneralError,"git reported failure")
30783077
}
30793078

3079+
/// Runs the commit on the specified files (unstaging and restaging currently staged files)
3080+
ClassMethod RunGitCommandReStage(Output outStream, Output errStream, command As %String, ByRef fileList As %Library.DynamicArray, args...) As %Integer
3081+
{
3082+
set sc = $$$OK
3083+
set tInitialTLevel = $TLevel
3084+
try {
3085+
LOCK +^GitCommit(42):5
3086+
if '$Test {
3087+
$$$ThrowStatus($$$ERROR($$$GeneralError, "Couldn't grab a lock. Try again later"))
3088+
}
3089+
set tGitCommitLocked = 1
3090+
3091+
3092+
TSTART
3093+
3094+
// Unstage and save all currently staged files
3095+
set sc = ..GitUnstage(.unstaged)
3096+
3097+
// Stage all files
3098+
set iterator = fileList.%GetIterator()
3099+
while iterator.%GetNext(.key, .value) {
3100+
do ..RunGitCommand("add",.err, .out, value)
3101+
}
3102+
3103+
// Run the git command
3104+
set returnCode = ..RunGitWithArgs(.errStream, .outStream, command, args...)
3105+
3106+
// Restage files
3107+
do ..GitStage(.unstaged)
3108+
3109+
TCOMMIT
3110+
} catch e {
3111+
set sc = e.AsStatus()
3112+
}
3113+
3114+
If tGitCommitLocked {
3115+
Lock -^GitCommit(42)
3116+
}
3117+
3118+
While $TLevel > tInitialTLevel {
3119+
TROLLBACK 1
3120+
}
3121+
3122+
return returnCode
3123+
}
3124+
3125+
ClassMethod GitStage(ByRef files As %Library.DynamicObject) As %Status
3126+
{
3127+
set staged = files.%Get("staged")
3128+
set tracked = files.%Get("tracked")
3129+
3130+
set iterator = staged.%GetIterator()
3131+
while iterator.%GetNext(.key, .value) {
3132+
do ..RunGitCommand("add",.errStream,.outStream, value)
3133+
}
3134+
3135+
set iterator = tracked.%GetIterator()
3136+
while iterator.%GetNext(.key, .value) {
3137+
do ..RunGitCommand("add",.errStream, .outStream, value, "--intent-to-add")
3138+
}
3139+
return $$$OK
3140+
}
3141+
3142+
/// Unstages all currently staged files and returns them in the array
3143+
ClassMethod GitUnstage(Output output As %Library.DynamicObject) As %Status
3144+
{
3145+
set stagedList = []
3146+
set trackedList = []
3147+
3148+
do ..RunGitCommandWithInput("status",, .errStream, .outStream, "--porcelain")
3149+
set line = outStream.ReadLine()
3150+
// Read through output
3151+
while (line'="") {
3152+
set staged = 0
3153+
set tracked = 0
3154+
set filename = $piece(line, " ", *-0)
3155+
if ($extract(line,1,1) '= " ") && ($extract(line,1,1) '= "?") {
3156+
set staged = 1
3157+
}
3158+
elseif ($extract(line,2,2) = "A") {
3159+
set tracked = 1
3160+
}
3161+
if staged {
3162+
do stagedList.%Push(filename)
3163+
do ..RunGitCommand("reset", .errStream, .out, filename)
3164+
} elseif tracked {
3165+
do trackedList.%Push(filename)
3166+
do ..RunGitCommand("reset",.errStream,.out, filename)
3167+
}
3168+
set line = outStream.ReadLine()
3169+
}
3170+
3171+
set output = {"staged": (stagedList), "tracked": (trackedList)}
3172+
return $$$OK
3173+
}
3174+
30803175
}

cls/SourceControl/Git/WebUIDriver.cls

+73-40
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
102102
do %request.Set("EXPIRES",0)
103103
do ##class(%CSP.StreamServer).OnPreHTTP() // Need to call this to set headers properly
104104
set %stream = 1 // Leak this to webuidriver.csp
105-
} elseif $match(pathStart,"git-command|git|dirname|hostname|viewonly|discarded-states|restore-discarded|contexts|create-branch") {
105+
} elseif $match(pathStart,"git-command|git|dirname|hostname|viewonly|discarded-states|restore-discarded|contexts|create-branch|git-command-unstage") {
106106
if (%request.Method = "GET") {
107107
set %data = ##class(%Stream.TmpCharacter).%New()
108108
// Things not handled from Python backend:
@@ -220,36 +220,15 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
220220
}
221221
// Want to invoke merge conflict autoresolver in case of issues
222222
set returnCode = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("-c",inFile,.errStream,.outStream,gitArgs...)
223-
224-
set %data = ##class(%Stream.TmpCharacter).%New()
225-
set changeTerminators = (%data.LineTerminator '= $char(13,10))
226-
set %data.LineTerminator = $char(13,10) // For the CSPGateway.
227-
do outStream.Rewind()
228-
while 'outStream.AtEnd {
229-
do %data.WriteLine(outStream.ReadLine())
230-
}
231223

232-
set nLines = 0
233-
do errStream.Rewind()
234-
while 'errStream.AtEnd {
235-
do %data.WriteLine(errStream.ReadLine())
236-
set:changeTerminators nLines = nLines + 1
237-
}
224+
do ..ConvertGitOutput(.outStream,.errStream,returnCode,.%data)
238225

239-
do %data.WriteLine("Git-Stderr-Length: " _ (errStream.Size + nLines))
240-
do %data.Write("Git-Return-Code: " _ returnCode) // No ending newline expected
241-
do %data.Rewind()
242226
if '$listfind(readOnlyCommands,baseCommand) {
243227
do ##class(SourceControl.Git.Change).RefreshUncommitted(,,,1)
244228
}
245229
set handled = 1
246230
} elseif (pathStart = "git-command") {
247-
set stringBody = ""
248-
while '%request.Content.AtEnd {
249-
set stringBody = stringBody _ %request.Content.Read()
250-
}
251-
set stringBody = $zconvert(stringBody,"I","UTF8")
252-
set requestBody = ##class(%Library.DynamicObject).%FromJSON(stringBody)
231+
do ..UnpackRequest(.%request, .requestBody)
253232
set command = requestBody.command
254233

255234
set gitCmd = command.%Get(0)
@@ -309,22 +288,7 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
309288
do %data.Rewind()
310289
} else {
311290
set returnCode = ##class(SourceControl.Git.Utils).RunGitCommandWithInput("-c", inFile, .errStream, .outStream, argsArr...)
312-
set %data = ##class(%Stream.TmpCharacter).%New()
313-
set changeTerminators = (%data.LineTerminator '= $char(13,10))
314-
set %data.LineTerminator = $char(13,10) // For the CSPGateway.
315-
while 'outStream.AtEnd {
316-
do %data.WriteLine(outStream.ReadLine())
317-
}
318-
319-
set nLines = 0
320-
while 'errStream.AtEnd {
321-
do %data.WriteLine(errStream.ReadLine())
322-
set:changeTerminators nLines = nLines + 1
323-
}
324-
325-
do %data.WriteLine("Git-Stderr-Length: " _ (errStream.Size + nLines))
326-
do %data.Write("Git-Return-Code: " _ returnCode) // No ending newline expected
327-
do %data.Rewind()
291+
do ..ConvertGitOutput(.outStream,.errStream,returnCode,.%data)
328292
}
329293
set handled = 1
330294

@@ -368,6 +332,41 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
368332
}
369333
set handled = 1
370334
}
335+
} elseif (pathStart = "git-command-unstage") {
336+
do ..UnpackRequest(.%request, .requestBody)
337+
338+
set flags = requestBody.flags
339+
if (flags '= "") {
340+
set flaglist = $listfromstring(flags,",")
341+
for i=1:1:$listlength(flaglist) {
342+
set flag = $listget(flaglist,i)
343+
set args($increment(args)) = flag
344+
}
345+
}
346+
set message = requestBody.message
347+
if (message '= "") {
348+
set args($increment(args)) = "-m"
349+
set args($increment(args)) = message
350+
}
351+
set details = requestBody.details
352+
if (details '= "") {
353+
set args($increment(args)) = "-m"
354+
set args($increment(args)) = details
355+
}
356+
set command = requestBody.command
357+
358+
// Extract Files
359+
set fileList = []
360+
set files = requestBody.files
361+
set iter = files.%GetIterator()
362+
while iter.%GetNext(,.value) {
363+
do fileList.%Push(value)
364+
}
365+
366+
set returnCode = ##class(SourceControl.Git.Utils).RunGitCommandReStage(.outStream,.errStream,command,.fileList,args...)
367+
368+
do ..ConvertGitOutput(.outStream,.errStream,returnCode,.%data)
369+
set handled = 1
371370
}
372371
}
373372
}
@@ -465,4 +464,38 @@ ClassMethod GetRemote() As %Library.DynamicObject
465464
quit {"remote": (remote)}
466465
}
467466

467+
ClassMethod UnpackRequest(ByRef %request As %CSP.Request, Output obj As %Library.DynamicObject) As %Status
468+
{
469+
set stringBody = ""
470+
while '%request.Content.AtEnd {
471+
set stringBody = stringBody _ %request.Content.Read()
472+
}
473+
set stringBody = $zconvert(stringBody,"I","UTF8")
474+
set obj = ##class(%Library.DynamicObject).%FromJSON(stringBody)
475+
return $$$OK
476+
}
477+
478+
ClassMethod ConvertGitOutput(ByRef outStream, ByRef errStream, returnCode As %String, Output %data) As %Status
479+
{
480+
set %data = ##class(%Stream.TmpCharacter).%New()
481+
set changeTerminators = (%data.LineTerminator '= $char(13,10))
482+
set %data.LineTerminator = $char(13,10) // For the CSPGateway.
483+
do outStream.Rewind()
484+
while 'outStream.AtEnd {
485+
do %data.WriteLine(outStream.ReadLine())
486+
}
487+
488+
set nLines = 0
489+
do errStream.Rewind()
490+
while 'errStream.AtEnd {
491+
do %data.WriteLine(errStream.ReadLine())
492+
set:changeTerminators nLines = nLines + 1
493+
}
494+
495+
do %data.WriteLine("Git-Stderr-Length: " _ (errStream.Size + nLines))
496+
do %data.Write("Git-Return-Code: " _ returnCode) // No ending newline expected
497+
do %data.Rewind()
498+
return $$$OK
499+
}
500+
468501
}

0 commit comments

Comments
 (0)