Commits

Dan Villiom Podlaski Christiansen committed 5fa0df4

A quick hack. So far, 'bpull' just logs what's in Bazaar.

Comments (0)

Files changed (2)

+\.pyc$
+'''Bazaar integration for Mercurial
+
+An antidote against bad taste in version control. Or rather, it would be
+if it actually worked. Which it doesn't. Sorry 'bout that.
+'''
+
+
+
+import pprint
+
+from mercurial import demandimport
+from mercurial import error
+
+class demandimportdisabler(object):
+    __slots__ = ['active']
+
+    def __enter__(self):
+        self.active = (__import__ == demandimport._demandimport)
+
+        if self.active:
+            demandimport.disable()
+
+    def __exit__(self, *args):
+        if self.active:
+            demandimport.enable()
+
+with demandimportdisabler():
+    import bzrlib.branch
+    import bzrlib.errors
+
+def bpull(ui, repo, source='default', **opts):
+    '''pull from a Bazaar source'''
+
+    source = ui.expandpath(source)
+    repo.ui.status('pulling from %s\n' % source)
+
+    with bzrlib.initialize():
+        try:
+            branch = bzrlib.branch.Branch.open(source)
+        except bzrlib.errors.NotBranchError as e:
+            ui.traceback()
+            raise error.RepoError("repository %s not found" % e.path)
+
+        try:
+            branch.lock_read()
+
+            def showrev(rev):
+                authors = [a.encode('utf-8')
+                           for a in rev.get_apparent_authors()]
+                message = rev.message.encode('utf-8')
+
+                ui.status('node: %s\n' % rev.revision_id)
+                ui.status('parents: %r\n' % rev.parent_ids)
+                for author in authors:
+                    ui.status('author: %s\n' % author)
+                if rev.properties:
+                    ui.status('extra: %s\n' % pprint.pformat(rev.properties))
+                ui.status('message:\n%s\n' % message)
+                ui.status('\n')
+
+            bzrtip = branch.last_revision()
+
+            for revid in branch.revision_history():
+                rev = branch.repository.get_revision(revid)
+                showrev(rev)
+
+            # tree = branch.repository.revision_tree(bzrtip)
+
+            # for change in tree.iter_files_bytes(parent):
+            #     print change
+
+            # revisions = branch.revision_history()
+
+        finally:
+            branch.unlock()
+
+
+cmdtable = {
+    "bzrpull|bpull":
+        (bpull, [], 'hg bpull SOURCE'),
+}