def revset_pushid(repo, subset, x): """``pushid(int)`` Changesets that were part of the specified numeric push id. """ l = revset.getargs(x, 1, 1, 'pushid requires one argument') try: pushid = int(revset.getstring(l[0], 'pushid requires a number')) except (TypeError, ValueError): raise error.ParseError('pushid expects a number') with repo.pushlog.conn(readonly=True) as conn: push = repo.pushlog.pushfromid(conn, pushid) if conn else None if not push: return revset.baseset() to_rev = repo.changelog.rev pushrevs = set() for node in push.nodes: try: pushrevs.add(to_rev(bin(node))) except RepoLookupError: pass return subset & pushrevs
def newini(fp=None): try: # TODO: optionxformvalue isn't used by INIConfig ? return INIConfig(fp=fp, optionxformvalue=None) except ConfigParser.MissingSectionHeaderError, err: raise error.ParseError(err.message.splitlines()[0], '%s:%d' % (err.filename, err.lineno))
def revset_svnrev(repo, subset, x): '''``svnrev(number)`` Select changesets that originate in the given Subversion revision. ''' args = revset.getargs(x, 1, 1, "svnrev takes one argument") rev = revset.getstring(args[0], "the argument to svnrev() must be a number") try: revnum = int(rev) except ValueError: raise error.ParseError("the argument to svnrev() must be a number") rev = rev + ' ' revs = [] meta = repo.svnmeta(skiperrorcheck=True) try: for l in maps.RevMap.readmapfile(meta.revmap_file, missingok=False): if l.startswith(rev): n = l.split(' ', 2)[1] r = repo[node.bin(n)].rev() if r in subset: revs.append(r) return revs except IOError, err: if err.errno != errno.ENOENT: raise raise hgutil.Abort("svn metadata is missing - " "run 'hg svn rebuildmeta' to reconstruct it")
def _readini(self): """Create iniparse object by reading every file""" if len(self._readfiles) > 1: raise NotImplementedError("wconfig does not support read() more " "than once") def newini(fp=None): try: # TODO: optionxformvalue isn't used by INIConfig ? return INIConfig(fp=fp, optionxformvalue=None) except ConfigParser.MissingSectionHeaderError, err: raise error.ParseError(err.message.splitlines()[0], '%s:%d' % (err.filename, err.lineno)) except ConfigParser.ParsingError, err: if err.errors: loc = '%s:%d' % (err.filename, err.errors[0][0]) else: loc = err.filename raise error.ParseError(err.message.splitlines()[0], loc)
def revset_svnrev(repo, subset, x): '''``svnrev(number)`` Select changesets that originate in the given Subversion revision. ''' args = revset.getargs(x, 1, 1, "svnrev takes one argument") rev = revset.getstring(args[0], "the argument to svnrev() must be a number") try: revnum = int(rev) except ValueError: raise error.ParseError("the argument to svnrev() must be a number") meta = repo.svnmeta(skiperrorcheck=True) if not meta.revmapexists: raise error.Abort("svn metadata is missing - " "run 'hg svn rebuildmeta' to reconstruct it") torev = repo.changelog.rev revs = revset.baseset(torev(r) for r in meta.revmap.revhashes(revnum)) return subset & revs
def revset_svnrev(repo, subset, x): '''``svnrev(number)`` Select changesets that originate in the given Subversion revision. ''' args = revset.getargs(x, 1, 1, "svnrev takes one argument") rev = revset.getstring(args[0], "the argument to svnrev() must be a number") try: rev = int(rev) except ValueError: raise error.ParseError("the argument to svnrev() must be a number") def matches(r): convertinfo = repo[r].extra().get('convert_revision', '') if convertinfo[:4] != 'svn:': return False return int(convertinfo[40:].rsplit('@', 1)[-1]) == rev return [r for r in subset if matches(r)]
def templatelabel(context, mapping, args): if len(args) != 2: # i18n: "label" is a keyword raise error.ParseError(_("label expects two arguments")) # add known effects to the mapping so symbols like 'red', 'bold', # etc. don't need to be quoted mapping.update(dict([(k, k) for k in _effects])) thing = args[1][0](context, mapping, args[1][1]) # apparently, repo could be a string that is the favicon? repo = mapping.get('repo', '') if isinstance(repo, str): return thing label = args[0][0](context, mapping, args[0][1]) thing = templater.stringify(thing) label = templater.stringify(label) return repo.ui.label(thing, label)
def templatelabel(context, mapping, args): if len(args) != 2: # i18n: "label" is a keyword raise error.ParseError(_("label expects two arguments")) thing = templater.stringify(args[1][0](context, mapping, args[1][1])) thing = templater.runtemplate(context, mapping, templater.compiletemplate(thing, context)) # apparently, repo could be a string that is the favicon? repo = mapping.get('repo', '') if isinstance(repo, str): return thing label = templater.stringify(args[0][0](context, mapping, args[0][1])) label = templater.runtemplate(context, mapping, templater.compiletemplate(label, context)) thing = templater.stringify(thing) label = templater.stringify(label) return repo.ui.label(thing, label)
def _parse(text): tree, pos = parser.parser(_elements).parse(_tokenize(text)) if pos != len(text): raise error.ParseError(b'invalid token', pos) return tree
def rebase(ui, repo, **opts): """move changeset (and descendants) to a different branch Rebase uses repeated merging to graft changesets from one part of history onto another. This can be useful for linearizing local changes relative to a master development tree. If a rebase is interrupted to manually resolve a merge, it can be continued with --continue/-c or aborted with --abort/-a. """ originalwd = target = None external = nullrev state = {} skipped = set() lock = wlock = None try: lock = repo.lock() wlock = repo.wlock() # Validate input and define rebasing points destf = opts.get('dest', None) srcf = opts.get('source', None) basef = opts.get('base', None) contf = opts.get('continue') abortf = opts.get('abort') collapsef = opts.get('collapse', False) extrafn = opts.get('extrafn') keepf = opts.get('keep', False) keepbranchesf = opts.get('keepbranches', False) if contf or abortf: if contf and abortf: raise error.ParseError('rebase', _('cannot use both abort and continue')) if collapsef: raise error.ParseError( 'rebase', _('cannot use collapse with continue or abort')) if srcf or basef or destf: raise error.ParseError( 'rebase', _('abort and continue do not allow specifying revisions')) (originalwd, target, state, collapsef, keepf, keepbranchesf, external) = restorestatus(repo) if abortf: abort(repo, originalwd, target, state) return else: if srcf and basef: raise error.ParseError( 'rebase', _('cannot specify both a ' 'revision and a base')) cmdutil.bail_if_changed(repo) result = buildstate(repo, destf, srcf, basef, collapsef) if result: originalwd, target, state, external = result else: # Empty state built, nothing to rebase ui.status(_('nothing to rebase\n')) return if keepbranchesf: if extrafn: raise error.ParseError( 'rebase', _('cannot use both keepbranches and extrafn')) def extrafn(ctx, extra): extra['branch'] = ctx.branch() # Rebase targetancestors = list(repo.changelog.ancestors(target)) targetancestors.append(target) for rev in sorted(state): if state[rev] == -1: storestatus(repo, originalwd, target, state, collapsef, keepf, keepbranchesf, external) rebasenode(repo, rev, target, state, skipped, targetancestors, collapsef, extrafn) ui.note(_('rebase merging completed\n')) if collapsef: p1, p2 = defineparents(repo, min(state), target, state, targetancestors) concludenode(repo, rev, p1, external, state, collapsef, last=True, skipped=skipped, extrafn=extrafn) if 'qtip' in repo.tags(): updatemq(repo, state, skipped, **opts) if not keepf: # Remove no more useful revisions if set(repo.changelog.descendants(min(state))) - set(state): ui.warn( _("warning: new changesets detected on source branch, " "not stripping\n")) else: repair.strip(ui, repo, repo[min(state)].node(), "strip") clearstatus(repo) ui.status(_("rebase completed\n")) if os.path.exists(repo.sjoin('undo')): util.unlink(repo.sjoin('undo')) if skipped: ui.note(_("%d revisions have been skipped\n") % len(skipped)) finally: release(lock, wlock)
def rebase(ui, repo, **opts): """move changeset (and descendants) to a different branch Rebase uses repeated merging to graft changesets from one part of history (the source) onto another (the destination). This can be useful for linearizing local changes relative to a master development tree. If you don't specify a destination changeset (``-d/--dest``), rebase uses the tipmost head of the current named branch as the destination. (The destination changeset is not modified by rebasing, but new changesets are added as its descendants.) You can specify which changesets to rebase in two ways: as a "source" changeset or as a "base" changeset. Both are shorthand for a topologically related set of changesets (the "source branch"). If you specify source (``-s/--source``), rebase will rebase that changeset and all of its descendants onto dest. If you specify base (``-b/--base``), rebase will select ancestors of base back to but not including the common ancestor with dest. Thus, ``-b`` is less precise but more convenient than ``-s``: you can specify any changeset in the source branch, and rebase will select the whole branch. If you specify neither ``-s`` nor ``-b``, rebase uses the parent of the working directory as the base. By default, rebase recreates the changesets in the source branch as descendants of dest and then destroys the originals. Use ``--keep`` to preserve the original source changesets. Some changesets in the source branch (e.g. merges from the destination branch) may be dropped if they no longer contribute any change. One result of the rules for selecting the destination changeset and source branch is that, unlike ``merge``, rebase will do nothing if you are at the latest (tipmost) head of a named branch with two heads. You need to explicitly specify source and/or destination (or ``update`` to the other head, if it's the head of the intended source branch). If a rebase is interrupted to manually resolve a merge, it can be continued with --continue/-c or aborted with --abort/-a. """ originalwd = target = None external = nullrev state = {} skipped = set() targetancestors = set() lock = wlock = None try: lock = repo.lock() wlock = repo.wlock() # Validate input and define rebasing points destf = opts.get('dest', None) srcf = opts.get('source', None) basef = opts.get('base', None) contf = opts.get('continue') abortf = opts.get('abort') collapsef = opts.get('collapse', False) extrafn = opts.get('extrafn') keepf = opts.get('keep', False) keepbranchesf = opts.get('keepbranches', False) detachf = opts.get('detach', False) if contf or abortf: if contf and abortf: raise error.ParseError('rebase', _('cannot use both abort and continue')) if collapsef: raise error.ParseError( 'rebase', _('cannot use collapse with continue or abort')) if detachf: raise error.ParseError( 'rebase', _('cannot use detach with continue or abort')) if srcf or basef or destf: raise error.ParseError( 'rebase', _('abort and continue do not allow specifying revisions')) (originalwd, target, state, collapsef, keepf, keepbranchesf, external) = restorestatus(repo) if abortf: abort(repo, originalwd, target, state) return else: if srcf and basef: raise error.ParseError( 'rebase', _('cannot specify both a ' 'revision and a base')) if detachf: if not srcf: raise error.ParseError( 'rebase', _('detach requires a revision to be specified')) if basef: raise error.ParseError( 'rebase', _('cannot specify a base with detach')) cmdutil.bail_if_changed(repo) result = buildstate(repo, destf, srcf, basef, detachf) if not result: # Empty state built, nothing to rebase ui.status(_('nothing to rebase\n')) return else: originalwd, target, state = result if collapsef: targetancestors = set(repo.changelog.ancestors(target)) external = checkexternal(repo, state, targetancestors) if keepbranchesf: if extrafn: raise error.ParseError( 'rebase', _('cannot use both keepbranches and extrafn')) def extrafn(ctx, extra): extra['branch'] = ctx.branch() # Rebase if not targetancestors: targetancestors = set(repo.changelog.ancestors(target)) targetancestors.add(target) for rev in sorted(state): if state[rev] == -1: ui.debug("rebasing %d:%s\n" % (rev, repo[rev])) storestatus(repo, originalwd, target, state, collapsef, keepf, keepbranchesf, external) p1, p2 = defineparents(repo, rev, target, state, targetancestors) if len(repo.parents()) == 2: repo.ui.debug('resuming interrupted rebase\n') else: stats = rebasenode(repo, rev, p1, p2, state) if stats and stats[3] > 0: raise util.Abort( _('fix unresolved conflicts with hg ' 'resolve then run hg rebase --continue')) updatedirstate(repo, rev, target, p2) if not collapsef: newrev = concludenode(repo, rev, p1, p2, extrafn=extrafn) else: # Skip commit if we are collapsing repo.dirstate.setparents(repo[p1].node()) newrev = None # Update the state if newrev is not None: state[rev] = repo[newrev].rev() else: if not collapsef: ui.note(_('no changes, revision %d skipped\n') % rev) ui.debug('next revision set to %s\n' % p1) skipped.add(rev) state[rev] = p1 ui.note(_('rebase merging completed\n')) if collapsef: p1, p2 = defineparents(repo, min(state), target, state, targetancestors) commitmsg = 'Collapsed revision' for rebased in state: if rebased not in skipped and state[rebased] != nullmerge: commitmsg += '\n* %s' % repo[rebased].description() commitmsg = ui.edit(commitmsg, repo.ui.username()) newrev = concludenode(repo, rev, p1, external, commitmsg=commitmsg, extrafn=extrafn) if 'qtip' in repo.tags(): updatemq(repo, state, skipped, **opts) if not keepf: # Remove no more useful revisions rebased = [rev for rev in state if state[rev] != nullmerge] if rebased: if set(repo.changelog.descendants(min(rebased))) - set(state): ui.warn( _("warning: new changesets detected " "on source branch, not stripping\n")) else: repair.strip(ui, repo, repo[min(rebased)].node(), "strip") clearstatus(repo) ui.status(_("rebase completed\n")) if os.path.exists(repo.sjoin('undo')): util.unlink(repo.sjoin('undo')) if skipped: ui.note(_("%d revisions have been skipped\n") % len(skipped)) finally: release(lock, wlock)
def rebase(ui, repo, **opts): """move changeset (and descendants) to a different branch Rebase uses repeated merging to graft changesets from one part of history onto another. This can be useful for linearizing local changes relative to a master development tree. If a rebase is interrupted to manually resolve a merge, it can be continued with --continue/-c or aborted with --abort/-a. """ originalwd = target = None external = nullrev state = {} skipped = set() targetancestors = set() lock = wlock = None try: lock = repo.lock() wlock = repo.wlock() # Validate input and define rebasing points destf = opts.get('dest', None) srcf = opts.get('source', None) basef = opts.get('base', None) contf = opts.get('continue') abortf = opts.get('abort') collapsef = opts.get('collapse', False) extrafn = opts.get('extrafn') keepf = opts.get('keep', False) keepbranchesf = opts.get('keepbranches', False) detachf = opts.get('detach', False) if contf or abortf: if contf and abortf: raise error.ParseError('rebase', _('cannot use both abort and continue')) if collapsef: raise error.ParseError( 'rebase', _('cannot use collapse with continue or abort')) if detachf: raise error.ParseError( 'rebase', _('cannot use detach with continue or abort')) if srcf or basef or destf: raise error.ParseError( 'rebase', _('abort and continue do not allow specifying revisions')) (originalwd, target, state, collapsef, keepf, keepbranchesf, external) = restorestatus(repo) if abortf: abort(repo, originalwd, target, state) return else: if srcf and basef: raise error.ParseError( 'rebase', _('cannot specify both a ' 'revision and a base')) if detachf: if not srcf: raise error.ParseError( 'rebase', _('detach requires a revision to be specified')) if basef: raise error.ParseError( 'rebase', _('cannot specify a base with detach')) cmdutil.bail_if_changed(repo) result = buildstate(repo, destf, srcf, basef, detachf) if not result: # Empty state built, nothing to rebase ui.status(_('nothing to rebase\n')) return else: originalwd, target, state = result if collapsef: targetancestors = set(repo.changelog.ancestors(target)) external = checkexternal(repo, state, targetancestors) if keepbranchesf: if extrafn: raise error.ParseError( 'rebase', _('cannot use both keepbranches and extrafn')) def extrafn(ctx, extra): extra['branch'] = ctx.branch() # Rebase if not targetancestors: targetancestors = set(repo.changelog.ancestors(target)) targetancestors.add(target) for rev in sorted(state): if state[rev] == -1: ui.debug("rebasing %d:%s\n" % (rev, repo[rev])) storestatus(repo, originalwd, target, state, collapsef, keepf, keepbranchesf, external) p1, p2 = defineparents(repo, rev, target, state, targetancestors) if len(repo.parents()) == 2: repo.ui.debug('resuming interrupted rebase\n') else: stats = rebasenode(repo, rev, p1, p2, state) if stats and stats[3] > 0: raise util.Abort( _('fix unresolved conflicts with hg ' 'resolve then run hg rebase --continue')) updatedirstate(repo, rev, target, p2) if not collapsef: extra = {'rebase_source': repo[rev].hex()} if extrafn: extrafn(repo[rev], extra) newrev = concludenode(repo, rev, p1, p2, extra=extra) else: # Skip commit if we are collapsing repo.dirstate.setparents(repo[p1].node()) newrev = None # Update the state if newrev is not None: state[rev] = repo[newrev].rev() else: if not collapsef: ui.note(_('no changes, revision %d skipped\n') % rev) ui.debug('next revision set to %s\n' % p1) skipped.add(rev) state[rev] = p1 ui.note(_('rebase merging completed\n')) if collapsef: p1, p2 = defineparents(repo, min(state), target, state, targetancestors) commitmsg = 'Collapsed revision' for rebased in state: if rebased not in skipped and state[rebased] != nullmerge: commitmsg += '\n* %s' % repo[rebased].description() commitmsg = ui.edit(commitmsg, repo.ui.username()) newrev = concludenode(repo, rev, p1, external, commitmsg=commitmsg, extra=extrafn) if 'qtip' in repo.tags(): updatemq(repo, state, skipped, **opts) if not keepf: # Remove no more useful revisions rebased = [rev for rev in state if state[rev] != nullmerge] if rebased: if set(repo.changelog.descendants(min(rebased))) - set(state): ui.warn( _("warning: new changesets detected " "on source branch, not stripping\n")) else: repair.strip(ui, repo, repo[min(rebased)].node(), "strip") clearstatus(repo) ui.status(_("rebase completed\n")) if os.path.exists(repo.sjoin('undo')): util.unlink(repo.sjoin('undo')) if skipped: ui.note(_("%d revisions have been skipped\n") % len(skipped)) finally: release(lock, wlock)