Skip to content

Commit

Permalink
Introduced .gitignore filter support
Browse files Browse the repository at this point in the history
fixed file logs
  • Loading branch information
evshvarov committed Apr 14, 2017
1 parent a50f634 commit 731345a
Showing 1 changed file with 47 additions and 3 deletions.
50 changes: 47 additions & 3 deletions sc.code.cls
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ClassMethod export(generated = 0, system = 0, percent = 0, mapped = 0, mask = ""
#define isGenerated(%code) ##class(%RoutineMgr).IsGenerated( %code )
#define isPercented(%code) ("%" = $e(%code))
#define isMapped(%code) ##class(%RoutineMgr).IsMapped( %code )
#define log w !, code, " -> ", ##class(%File).GetFilename(filename), " "
#define log w !, code, " -> ", $piece(filename,..workdir(),2), " "

#define mkdir(%filename) ##continue
s path = ##class(%File).GetDirectory( %filename ) ##continue
Expand Down Expand Up @@ -91,10 +91,11 @@ ClassMethod import(filemask = "*.*", qspec = "cku-d", ByRef err = "", recurse =
#define push(%dir) s dirs( $i( dirs ) ) = %dir
#define next(%i,%dir) s %i=$o( dirs( "" ), 1, %dir ) k:%i'="" dirs(%i)
#define isDirectory(%type) ( %type = "D" )
#define log w !, ##class(%File).GetFilename(filename), " " w:sc "Ok" d:'sc $system.OBJ.DisplayError(sc)
#define log w !, $piece(filename,..workdir(),2), " " w:sc "Ok" d:'sc $system.OBJ.DisplayError(sc)

s sc = 1, dirs = "", dir = ..workdir() $$$push(dir)
if verbose w "#; Importing from ", dir,!
d ..setIgnore(.fm)
for { $$$next(i,dir) Q:i="" Q:dir=""

s rs = ##class(%File).FileSetFunc( dir, filemask, , 1 )
Expand All @@ -106,6 +107,8 @@ ClassMethod import(filemask = "*.*", qspec = "cku-d", ByRef err = "", recurse =
if recurse $$$push(filename)
continue
}
// check file filter
if ..inFilter(.fm,filename) continue

s ext = $p( filename, ".", * )

Expand All @@ -123,6 +126,43 @@ ClassMethod import(filemask = "*.*", qspec = "cku-d", ByRef err = "", recurse =
Q sc
}

ClassMethod inFilter(ByRef filtermask,filename) as %Boolean
{
s result=0
for
{
if '$d(filtermask($I(i))) quit
set filter=$piece(filtermask(i),"*")
if $length(filename,filter)>1 set result=1
}

quit result
}

/// get the filtermask for the repository.
/// looks for .gitignore file and applies all the lines to filters
ClassMethod setIgnore(ByRef filtermask)
{

// working with .gitignore file
// gitignore consists of masks of filtering files
s filename=..workdir()_"/.gitignore"
if '##class(%File).Exists(filename) quit
s file=##class(%File).%New(filename)
s sc=file.Open("R")
if 'sc
{
if verbose d $System.OBJ.DisplayError(sc) return
}

While 'file.AtEnd
{
s filtermask($I(filtermask))=file.ReadLine()
}
quit
}


/// get or set working directory for export/import source
ClassMethod workdir(workdir)
{
Expand Down Expand Up @@ -181,10 +221,11 @@ ClassMethod importUpdated(filemask = "*.*", qspec = "cku-d", ByRef err = "", rec
#define push(%dir) s dirs( $i( dirs ) ) = %dir
#define next(%i,%dir) s %i=$o( dirs( "" ), 1, %dir ) k:%i'="" dirs(%i)
#define isDirectory(%type) ( %type = "D" )
#define log w !, ##class(%File).GetFilename(filename)," " w:sc "Ok" d:'sc $system.OBJ.DisplayError( sc )
#define log w !, $piece(filename,..workdir(),2)," " w:sc "Ok" d:'sc $system.OBJ.DisplayError( sc )

s sc = 1, dirs = "", dir = ..workdir() $$$push(dir)
if verbose w "#; Importing updated from ", dir,!
d ..setIgnore(.fm)
for { $$$next(i,dir) Q:i="" Q:dir=""

s rs = ##class(%File).FileSetFunc( dir, filemask, , 1 )
Expand All @@ -197,6 +238,9 @@ ClassMethod importUpdated(filemask = "*.*", qspec = "cku-d", ByRef err = "", rec
continue
}

// check file filter
if ..inFilter(.fm,filename) continue

s filets = rs.DateModified
s codename = ..codename( filename, .ext )
s codets = ..codets( codename, ext )
Expand Down

0 comments on commit 731345a

Please sign in to comment.