Skip to content

Commit 163e437

Browse files
authored
Fix behavior in package manager context (#205)
* Fix package manager awareness Also improves performance by reducing duplication of git commands * Bump version + update changelog * Fix outdated unit test
1 parent b5128cc commit 163e437

File tree

6 files changed

+42
-6
lines changed

6 files changed

+42
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [2.0.3+snapshot]
9+
10+
### Fixed
11+
- Correctly detects filesystem mappings in a package manager context
12+
- Improved performance by removing redundant git status calls
13+
814
## [2.0.2] - 2022-08-09
915

1016
### Fixed

cls/SourceControl/Git/Change.cls

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@ ClassMethod IsUncommitted(Filename, ByRef ID) As %Boolean
7979
}
8080

8181
/// Goes through Uncommitted queue and removes any items of action 'edit' or 'add' which are ReadOnly or non-existent on the filesystem
82-
ClassMethod RefreshUncommitted(Display = 0, IncludeRevert = 0) As %Status
82+
ClassMethod RefreshUncommitted(Display = 0, IncludeRevert = 0, Output gitFiles) As %Status
8383
{
84+
kill gitFiles
85+
8486
// files from the uncommitted queue
8587
set sc=..ListUncommitted(.tFileList,IncludeRevert,0)
8688
if $$$ISERR(sc) quit sc
@@ -127,3 +129,4 @@ ClassMethod RefreshUncommitted(Display = 0, IncludeRevert = 0) As %Status
127129
}
128130

129131
}
132+

cls/SourceControl/Git/Extension.cls

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,18 @@ Method GetStatus(InternalName As %String, ByRef IsInSourceControl As %Boolean, B
289289
if '$$$FileExists(filename) {
290290
set IsCheckedOut=0
291291
}
292-
do ##class(SourceControl.Git.Change).RefreshUncommitted()
293-
do ##class(SourceControl.Git.Utils).GitStatus(.files)
292+
// %MenuName and %InternalName set up by %Studio.SourceControl.Interface:MenuItems class query
293+
if $Data(%MenuName)#2 && $Data(%InternalName)#2 {
294+
if $Data(%MenuName(%InternalName)) {
295+
merge files = %MenuName(%InternalName)
296+
} else {
297+
do ##class(SourceControl.Git.Change).RefreshUncommitted(,,.files)
298+
// Cache to optimize rendering menu with multiple items dependent on status
299+
merge %MenuName(%InternalName) = files
300+
}
301+
} else {
302+
do ##class(SourceControl.Git.Change).RefreshUncommitted(,,.files)
303+
}
294304
if $get(files(InternalName)) '= "" {
295305
///it's in source control, checked out, and should be locked to editing by other users
296306
///find out who has it edited
@@ -319,3 +329,4 @@ Method GetStatus(InternalName As %String, ByRef IsInSourceControl As %Boolean, B
319329
}
320330

321331
}
332+

cls/SourceControl/Git/Utils.cls

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ ClassMethod IsInSourceControl(InternalName As %String, ByRef sourceControlItem A
853853
if isInSourceControl {
854854
// Direct reference to namespace-default project
855855
set sourceControlItem = InternalName
856-
} elseif context.IsInGitEnabledPackage && (InternalName = context.InternalName) {
856+
} elseif context.IsInGitEnabledPackage && (InternalName = ..NormalizeExtension(context.InternalName)) {
857857
// Next thing to check is if we're in a package manager-based package
858858
set isInSourceControl = 1
859859
set sourceControlItem = context.ResourceReference.Name
@@ -1537,7 +1537,12 @@ ClassMethod NameToInternalName(Name, IgnorePercent = 1, IgnoreNonexistent = 1, V
15371537
{
15381538
set InternalName=""
15391539
set Deleted = 0
1540-
if ($zconvert(Name,"U")'[$zconvert($$$SourceRoot,"U")) {
1540+
set context = ##class(SourceControl.Git.PackageManagerContext).%Get()
1541+
if (context.IsInGitEnabledPackage) {
1542+
if ($zconvert(Name,"U")'[$zconvert(context.Package.Root,"U")) {
1543+
set Name = ##class(%File).NormalizeFilename(context.Package.Root_Name)
1544+
}
1545+
} elseif ($zconvert(Name,"U")'[$zconvert($$$SourceRoot,"U")) {
15411546
set Name = ##class(%File).NormalizeFilename(..TempFolder()_Name)
15421547
}
15431548
if (##class(%File).Exists(Name)) {
@@ -1546,6 +1551,10 @@ ClassMethod NameToInternalName(Name, IgnorePercent = 1, IgnoreNonexistent = 1, V
15461551
if (($data(outName)=1) || ($data(outName) = 11 && ($order(outName(""),-1) = $order(outName(""))))) && ($zconvert(..Type(outName),"U") '= "CSP") {
15471552
//only set if a single Name was returned ... ignore multi-item files
15481553
set InternalName=outName
1554+
if (context.IsInGitEnabledPackage) {
1555+
// Don't need mappings!
1556+
return ..NormalizeInternalName(InternalName)
1557+
}
15491558
}
15501559
} else {
15511560
// check for file in uncommitted queue
@@ -1716,3 +1725,4 @@ ClassMethod GetSourceControlInclude() As %String
17161725
}
17171726

17181727
}
1728+

module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<Document name="git-source-control.ZPM">
44
<Module>
55
<Name>git-source-control</Name>
6-
<Version>2.0.2</Version>
6+
<Version>2.0.3+snapshot</Version>
77
<Description>Server-side source control extension for use of Git on InterSystems platforms</Description>
88
<Keywords>git source control studio vscode</Keywords>
99
<Packaging>module</Packaging>

test/UnitTest/SourceControl/Git/NameToInternalNameTest.cls

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Property Mappings [ MultiDimensional ];
99

1010
Property OldNamespaceTemp As %String;
1111

12+
Property OldPercentClassReplace As %String;
13+
1214
Method TestRegularClassNames()
1315
{
1416
// Regular class that exists
@@ -93,7 +95,9 @@ Method OnBeforeAllTests() As %Status
9395
{
9496
set settings = ##class(SourceControl.Git.Settings).%New()
9597
set ..OldNamespaceTemp = settings.namespaceTemp
98+
set ..OldPercentClassReplace = settings.percentClassReplace
9699
set settings.namespaceTemp = $Piece(..Manager.CurrentDir,"test",1)
100+
set settings.percentClassReplace = "_"
97101
$$$ThrowOnError(settings.%Save())
98102
merge ..Mappings = @##class(SourceControl.Git.Utils).MappingsNode()
99103
kill @##class(SourceControl.Git.Utils).MappingsNode()
@@ -115,10 +119,12 @@ Method %OnClose() As %Status
115119
{
116120
set settings = ##class(SourceControl.Git.Settings).%New()
117121
set settings.namespaceTemp = ..OldNamespaceTemp
122+
set settings.percentClassReplace = ..OldPercentClassReplace
118123
do settings.%Save()
119124
kill @##class(SourceControl.Git.Utils).MappingsNode()
120125
merge @##class(SourceControl.Git.Utils).MappingsNode() = ..Mappings
121126
quit $$$OK
122127
}
123128

124129
}
130+

0 commit comments

Comments
 (0)