Skip to content

No more sclist #125

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 10 commits into from
Feb 16, 2022
17 changes: 4 additions & 13 deletions cls/SourceControl/Git/Extension.cls
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ Method UserAction(Type As %Integer, Name As %String, InternalName As %String, Se
if menu '= "%SourceMenu", menu'="%SourceContext" {
quit $$$OK
}
do $System.OBJ.GetPackageList(.files,InternalName)
if ($DATA(files) '= 0) {
set InternalName = ($piece($order(files("")), ".", 1)_".pkg")
}

set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)
set ec = ##class(Utils).UserAction(InternalName, Name, .Target, .Action, .Reload)
Expand Down Expand Up @@ -135,7 +132,9 @@ Method OnSourceMenuContextItem(itemName As %String, menuItemName As %String, ByR
{
if (itemName = "") || '##class(Utils).IsNamespaceInGit() {
set Enabled = -1
} elseif $find(itemName,",") > 0 { //if more than one item is selected, we can only add/remove, no diff or blame
} elseif (($find(itemName,",") > 0) || (##class(SourceControl.Git.Utils).Type(itemName) = "pkg")) {
//if more than one item is selected, we can only add/remove, no diff or blame
// if a package is selected we should show options to add missing items and remove exisiting ones
set Enabled = $case(menuItemName,"AddToSC":1,"RemoveFromSC":1,:-1)
} elseif menuItemName = "Revert" {
set Enabled = 1
Expand Down Expand Up @@ -164,14 +163,6 @@ Method OnSourceMenuContextItem(itemName As %String, menuItemName As %String, ByR
/// this menu item from the list totally, 0 will gray the menu item out and the default 1 will display the menu item as normal.
Method OnMenuItem(MenuName As %String, InternalName As %String, SelectedText As %String, ByRef Enabled As %Boolean, ByRef DisplayName As %String) As %Status
{

if (InternalName '= ""){
do $System.OBJ.GetPackageList(.files,InternalName)
if ($DATA(files) '= 0) {
set InternalName = ($piece($order(files("")), ".", 1)_".pkg")
}
}

set InternalName = ##class(Utils).NormalizeInternalName(InternalName)
set context = ##class(SourceControl.Git.PackageManagerContext).ForInternalName(InternalName)

Expand Down
32 changes: 0 additions & 32 deletions cls/SourceControl/Git/PullEventHandler/IncrementalLoad.cls
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,6 @@ Method OnPull() As %Status
set internalName = ..ModifiedFiles(i).internalName
if ((internalName = "") && (..ModifiedFiles(i).changeType '= "D")) {
write ..ModifiedFiles(i).externalName, " was not imported into the database and will not be compiled. ", !
} elseif ..ModifiedFiles(i).changeType = "D" {
#dim type as %String = ##class(SourceControl.Git.Utils).Type(internalName)
#dim name as %String = ##class(SourceControl.Git.Utils).NameWithoutExtension(internalName)
#dim deleted as %Boolean = 1
write !

if type = "prj" {
set loadSC = $$$ADDSC(loadSC, $system.OBJ.DeleteProject(name))
}elseif type = "cls" {
set loadSC = $$$ADDSC(loadSC, $system.OBJ.Delete(internalName))
}elseif $listfind($listbuild("mac","int","inc","bas","mvb","mvi","dfi"), type) > 0 {
set loadSC = $$$ADDSC(loadSC, ##class(%Routine).Delete(internalName))
}elseif type = "csp" {
#dim filename = $system.CSP.GetFileName(internalName)
if ##class(%File).Exists(filename) && '##class(%File).Delete(filename) {
set loadSC = $$$ADDSC(loadSC, ##class(SourceControl.Git.Utils).MakeError("Error while removing "_internalName))
}
} else {
set deleted = 0
}

if deleted && loadSC {
do ##class(SourceControl.Git.Utils).RemoveRoutineTSH(internalName)
} else {
if +$system.Status.GetErrorCodes(loadSC) '= $$$ClassDoesNotExist {
write "Error: could not delete ", internalName, !
} else {
// if something we wanted to delete is already deleted -- good!
set loadSC = $$$OK
}
}
} else {
set compilelist(internalName) = ""
set nFiles = nFiles + 1
Expand All @@ -62,4 +31,3 @@ Method OnPull() As %Status
}

}

181 changes: 88 additions & 93 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Parameter InstallNamespace = "%SYS";
Parameter Slash = {$case($system.Version.GetOS(),"Windows":"\",:"/")};

/// Name of the file with version controlled items
Parameter SCListFilename = "sc-list.txt";

Parameter GitMenuItems = ",Settings,Commit,Pull,Fetch,Push,Revert,";

Parameter ImportAfterGitMenuItems = ",Commit,Pull,Fetch,Push,";
Expand Down Expand Up @@ -336,9 +334,14 @@ ClassMethod Pull(remote As %String = "origin") As %Status
while (outStream.AtEnd = 0) {
set file = outStream.ReadLine()
set modification = ##class(SourceControl.Git.Modification).%New()
set modification.changeType = $piece(file, " ", 1)
set modification.externalName = $zstrip($piece(file," ",2,*),"<W")
set modification.internalName = ##class(SourceControl.Git.Utils).NameToInternalName(modification.externalName,,0)
set modification.changeType = $piece(file, $c(9), 1)
set modification.externalName = $zstrip($piece(file, $c(9),2),"<W")
if (modification.changeType '= "A"){
set modification.internalName = ##class(SourceControl.Git.Utils).NameToInternalName(modification.externalName,,0)
}
else {
set modification.internalName = ""
}
set files($increment(files)) = modification
write !, ?4, modification.changeType, ?4, modification.internalName, ?4 , modification.externalName
}
Expand All @@ -348,7 +351,6 @@ ClassMethod Pull(remote As %String = "origin") As %Status
quit $$$OK
}


set sc = ..RunGitWithArgs(.errStream, .outStream, "pull", remote, branchName)
if (sc=1){
do errStream.OutputToDevice()
Expand All @@ -359,6 +361,31 @@ ClassMethod Pull(remote As %String = "origin") As %Status
do outStream.OutputToDevice()
write !

set key = $order(files(""))
set deletedFiles = ""
set addedFiles = ""
while(key '= "") {
set modification = files(key)
if (modification.changeType = "D"){
set deletedFiles = deletedFiles_","_modification.internalName
} elseif (modification.changeType = "A"){
set modification.internalName = ##class(SourceControl.Git.Utils).NameToInternalName(modification.externalName,,0)
set addedFiles = addedFiles_","_modification.internalName
set files(key) = modification
}
set key = $order(files(key))
}

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)
}

set event = $classmethod(..PullEventClass(),"%New")
set event.LocalRoot = ..TempFolder()
merge event.ModifiedFiles = files
Expand Down Expand Up @@ -386,15 +413,34 @@ ClassMethod ExternalName(InternalName As %String) As %String
quit ..Name(InternalName)
}

ClassMethod AddToServerSideSourceControl(InternalName As %String) As %Status
{
#dim i as %Integer
#dim ec as %Status = $$$OK
for i = 1:1:$length(InternalName, ",") {
#dim item as %String = ..NormalizeExtension($piece(InternalName, ",", i))
set @..#Storage@("items", item) = ""
#dim sc as %Status = ..ImportItem(item, 1)
if 'sc {
set ec = $$$ADDSC(ec, sc)
}
}
quit ec
}

ClassMethod AddToSourceControl(InternalName As %String) As %Status
{
#dim i as %Integer
#dim ec as %Status = $$$OK
for i = 1:1:$length(InternalName, ",") {
#dim item as %String = ..NormalizeExtension($piece(InternalName, ",", i))
set @..#Storage@("items", item) = ""
#dim type as %String = ..Type(item)

if ((type '= "pkg") && (type '= "prj")){
set @..#Storage@("items", item) = ""
}

#dim sc as %Status = ..ExportItem(item,,,.filenames)
zwrite filenames
if 'sc {
set ec = $$$ADDSC(ec, sc)
}
Expand All @@ -404,22 +450,14 @@ ClassMethod AddToSourceControl(InternalName As %String) As %Status
set FileType = ##class(SourceControl.Git.Utils).Type(FileInternalName)

continue:..NormalizeExtension(FileInternalName)=item

if (FileType = "cls"){
set potentialMissingPackage = $case($piece(FileInternalName, ".", 1, *-2), "":"", :$piece(FileInternalName, ".", 1, *-2)_".pkg")

if (potentialMissingPackage '= "") {
set @..#Storage@("items", potentialMissingPackage) = ""
}
}

continue:$DATA(@..#Storage@("items", FileInternalName))
set @..#Storage@("items", FileInternalName) = ""
do ..RunGitCommand("add",.errStream,.outStream,filenames(i))
write !, "Added ", FileInternalName, " to source control."
do outStream.OutputToDevice()
do errStream.OutputToDevice()
}
}
set ec = $$$ADDSC(ec, ..ExportSCList())
quit ec
}

Expand Down Expand Up @@ -572,6 +610,26 @@ ClassMethod FindTrackedParent(InternalName As %String, ByRef parentElement As %S
quit isInSourceControl
}

ClassMethod RemoveFromServerSideSourceControl(InternalName As %String) As %Status
{
#dim i as %Integer
#dim ec as %Status = $$$OK
for i = 1:1:$length(InternalName, ",") {
#dim item as %String = ..NormalizeExtension($piece(InternalName, ",", i))
#dim tsc as %Status = $$$OK
#dim type as %String = ..Type(InternalName)

if $data(@..#Storage@("items", item)) {
kill @..#Storage@("items", item)
do ..RemoveFolderIfEmpty(..TempFolder())
} elseif (type = "cls") {
set tsc = ..MakeError(item _ " is not in SourceControl")
}
set ec = $$$ADDSC(tsc, ec)
}
quit ec
}

ClassMethod RemoveFromSourceControl(InternalName As %String, cascadeDelete As %Boolean = 1) As %Status
{
write !
Expand All @@ -591,30 +649,21 @@ ClassMethod RemoveFromSourceControl(InternalName As %String, cascadeDelete As %B

if $data(@..#Storage@("items", item)) {
kill @..#Storage@("items", item)
set tsc = ..DeleteExternalsForItem(item)
} elseif ((type="cls") || (type="inc") || (type="mac")){
set tsc = ..MakeError(item _ " is not in SourceControl")
}

if (cascadeDelete) {
if ((type="pkg") || (type="csp") || (type="prj")) {
set tsc = $$$ADDSC(tsc, ..FindTrackedFiles(InternalName, .trackedFiles))
if (trackedFiles '= ""){
set tsc = $$$ADDSC(tsc, ..RemoveFromSourceControl(trackedFiles, 0))
}
if (cascadeDelete) {
if ((type="pkg") || (type="csp") || (type="prj")) {
set tsc = $$$ADDSC(tsc, ..FindTrackedFiles(InternalName, .trackedFiles))
if (trackedFiles '= ""){
set tsc = $$$ADDSC(tsc, ..RemoveFromSourceControl(trackedFiles, 0))
}
}
}
do ..RemoveFolderIfEmpty(..TempFolder())

set tsc = ..DeleteExternalsForItem(item)
do ..RemoveFolderIfEmpty(..TempFolder())
set tsc = $$$ADDSC(tsc, ..ExportSCList())

// remove the parent element if it exists
#dim parentElement as %String = ""
set found = ..FindTrackedParent(item, .parentElement)

if (found){
do ..RemoveFromSourceControl(parentElement, 0)
}
} elseif (type = "cls") {
set tsc = ..MakeError(item _ " is not in SourceControl")
}

set sc = $$$ADDSC(tsc, sc)
}
Expand Down Expand Up @@ -1179,14 +1228,12 @@ ClassMethod ExportProject(project As %String, force As %Boolean = 0, ByRef filen
/// if <var>force</var> = 1 then we export item even if timestamp in system is older
ClassMethod ExportAll(force As %Boolean = 0) As %Status
{
$$$QuitOnError(..ExportRoutines(force))
quit ..ExportSCList()
quit ..ExportRoutines(force)
}

/// if <var>force</var> = 1 then we import item even if timestamp in system is newer
ClassMethod ImportAll(force As %Boolean = 0) As %Status
{
$$$QuitOnError(..ImportSCList())
quit ..ImportRoutines(force)
}

Expand All @@ -1203,58 +1250,6 @@ ClassMethod ExportRoutines(force As %Boolean = 0) As %Status
quit ec
}

ClassMethod ExportSCList() As %Status
{
#dim filename = ..TempFolder()_..#SCListFilename
#dim file as %File = ##class(%File).%New(filename)
#dim item as %String = ""
#dim defaultCspApp as %String = $system.CSP.GetDefaultApp($znspace)
$$$QuitOnError(file.Open("WSN"))

for {
set item = $order(@..#Storage@("items",item))
quit:item=""
#dim fixedItem as %String = item
if $extract(fixedItem, 1, $length(defaultCspApp)) = defaultCspApp {
set $extract(fixedItem, 1, $length(defaultCspApp)) = "<cspapp>"
}

do file.WriteLine(fixedItem)

}
$$$QuitOnError(file.%Save())
do file.Close()
kill file

do ..RunGitWithArgs(.errStream, .outStream, "add", ..#SCListFilename)
do errStream.OutputToDevice()
do outStream.OutputToDevice()
quit $$$OK
}

ClassMethod ImportSCList() As %Status
{
#dim filename = ..TempFolder()_..#SCListFilename
#dim file as %File = ##class(%File).%New(filename)
#dim defaultCspApp as %String = $system.CSP.GetDefaultApp($znspace)
#dim eol as %Boolean

$$$QuitOnError(file.Open("R", 10))

#dim a
while 'file.AtEnd {
#dim s as %String = file.ReadLine(,,.eol)
continue:s=""
#dim item as %String = $replace(s, "<cspapp>", defaultCspApp)
set a(..NormalizeExtension(item)) = ""
}
kill @..#Storage("items")
merge @..#Storage("items") = a
do file.Close()
kill file
quit $$$OK
}

/// returns true if directory was deleted
ClassMethod RemoveFolderIfEmpty(path As %String) As %Boolean
{
Expand Down
17 changes: 0 additions & 17 deletions sc-list.txt

This file was deleted.