hgext/uncommit.py
changeset 36980 435b8b05affd
parent 36979 d63c5c651183
child 38429 32fba6fe893d
equal deleted inserted replaced
36979:d63c5c651183 36980:435b8b05affd
    49 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
    49 # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should
    50 # be specifying the version(s) of Mercurial they are tested with, or
    50 # be specifying the version(s) of Mercurial they are tested with, or
    51 # leave the attribute unspecified.
    51 # leave the attribute unspecified.
    52 testedwith = 'ships-with-hg-core'
    52 testedwith = 'ships-with-hg-core'
    53 
    53 
    54 def _commitfiltered(repo, ctx, match, allowempty):
    54 def _commitfiltered(repo, ctx, match, keepcommit):
    55     """Recommit ctx with changed files not in match. Return the new
    55     """Recommit ctx with changed files not in match. Return the new
    56     node identifier, or None if nothing changed.
    56     node identifier, or None if nothing changed.
    57     """
    57     """
    58     base = ctx.p1()
    58     base = ctx.p1()
    59     # ctx
    59     # ctx
    64     if not exclude:
    64     if not exclude:
    65         return None
    65         return None
    66 
    66 
    67     files = (initialfiles - exclude)
    67     files = (initialfiles - exclude)
    68     # return the p1 so that we don't create an obsmarker later
    68     # return the p1 so that we don't create an obsmarker later
    69     if not files and not allowempty:
    69     if not keepcommit:
    70         return ctx.parents()[0].node()
    70         return ctx.parents()[0].node()
    71 
    71 
    72     # Filter copies
    72     # Filter copies
    73     copied = copies.pathcopies(base, ctx)
    73     copied = copies.pathcopies(base, ctx)
    74     copied = dict((dst, src) for dst, src in copied.iteritems()
    74     copied = dict((dst, src) for dst, src in copied.iteritems()
   167         if len(old.parents()) > 1:
   167         if len(old.parents()) > 1:
   168             raise error.Abort(_("cannot uncommit merge changeset"))
   168             raise error.Abort(_("cannot uncommit merge changeset"))
   169 
   169 
   170         with repo.transaction('uncommit'):
   170         with repo.transaction('uncommit'):
   171             match = scmutil.match(old, pats, opts)
   171             match = scmutil.match(old, pats, opts)
   172             allowempty = opts.get('keep') or pats
   172             keepcommit = opts.get('keep') or pats
   173             newid = _commitfiltered(repo, old, match, allowempty)
   173             newid = _commitfiltered(repo, old, match, keepcommit)
   174             if newid is None:
   174             if newid is None:
   175                 ui.status(_("nothing to uncommit\n"))
   175                 ui.status(_("nothing to uncommit\n"))
   176                 return 1
   176                 return 1
   177 
   177 
   178             mapping = {}
   178             mapping = {}