Skip to content

Instance wide uncommitted queue #436

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 12 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.5.0] - Unreleased

### Added
- Files in uncommitted queue in any namespace warn users when opened except for in VSCode (#370)

## [2.4.1] - Unreleased

### Fixed
Expand Down
40 changes: 40 additions & 0 deletions cls/SourceControl/Git/Change.cls
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,46 @@ ClassMethod RefreshUncommitted(Display = 0, IncludeRevert = 0, Output gitFiles,
quit sc
}

Query InstanceUncommitted() As %Query(ROWSPEC = "InternalName:%String,User:%String")
{
}

ClassMethod InstanceUncommittedExecute(ByRef qHandle As %Binary) As %Status
{
set qHandle("q") = "SELECT InternalName, ChangedBy FROM SourceControl_Git.Change"
set namespaces = ##class(SourceControl.Git.Utils).GetGitEnabledNamespaces()
set tPtr = 0
set qHandle("i") = 1
while $LISTNEXT(namespaces, tPtr, tValue) {
set namespace = $ZCONVERT(tValue, "U")
set $NAMESPACE = namespace
set resultSet = ##class(%SQL.Statement).%ExecDirect(, qHandle("q"))
while resultSet.%Next() {
set qHandle("changes", $increment(qHandle("changes")), "InternalName") = resultSet.%GetData(1)
set qHandle("changes", qHandle("changes"), "User") = resultSet.%GetData(2)
}
}

Quit $$$OK
}

ClassMethod InstanceUncommittedFetch(ByRef qHandle As %Binary, ByRef Row As %List, ByRef AtEnd As %Integer = 0) As %Status [ PlaceAfter = InstanceUncommittedExecute ]
{
set i = qHandle("i")
set Row = $listbuild(qHandle("changes", i, "InternalName"), qHandle("changes", i, "User"))
if i = qHandle("changes") {
set AtEnd = 1
} else {
set qHandle("i") = $increment(qHandle("i"))
}
Quit $$$OK
}

ClassMethod InstanceUncommittedClose(ByRef qHandle As %Binary) As %Status [ PlaceAfter = InstanceUncommittedFetch ]
{
Quit $$$OK
}

Storage Default
{
<Data name="ChangeDefaultData">
Expand Down
9 changes: 9 additions & 0 deletions cls/SourceControl/Git/Extension.cls
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ Method UserAction(Type As %Integer, Name As %String, InternalName As %String, Se
set Name = "%SourceMenu,Status"
}

if (Type = 1) && (Name = 3) {
set user = ""
if ##class(SourceControl.Git.Utils).FileIsUncommitted(InternalName, .user) && (user '= $USERNAME){
set Target = InternalName _ " is currently being modified by " _ user
write !, Target
set Action = 6
}
}

if (Type = 1) && ((Name = 1) || (Name = 7)) {
do ..AddToSourceControl(InternalName)
}
Expand Down
57 changes: 57 additions & 0 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -2418,6 +2418,63 @@ ClassMethod UncommittedWithAction() As %Library.DynamicObject
quit fileToOtherDevelopers
}

/// Retrieve the list of Namespaces that have git enabled
ClassMethod GetGitEnabledNamespaces() As %String
{
// Get all namespaces
set allNamespaces = ""
do ##class(%SYS.Namespace).ListAll(.allNamespaces)

set enabledNamespaces = ""

// Write query for verifying git sourcecontrol in namespace
set gitscQuery = 9
set gitscQuery(1) = "SELECT CASE"
set gitscQuery(2) = "WHEN EXISTS ("
set gitscQuery(3) = "SELECT TABLE_SCHEMA"
set gitscQuery(4) = "FROM INFORMATION_SCHEMA.TABLES"
set gitscQuery(5) = "WHERE TABLE_TYPE = 'BASE TABLE'"
set gitscQuery(6) = "AND TABLE_SCHEMA = 'SourceControl_Git'"
set gitscQuery(7) = ") THEN 1"
set gitscQuery(8) = "ELSE 0"
set gitscQuery(9) = "END AS SchemaExists;"


set namespace = ""
new $NAMESPACE
for {
set namespace = $ORDER(allNamespaces(namespace))
quit:namespace=""
set $NAMESPACE = namespace
set statement = ##class(%SQL.Statement).%New()
set status = statement.%Prepare(.gitscQuery)
set result = statement.%Execute()
do result.%Next()
set gitEnabled = result.%GetData(1)
if (gitEnabled) set enabledNamespaces = enabledNamespaces _ $listbuild(namespace)



}

quit enabledNamespaces
}

ClassMethod FileIsUncommitted(InternalName As %String, Output User) As %Boolean
{
set isUncommitted = 0
set resultSet = ##class(SourceControl.Git.Change).InstanceUncommittedFunc()
while resultSet.%Next() {
set fileName = resultSet.InternalName
if InternalName = fileName {
set isUncommitted = 1
set User = resultSet.User
}
}

quit isUncommitted
}

ClassMethod BuildCEInstallationPackage(ByRef destination As %String) As %Status
{
#define sourcedir $System.Util.InstallDirectory()_"devuser/studio/templates/gitsourcecontrol/"
Expand Down
Loading