From ec7d961359cabb631d7769eb90aacd5d6d7d0262 Mon Sep 17 00:00:00 2001 From: Göran Krampe Date: Wed, 19 Nov 2014 10:36:39 +0100 Subject: [PATCH] Added option --filter and fixed some bugs. --- blimp.nim | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/blimp.nim b/blimp.nim index 27383b0..4f988a7 100644 --- a/blimp.nim +++ b/blimp.nim @@ -37,7 +37,7 @@ const var blimpStore, remoteBlimpStore, uploadCommandFormat, downloadCommandFormat, deleteCommandFormat, rsyncPassword, blimpVersion: string = nil homeDir, currentDir, gitRootDir: string - verbose, stdio, inflateAll: bool + verbose, stdio, onAllDeflated, onAllFiltered: bool stdinContent: string = nil let @@ -69,10 +69,8 @@ delete = "rsync --password-file $3/.blimp.pass -dv --delete --existing --ignore- [blimp] # Minimal version, otherwise stop -# version = 0.2 -""" +# version = """ & versionAsString - proc cmd(cmd: string): string = try: @@ -201,7 +199,7 @@ proc copyToBlimpStore(filename, blimpFilename: string) = quit("Failed writing file: " & blimpStore / blimpFilename & " from stdin", 1) else: copyFile(filename, blimpStore / blimpFilename) - uploadFile(blimpFilename) + uploadFile(blimpFilename) # Copy content from blimpStore, and downloading first if needed proc copyFromBlimpStore(blimpFilename, filename: string) = @@ -270,6 +268,14 @@ iterator allDeflated() = for fn in filenames: if not blimpFilename(fn).isNil: yield fn + +# Iterator over all files matching the blimp filter in the git clone +iterator allFiltered() = + let lines = cmd("git ls-files | git check-attr --stdin filter").split('\l') + for line in lines: + let status = line.split(':') + if strip(status[2]) == "blimp": + yield status[0] # Parse out hash from hash stub and copy back original content from blimpStore. proc inflate(filename: string) = @@ -329,6 +335,7 @@ let synopsis = """ ---------- (string) (d)eflate, (i)nflate, remove -a,--all Operate on all deflated files in clone + -f,--filter Operate on all files matching blimp filter ---------- -s,--stdio If given, use stdin/stdout for content. (string...) One or more filepaths to inflate/deflate @@ -387,7 +394,7 @@ let help = """ In order to have blimp work automatically you can: * Create a .gitattributes file with lines like: - *.png filter=blimp -text + *.png filter=blimp binary * Configure blimp as a filter by running: git config filter.blimp.clean "blimp -s d %f" @@ -418,7 +425,8 @@ gitRootDir = gitRoot() var args = parse(synopsis) verbose = args["verbose"].asBool stdio = args["stdio"].asBool -inflateAll = args["all"].asBool +onAllDeflated = args["all"].asBool +onAllFiltered = args["filter"].asBool # Can't do verbose with -s, that messes up stdout, # read in all of stdin once and for all @@ -471,12 +479,19 @@ setupBlimpStore() # Do the deed if command != "": if command == "d" or command == "deflate": - for fn in filenames: - deflate(fn.asString) + if onAllFiltered: + for fn in allFiltered(): + deflate(fn) + else: + for fn in filenames: + deflate(fn.asString) elif command == "i" or command == "inflate": - if inflateAll: + if onAllDeflated: for fn in allDeflated(): inflate(fn) + elif onAllFiltered: + for fn in allFiltered(): + inflate(fn) else: for fn in filenames: inflate(fn.asString) @@ -484,7 +499,7 @@ if command != "": for fn in filenames: remove(fn.asString) else: - quit("Unknown command, only (d)eflate or (i)inflate are valid.", 6) + quit("Unknown command, only (d)eflate, (i)inflate or remove are valid.", 6) # All good quit(0) -- libgit2 0.22.2