Changeset 457


Ignore:
Timestamp:
29-12-09 21:21:52 (3 years ago)
Author:
jelmer
bzr:base-revision:
svn-v4:375192ae-a00c-0410-900a-bafd95fcb19a:trunk:456
bzr:committer:
Jelmer Vernooij <jelmer@samba.org>
bzr:file-ids:

moap/test/test_vcs_bzr.py 258@375192ae-a00c-0410-900a-bafd95fcb19a:trunk%2Fmoap%2Ftest%2Ftest_vcs_bzr.py
moap/vcs/bzr.py 256@375192ae-a00c-0410-900a-bafd95fcb19a:trunk%2Fmoap%2Fvcs%2Fbzr.py
bzr:mapping-version:
v4
bzr:repository-uuid:
375192ae-a00c-0410-900a-bafd95fcb19a
bzr:revision-id:
jelmer@samba.org-20091229163546-ybnssv2k37df4bgj
bzr:revno:
441
bzr:revprop:branch-nick:
trunk
bzr:revprop:bugs:
http://thomas.apestaart.org/moap/trac/ticket/296 fixed
bzr:root:
trunk
bzr:text-parents:

moap/test/test_vcs_bzr.py svn-v4:375192ae-a00c-0410-900a-bafd95fcb19a:trunk:402
moap/vcs/bzr.py svn-v4:375192ae-a00c-0410-900a-bafd95fcb19a:trunk:419
bzr:timestamp:
2009-12-29 17:35:46.413000107 +0100
bzr:user-agent:
bzr2.0.3+bzr-svn1.0.2dev0
svn:original-date:
2009-12-29T16:35:46.413000Z
Message:

Use bzrlib directly for bzr branches rather than invoking the bzr command.

This fixes some of the tests for me and it should make use of bzr from moap somewhat faster.

Location:
trunk/moap
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/moap/test/test_vcs_bzr.py

    r402 r457  
    9090        v.ignore(['test', ]) 
    9191         
     92        self.assertEquals(v.getIgnored(v.path), ["test"]) 
    9293        self.assertEquals(v.getUnknown(v.path), []) 
    9394 
  • trunk/moap/vcs/bzr.py

    r419 r457  
    66""" 
    77 
    8 import os 
    9 import commands 
     8from cStringIO import StringIO 
    109import re 
    1110 
     
    1918    @return: True if the given path looks like a Bazaar tree. 
    2019    """ 
    21     while path and path != '/': 
    22         if (os.path.exists(os.path.join(path, '.bzr')) 
    23             and os.path.exists(os.path.join(path, '.bzr', 'checkout'))): 
    24             return True 
    25         path = os.path.dirname(path) 
    26     return False 
     20    from bzrlib.bzrdir import BzrDir 
     21    from bzrlib.errors import NotBranchError 
     22    try: 
     23        return BzrDir.open(path).has_workingtree() 
     24    except NotBranchError: 
     25        return False 
    2726 
    2827 
     
    3130 
    3231    def getUnknown(self, path): 
    33         oldPath = os.getcwd() 
    34         os.chdir(path) 
     32        wt, _ = self._get_workingtree() 
     33        return list(wt.unknowns()) 
    3534 
    36         result = commands.getoutput("bzr unknowns").split('\n') 
    37         # one empty line does not a return value make 
    38         if result and result == ['']: 
    39             result = [] 
    40  
    41         os.chdir(oldPath) 
    42         return result 
     35    def getIgnored(self, path): 
     36        wt, _ = self._get_workingtree() 
     37        wt.lock_read() 
     38        try: 
     39            return [path for path, pattern in wt.ignored_files()] 
     40        finally: 
     41            wt.unlock() 
    4342 
    4443    def ignore(self, paths, commit=True): 
     
    4645            return 
    4746 
    48         oldPath = os.getcwd() 
    49         os.chdir(self.path) 
    50  
    5147        self.debug("Ignoring %d paths" % len(paths)) 
    5248 
    53         cmd = "bzr ignore %s" % " ".join(paths) 
    54         self.debug("Running %s" % cmd) 
    55         os.system(cmd) 
     49        wt, _ = self._get_workingtree() 
    5650 
    57         if commit: 
    58             self.commit([os.path.join(self.path, '.bzrignore'), ], 
    59                         'moap ignore') 
     51        from bzrlib.ignores import tree_ignores_add_patterns 
    6052 
    61         os.chdir(oldPath) 
     53        tree_ignores_add_patterns(wt, paths) 
     54 
     55        wt.commit(message="moap ignore", specific_files=['.bzrignore']) 
     56 
     57    def _get_workingtree(self): 
     58        from bzrlib.workingtree import WorkingTree 
     59        return WorkingTree.open_containing(self.path) 
    6260 
    6361    def commit(self, paths, message): 
    64         try: 
    65             oldPath = os.getcwd() 
    66             os.chdir(self.path) 
    67             temp = util.writeTemp([message, ]) 
    68             os.system("bzr commit --file %s %s" % (temp, " ".join(paths))) 
    69             os.unlink(temp) 
    70         finally: 
    71             os.chdir(oldPath) 
     62        wt, _ = self._get_workingtree()  
     63        wt.commit(message=message, specific_files=paths) 
    7264 
    7365    def diff(self, path, revision1=None, revision2=None): 
    74         output = commands.getoutput("bzr diff %s" % path) 
    75  
    76         return output 
     66        from bzrlib.diff import show_diff_trees 
     67        wt, _ = self._get_workingtree() 
     68        outf = StringIO() 
     69        show_diff_trees(wt.basis_tree(), wt, outf, [wt.relpath(path)], 
     70                        old_label="", new_label="") 
     71        outf.seek(0) 
     72        return outf.read() 
    7773 
    7874    def getFileMatcher(self): 
     
    8076 
    8177    def update(self, path, revision=None): 
    82         # FIXME: No way to pull just updates to the given path 
    83         status, output = commands.getstatusoutput("bzr pull") 
    84         if status != 0: 
    85             raise vcs.VCSException(output) 
    86  
    87         return output 
     78        wt, _ = self._get_workingtree() 
     79        wt.pull() 
     80        return "" 
    8881 
    8982VCSClass = Bzr 
Note: See TracChangeset for help on using the changeset viewer.