More fixes for libbe.storage.vcs.hg + .git transition.
authorW. Trevor King <wking@drexel.edu>
Sun, 13 Dec 2009 12:39:55 +0000 (07:39 -0500)
committerW. Trevor King <wking@drexel.edu>
Sun, 13 Dec 2009 12:39:55 +0000 (07:39 -0500)
libbe/storage/vcs/base.py
libbe/storage/vcs/git.py
libbe/storage/vcs/hg.py
libbe/ui/util/user.py

index 5d7be7dd6f91cd8268ff93adc86549c19966e56b..530881323627d782db0312baf6865780326ae5ff 100644 (file)
@@ -621,7 +621,8 @@ os.listdir(self.get_path("bugs")):
     def _destroy(self):
         self._vcs_destroy()
         self._cached_path_id.destroy()
-        shutil.rmtree(self.be_dir)
+        if os.path.exists(self.be_dir):
+            shutil.rmtree(self.be_dir)
 
     def _connect(self):
         self.root()
index 7f6e53ae50bdc09475fc1a1ed193fe2096cfcfe4..02144b5898b612b76b29151918da6446b790c185 100644 (file)
@@ -27,7 +27,8 @@ import sys
 import unittest
 
 import libbe
-import vcs
+import libbe.ui.util.user
+import base
 if libbe.TESTING == True:
     import doctest
 
@@ -35,108 +36,113 @@ if libbe.TESTING == True:
 def new():
     return Git()
 
-class Git(vcs.VCS):
-    name="git"
-    client="git"
+class Git(base.VCS):
+    name='git'
+    client='git'
     versioned=True
+
     def _vcs_version(self):
-        status,output,error = self._u_invoke_client("--version")
+        status,output,error = self._u_invoke_client('--version')
         return output
+
+    def _vcs_get_user_id(self):
+        status,output,error = \
+            self._u_invoke_client('config', 'user.name', expect=(0,1))
+        if status == 0:
+            name = output.rstrip('\n')
+        else:
+            name = ''
+        status,output,error = \
+            self._u_invoke_client('config', 'user.email', expect=(0,1))
+        if status == 0:
+            email = output.rstrip('\n')
+        else:
+            email = ''
+        if name != '' or email != '': # got something!
+            # guess missing info, if necessary
+            if name == '':
+                name = libbe.ui.util.user.get_fallback_username()
+            if email == '':
+                email = libe.ui.util.user.get_fallback_email()
+            return libbe.ui.util.user.create_user_id(name, email)
+        return None # Git has no infomation
+
     def _vcs_detect(self, path):
-        if self._u_search_parent_directories(path, ".git") != None :
+        if self._u_search_parent_directories(path, '.git') != None :
             return True
         return False 
+
     def _vcs_root(self, path):
         """Find the root of the deepest repository containing path."""
         # Assume that nothing funny is going on; in particular, that we aren't
         # dealing with a bare repo.
         if os.path.isdir(path) != True:
             path = os.path.dirname(path)
