Skip to content

Commit 593c858

Browse files
committed
Merge branch 'main' into fix-production-conflicts
2 parents 5cbf1b6 + 59aff2d commit 593c858

File tree

9 files changed

+166
-87
lines changed

9 files changed

+166
-87
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
- Command-line utility to do a baseline export of items in a namespace
2121
- 'New Branch' menu option in basic now will create new branches from the configured default merge branch (#366)
2222
- Merging back with the default merge branch is now a part of the basic mode's Sync flow (#366)
23+
- Added a new option "compileOnImport". If true, Import options will compile files using the pull event handler. (#362)
2324

2425
### Fixed
2526
- Modifications to local repo files are now synced with IRIS (#153)
2627
- Menu items names are properly translated from internal name in VSCode, Management Portal (#372)
28+
- Now has proper locking behavior in `##class(SourceControl.Git.WebUIDriver).HandleRequest()`(#385)
29+
- Git operations from the WebUI now don't unlock the session if they aren't read-only
2730

2831
## [2.3.1] - 2024-04-30
2932

cls/SourceControl/Git/PullEventHandler/IncrementalLoad.cls

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,36 @@ Method OnPull() As %Status
3838
quit $system.OBJ.CompileList(.compilelist, "cukb")
3939
}
4040

41-
Method DeleteFile(item As %String)
41+
Method DeleteFile(item As %String) As %Status
4242
{
43+
set sc = $$$OK
4344
set type = ##class(SourceControl.Git.Utils).Type(item)
44-
if (type = "cls") {
45-
quit $System.OBJ.Delete(item)
46-
} elseif (type = "csp") {
47-
quit $System.CSP.DeletePage(item)
45+
set name = ##class(SourceControl.Git.Utils).NameWithoutExtension(item)
46+
set deleted = 1
47+
if type = "prj" {
48+
set sc = $system.OBJ.DeleteProject(name)
49+
}elseif type = "cls" {
50+
set sc = $system.OBJ.Delete(item)
51+
}elseif $listfind($listbuild("mac","int","inc","bas","mvb","mvi"), type) > 0 {
52+
set sc = ##class(%Routine).Delete(item)
53+
}elseif type = "csp" {
54+
set sc = $System.CSP.DeletePage(item)
55+
}elseif ##class(SourceControl.Git.Utils).UserTypeCached(item) {
56+
set sc = ##class(%Library.RoutineMgr).Delete(item)
4857
} else {
49-
quit ##class(%Library.RoutineMgr).Delete(item)
58+
set deleted = 0
5059
}
60+
61+
if deleted && $$$ISOK(sc) {
62+
do ##class(SourceControl.Git.Utils).RemoveRoutineTSH(item)
63+
kill $$$TrackedItems(##class(SourceControl.Git.Utils).NormalizeExtension(item))
64+
} else {
65+
if +$system.Status.GetErrorCodes(sc) = $$$ClassDoesNotExist {
66+
// if something we wanted to delete is already deleted -- good!
67+
set sc = $$$OK
68+
}
69+
}
70+
return sc
5171
}
5272

5373
}

cls/SourceControl/Git/Settings.cls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Property systemBasicMode As %Boolean [ InitialExpression = {##class(SourceContro
4444
/// In Basic mode, Sync will merge changes from this remote branch
4545
Property defaultMergeBranch As %String [ InitialExpression = {##class(SourceControl.Git.Utils).DefaultMergeBranch()} ];
4646

47+
/// Import All options compile imported options using the configured pull event handler
48+
Property compileOnImport As %Boolean [ InitialExpression = {##class(SourceControl.Git.Utils).CompileOnImport()} ];
49+
4750
Property Mappings [ MultiDimensional ];
4851

4952
Method %OnNew() As %Status
@@ -97,6 +100,7 @@ Method %Save() As %Status
97100
set @storage@("settings","settingsUIReadOnly") = ..settingsUIReadOnly
98101
set @storage@("settings", "mappedItemsReadOnly") = ..mappedItemsReadOnly
99102
set @storage@("settings", "defaultMergeBranch") = ..defaultMergeBranch
103+
set @storage@("settings", "compileOnImport") = ..compileOnImport
100104
set @storage@("settings", "basicMode") = ..systemBasicMode
101105
if ..basicMode = "system" {
102106
kill @storage@("settings", "user", $username, "basicMode")

cls/SourceControl/Git/Utils.cls

Lines changed: 97 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,11 @@ ClassMethod PrivateKeyFile() As %String
153153
quit $get(@..#Storage@("settings","ssh","privateKeyFile"))
154154
}
155155

156+
ClassMethod CompileOnImport() As %Boolean
157+
{
158+
quit $get(@..#Storage@("settings","compileOnImport"),1)
159+
}
160+
156161
ClassMethod NeedSettings() As %Boolean [ CodeMode = expression ]
157162
{
158163
(..TempFolder() = "") || (..GitBinPath() = "") || (..GitBinPath() = """")
@@ -517,7 +522,7 @@ ClassMethod Pull(remote As %String = "origin") As %Status
517522
set branchName = outStream.ReadLine(outStream.Size)
518523
write !, "Pulling from branch: ", branchName
519524
kill errStream, outStream
520-
set returnCode = ..RunGitWithArgs(.errStream, .outStream, "pull", remote, branchName)
525+
set returnCode = ..RunGitWithArgs(.errStream, .outStream, "pull", remote)
521526

522527
w !, "Pull ran with return code: " _ returnCode
523528
quit $$$OK
@@ -1337,13 +1342,17 @@ ClassMethod ImportRoutines(force As %Boolean = 0) As %Status
13371342

13381343
#dim ec as %Status = ..ListItemsInFiles(.itemList, .err)
13391344
quit:'ec ec
1345+
1346+
kill files
13401347

1348+
set settings = ##class(SourceControl.Git.Settings).%New()
13411349
#dim internalName as %String = ""
13421350
for {
13431351
set internalName = $order(itemList(internalName))
13441352
quit:internalName=""
13451353
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(internalName)
13461354
continue:context.Package'=refPackage
1355+
set doImport = ..IsRoutineOutdated(internalName) || force
13471356
if ..IsInSourceControl(internalName) {
13481357
set sc = ..ImportItem(internalName, force)
13491358
} else {
@@ -1352,7 +1361,15 @@ ClassMethod ImportRoutines(force As %Boolean = 0) As %Status
13521361
if $$$ISERR(sc) {
13531362
set ec = $$$ADDSC(ec, sc)
13541363
}
1364+
if doImport && settings.compileOnImport {
1365+
set modification = ##class(SourceControl.Git.Modification).%New()
1366+
set modification.changeType = "M"
1367+
set modification.internalName = internalName
1368+
set modification.externalName = ..FullExternalName(internalName)
1369+
set files($increment(files)) = modification
1370+
}
13551371
}
1372+
13561373

13571374
//let's delete all items for which corresponding files had been deleted
13581375
#dim item as %String = ""
@@ -1366,41 +1383,21 @@ ClassMethod ImportRoutines(force As %Boolean = 0) As %Status
13661383
set fullExternalName = ..FullExternalName(item)
13671384
if '##class(%File).Exists(fullExternalName) {
13681385
write !,fullExternalName," does not exist - deleting ",item
1369-
#dim type as %String = ..Type(item)
1370-
#dim name as %String = ..NameWithoutExtension(item)
1371-
#dim deleted as %Boolean = 1
1372-
if type = "prj" {
1373-
set ec = $$$ADDSC(ec, $system.OBJ.DeleteProject(name))
1374-
}elseif type = "cls" {
1375-
set ec = $$$ADDSC(ec, $system.OBJ.Delete(item))
1376-
}elseif $listfind($listbuild("mac","int","inc","bas","mvb","mvi"), type) > 0 {
1377-
set ec = $$$ADDSC(ec, ##class(%Routine).Delete(item))
1378-
}elseif type = "csp" {
1379-
#dim filename = $system.CSP.GetFileName(item)
1380-
if ##class(%File).Exists(filename) && '##class(%File).Delete(filename) {
1381-
set ec = $$$ADDSC(ec, ..MakeError("Error while removing "_item))
1382-
}
1383-
}elseif ..UserTypeCached(item) {
1384-
set ec = $$$ADDSC(ec, ##class(%Library.RoutineMgr).Delete(item))
1385-
} else {
1386-
set deleted = 0
1387-
}
1388-
1389-
if deleted && ec {
1390-
do ..RemoveRoutineTSH(item)
1391-
kill $$$TrackedItems(..NormalizeExtension(item))
1392-
write !, item, " was deleted"
1393-
} else {
1394-
if +$system.Status.GetErrorCodes(ec) '= $$$ClassDoesNotExist {
1395-
write !, "Error: could not delete ", item
1396-
} else {
1397-
// if something we wanted to delete is already deleted -- good!
1398-
set ec = $$$OK
1399-
}
1400-
}
1386+
set modification = ##class(SourceControl.Git.Modification).%New()
1387+
set modification.changeType = "D"
1388+
set modification.internalName = item
1389+
set modification.externalName = fullExternalName
1390+
set files($increment(files)) = modification
14011391
}
14021392
}
14031393

1394+
set eventHandler = $classmethod(..PullEventClass(),"%New")
1395+
set eventHandler.LocalRoot = ..TempFolder()
1396+
merge eventHandler.ModifiedFiles = files
1397+
set sc = eventHandler.OnPull()
1398+
if $$$ISERR(sc) {
1399+
set ec = $$$ADDSC(ec,sc)
1400+
}
14041401
write !, "==import done=="
14051402
quit ec
14061403
}
@@ -1577,10 +1574,6 @@ ClassMethod RunGitCommand(command As %String, Output errStream, Output outStream
15771574

15781575
ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", Output errStream, Output outStream, args...) As %Integer
15791576
{
1580-
set pullArg = ""
1581-
if command = "pull" {
1582-
set pullArg = $Get(args(1))
1583-
}
15841577
// Special case: git --version is used internally even when the settings incorporated here may be invalid/unspecified.
15851578
if (command '= "--version") {
15861579
set newArgs($increment(newArgs)) = "-C"
@@ -1608,44 +1601,43 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16081601

16091602
set newArgs($increment(newArgs)) = command
16101603

1611-
// defining variables for if statement use later
1612-
set syncIris = 0
1604+
set syncIrisWithDiff = 0 // whether IRIS needs to be synced with repo file changes using diff output
1605+
set syncIrisWithCommand = 0 // // whether IRIS needs to be synced with repo file changes using command output
16131606
set diffBase = ""
16141607
set diffCompare = ""
1615-
set pullOriginIndex = ""
1616-
if (command = "checkout") || (command = "merge") || (command = "rebase") || (command = "pull") {
1617-
set syncIris = 1
1618-
if $data(args) && $data(args(args),diffCompare) {
1619-
// no-op
1620-
}
1608+
1609+
if (command = "checkout"){
1610+
set syncIrisWithDiff = 1
1611+
set diffCompare = args(args)
1612+
} elseif (command = "merge") || (command = "rebase") || (command = "pull"){
1613+
set syncIrisWithCommand = 1
1614+
set diffCompare = args(args)
16211615
}
16221616

16231617
for i=1:1:$get(args) {
16241618
if ($data(args(i))) {
16251619
set newArgs($increment(newArgs)) = args(i)
1626-
if newArgs(newArgs) = pullArg {
1627-
set pullOriginIndex = newArgs
1628-
}
1629-
if (args(i) = "checkout") || (args(i) = "merge") || (args(i) = "rebase") || (args(i) = "pull"){
1630-
set syncIris = 1
1620+
if (args(i) = "checkout") {
1621+
set syncIrisWithDiff = 1
16311622
set diffCompare = args(i + 1)
16321623

16331624
if args = (i + 2) {
16341625
set diffBase = args(i + 2)
16351626
}
1627+
} elseif (args(i) = "merge") || (args(i) = "rebase") || (args(i) = "pull") {
1628+
set syncIrisWithCommand = 1
1629+
set diffCompare = args(i + 1)
16361630
}
16371631

1638-
if (args(i) = "pull") {
1639-
set pullOriginIndex = i
1640-
}
16411632
}
16421633
}
16431634

1644-
if (diffCompare = "--no-commit") || (diffCompare = "--abort") {
1645-
set syncIris = 0
1635+
if (diffCompare = "--no-commit") || (diffCompare = "--abort") || (diffCompare = "-b") {
1636+
set syncIrisWithDiff = 0
1637+
set syncIrisWithCommand = 0
16461638
}
16471639

1648-
if syncIris {
1640+
if syncIrisWithDiff {
16491641
if diffBase = "" {
16501642
set diffBase = ..GetCurrentBranch()
16511643
}
@@ -1665,13 +1657,9 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
16651657
set modification.internalName = ""
16661658
}
16671659
set files($increment(files)) = modification
1668-
set mod = files(files)
16691660
write !, ?4, modification.changeType, ?4, modification.internalName, ?4 , modification.externalName
16701661
}
16711662

1672-
if pullOriginIndex '= "" {
1673-
set newArgs(pullOriginIndex) = $piece(newArgs(pullOriginIndex), "/", 1)
1674-
}
16751663
}
16761664

16771665
set outLog = ##class(%Library.File).TempFilename()
@@ -1700,16 +1688,61 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
17001688
for stream=errStream,outStream {
17011689
set stream.RemoveOnClose = 1
17021690
}
1703-
if syncIris {
1704-
do ..PrintStreams(errStream, outStream)
1705-
$$$ThrowOnError(..SyncIrisWithRepo(.files))
1691+
do ..PrintStreams(errStream, outStream)
1692+
if syncIrisWithDiff {
1693+
$$$ThrowOnError(..SyncIrisWithRepoThroughDiff(.files))
1694+
} elseif syncIrisWithCommand {
1695+
$$$ThrowOnError(..SyncIrisWithRepoThroughCommand(.outStream))
17061696
}
17071697
quit returnCode
17081698
}
17091699

1710-
ClassMethod SyncIrisWithRepo(ByRef files)
1700+
ClassMethod SyncIrisWithRepoThroughCommand(ByRef outStream) As %Status
17111701
{
1702+
set deletedFiles = ""
1703+
set addedFiles = ""
1704+
set files = ""
1705+
while (outStream.AtEnd = 0) {
1706+
1707+
set line = outStream.ReadLine()
1708+
set lineStart = $piece(line, " ", 2)
1709+
if (lineStart = "delete") || (lineStart = "create") {
1710+
set fileOperation = $select(lineStart = "create" : "A", 1: "D")
1711+
set externalName = $piece(line, " ", *)
1712+
set internalName = ##class(SourceControl.Git.Utils).NameToInternalName(externalName,,0)
1713+
set modification = ##class(SourceControl.Git.Modification).%New()
1714+
set modification.changeType = fileOperation
1715+
set modification.internalName = internalName
1716+
set modification.externalName = externalName
1717+
set files($i(files)) = modification
1718+
if fileOperation = "A" {
1719+
set addedFiles = addedFiles_","_internalName
1720+
} else {
1721+
set deletedFiles = deletedFiles_","_internalName
1722+
}
1723+
}
1724+
}
1725+
1726+
set deletedFiles = $extract(deletedFiles, 2, *)
1727+
set addedFiles = $extract(addedFiles, 2, *)
1728+
17121729

1730+
if (deletedFiles '= ""){
1731+
set sc = ##class(SourceControl.Git.Utils).RemoveFromServerSideSourceControl(deletedFiles)
1732+
}
1733+
if (addedFiles '= ""){
1734+
set sc = ##class(SourceControl.Git.Utils).AddToServerSideSourceControl(addedFiles)
1735+
}
1736+
1737+
do outStream.Rewind()
1738+
set event = $classmethod(..PullEventClass(),"%New")
1739+
set event.LocalRoot = ..TempFolder()
1740+
merge event.ModifiedFiles = files
1741+
quit event.OnPull()
1742+
}
1743+
1744+
ClassMethod SyncIrisWithRepoThroughDiff(ByRef files) As %Status
1745+
{
17131746
set key = $order(files(""))
17141747
set deletedFiles = ""
17151748
set addedFiles = ""

cls/SourceControl/Git/WebUIDriver.cls

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ Class SourceControl.Git.WebUIDriver
33

44
ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Output handled As %Boolean = 0, Output %data As %Stream.Object)
55
{
6-
do %session.Unlock()
76
// Make sure we capture any stray output
87
set buffer = ##class(SourceControl.Git.Util.Buffer).%New()
98
do buffer.BeginCaptureOutput()
@@ -13,6 +12,7 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
1312
#dim %request as %CSP.Request
1413
set pathStart = $piece(pagePath,"/",2)
1514
if pathStart = "api" {
15+
do %session.Unlock()
1616
set handled = 1
1717
set %data = ##class(%Stream.FileCharacter).%New()
1818
if $extract(pagePath,6,*) = "userinfo" {
@@ -42,6 +42,7 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
4242
SimpleHTTPRequestHandler.do_GET(self)
4343
*/
4444
if (pathStart = "git") {
45+
do %session.Unlock()
4546
if $piece(pagePath,"/",3) = "cat-file" {
4647
set blob = $piece(pagePath,"/",4)
4748
set name = $Piece(pagePath,"/",*)
@@ -107,6 +108,10 @@ ClassMethod HandleRequest(pagePath As %String, InternalName As %String = "", Out
107108
}
108109
set readOnlyCommands = $listbuild("branch","tag","log","ls-files","ls-tree","show","status","diff")
109110
set baseCommand = $Piece(args(1)," ")
111+
112+
if $listfind(readOnlyCommands,baseCommand) {
113+
do %session.Unlock()
114+
}
110115

111116
set gitArgs($increment(gitArgs)) = "color.ui=true"
112117

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ ClassMethod Run()
1515
set branchName = ##class(SourceControl.Git.Utils).GetCurrentBranch()
1616
do ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "fetch")
1717
kill errStream, outStream
18-
do ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "diff", "origin/"_branchName, "--name-status")
18+
do ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "log", "HEAD..origin", "--name-status")
1919
} ElseIf %request.Get("method") = "pull" {
2020
Do ##class(SourceControl.Git.API).Pull()
2121
} ElseIf %request.Get("method") = "init" {

0 commit comments

Comments
 (0)