Skip to content

Make expanding truncated filenames more general and add support for lookup tables #515

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

Closed
wants to merge 2 commits into from
Closed
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
56 changes: 33 additions & 23 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -1910,22 +1910,18 @@ ClassMethod SyncIrisWithRepoThroughCommand(ByRef outStream) As %Status
set externalName = $zstrip($piece(line,"|",1),"<>W")
if $Extract(externalName,1,3) = "..." {
// For extremely long file names, git may truncate the path.
// Simplifying assumption: this is a class, because nothing else would have that long a name.
// In other cases, we'll just end up logging the invalid externalName.
if $Piece(externalName,".",*) = "cls" {
set possibleClasses = ..ExpandClasses(externalName)
if $ListLength(possibleClasses) '= 0 {
set pointer = 0
while $ListNext(possibleClasses,pointer,class) {
set modification = ##class(SourceControl.Git.Modification).%New()
set modification.changeType = "C"
set modification.internalName = class_".CLS"
set modification.externalName = ..ExternalName(modification.internalName)
set files($i(files)) = modification
}
} else {
write !,"WARNING: unable to translate external name ",externalName
continue
// Attempt to expand truncated names by matching them against one or more internal names.
// Not all file types may be supported, where they are then a list of possible internal names is returned.
// In other cases no names are returned, we'll just end up logging the invalid externalName.
set possibleNames = ..ExpandTruncatedNames(externalName)
if $ListLength(possibleNames) '= 0 {
set pointer = 0
while $ListNext(possibleNames,pointer,name) {
set modification = ##class(SourceControl.Git.Modification).%New()
set modification.changeType = "C"
set modification.internalName = name_"."_$Piece(externalName,".",*)
set modification.externalName = ..ExternalName(modification.internalName)
set files($i(files)) = modification
}
} else {
write !,"WARNING: unable to translate external name ",externalName
Expand Down Expand Up @@ -1955,28 +1951,42 @@ ClassMethod SyncIrisWithRepoThroughCommand(ByRef outStream) As %Status
quit ##class(SourceControl.Git.PullEventHandler).ForModifications(.files)
}

ClassMethod ExpandClasses(externalName As %String) As %List
ClassMethod ExpandTruncatedNames(externalName As %String) As %List
{
set internalName = $Piece(externalName,".",1,*-1)
set internalName = $Extract(internalName,4,*)
set internalName = $Translate(internalName,"/\%",".."_..PercentClassReplace())
set internalName = $Translate(internalName,"/\","..")

set externalNameExtension = $Piece(externalName,".",*)
if (externalNameExtension = "cls") {
set internalName = $Translate(internalName,"%",..PercentClassReplace())
}

set possibleNames = ""
do {
&sql(select %DLIST(Name) into :classes from %Dictionary.ClassDefinition where Name like '%'||:internalName)
if (externalNameExtension = "cls") {
&sql(select %DLIST(Name) into :possibleNames from %Dictionary.ClassDefinition where Name like '%'||:internalName)
} elseif (externalNameExtension = "lut") {
&sql(select %DLIST(distinct TableName) into :possibleNames from Ens_Util.LookupTable where TableName like '%'||:internalName)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think some additional work might be needed to generalize this. Two major reasons:

  • We want this to work on non-interoperability-enabled namespaces, where Ens_Util.LookupTable isn't available. This is a blocking issue for merge of this PR.
  • We want this to work for other document types as well, not just cls and lut. (e.g., I could also see truncation popping up with with .DFI)

There might be an elegant (code-wise) approach using %Library.RoutineMgr:StudioOpenDialog that would hit all relevant cases at once, but I'd be concerned about the possible performance impact. Another approach could be using the List query of the relevant %Studio.AbstractDocument subclass directly based on the extension.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the excellent feedback. Based on this I am thinking that attempting to address this by improving the truncated name expanding logic may not be the ideal approach and I have instead put together #517 to hopefully address this more robustly, at least for pulls initially.

} else {
// Unsupported extension, do nothing.
quit
}
if (SQLCODE < 0) {
Throw ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE,%msg)
}

// If nothing was found then remove period-delimited pieces from the start of internalName
// until we either find something or run out of pieces.
// This will allow for classes to potentially still be identified when the
// repository directory structure does not align with class packages.
if ($ListLength(classes) = 0) {
// This will allow for truncated names to potentially still be identified when the
// repository directory structure does not align with internal names.
if ($ListLength(possibleNames) = 0) {
set internalName = $Piece(internalName,".",2,*)
} else {
set internalName = ""
}
} while (internalName '= "")
quit classes
quit possibleNames
}

ClassMethod ParseDiffStream(stream As %Stream.Object, verbose As %Boolean = 1, Output files)
Expand Down
Loading