diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2019-02-06 15:10:19 -0600 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2019-02-06 15:10:19 -0600 |
| commit | e3b3750ef0b2e36ac0fa046f59f02f637ca46c77 (patch) | |
| tree | fb08b68885a435e7e88fbac79e5f2cb4de41f7e4 | |
| parent | 10aef55dadfbb9a4a1b4cab5ce64242cc1a63d66 (diff) | |
| download | nimterop-e3b3750ef0b2e36ac0fa046f59f02f637ca46c77.tar.gz nimterop-e3b3750ef0b2e36ac0fa046f59f02f637ca46c77.zip | |
Revert relativePath
| -rw-r--r-- | nimterop/git.nim | 45 |
1 files changed, 8 insertions, 37 deletions
diff --git a/nimterop/git.nim b/nimterop/git.nim index 5b657b9..86a042e 100644 --- a/nimterop/git.nim +++ b/nimterop/git.nim @@ -50,43 +50,14 @@ proc mvFile*(source, dest: string) = cpFile(source, dest, move=true) when (NimMajor, NimMinor, NimPatch) < (0, 19, 9): - proc relativePath*(path, base: string; sep = DirSep): string = - ## Copied from `os.relativePath` ; remove after nim >= 0.19.9 - if path.len == 0: return "" - var f, b: PathIter - var ff = (0, -1) - var bb = (0, -1) # (int, int) - result = newStringOfCap(path.len) - while f.hasNext(path) and b.hasNext(base): - ff = next(f, path) - bb = next(b, base) - let diff = ff[1] - ff[0] - if diff != bb[1] - bb[0]: break - var same = true - for i in 0..diff: - if path[i + ff[0]] !=? base[i + bb[0]]: - same = false - break - if not same: break - ff = (0, -1) - bb = (0, -1) - - while true: - if bb[1] >= bb[0]: - if result.len > 0 and result[^1] != sep: - result.add sep - result.add ".." - if not b.hasNext(base): break - bb = b.next(base) - - while true: - if ff[1] >= ff[0]: - if result.len > 0 and result[^1] != sep: - result.add sep - for i in 0..ff[1] - ff[0]: - result.add path[i + ff[0]] - if not f.hasNext(path): break - ff = f.next(path) + proc relativePath*(file, base: string): string = + ## naive version of `os.relativePath` ; remove after nim >= 0.19.9 + runnableExamples: + doAssert "/foo/bar/baz/log.txt".relativePath("/foo/bar") == "baz/log.txt" + var base = base + if not base.endsWith "/": base.add "/" + doAssert file.startsWith base + result = file[base.len .. ^1] proc extractZip*(zipfile, outdir: string) = var cmd = "unzip -o $#" |
