aboutsummaryrefslogtreecommitdiffstats
path: root/libbe
diff options
context:
space:
mode:
authorW. Trevor King <wking@drexel.edu>2009-12-13 07:39:55 -0500
committerW. Trevor King <wking@drexel.edu>2009-12-13 07:39:55 -0500
commit55e0abfa27b693768f495044d10444d9d92e4fca (patch)
treef7d5f1b3efb28ea4dbd8fe37a1a083c44b0562f8 /libbe
parent85aa14161c125f996f0d146b93f9cb06a0b3928f (diff)
downloadbugseverywhere-55e0abfa27b693768f495044d10444d9d92e4fca.tar.gz
More fixes for libbe.storage.vcs.hg + .git transition.
Diffstat (limited to 'libbe')
-rw-r--r--libbe/storage/vcs/base.py3
-rw-r--r--libbe/storage/vcs/git.py120
-rw-r--r--libbe/storage/vcs/hg.py7
-rw-r--r--libbe/ui/util/user.py12
4 files changed, 78 insertions, 64 deletions
diff --git a/libbe/storage/vcs/base.py b/libbe/storage/vcs/base.py
index 5d7be7d..5308813 100644
--- a/libbe/storage/vcs/base.py
+++ b/libbe/storage/vcs/base.py
@@ -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()
diff --git a/libbe/storage/vcs/git.py b/libbe/storage/vcs/git.py
index 7f6e53a..02144b5 100644
--- a/libbe/storage/vcs/git.py
+++ b/libbe/storage/vcs/git.py
@@ -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):
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()])
diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py
index 67c5bf3..fb3ee3f 100644
--- a/libbe/storage/vcs/hg.py
+++ b/libbe/storage/vcs/hg.py
@@ -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)
diff --git a/libbe/ui/util/user.py b/libbe/ui/util/user.py
index 64eb30c..a58f83a 100644
--- a/libbe/ui/util/user.py
+++ b/libbe/ui/util/user.py
@@ -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):