From 49a7771336ce09f6d42c7699ef32aecea0e83182 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Mon, 7 Dec 2009 20:07:55 -0500 Subject: Initial directory restructuring to clarify dependencies --- libbe/storage/vcs/hg.py | 108 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 libbe/storage/vcs/hg.py (limited to 'libbe/storage/vcs/hg.py') diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py new file mode 100644 index 0000000..ed27717 --- /dev/null +++ b/libbe/storage/vcs/hg.py @@ -0,0 +1,108 @@ +# Copyright (C) 2007-2009 Aaron Bentley and Panometrics, Inc. +# Ben Finney +# Gianluca Montecchi +# W. Trevor King +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +""" +Mercurial (hg) backend. +""" + +import os +import re +import sys + +import libbe +import vcs + +if libbe.TESTING == True: + import unittest + import doctest + + +def new(): + return Hg() + +class Hg(vcs.VCS): + name="hg" + client="hg" + versioned=True + def _vcs_version(self): + status,output,error = self._u_invoke_client("--version") + return output + def _vcs_detect(self, path): + """Detect whether a directory is revision-controlled using Mercurial""" + if self._u_search_parent_directories(path, ".hg") != None: + return True + return False + def _vcs_root(self, path): + status,output,error = self._u_invoke_client("root", cwd=path) + return output.rstrip('\n') + 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("showconfig","ui.username") + return output.rstrip('\n') + def _vcs_set_user_id(self, value): + """ + Supported by the Config Extension, but that is not part of + standard Mercurial. + http://www.selenic.com/mercurial/wiki/index.cgi/ConfigExtension + """ + raise vcs.SettingIDnotSupported + def _vcs_add(self, path): + self._u_invoke_client("add", path) + def _vcs_remove(self, path): + self._u_invoke_client("rm", "--force", path) + def _vcs_update(self, path): + pass + def _vcs_get_file_contents(self, path, revision=None, binary=False): + if revision == None: + return vcs.VCS._vcs_get_file_contents(self, path, revision, binary=binary) + else: + status,output,error = \ + self._u_invoke_client("cat","-r",revision,path) + return output + def _vcs_duplicate_repo(self, directory, revision=None): + if revision == None: + return vcs.VCS._vcs_duplicate_repo(self, directory, revision) + else: + self._u_invoke_client("archive", "--rev", revision, directory) + def _vcs_commit(self, commitfile, allow_empty=False): + args = ['commit', '--logfile', commitfile] + status,output,error = self._u_invoke_client(*args) + if allow_empty == False: + strings = ["nothing changed"] + if self._u_any_in_string(strings, output) == True: + raise vcs.EmptyCommit() + return self._vcs_revision_id(-1) + def _vcs_revision_id(self, index, style="id"): + args = ["identify", "--rev", str(int(index)), "--%s" % style] + kwargs = {"expect": (0,255)} + status,output,error = self._u_invoke_client(*args, **kwargs) + if status == 0: + id = output.strip() + if id == '000000000000': + return None # before initial commit. + return id + return None + + +if libbe.TESTING == True: + vcs.make_vcs_testcase_subclasses(Hg, sys.modules[__name__]) + + unitsuite =unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) + suite = unittest.TestSuite([unitsuite, doctest.DocTestSuite()]) -- cgit From 6f23fccbde4ede1121d5baf35c81932b7c8aa7bb Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 13 Dec 2009 07:20:31 -0500 Subject: Converted libbe.storage.vcs.hg to new Storage format. --- libbe/storage/vcs/hg.py | 73 ++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 34 deletions(-) (limited to 'libbe/storage/vcs/hg.py') diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index ed27717..67c5bf3 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -26,7 +26,7 @@ import re import sys import libbe -import vcs +import base if libbe.TESTING == True: import unittest @@ -36,62 +36,67 @@ if libbe.TESTING == True: def new(): return Hg() -class Hg(vcs.VCS): - name="hg" - client="hg" +class Hg(base.VCS): + name='hg' + client='hg' 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( + 'showconfig', 'ui.username') + return output.rstrip('\n') + def _vcs_detect(self, path): """Detect whether a directory is revision-controlled using Mercurial""" - if self._u_search_parent_directories(path, ".hg") != None: + if self._u_search_parent_directories(path, '.hg') != None: return True return False + def _vcs_root(self, path): - status,output,error = self._u_invoke_client("root", cwd=path) + status,output,error = self._u_invoke_client( + 'root', expect=(0,255), cwd=path) + if status == 255: + # "abort: There is no Mercurial repository here + # (.hg not found)!" + return None return output.rstrip('\n') + 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("showconfig","ui.username") - return output.rstrip('\n') - def _vcs_set_user_id(self, value): - """ - Supported by the Config Extension, but that is not part of - standard Mercurial. - http://www.selenic.com/mercurial/wiki/index.cgi/ConfigExtension - """ - raise vcs.SettingIDnotSupported + self._u_invoke_client('init', cwd=path) + def _vcs_add(self, path): - self._u_invoke_client("add", path) + self._u_invoke_client('add', path) + def _vcs_remove(self, path): - self._u_invoke_client("rm", "--force", path) + self._u_invoke_client('rm', '--force', path) + def _vcs_update(self, path): pass - 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: status,output,error = \ - self._u_invoke_client("cat","-r",revision,path) + self._u_invoke_client('cat', '-r', revision, path) return output - def _vcs_duplicate_repo(self, directory, revision=None): - if revision == None: - return vcs.VCS._vcs_duplicate_repo(self, directory, revision) - else: - self._u_invoke_client("archive", "--rev", revision, directory) + def _vcs_commit(self, commitfile, allow_empty=False): args = ['commit', '--logfile', commitfile] status,output,error = self._u_invoke_client(*args) if allow_empty == False: - strings = ["nothing changed"] + strings = ['nothing changed'] if self._u_any_in_string(strings, output) == True: - raise vcs.EmptyCommit() + raise base.EmptyCommit() return self._vcs_revision_id(-1) - def _vcs_revision_id(self, index, style="id"): - args = ["identify", "--rev", str(int(index)), "--%s" % style] - kwargs = {"expect": (0,255)} + + def _vcs_revision_id(self, index, style='id'): + args = ['identify', '--rev', str(int(index)), '--%s' % style] + kwargs = {'expect': (0,255)} status,output,error = self._u_invoke_client(*args, **kwargs) if status == 0: id = output.strip() @@ -102,7 +107,7 @@ class Hg(vcs.VCS): if libbe.TESTING == True: - vcs.make_vcs_testcase_subclasses(Hg, sys.modules[__name__]) + base.make_vcs_testcase_subclasses(Hg, sys.modules[__name__]) unitsuite =unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) suite = unittest.TestSuite([unitsuite, doctest.DocTestSuite()]) -- cgit From 55e0abfa27b693768f495044d10444d9d92e4fca Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 13 Dec 2009 07:39:55 -0500 Subject: More fixes for libbe.storage.vcs.hg + .git transition. --- libbe/storage/vcs/hg.py | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'libbe/storage/vcs/hg.py') 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) -- cgit From ca52b5cca130fb3bd810276d9de1f198df3cf5b7 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 13 Dec 2009 07:45:43 -0500 Subject: .bzr transition. --- libbe/storage/vcs/hg.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'libbe/storage/vcs/hg.py') diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index fb3ee3f..a8504d0 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -41,7 +41,10 @@ def new(): class Hg(base.VCS): name='hg' client='hg' - versioned=True + + def __init__(self, *args, **kwargs): + base.VCS.__init__(self, *args, **kwargs) + self.versioned = True def _vcs_version(self): status,output,error = self._u_invoke_client('--version') -- cgit From 9147ab9e77cd5730c1b2d5a76c92f87564f4af8e Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 13 Dec 2009 07:53:17 -0500 Subject: Use detect rather than catching errors in _vcs_root(). --- libbe/storage/vcs/hg.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'libbe/storage/vcs/hg.py') diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index a8504d0..f1a7eef 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -62,12 +62,7 @@ class Hg(base.VCS): return False def _vcs_root(self, path): - status,output,error = self._u_invoke_client( - 'root', expect=(0,255), cwd=path) - if status == 255: - # "abort: There is no Mercurial repository here - # (.hg not found)!" - return None + status,output,error = self._u_invoke_client('root', cwd=path) return output.rstrip('\n') def _vcs_init(self, path): -- cgit From 1cd02476257a7673668f1bdcdeac2902f3f21adb Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 13 Dec 2009 08:03:58 -0500 Subject: Adjust Hg._vcs_revision_id to bail cleanly on non-int revids --- libbe/storage/vcs/hg.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libbe/storage/vcs/hg.py') diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index f1a7eef..260f0c4 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -100,6 +100,10 @@ class Hg(base.VCS): return self._vcs_revision_id(-1) def _vcs_revision_id(self, index, style='id'): + try: + index = str(int(index)) + except ValueError: + return None args = ['identify', '--rev', str(int(index)), '--%s' % style] kwargs = {'expect': (0,255)} status,output,error = self._u_invoke_client(*args, **kwargs) -- cgit From 9fa977a31982a2eda08c2c18ade73bd114f477b1 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 13 Dec 2009 08:12:47 -0500 Subject: Handle non-int args to VCS.revision_id at the VCS level. --- libbe/storage/vcs/hg.py | 4 ---- 1 file changed, 4 deletions(-) (limited to 'libbe/storage/vcs/hg.py') diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index 260f0c4..f1a7eef 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -100,10 +100,6 @@ class Hg(base.VCS): return self._vcs_revision_id(-1) def _vcs_revision_id(self, index, style='id'): - try: - index = str(int(index)) - except ValueError: - return None args = ['identify', '--rev', str(int(index)), '--%s' % style] kwargs = {'expect': (0,255)} status,output,error = self._u_invoke_client(*args, **kwargs) -- cgit From d21c50ece316536b5972725eced19b40d6e2589d Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 13 Dec 2009 08:31:33 -0500 Subject: Fix Git._vcs_revision_id() offset bug. --- libbe/storage/vcs/hg.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'libbe/storage/vcs/hg.py') diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index f1a7eef..633987a 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -25,14 +25,14 @@ import os import os.path import re import shutil -import sys import libbe import base if libbe.TESTING == True: - import unittest import doctest + import sys + import unittest def new(): -- cgit From 5fb31c1fa646de076b999532690375319b5d4eb6 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 13 Dec 2009 19:40:06 -0500 Subject: Work around mercurial (hg) issue 618. --- libbe/storage/vcs/hg.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'libbe/storage/vcs/hg.py') diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index 633987a..776d986 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -25,6 +25,7 @@ import os import os.path import re import shutil +import time # work around http://mercurial.selenic.com/bts/issue618 import libbe import base @@ -45,6 +46,7 @@ class Hg(base.VCS): def __init__(self, *args, **kwargs): base.VCS.__init__(self, *args, **kwargs) self.versioned = True + self.__updated = [] # work around http://mercurial.selenic.com/bts/issue618 def _vcs_version(self): status,output,error = self._u_invoke_client('--version') @@ -80,7 +82,7 @@ class Hg(base.VCS): self._u_invoke_client('rm', '--force', path) def _vcs_update(self, path): - pass + self.__updated.append(path) # work around http://mercurial.selenic.com/bts/issue618 def _vcs_get_file_contents(self, path, revision=None): if revision == None: @@ -93,6 +95,16 @@ class Hg(base.VCS): def _vcs_commit(self, commitfile, allow_empty=False): args = ['commit', '--logfile', commitfile] status,output,error = self._u_invoke_client(*args) + # work around http://mercurial.selenic.com/bts/issue618 + strings = ['nothing changed'] + if self._u_any_in_string(strings, output) == True \ + and len(self.__updated) > 0: + time.sleep(1) + for path in self.__updated: + os.utime(os.path.join(self.repo, path), None) + status,output,error = self._u_invoke_client(*args) + self.__updated = [] + # end work around if allow_empty == False: strings = ['nothing changed'] if self._u_any_in_string(strings, output) == True: -- cgit From 7dc16313f3426640830a79be914be9dc01d08849 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sun, 13 Dec 2009 20:09:51 -0500 Subject: Adjust Hg._vcs_revision_id for 1-indexed revision ids. --- libbe/storage/vcs/hg.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libbe/storage/vcs/hg.py') diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index 776d986..7e0643b 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -112,6 +112,8 @@ class Hg(base.VCS): return self._vcs_revision_id(-1) def _vcs_revision_id(self, index, style='id'): + if index > 0: + index -= 1 args = ['identify', '--rev', str(int(index)), '--%s' % style] kwargs = {'expect': (0,255)} status,output,error = self._u_invoke_client(*args, **kwargs) -- cgit From 89b7a1411e4658e831f5d635534b24355dbb941d Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 15 Dec 2009 06:44:20 -0500 Subject: Fixed libbe.command.diff + ugly BugDir.duplicate_bugdir implementation duplicate_bugdir() works, but for the vcs backends, it could require shelling out for _every_ file read. This could, and probably will, be horribly slow. Still it works ;). I'm not sure what a better implementation would be. The old implementation checked out the entire earlier state into a temporary directory pros: single shell out, simple upgrade implementation cons: wouldn't work well for HTTP backens I think a good solution would run along the lines of the currently commented out code in duplicate_bugdir(), where a VersionedStorage.changed_since(revision) call would give you a list of changed files. diff could work off of that directly, without the need to generate a whole duplicate bugdir. I'm stuck on how to handle upgrades though... Also removed trailing whitespace from all python files. --- libbe/storage/vcs/hg.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libbe/storage/vcs/hg.py') diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index 7e0643b..d2d3281 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -124,7 +124,7 @@ class Hg(base.VCS): return id return None - + if libbe.TESTING == True: base.make_vcs_testcase_subclasses(Hg, sys.modules[__name__]) -- cgit From 0aa80631bd2dc0a5f28f1dd7db2cbda7d14e67fe Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 29 Dec 2009 05:52:27 -0500 Subject: Hg storage now based off mercurial module, not 'hg' executible. This should make repeated calls to Hg storage instances _much_ faster, since we avoid repeatedly loading and tearing down a python subprocess. For example, the testsuite runs ~6x faster on my box. Here's a run with the old Hg implementation: $ python test.py libbe.storage.vcs.hg ... ================================= ERROR: test_get_previous_children --------------------------------- Traceback (most recent call last): ... NotImplementedError --------------------------------- Ran 49 tests in 133.285s FAILED (errors=1) A run with the new implementation gives the same results, except for: Ran 49 tests in 22.328s --- libbe/storage/vcs/hg.py | 60 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 21 deletions(-) (limited to 'libbe/storage/vcs/hg.py') diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index d2d3281..373dfd2 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -21,10 +21,21 @@ Mercurial (hg) backend. """ +try: + # enable importing on demand to reduce startup time + from mercurial import demandimport; demandimport.enable() + import mercurial + import mercurial.version + import mercurial.dispatch + import mercurial.ui +except ImportError: + mercurial = None import os import os.path import re import shutil +import StringIO +import sys import time # work around http://mercurial.selenic.com/bts/issue618 import libbe @@ -41,7 +52,7 @@ def new(): class Hg(base.VCS): name='hg' - client='hg' + client=None # mercurial module def __init__(self, *args, **kwargs): base.VCS.__init__(self, *args, **kwargs) @@ -49,13 +60,26 @@ class Hg(base.VCS): self.__updated = [] # work around http://mercurial.selenic.com/bts/issue618 def _vcs_version(self): - status,output,error = self._u_invoke_client('--version') - return output + if mercurial == None: + return None + return mercurial.version.get_version() + + def _u_invoke_client(self, *args, **kwargs): + if 'cwd' not in kwargs: + kwargs['cwd'] = self.repo + assert len(kwargs) == 1, kwargs + ui = mercurial.ui.ui(interactive=False) + fullargs = ['--cwd', kwargs['cwd']] + fullargs.extend(args) + stdout = sys.stdout + tmp_stdout = StringIO.StringIO() + sys.stdout = tmp_stdout + mercurial.dispatch._dispatch(ui, fullargs) + sys.stdout = stdout + return tmp_stdout.getvalue().rstrip('\n') def _vcs_get_user_id(self): - status,output,error = self._u_invoke_client( - 'showconfig', 'ui.username') - return output.rstrip('\n') + return self._u_invoke_client('showconfig', 'ui.username') def _vcs_detect(self, path): """Detect whether a directory is revision-controlled using Mercurial""" @@ -64,8 +88,7 @@ class Hg(base.VCS): return False def _vcs_root(self, path): - status,output,error = self._u_invoke_client('root', cwd=path) - return output.rstrip('\n') + return self._u_invoke_client('root', cwd=path) def _vcs_init(self, path): self._u_invoke_client('init', cwd=path) @@ -88,13 +111,11 @@ class Hg(base.VCS): if revision == None: return base.VCS._vcs_get_file_contents(self, path, revision) else: - status,output,error = \ - self._u_invoke_client('cat', '-r', revision, path) - return output + return self._u_invoke_client('cat', '-r', revision, path) def _vcs_commit(self, commitfile, allow_empty=False): args = ['commit', '--logfile', commitfile] - status,output,error = self._u_invoke_client(*args) + output = self._u_invoke_client(*args) # work around http://mercurial.selenic.com/bts/issue618 strings = ['nothing changed'] if self._u_any_in_string(strings, output) == True \ @@ -102,7 +123,7 @@ class Hg(base.VCS): time.sleep(1) for path in self.__updated: os.utime(os.path.join(self.repo, path), None) - status,output,error = self._u_invoke_client(*args) + output = self._u_invoke_client(*args) self.__updated = [] # end work around if allow_empty == False: @@ -115,14 +136,11 @@ class Hg(base.VCS): if index > 0: index -= 1 args = ['identify', '--rev', str(int(index)), '--%s' % style] - kwargs = {'expect': (0,255)} - status,output,error = self._u_invoke_client(*args, **kwargs) - if status == 0: - id = output.strip() - if id == '000000000000': - return None # before initial commit. - return id - return None + output = self._u_invoke_client(*args) + id = output.strip() + if id == '000000000000': + return None # before initial commit. + return id if libbe.TESTING == True: -- cgit From aba3a8b27063a1765c49194cb7f9aba8b277d92f Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 29 Dec 2009 06:36:23 -0500 Subject: Updated Hg backend to support .children(revision). --- libbe/storage/vcs/hg.py | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'libbe/storage/vcs/hg.py') diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index 373dfd2..6baf19c 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -43,7 +43,6 @@ import base if libbe.TESTING == True: import doctest - import sys import unittest @@ -113,6 +112,38 @@ class Hg(base.VCS): else: return self._u_invoke_client('cat', '-r', revision, path) + def _vcs_path(self, id, revision): + output = self._u_invoke_client('manifest', '--rev', revision) + be_dir = self._cached_path_id._spacer_dirs[0] + be_dir_sep = self._cached_path_id._spacer_dirs[0] + os.path.sep + files = [f for f in output.splitlines() if f.startswith(be_dir_sep)] + for file in files: + if not file.startswith(be_dir+os.path.sep): + continue + parts = file.split(os.path.sep) + dir = parts.pop(0) # don't add the first spacer dir + for part in parts[:-1]: + dir = os.path.join(dir, part) + if not dir in files: + files.append(dir) + for file in files: + if self._u_path_to_id(file) == id: + return file + raise base.InvalidId(id, revision=revision) + + def _vcs_isdir(self, path, revision): + output = self._u_invoke_client('manifest', '--rev', revision) + files = output.splitlines() + if path in files: + return False + return True + + def _vcs_listdir(self, path, revision): + output = self._u_invoke_client('manifest', '--rev', revision) + files = output.splitlines() + path = path.rstrip(os.path.sep) + os.path.sep + return [self._u_rel_path(f, path) for f in files if f.startswith(path)] + def _vcs_commit(self, commitfile, allow_empty=False): args = ['commit', '--logfile', commitfile] output = self._u_invoke_client(*args) -- cgit From d595aba006a39a2d75067fb7fc82956538e7e16d Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 29 Dec 2009 20:13:43 -0500 Subject: We don't do much with Mercurial's ui, so _dispatch -> dispatch --- libbe/storage/vcs/hg.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'libbe/storage/vcs/hg.py') diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index 6baf19c..19e3585 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -67,13 +67,12 @@ class Hg(base.VCS): if 'cwd' not in kwargs: kwargs['cwd'] = self.repo assert len(kwargs) == 1, kwargs - ui = mercurial.ui.ui(interactive=False) fullargs = ['--cwd', kwargs['cwd']] fullargs.extend(args) stdout = sys.stdout tmp_stdout = StringIO.StringIO() sys.stdout = tmp_stdout - mercurial.dispatch._dispatch(ui, fullargs) + mercurial.dispatch.dispatch(fullargs) sys.stdout = stdout return tmp_stdout.getvalue().rstrip('\n') -- cgit From ec2472daa930a46949fcdb3fb9ca715f9bb3f200 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 29 Dec 2009 21:25:33 -0500 Subject: Disable mercurial.demandimport, since it breaks Bzr Running python test.py libbe.storage.vcs.hg libbe.storage.vcs.bzr with the old setup produced lots of Traceback (most recent call last): File ".../libbe/storage/vcs/base.py", line 1010, in setUp self.s.init() File ".../libbe/storage/base.py", line 170, in init return self._init() File ".../libbe/storage/vcs/base.py", line 664, in _init self._vcs_init(self.repo) File ".../libbe/storage/vcs/bzr.py", line 88, in _vcs_init cmd.run(location=path) File ".../python2.5/site-packages/bzrlib/builtins.py", line 1685, in run format = bzrdir.format_registry.make_bzrdir('default') File ".../python2.5/site-packages/bzrlib/bzrdir.py", line 3452, in make_bzrdir return self.get(key)() File ".../python2.5/site-packages/bzrlib/bzrdir.py", line 3398, in helper bd.set_branch_format(_load(branch_format)) File ".../python2.5/site-packages/bzrlib/bzrdir.py", line 3385, in _load [factory_name]) File "/var/lib/python-support/python2.5/mercurial/demandimport.py", line 108, in _demandimport setattr(mod, x, _demandmod(x, mod.__dict__, locals)) File ".../python2.5/site-packages/bzrlib/lazy_import.py", line 106, in __getattribute__ obj = _replace() File ".../python2.5/site-packages/bzrlib/lazy_import.py", line 88, in _replace extra=e) IllegalUseOfScopeReplacer: ScopeReplacer object 'branch' was used incorrectly: Object already cleaned up, did you assign it to another variable?: _factory --- libbe/storage/vcs/hg.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'libbe/storage/vcs/hg.py') diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index 19e3585..b280ff2 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -22,8 +22,6 @@ Mercurial (hg) backend. """ try: - # enable importing on demand to reduce startup time - from mercurial import demandimport; demandimport.enable() import mercurial import mercurial.version import mercurial.dispatch -- cgit From 16877141d526a5387a0f673b56c1cd6f3b900674 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Tue, 29 Dec 2009 21:37:14 -0500 Subject: Correct for possible directory changes in mercurial.dispatch.dispatch() I ran across this when the hg unittests broke the vcs.base unittests: $ python test.py libbe.storage.vcs.base libbe.storage.vcs.hg ... OK $ python test.py libbe.storage.vcs.hg libbe.storage.vcs.base ... File ".../libbe/storage/vcs/base.py", line 914, in libbe.storage.vcs.base.VCSTestCase.Class._u_rel_path Failed example: vcs._u_rel_path("./a", ".") Exception raised: Traceback (most recent call last): File "/usr/lib/python2.5/doctest.py", line 1228, in __run compileflags, 1) in test.globs File "", line 1, in vcs._u_rel_path("./a", ".") File ".../libbe/storage/vcs/base.py", line 921, in _u_rel_path path = os.path.abspath(path) File "/usr/lib/python2.5/posixpath.py", line 403, in abspath path = join(os.getcwd(), path) OSError: [Errno 2] No such file or directory ... FAILED (failures=1) --- libbe/storage/vcs/hg.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'libbe/storage/vcs/hg.py') diff --git a/libbe/storage/vcs/hg.py b/libbe/storage/vcs/hg.py index b280ff2..11494a9 100644 --- a/libbe/storage/vcs/hg.py +++ b/libbe/storage/vcs/hg.py @@ -70,7 +70,9 @@ class Hg(base.VCS): stdout = sys.stdout tmp_stdout = StringIO.StringIO() sys.stdout = tmp_stdout + cwd = os.getcwd() mercurial.dispatch.dispatch(fullargs) + os.chdir(cwd) sys.stdout = stdout return tmp_stdout.getvalue().rstrip('\n') -- cgit