[meld/meld-3-16] vcview: Go to parent directory until existing one found (bgo#770076)
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld/meld-3-16] vcview: Go to parent directory until existing one found (bgo#770076)
- Date: Fri, 19 Aug 2016 22:02:02 +0000 (UTC)
commit 34db619762131bd96327eb12a37e82bb4006d8e2
Author: Vasily Galkin <galkin-vv yandex ru>
Date: Thu Aug 18 11:56:28 2016 +0300
vcview: Go to parent directory until existing one found (bgo#770076)
After this change when meld is passed non-existing path it opens the first
existing parent.
meld/vcview.py | 52 +++++++++++++++++++++++++++++-----------------------
1 files changed, 29 insertions(+), 23 deletions(-)
---
diff --git a/meld/vcview.py b/meld/vcview.py
index e4422a7..a5f678e 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -239,30 +239,36 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
vcs_model = self.combobox_vcs.get_model()
vcs_model.clear()
- # VC systems work at the directory level, so make sure we're checking
- # for VC support there instead of on a specific file.
+ # VC systems can be executed at the directory level, so make sure
+ # we're checking for VC support there instead of
+ # on a specific file or on deleted/unexisting path inside vc
location = os.path.abspath(location or ".")
- if os.path.isfile(location):
- location = os.path.dirname(location)
-
- for avc in vc.get_vcs(location):
- err_str = ''
- vc_details = {'name': avc.NAME, 'cmd': avc.CMD}
-
- if not avc.is_installed():
- # Translators: This error message is shown when a version
- # control binary isn't installed.
- err_str = _("%(name)s (%(cmd)s not installed)")
- elif not avc.valid_repo(location):
- # Translators: This error message is shown when a version
- # controlled repository is invalid.
- err_str = _("%(name)s (Invalid repository)")
-
- if err_str:
- vcs_model.append([err_str % vc_details, avc, False])
- continue
-
- vcs_model.append([avc.NAME, avc(location), True])
+ while not os.path.isdir(location):
+ parent_location = os.path.dirname(location)
+ if len(parent_location) >= len(location):
+ # no existing parent: for example unexisting drive on Windows
+ break
+ location = parent_location
+ else:
+ # existing parent directory was found
+ for avc in vc.get_vcs(location):
+ err_str = ''
+ vc_details = {'name': avc.NAME, 'cmd': avc.CMD}
+
+ if not avc.is_installed():
+ # Translators: This error message is shown when a version
+ # control binary isn't installed.
+ err_str = _("%(name)s (%(cmd)s not installed)")
+ elif not avc.valid_repo(location):
+ # Translators: This error message is shown when a version
+ # controlled repository is invalid.
+ err_str = _("%(name)s (Invalid repository)")
+
+ if err_str:
+ vcs_model.append([err_str % vc_details, avc, False])
+ continue
+
+ vcs_model.append([avc.NAME, avc(location), True])
valid_vcs = [(i, r[1].NAME) for i, r in enumerate(vcs_model) if r[2]]
default_active = min(valid_vcs)[0] if valid_vcs else 0
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]