Commit ec7d961359cabb631d7769eb90aacd5d6d7d0262
1 parent
14d16aa7
Added option --filter and fixed some bugs.
Showing
1 changed file
with
26 additions
and
11 deletions
blimp.nim
@@ -37,7 +37,7 @@ const | @@ -37,7 +37,7 @@ const | ||
37 | var | 37 | var |
38 | blimpStore, remoteBlimpStore, uploadCommandFormat, downloadCommandFormat, deleteCommandFormat, rsyncPassword, blimpVersion: string = nil | 38 | blimpStore, remoteBlimpStore, uploadCommandFormat, downloadCommandFormat, deleteCommandFormat, rsyncPassword, blimpVersion: string = nil |
39 | homeDir, currentDir, gitRootDir: string | 39 | homeDir, currentDir, gitRootDir: string |
40 | - verbose, stdio, inflateAll: bool | 40 | + verbose, stdio, onAllDeflated, onAllFiltered: bool |
41 | stdinContent: string = nil | 41 | stdinContent: string = nil |
42 | 42 | ||
43 | let | 43 | let |
@@ -69,10 +69,8 @@ delete = "rsync --password-file $3/.blimp.pass -dv --delete --existing --ignore- | @@ -69,10 +69,8 @@ delete = "rsync --password-file $3/.blimp.pass -dv --delete --existing --ignore- | ||
69 | 69 | ||
70 | [blimp] | 70 | [blimp] |
71 | # Minimal version, otherwise stop | 71 | # Minimal version, otherwise stop |
72 | -# version = 0.2 | ||
73 | -""" | 72 | +# version = """ & versionAsString |
74 | 73 | ||
75 | - | ||
76 | 74 | ||
77 | proc cmd(cmd: string): string = | 75 | proc cmd(cmd: string): string = |
78 | try: | 76 | try: |
@@ -201,7 +199,7 @@ proc copyToBlimpStore(filename, blimpFilename: string) = | @@ -201,7 +199,7 @@ proc copyToBlimpStore(filename, blimpFilename: string) = | ||
201 | quit("Failed writing file: " & blimpStore / blimpFilename & " from stdin", 1) | 199 | quit("Failed writing file: " & blimpStore / blimpFilename & " from stdin", 1) |
202 | else: | 200 | else: |
203 | copyFile(filename, blimpStore / blimpFilename) | 201 | copyFile(filename, blimpStore / blimpFilename) |
204 | - uploadFile(blimpFilename) | 202 | + uploadFile(blimpFilename) |
205 | 203 | ||
206 | # Copy content from blimpStore, and downloading first if needed | 204 | # Copy content from blimpStore, and downloading first if needed |
207 | proc copyFromBlimpStore(blimpFilename, filename: string) = | 205 | proc copyFromBlimpStore(blimpFilename, filename: string) = |
@@ -270,6 +268,14 @@ iterator allDeflated() = | @@ -270,6 +268,14 @@ iterator allDeflated() = | ||
270 | for fn in filenames: | 268 | for fn in filenames: |
271 | if not blimpFilename(fn).isNil: | 269 | if not blimpFilename(fn).isNil: |
272 | yield fn | 270 | yield fn |
271 | + | ||
272 | +# Iterator over all files matching the blimp filter in the git clone | ||
273 | +iterator allFiltered() = | ||
274 | + let lines = cmd("git ls-files | git check-attr --stdin filter").split('\l') | ||
275 | + for line in lines: | ||
276 | + let status = line.split(':') | ||
277 | + if strip(status[2]) == "blimp": | ||
278 | + yield status[0] | ||
273 | 279 | ||
274 | # Parse out hash from hash stub and copy back original content from blimpStore. | 280 | # Parse out hash from hash stub and copy back original content from blimpStore. |
275 | proc inflate(filename: string) = | 281 | proc inflate(filename: string) = |
@@ -329,6 +335,7 @@ let synopsis = """ | @@ -329,6 +335,7 @@ let synopsis = """ | ||
329 | ---------- | 335 | ---------- |
330 | <command> (string) (d)eflate, (i)nflate, remove | 336 | <command> (string) (d)eflate, (i)nflate, remove |
331 | -a,--all Operate on all deflated files in clone | 337 | -a,--all Operate on all deflated files in clone |
338 | + -f,--filter Operate on all files matching blimp filter | ||
332 | ---------- | 339 | ---------- |
333 | -s,--stdio If given, use stdin/stdout for content. | 340 | -s,--stdio If given, use stdin/stdout for content. |
334 | <filenames> (string...) One or more filepaths to inflate/deflate | 341 | <filenames> (string...) One or more filepaths to inflate/deflate |
@@ -387,7 +394,7 @@ let help = """ | @@ -387,7 +394,7 @@ let help = """ | ||
387 | In order to have blimp work automatically you can: | 394 | In order to have blimp work automatically you can: |
388 | 395 | ||
389 | * Create a .gitattributes file with lines like: | 396 | * Create a .gitattributes file with lines like: |
390 | - *.png filter=blimp -text | 397 | + *.png filter=blimp binary |
391 | 398 | ||
392 | * Configure blimp as a filter by running: | 399 | * Configure blimp as a filter by running: |
393 | git config filter.blimp.clean "blimp -s d %f" | 400 | git config filter.blimp.clean "blimp -s d %f" |
@@ -418,7 +425,8 @@ gitRootDir = gitRoot() | @@ -418,7 +425,8 @@ gitRootDir = gitRoot() | ||
418 | var args = parse(synopsis) | 425 | var args = parse(synopsis) |
419 | verbose = args["verbose"].asBool | 426 | verbose = args["verbose"].asBool |
420 | stdio = args["stdio"].asBool | 427 | stdio = args["stdio"].asBool |
421 | -inflateAll = args["all"].asBool | 428 | +onAllDeflated = args["all"].asBool |
429 | +onAllFiltered = args["filter"].asBool | ||
422 | 430 | ||
423 | # Can't do verbose with -s, that messes up stdout, | 431 | # Can't do verbose with -s, that messes up stdout, |
424 | # read in all of stdin once and for all | 432 | # read in all of stdin once and for all |
@@ -471,12 +479,19 @@ setupBlimpStore() | @@ -471,12 +479,19 @@ setupBlimpStore() | ||
471 | # Do the deed | 479 | # Do the deed |
472 | if command != "": | 480 | if command != "": |
473 | if command == "d" or command == "deflate": | 481 | if command == "d" or command == "deflate": |
474 | - for fn in filenames: | ||
475 | - deflate(fn.asString) | 482 | + if onAllFiltered: |
483 | + for fn in allFiltered(): | ||
484 | + deflate(fn) | ||
485 | + else: | ||
486 | + for fn in filenames: | ||
487 | + deflate(fn.asString) | ||
476 | elif command == "i" or command == "inflate": | 488 | elif command == "i" or command == "inflate": |
477 | - if inflateAll: | 489 | + if onAllDeflated: |
478 | for fn in allDeflated(): | 490 | for fn in allDeflated(): |
479 | inflate(fn) | 491 | inflate(fn) |
492 | + elif onAllFiltered: | ||
493 | + for fn in allFiltered(): | ||
494 | + inflate(fn) | ||
480 | else: | 495 | else: |
481 | for fn in filenames: | 496 | for fn in filenames: |
482 | inflate(fn.asString) | 497 | inflate(fn.asString) |
@@ -484,7 +499,7 @@ if command != "": | @@ -484,7 +499,7 @@ if command != "": | ||
484 | for fn in filenames: | 499 | for fn in filenames: |
485 | remove(fn.asString) | 500 | remove(fn.asString) |
486 | else: | 501 | else: |
487 | - quit("Unknown command, only (d)eflate or (i)inflate are valid.", 6) | 502 | + quit("Unknown command, only (d)eflate, (i)inflate or remove are valid.", 6) |
488 | 503 | ||
489 | # All good | 504 | # All good |
490 | quit(0) | 505 | quit(0) |