-        status,output,error = self._u_invoke_client("rev-parse", "--git-dir",
+        status,output,error = self._u_invoke_client('rev-parse', '--git-dir',
                                                     cwd=path)
         gitdir = os.path.join(path, output.rstrip('\n'))
         dirname = os.path.abspath(os.path.dirname(gitdir))
         return dirname
+
     def _vcs_init(self, path):
-        self._u_invoke_client("init", cwd=path)
-    def _vcs_get_user_id(self):
-        status,output,error = \
-            self._u_invoke_client("config", "user.name", expect=(0,1))
-        if status == 0:
-            name = output.rstrip('\n')
-        else:
-            name = ""
-        status,output,error = \
-            self._u_invoke_client("config", "user.email", expect=(0,1))
-        if status == 0:
-            email = output.rstrip('\n')
-        else:
-            email = ""
-        if name != "" or email != "": # got something!
-            # guess missing info, if necessary
-            if name == "":
-                name = self._u_get_fallback_username()
-            if email == "":
-                email = self._u_get_fallback_email()
-            return self._u_create_id(name, email)
-        return None # Git has no infomation
-    def _vcs_set_user_id(self, value):
-        name,email = self._u_parse_id(value)
-        if email != None:
-            self._u_invoke_client("config", "user.email", email)
-        self._u_invoke_client("config", "user.name", name)
+        self._u_invoke_client('init', cwd=path)
+
+    def _vcs_destroy(self):
+        vcs_dir = os.path.join(self.repo, '.git')
+        if os.path.exists(vcs_dir):
+            shutil.rmtree(vcs_dir)
+
     def _vcs_add(self, path):
         if os.path.isdir(path):
             return
-        self._u_invoke_client("add", path)
+        self._u_invoke_client('add', path)
+
     def _vcs_remove(self, path):
         if not os.path.isdir(self._u_abspath(path)):
-            self._u_invoke_client("rm", "-f", path)
+            self._u_invoke_client('rm', '-f', path)
+
     def _vcs_update(self, path):
         self._vcs_add(path)
-    def _vcs_get_file_contents(self, path, revision=None, binary=False):
+
+    def _vcs_get_file_contents(self, path, revision=None):
         if revision == None:
-            return vcs.VCS._vcs_get_file_contents(self, path, revision, binary=binary)
+            return base.VCS._vcs_get_file_contents(self, path, revision)
         else:
-            arg = "%s:%s" % (revision,path)
-            status,output,error = self._u_invoke_client("show", arg)
+            arg = '%s:%s' % (revision,path)
+            status,output,error = self._u_invoke_client('show', arg)
             return output
-    def _vcs_duplicate_repo(self, directory, revision=None):
-        if revision==None:
-            vcs.VCS._vcs_duplicate_repo(self, directory, revision)
-        else:
-            self._u_invoke_client("clone", "--no-checkout", ".", directory)
-            self._u_invoke_client("checkout", revision, cwd=directory)
+
     def _vcs_commit(self, commitfile, allow_empty=False):
         args = ['commit', '--all', '--file', commitfile]
         if allow_empty == True:
-            args.append("--allow-empty")
+            args.append('--allow-empty')
             status,output,error = self._u_invoke_client(*args)
         else:
-            kwargs = {"expect":(0,1)}
+            kwargs = {'expect':(0,1)}
             status,output,error = self._u_invoke_client(*args, **kwargs)
-            strings = ["nothing to commit",
-                       "nothing added to commit"]
+            strings = ['nothing to commit',
+                       'nothing added to commit']
             if self._u_any_in_string(strings, output) == True:
-                raise vcs.EmptyCommit()
+                raise base.EmptyCommit()
         revision = None
-        revline = re.compile("(.*) (.*)[:\]] (.*)")
+        revline = re.compile('(.*) (.*)[:\]] (.*)')
         match = revline.search(output)
         assert match != None, output+error
         assert len(match.groups()) == 3
         revision = match.groups()[1]
         full_revision = self._vcs_revision_id(-1)
         assert full_revision.startswith(revision), \
-            "Mismatched revisions:\n%s\n%s" % (revision, full_revision)
+            'Mismatched revisions:\n%s\n%s' % (revision, full_revision)
         return full_revision
+
     def _vcs_revision_id(self, index):
-        args = ["rev-list", "--first-parent", "--reverse", "HEAD"]
-        kwargs = {"expect":(0,128)}
+        args = ['rev-list', '--first-parent', '--reverse', 'HEAD']
+        kwargs = {'expect':(0,128)}
         status,output,error = self._u_invoke_client(*args, **kwargs)
         if status == 128:
             if error.startswith("fatal: ambiguous argument 'HEAD': unknown "):
                 return None
-            raise vcs.CommandError(args, status, stderr=error)
+            raise base.CommandError(args, status, stderr=error)
         commits = output.splitlines()
         try:
             return commits[index]
@@ -145,7 +151,7 @@ class Git(vcs.VCS):
 
 \f    
 if libbe.TESTING == True:
-    vcs.make_vcs_testcase_subclasses(Git, sys.modules[__name__])
+    base.make_vcs_testcase_subclasses(Git, sys.modules[__name__])
 
     unitsuite =unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
     suite = unittest.TestSuite([unitsuite, doctest.DocTestSuite()])
index 67c5bf3114fa7c5f6a43b88b0f3927ea6a91659f..fb3ee3f0397c1efa2eea9ba381421d80d27424a9 100644 (file)
@@ -22,7 +22,9 @@ Mercurial (hg) backend.
 """
 
 import os
+import os.path
 import re
+import shutil
 import sys
 
 import libbe
@@ -68,6 +70,11 @@ class Hg(base.VCS):
     def _vcs_init(self, path):
         self._u_invoke_client('init', cwd=path)
 
+    def _vcs_destroy(self):
+        vcs_dir = os.path.join(self.repo, '.hg')
+        if os.path.exists(vcs_dir):
+            shutil.rmtree(vcs_dir)
+
     def _vcs_add(self, path):
         self._u_invoke_client('add', path)
 
index 64eb30c931caa9d2b44379596182eee571f78087..a58f83a9ac1487edeab2230d02569bc249730fde 100644 (file)
@@ -13,7 +13,7 @@ from socket import gethostname
 import libbe
 import libbe.storage.util.config
 
-def _get_fallback_username(self):
+def get_fallback_username(self):
     name = None
     for env in ["LOGNAME", "USERNAME"]:
         if os.environ.has_key(env):
@@ -22,9 +22,9 @@ def _get_fallback_username(self):
     assert name != None
     return name
 
-def _get_fallback_email(self):
+def get_fallback_email(self):
     hostname = gethostname()
-    name = _get_fallback_username()
+    name = get_fallback_username()
     return "%s@%s" % (name, hostname)
 
 def create_user_id(name, email=None):
@@ -77,9 +77,9 @@ def get_user_id(self, storage=None):
         user = vcs.get_user_id()
         if user != None:
             return user
-    name = _get_fallback_username()
-    email = _get_fallback_email()
-    user = _create_user_id(name, email)
+    name = get_fallback_username()
+    email = get_fallback_email()
+    user = create_user_id(name, email)
     return user
 
 def set_user_id(self, user_id):