def apply_change(node, reverse, push_patch=True, name=None):
        p1, p2 = repo.changelog.parents(node)
        if p2 != nullid:
            raise util.Abort('cannot %s a merge changeset' % desc['action'])

        opts = mdiff.defaultopts
        opts.git = True
        rpatch = StringIO.StringIO()
        orig, mod = (node, p1) if reverse else (p1, node)
        for chunk in patch.diff(repo, node1=orig, node2=mod, opts=opts):
            rpatch.write(chunk)
        rpatch.seek(0)

        saved_stdin = None
        try:
            save_fin = ui.fin
            ui.fin = rpatch
        except:
            # Old versions of hg did not use the ui.fin mechanism
            saved_stdin = sys.stdin
            sys.stdin = rpatch

        if push_patch:
            commands.import_(ui, repo, '-',
                             force=True,
                             no_commit=True,
                             strip=1,
                             base='')
        else:
            mq.qimport(ui, repo, '-', name=name, rev=[], git=True)

        if saved_stdin is None:
            ui.fin = save_fin
        else:
            sys.stdin = saved_stdin
Beispiel #2
0
def create_fixture_repo(name, dirname=None):
    """Create the fixture repo and return thgrepo object"""
    path = os.path.join(_reposdir, dirname or name)
    repo = thgrepo.repository(ui.ui(), path, create=True)
    commands.import_(repo.ui, repo, os.path.join(FIXTURES_DIR, name + '.diff'),
                     base='', strip=1, exact=True)
    return repo
 def handle_change(desc, node, **kwargs):
     commands.import_(ui, repo, '-',
                      force=True,
                      no_commit=True,
                      strip=1,
                      base='',
                      prefix='',
                      obsolete=[])
 def handle_change(desc, node, **kwargs):
     commands.import_(ui, repo, '-',
                      force=True,
                      no_commit=True,
                      strip=1,
                      base='',
                      prefix='',
                      obsolete=[])
 def handle_change(desc, node, qimport=False):
     if qimport:
         name = compute_patch_name(desc['name'], opts.get('name'), node=node)
         mq.qimport(ui, repo, '-', name=name, rev=[], git=True)
     else:
         commands.import_(ui, repo, '-',
                          force=True,
                          no_commit=True,
                          strip=1,
                          base='',
                          prefix='',
                          obsolete=[])
 def handle_change(desc, node, qimport=False):
     if qimport:
         name = compute_patch_name(desc['name'], opts.get('name'), node=node)
         mq.qimport(ui, repo, '-', name=name, rev=[], git=True)
     else:
         commands.import_(ui, repo, '-',
                          force=True,
                          no_commit=True,
                          strip=1,
                          base='',
                          prefix='',
                          obsolete=[])
Beispiel #7
0
    def pfinish(self, patch_name):
        """
        [pbranch] Execute 'pfinish' command.
        
        The workdir must be clean.
        The patch branch dependencies must be merged.
        
        :param patch_name: A patch branch (not an internal branch)
        """
        # Check preconditions for pfinish

        assert self.is_patch(patch_name)

        pmerge_status = self.pstatus(patch_name)
        if pmerge_status != []:
            dialog.error_dialog(self.parent_window,
            _('Pending Pmerge'),
            _('You cannot finish this patch branch unless you pmerge it first.\n'
              'pmerge will solve the following issues with %(patch)s:\n'
              '* %(issuelist)s') %
            {'patch': patch_name,
             'issuelist': '* '.join(pmerge_status)}
            )
            return

        if not self.workdir_is_clean():
            dialog.error_dialog(self.parent_window,
            _('Uncommitted Local Changes'),
            _('pfinish uses your working directory for temporary work.\n'
              'Please commit your local changes before issuing pfinish.')
            )
            return

        if hasattr(self.repo, 'mq') and len(self.repo.mq.applied) > 0:
            dialog.error_dialog(self.parent_window,
            _('Applied MQ patch'),
            _('pfinish must be able to commit, but this is not allowed\n'
              'as long as you have MQ patches applied.')
            )
            return

        # Set up environment for mercurial commands
        class CmdWidgetUi(mercurial.ui.ui):
            def __init__(self, cmdLogWidget):
                src = None
                super(CmdWidgetUi, self).__init__(src)
                self.cmdLogWidget = cmdLogWidget
            def write(self, *args, **opts):
                for a in args:
                    self.cmdLogWidget.append(str(a))
            def write_err(self, *args, **opts):
                for a in args:
                    self.cmdLogWidget.append(str(a), error=True)
            def flush(self):
                pass
            def prompt(self, msg, choices=None, default="y"):
                raise util.Abort("Internal Error: prompt not available")
            def promptchoice(self, msg, choices, default=0):
                raise util.Abort("Internal Error: promptchoice not available")
            def getpass(self, prompt=None, default=None):
                raise util.Abort("Internal Error: getpass not available")
        repo = self.repo
        ui = CmdWidgetUi(self.cmd.log)
        old_ui = repo.ui
        repo.ui = ui

        # Commit patch to dependency
        fd, patch_file_name = tempfile.mkstemp(prefix='thg-patch-')
        patch_file = os.fdopen(fd, 'w')
        patch_file.writelines(self.pdiff(patch_name))
        patch_file.close()    
        upstream_branch = self.pgraph().deps(patch_name)[0]
        hg.update(ui, repo, rev=upstream_branch)
        hg.import_(ui, repo, patch_file_name, base='', strip=1)
        os.unlink(patch_file_name)
        
        # Close patch branch
        hg.update(ui, repo, rev=patch_name)
        hg.merge(ui, repo, upstream_branch)
        msg = _('Patch branch finished')
        hg.commit(ui, repo, close_branch=True, message=msg)
        
        # Update GUI
        repo.ui = old_ui
        self.emit('repo-invalidated')
Beispiel #8
0
 def handle_change(desc, node, qimport=False):
     if qimport:
         name = compute_patch_name(desc["name"], opts.get("name"), node=node)
         mq.qimport(ui, repo, "-", name=name, rev=[], git=True)
     else:
         commands.import_(ui, repo, "-", force=True, no_commit=True, strip=1, base="", prefix="", obsolete=[])