From c1940b2d382f792fcabe9e991c91c36ac8d073b2 Mon Sep 17 00:00:00 2001 From: Steven Walter Date: Wed, 20 Aug 2008 16:54:24 -0400 Subject: [PATCH] cmd_status: properly strip the common prefix This code assumed that os.path.split would return an n-tuple, but it fact it always returns only two components, the basename and the dirname. --- yap/yap.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/yap/yap.py b/yap/yap.py index b4233bf..066dc9d 100644 --- a/yap/yap.py +++ b/yap/yap.py @@ -70,17 +70,25 @@ class YapCore(object): prefix = get_output("git rev-parse --show-prefix") if not prefix: return path - prefix = os.path.split(prefix[0]) - # strip empty components from prefix - tmp = [] - for x in prefix: - if not x: - continue - tmp.append(x) - prefix = tmp + prefix = [ prefix[0] ] + while True: + head, tail = os.path.split(prefix[0]) + if not head: + break + prefix[0] = head + if tail: + prefix.insert(1, tail) + + path = [ path ] + while True: + head, tail = os.path.split(path[0]) + if not head: + break + path[0] = head + if tail: + path.insert(1, tail) - path = os.path.split(path) common = 0 for a, b in zip(prefix, path): if a != b: -- 2.11.4.GIT