Skip to content

Merge, Pull and Rebase now don't use diff to synchronize file system with IRIS #384

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cls/SourceControl/Git/Util/Buffer.cls
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,4 @@ Method UsePreviousDeviceAndSettings() [ Internal, Private ]
}

}

95 changes: 67 additions & 28 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ ClassMethod Pull(remote As %String = "origin") As %Status
set branchName = outStream.ReadLine(outStream.Size)
write !, "Pulling from branch: ", branchName
kill errStream, outStream
set returnCode = ..RunGitWithArgs(.errStream, .outStream, "pull", remote _ "/" _ branchName)
set returnCode = ..RunGitWithArgs(.errStream, .outStream, "pull", remote)

w !, "Pull ran with return code: " _ returnCode
quit $$$OK
Expand Down Expand Up @@ -1534,10 +1534,6 @@ ClassMethod RunGitCommand(command As %String, Output errStream, Output outStream

ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", Output errStream, Output outStream, args...) As %Integer
{
set pullArg = ""
if command = "pull" {
set pullArg = args(1)
}
// Special case: git --version is used internally even when the settings incorporated here may be invalid/unspecified.
if (command '= "--version") {
set newArgs($increment(newArgs)) = "-C"
Expand Down Expand Up @@ -1565,43 +1561,44 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O

set newArgs($increment(newArgs)) = command

// defining variables for if statement use later
set syncIris = 0
set syncIrisWithDiff = 0 // whether IRIS needs to be synced with repo file changes using diff output
set syncIrisWithCommand = 0 // // whether IRIS needs to be synced with repo file changes using command output
set diffBase = ""
set diffCompare = ""
set pullOriginIndex = ""
if (command = "checkout") || (command = "merge") || (command = "rebase") || (command = "pull"){
set syncIris = 1

if (command = "checkout"){
set syncIrisWithDiff = 1
set diffCompare = args(args)
} elseif (command = "merge") || (command = "rebase") || (command = "pull"){
set syncIrisWithCommand = 1
set diffCompare = args(args)
}


for i=1:1:$get(args) {
if ($data(args(i))) {
set newArgs($increment(newArgs)) = args(i)
if newArgs(newArgs) = pullArg {
set pullOriginIndex = newArgs
}
if (args(i) = "checkout") || (args(i) = "merge") || (args(i) = "rebase") || (args(i) = "pull"){
set syncIris = 1
if (args(i) = "checkout") {
set syncIrisWithDiff = 1
set diffCompare = args(i + 1)

if args = (i + 2) {
set diffBase = args(i + 2)
}
} elseif (args(i) = "merge") || (args(i) = "rebase") || (args(i) = "pull") {
set syncIrisWithCommand = 1
set diffCompare = args(i + 1)
}

if (args(i) = "pull") {
set pullOriginIndex = i
}
}
}

if (diffCompare = "--no-commit") || (diffCompare = "--abort") {
set syncIris = 0
if (diffCompare = "--no-commit") || (diffCompare = "--abort") || (diffCompare = "-b") {
set syncIrisWithDiff = 0
set syncIrisWithCommand = 0
}

if syncIris {
if syncIrisWithDiff {
if diffBase = "" {
set diffBase = ..GetCurrentBranch()
}
Expand All @@ -1621,13 +1618,9 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
set modification.internalName = ""
}
set files($increment(files)) = modification
set mod = files(files)
write !, ?4, modification.changeType, ?4, modification.internalName, ?4 , modification.externalName
}

if pullOriginIndex '= "" {
set newArgs(pullOriginIndex) = $piece(newArgs(pullOriginIndex), "/", 1)
}
}

set outLog = ##class(%Library.File).TempFilename()
Expand Down Expand Up @@ -1657,15 +1650,60 @@ ClassMethod RunGitCommandWithInput(command As %String, inFile As %String = "", O
set stream.RemoveOnClose = 1
}
do ..PrintStreams(errStream, outStream)
if syncIris {
$$$ThrowOnError(..SyncIrisWithRepo(.files))
if syncIrisWithDiff {
$$$ThrowOnError(..SyncIrisWithRepoThroughDiff(.files))
} elseif syncIrisWithCommand {
$$$ThrowOnError(..SyncIrisWithRepoThroughCommand(.outStream))
}
quit returnCode
}

ClassMethod SyncIrisWithRepo(ByRef files)
ClassMethod SyncIrisWithRepoThroughCommand(ByRef outStream) As %Status
{
set deletedFiles = ""
set addedFiles = ""
set files = ""
while (outStream.AtEnd = 0) {

set line = outStream.ReadLine()
set lineStart = $piece(line, " ", 2)
if (lineStart = "delete") || (lineStart = "create") {
set fileOperation = $select(lineStart = "create" : "A", 1: "D")
set externalName = $piece(line, " ", *)
set internalName = ##class(SourceControl.Git.Utils).NameToInternalName(externalName,,0)
set modification = ##class(SourceControl.Git.Modification).%New()
set modification.changeType = fileOperation
set modification.internalName = internalName
set modification.externalName = externalName
set files($i(files)) = modification
if fileOperation = "A" {
set addedFiles = addedFiles_","_internalName
} else {
set deletedFiles = deletedFiles_","_internalName
}
}
}

set deletedFiles = $extract(deletedFiles, 2, *)
set addedFiles = $extract(addedFiles, 2, *)


if (deletedFiles '= ""){
set sc = ##class(SourceControl.Git.Utils).RemoveFromServerSideSourceControl(deletedFiles)
}
if (addedFiles '= ""){
set sc = ##class(SourceControl.Git.Utils).AddToServerSideSourceControl(addedFiles)
}

do outStream.Rewind()
set event = $classmethod(..PullEventClass(),"%New")
set event.LocalRoot = ..TempFolder()
merge event.ModifiedFiles = files
quit event.OnPull()
}

ClassMethod SyncIrisWithRepoThroughDiff(ByRef files) As %Status
{
set key = $order(files(""))
set deletedFiles = ""
set addedFiles = ""
Expand Down Expand Up @@ -2348,3 +2386,4 @@ ClassMethod BaselineExport(pCommitMessage = "", pPushToRemote = "") As %Status
}

}

1 change: 1 addition & 0 deletions cls/SourceControl/Git/WebUIDriver.cls
Original file line number Diff line number Diff line change
Expand Up @@ -243,3 +243,4 @@ ClassMethod GetPackageVersion() As %Library.DynamicObject
}

}

2 changes: 1 addition & 1 deletion cls/_zpkg/isc/sc/git/Socket.cls
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ ClassMethod Run()
set branchName = ##class(SourceControl.Git.Utils).GetCurrentBranch()
do ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "fetch")
kill errStream, outStream
do ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "diff", "origin/"_branchName, "--name-status")
do ##class(SourceControl.Git.Utils).RunGitWithArgs(.errStream, .outStream, "log", "HEAD..origin", "--name-status")
} ElseIf %request.Get("method") = "pull" {
Do ##class(SourceControl.Git.API).Pull()
} ElseIf %request.Get("method") = "init" {
Expand Down
Loading