[meld/VersionControlRework: 114/123] misc, vcview, ui.vcdialogs: Remove custom common-prefix implementation



commit 68733371150ec560fe0a2db4f4cfb2bfb23ed28f
Author: Kai Willadsen <kai willadsen gmail com>
Date:   Sat Apr 18 09:55:34 2015 +1000

    misc, vcview, ui.vcdialogs: Remove custom common-prefix implementation

 meld/misc.py         |   17 -----------------
 meld/ui/vcdialogs.py |   12 +-----------
 meld/vcview.py       |   11 ++---------
 3 files changed, 3 insertions(+), 37 deletions(-)
---
diff --git a/meld/misc.py b/meld/misc.py
index 33b29f8..ecece7e 100644
--- a/meld/misc.py
+++ b/meld/misc.py
@@ -244,23 +244,6 @@ def write_pipe(command, text, error=None):
     return proc.wait()
 
 
-def commonprefix(dirs):
-    """Given a list of pathnames, returns the longest common leading component.
-    """
-    if not dirs:
-        return ''
-    n = [d.split(os.sep) for d in dirs]
-    prefix = n[0]
-    for item in n:
-        for i in range(len(prefix)):
-            if prefix[:i+1] != item[:i+1]:
-                prefix = prefix[:i]
-                if i == 0:
-                    return ''
-                break
-    return os.sep.join(prefix)
-
-
 def copy2(src, dst):
     """Like shutil.copy2 but ignores chmod errors, and copies symlinks as links
     See [Bug 568000] Copying to NTFS fails
diff --git a/meld/ui/vcdialogs.py b/meld/ui/vcdialogs.py
index 47fb1af..e5f0342 100644
--- a/meld/ui/vcdialogs.py
+++ b/meld/ui/vcdialogs.py
@@ -25,20 +25,10 @@ from gi.repository import Gtk
 from gi.repository import Pango
 
 from meld.conf import _
-from meld.misc import commonprefix
 from meld.settings import meldsettings, settings
 from meld.ui.gnomeglade import Component
 
 
-# FIXME: Duplication from vcview
-def _commonprefix(files):
-    if len(files) != 1:
-        workdir = commonprefix(files)
-    else:
-        workdir = os.path.dirname(files[0]) or "."
-    return workdir
-
-
 class CommitDialog(GObject.GObject, Component):
 
     __gtype_name__ = "CommitDialog"
@@ -59,7 +49,7 @@ class CommitDialog(GObject.GObject, Component):
             else:
                 to_commit = ["\t" + _("No files will be committed")]
         except NotImplementedError:
-            topdir = _commonprefix(selected)
+            topdir = os.path.dirname(os.path.commonprefix(selected))
             to_commit = ["\t" + s[len(topdir) + 1:] for s in selected]
         self.changedfiles.set_text("(in %s)\n%s" %
                                    (topdir, "\n".join(to_commit)))
diff --git a/meld/vcview.py b/meld/vcview.py
index c08fd08..fee53bd 100644
--- a/meld/vcview.py
+++ b/meld/vcview.py
@@ -48,14 +48,6 @@ from meld.vc import _null
 log = logging.getLogger(__name__)
 
 
-def _commonprefix(files):
-    if len(files) != 1:
-        workdir = misc.commonprefix(files)
-    else:
-        workdir = os.path.dirname(files[0]) or "."
-    return workdir
-
-
 def cleanup_temp():
     temp_location = tempfile.gettempdir()
     # The strings below will probably end up as debug log, and are deliberately
@@ -676,7 +668,8 @@ class VcView(melddoc.MeldDoc, gnomeglade.Component):
                 gfile.trash(None)
             except GLib.GError as e:
                 misc.error_dialog(_("Error removing %s") % name, str(e))
-        workdir = _commonprefix(files)
+
+        workdir = os.path.dirname(os.path.commonprefix(files))
         self.refresh_partial(workdir)
 
     def on_button_diff_clicked(self, obj):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]