Created
April 7, 2010 09:36
-
-
Save anonymous/358700 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
comparing with ../sumatra_hg | |
searching for changes | |
changeset: 75:9b5eb05b435b | |
user: Michele Mattioni <mattioni@ebi.ac.uk> | |
date: Mon Mar 29 11:14:21 2010 +0100 | |
summary: Initial work to support git repositories. | |
diff -r 5ff03559f848 -r 9b5eb05b435b src/versioncontrol/_git.py | |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 | |
+++ b/src/versioncontrol/_git.py Mon Mar 29 11:14:21 2010 +0100 | |
@@ -0,0 +1,113 @@ | |
+""" | |
+Defines the Sumatra version control interface for Git. | |
+Based (heavily) on the Mercurial class | |
+ | |
+Classes | |
+------- | |
+ | |
+GitWorkingCopy | |
+GitRepository | |
+ | |
+Functions | |
+--------- | |
+ | |
+may_have_working_copy() - determine whether a .git subdirectory exists at a given | |
+ path | |
+get_working_copy() - return a GitWorkingCopy object for a given path | |
+get_repository() - return a GitRepository object for a given URL. | |
+""" | |
+ | |
+#from mercurial import hg, ui, patch | |
+ | |
+import git | |
+import os | |
+import binascii | |
+ | |
+from base import Repository, WorkingCopy | |
+ | |
+ | |
+def may_have_working_copy(path=None): | |
+ path = path or os.getcwd() | |
+ if git.cmd.is_git_dir(path): | |
+ #return os.path.exists(os.path.join(path, ".git")) | |
+ return path | |
+ | |
+def get_working_copy(path=None): | |
+ return GitWorkingCopy(path) | |
+ | |
+def get_repository(url): | |
+ return GitRepository(url) | |
+ | |
+ | |
+class GitWorkingCopy(WorkingCopy): | |
+ | |
+ def __init__(self, path=None): | |
+ self.path = path or os.getcwd() | |
+ self.repository = GitRepository(self.path) | |
+ self.repository.working_copy = self | |
+ | |
+ def current_version(self):# TODO Check | |
+ if hasattr(self.repository._repository, 'workingctx'): # handle different versions of Mercurial | |
+ ctx = self.repository._repository.workingctx().parents()[0] | |
+ else: | |
+ ctx = self.repository._repository.parents()[0] | |
+ return binascii.hexlify(ctx.node()[:6]) | |
+ | |
+ def use_version(self, version): | |
+ assert not self.has_changed() | |
+ hg.clean(self.repository._repository, version) | |
+ | |
+ def use_latest_version(self): | |
+ # any changes to the working copy are retained/merged in | |
+ hg.update(self.repository._repository, 'tip') | |
+ | |
+ def status(self): | |
+ modified, added, removed, deleted, unknown, ignored, clean = self.repository._repository.status() #unknown=True) | |
+ return {'modified': modified, 'removed': removed, | |
+ 'deleted': deleted, 'unknown': unknown} | |
+ | |
+ def has_changed(self): | |
+ status = self.status() | |
+ changed = False | |
+ for st in 'modified', 'removed', 'deleted': | |
+ if status[st]: | |
+ changed = True | |
+ break | |
+ return changed | |
+ | |
+ def diff(self): | |
+ """Difference between working copy and repository.""" | |
+ opts = patch.mdiff.diffopts(nodates=True) | |
+ diff = patch.diff(self.repository._repository, opts=opts) | |
+ return "".join(diff) | |
+ | |
+class GitRepository(Repository): | |
+ | |
+ def __init__(self, url): | |
+ Repository.__init__(self, url) | |
+ self._repository = git.Repo(url) | |
+ self.working_copy = None | |
+ | |
+ def checkout(self, path="."): | |
+ """Clone a repository.""" | |
+ path = os.path.abspath(path) | |
+ if self.url == path: | |
+ # update | |
+ hg.update(self._repository, None) | |
+ | |
+ else: | |
+ # can't clone into an existing directory, so we create | |
+ # an empty repository and then do a pull and update | |
+ local_repos = hg.repository(self._ui, path, create=True) | |
+ local_repos.pull(self._repository) | |
+ hg.update(local_repos, None) | |
+ self.working_copy = MercurialWorkingCopy() | |
+ | |
+ def __getstate__(self): | |
+ """For pickling""" | |
+ return {'url': self.url, 'wc': self.working_copy} | |
+ | |
+ def __setstate__(self, state): | |
+ """For unpickling""" | |
+ self.__init__(state['url']) | |
+ self.working_copy = state['wc'] | |
changeset: 76:069d943fb2b4 | |
user: Michele Mattioni <mattioni@ebi.ac.uk> | |
date: Mon Mar 29 17:08:36 2010 +0100 | |
summary: Implemented some fo the methods for git. Some methods were not clear, added a TODO comment with relative questions | |
diff -r 9b5eb05b435b -r 069d943fb2b4 src/versioncontrol/_git.py | |
--- a/src/versioncontrol/_git.py Mon Mar 29 11:14:21 2010 +0100 | |
+++ b/src/versioncontrol/_git.py Mon Mar 29 17:08:36 2010 +0100 | |
@@ -17,20 +17,16 @@ | |
get_repository() - return a GitRepository object for a given URL. | |
""" | |
-#from mercurial import hg, ui, patch | |
- | |
import git | |
import os | |
-import binascii | |
from base import Repository, WorkingCopy | |
def may_have_working_copy(path=None): | |
path = path or os.getcwd() | |
- if git.cmd.is_git_dir(path): | |
- #return os.path.exists(os.path.join(path, ".git")) | |
- return path | |
+ if git.cmd.is_git_dir(path, ".git"): | |
+ return os.path.exists(os.path.join(path, ".git")) | |
def get_working_copy(path=None): | |
return GitWorkingCopy(path) | |
@@ -46,40 +42,37 @@ | |
self.repository = GitRepository(self.path) | |
self.repository.working_copy = self | |
- def current_version(self):# TODO Check | |
- if hasattr(self.repository._repository, 'workingctx'): # handle different versions of Mercurial | |
- ctx = self.repository._repository.workingctx().parents()[0] | |
- else: | |
- ctx = self.repository._repository.parents()[0] | |
- return binascii.hexlify(ctx.node()[:6]) | |
+ def current_version(self): | |
+ head = self.repository._repository.commits()[0] | |
+ return head.id | |
def use_version(self, version): | |
- assert not self.has_changed() | |
- hg.clean(self.repository._repository, version) | |
+ pass | |
+ # TODO: | |
+ # What exactly should happen here? | |
def use_latest_version(self): | |
- # any changes to the working copy are retained/merged in | |
- hg.update(self.repository._repository, 'tip') | |
- | |
+ pass | |
+ # TODO: | |
+ # Shall we use the last version available from the repo? | |
+ | |
def status(self): | |
- modified, added, removed, deleted, unknown, ignored, clean = self.repository._repository.status() #unknown=True) | |
- return {'modified': modified, 'removed': removed, | |
- 'deleted': deleted, 'unknown': unknown} | |
+ # We don't need to use this. | |
+ pass | |
def has_changed(self): | |
- status = self.status() | |
changed = False | |
- for st in 'modified', 'removed', 'deleted': | |
- if status[st]: | |
- changed = True | |
- break | |
+ if self.repository._repository.is_dirty(): | |
+ changed = True | |
return changed | |
def diff(self): | |
"""Difference between working copy and repository.""" | |
- opts = patch.mdiff.diffopts(nodates=True) | |
- diff = patch.diff(self.repository._repository, opts=opts) | |
- return "".join(diff) | |
+# opts = patch.mdiff.diffopts(nodates=True) | |
+# diff = patch.diff(self.repository._repository, opts=opts) | |
+# return "".join(diff) | |
+ pass | |
+ # TODO: This can be done, need to check a bit more. | |
class GitRepository(Repository): | |
@@ -90,18 +83,23 @@ | |
def checkout(self, path="."): | |
"""Clone a repository.""" | |
- path = os.path.abspath(path) | |
- if self.url == path: | |
- # update | |
- hg.update(self._repository, None) | |
- | |
- else: | |
- # can't clone into an existing directory, so we create | |
- # an empty repository and then do a pull and update | |
- local_repos = hg.repository(self._ui, path, create=True) | |
- local_repos.pull(self._repository) | |
- hg.update(local_repos, None) | |
- self.working_copy = MercurialWorkingCopy() | |
+ | |
+ pass | |
+ # TODO: We need to checkout the last commit? | |
+ # Or we need to clone the last commit somewhere (light branch?) | |
+ | |
+# path = os.path.abspath(path) | |
+# if self.url == path: | |
+# # update | |
+# hg.update(self._repository, None) | |
+# | |
+# else: | |
+# # can't clone into an existing directory, so we create | |
+# # an empty repository and then do a pull and update | |
+# local_repos = hg.repository(self._ui, path, create=True) | |
+# local_repos.pull(self._repository) | |
+# hg.update(local_repos, None) | |
+# self.working_copy = MercurialWorkingCopy() | |
def __getstate__(self): | |
"""For pickling""" | |
changeset: 77:2e06e43917db | |
user: Michele Mattioni <mattioni@ebi.ac.uk> | |
date: Mon Mar 29 17:49:45 2010 +0100 | |
summary: Fixed the dir checking in the path, added git to the supported vcs in the init | |
diff -r 069d943fb2b4 -r 2e06e43917db src/versioncontrol/__init__.py | |
--- a/src/versioncontrol/__init__.py Mon Mar 29 17:08:36 2010 +0100 | |
+++ b/src/versioncontrol/__init__.py Mon Mar 29 17:49:45 2010 +0100 | |
@@ -11,7 +11,7 @@ | |
base - defines the base WorkingCopy and Repository classes | |
_mercurial - defines MercurialWorkingCopy and MercurialRepository classes | |
_subversion - defines SubversionWorkingCopy and SubversionRepository classes | |
- | |
+_git - defines GitWorkingCopy and GitRepository classes | |
Exceptions | |
---------- | |
@@ -38,7 +38,7 @@ | |
vcs_list = [] | |
-for vcs in ['mercurial', 'subversion']: | |
+for vcs in ['mercurial', 'subversion', 'git']: | |
try: | |
__import__('sumatra.versioncontrol._%s' % vcs) | |
vcs_list.append(sys.modules['sumatra.versioncontrol._%s' % vcs]) | |
diff -r 069d943fb2b4 -r 2e06e43917db src/versioncontrol/_git.py | |
--- a/src/versioncontrol/_git.py Mon Mar 29 17:08:36 2010 +0100 | |
+++ b/src/versioncontrol/_git.py Mon Mar 29 17:49:45 2010 +0100 | |
@@ -25,7 +25,7 @@ | |
def may_have_working_copy(path=None): | |
path = path or os.getcwd() | |
- if git.cmd.is_git_dir(path, ".git"): | |
+ if git.cmd.is_git_dir(os.path.join(path, ".git")): | |
return os.path.exists(os.path.join(path, ".git")) | |
def get_working_copy(path=None): | |
changeset: 92:719a23068010 | |
parent: 77:2e06e43917db | |
user: Michele Mattioni <mattioni@ebi.ac.uk> | |
date: Thu Apr 01 10:54:38 2010 +0100 | |
summary: Fixed the diff method for git | |
diff -r 2e06e43917db -r 719a23068010 src/versioncontrol/_git.py | |
--- a/src/versioncontrol/_git.py Mon Mar 29 17:49:45 2010 +0100 | |
+++ b/src/versioncontrol/_git.py Thu Apr 01 10:54:38 2010 +0100 | |
@@ -68,11 +68,8 @@ | |
def diff(self): | |
"""Difference between working copy and repository.""" | |
-# opts = patch.mdiff.diffopts(nodates=True) | |
-# diff = patch.diff(self.repository._repository, opts=opts) | |
-# return "".join(diff) | |
- pass | |
- # TODO: This can be done, need to check a bit more. | |
+ return self.repository._repository.commit_diff('HEAD') | |
+ | |
class GitRepository(Repository): | |
changeset: 97:12681cd09a30 | |
user: Michele Mattioni <mattioni@ebi.ac.uk> | |
date: Tue Apr 06 13:15:17 2010 +0100 | |
summary: Implemented the checkout methos. Remote cloning of the repo still on the TODO. | |
diff -r 3a9067f68eb9 -r 12681cd09a30 src/versioncontrol/_git.py | |
--- a/src/versioncontrol/_git.py Fri Apr 02 14:04:12 2010 +0200 | |
+++ b/src/versioncontrol/_git.py Tue Apr 06 13:15:17 2010 +0100 | |
@@ -50,16 +50,14 @@ | |
return head.id | |
def use_version(self, version): | |
- pass | |
- # TODO: | |
- # this command should move the tree to some older | |
- # revision (if I have understood git terminology correctly) | |
- # this is perhaps equivalent to the git checkout command? | |
+ if not git.cmd.is_dirty(): | |
+ g = git.Git(self.path) | |
+ g.checkout(version) | |
def use_latest_version(self): | |
- pass | |
- # TODO: | |
- # use the last version available from the repo | |
+ if not git.cmd.is_dirty(): | |
+ g = git.Git(self.path) | |
+ g.checkout('HEAD') | |
def status(self): | |
# We don't need to use this. | |
@@ -104,4 +102,4 @@ | |
def __setstate__(self, state): | |
"""For unpickling""" | |
self.__init__(state['url']) | |
- self.working_copy = state['wc'] | |
+ self.working_copy = state['wc'] | |
\ No newline at end of file | |
changeset: 98:ea5697ab2c86 | |
tag: tip | |
user: Michele Mattioni <mattioni@ebi.ac.uk> | |
date: Tue Apr 06 16:48:07 2010 +0100 | |
summary: Implemented the checkout method and ran for the first time with a git repo. It seems to work. | |
diff -r 12681cd09a30 -r ea5697ab2c86 src/versioncontrol/_git.py | |
--- a/src/versioncontrol/_git.py Tue Apr 06 13:15:17 2010 +0100 | |
+++ b/src/versioncontrol/_git.py Tue Apr 06 16:48:07 2010 +0100 | |
@@ -55,7 +55,7 @@ | |
g.checkout(version) | |
def use_latest_version(self): | |
- if not git.cmd.is_dirty(): | |
+ if not self.repository._repository.is_dirty: | |
g = git.Git(self.path) | |
g.checkout('HEAD') | |
@@ -68,7 +68,7 @@ | |
def diff(self): | |
"""Difference between working copy and repository.""" | |
- return self.repository._repository.commit_diff('HEAD') | |
+ return self._repository.commit_diff('HEAD') | |
class GitRepository(Repository): | |
@@ -76,11 +76,12 @@ | |
def __init__(self, url): | |
Repository.__init__(self, url) | |
self.working_copy = None | |
+ self.checkout(url) | |
def checkout(self, path="."): | |
"""Clone a repository.""" | |
path = os.path.abspath(path) | |
- g = git.Git() | |
+ g = git.Git(path) | |
if self.url == path: | |
# already have a repository in the working directory | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment