mercurial/commands.py
changeset 38361 2ceea1554d1e
parent 38358 57dc72b56b6c
child 38421 7fbb5d76c555
equal deleted inserted replaced
38360:c1fca51c26f3 38361:2ceea1554d1e
    38     formatter,
    38     formatter,
    39     graphmod,
    39     graphmod,
    40     hbisect,
    40     hbisect,
    41     help,
    41     help,
    42     hg,
    42     hg,
    43     lock as lockmod,
       
    44     logcmdutil,
    43     logcmdutil,
    45     merge as mergemod,
    44     merge as mergemod,
    46     obsolete,
    45     obsolete,
    47     obsutil,
    46     obsutil,
    48     patch,
    47     patch,
    64 )
    63 )
    65 from .utils import (
    64 from .utils import (
    66     dateutil,
    65     dateutil,
    67     stringutil,
    66     stringutil,
    68 )
    67 )
    69 
       
    70 release = lockmod.release
       
    71 
    68 
    72 table = {}
    69 table = {}
    73 table.update(debugcommandsmod.command._table)
    70 table.update(debugcommandsmod.command._table)
    74 
    71 
    75 command = registrar.command(table)
    72 command = registrar.command(table)
  3109             raise error.Abort(_('cannot use --exact with --edit'))
  3106             raise error.Abort(_('cannot use --exact with --edit'))
  3110         if opts.get('prefix'):
  3107         if opts.get('prefix'):
  3111             raise error.Abort(_('cannot use --exact with --prefix'))
  3108             raise error.Abort(_('cannot use --exact with --prefix'))
  3112 
  3109 
  3113     base = opts["base"]
  3110     base = opts["base"]
  3114     dsguard = lock = tr = None
       
  3115     msgs = []
  3111     msgs = []
  3116     ret = 0
  3112     ret = 0
  3117 
  3113 
  3118     with repo.wlock():
  3114     with repo.wlock():
  3119         try:
  3115         if update:
  3120             if update:
  3116             cmdutil.checkunfinished(repo)
  3121                 cmdutil.checkunfinished(repo)
  3117             if (exact or not opts.get('force')):
  3122                 if (exact or not opts.get('force')):
  3118                 cmdutil.bailifchanged(repo)
  3123                     cmdutil.bailifchanged(repo)
  3119 
  3124 
  3120         if not opts.get('no_commit'):
  3125             if not opts.get('no_commit'):
  3121             lock = repo.lock
  3126                 lock = repo.lock()
  3122             tr = lambda: repo.transaction('import')
  3127                 tr = repo.transaction('import')
  3123             dsguard = util.nullcontextmanager
  3128             else:
  3124         else:
  3129                 dsguard = dirstateguard.dirstateguard(repo, 'import')
  3125             lock = util.nullcontextmanager
       
  3126             tr = util.nullcontextmanager
       
  3127             dsguard = lambda: dirstateguard.dirstateguard(repo, 'import')
       
  3128         with lock(), tr(), dsguard():
  3130             parents = repo[None].parents()
  3129             parents = repo[None].parents()
  3131             for patchurl in patches:
  3130             for patchurl in patches:
  3132                 if patchurl == '-':
  3131                 if patchurl == '-':
  3133                     ui.status(_('applying patch from stdin\n'))
  3132                     ui.status(_('applying patch from stdin\n'))
  3134                     patchfile = ui.fin
  3133                     patchfile = ui.fin
  3160                         break
  3159                         break
  3161 
  3160 
  3162                 if not haspatch:
  3161                 if not haspatch:
  3163                     raise error.Abort(_('%s: no diffs found') % patchurl)
  3162                     raise error.Abort(_('%s: no diffs found') % patchurl)
  3164 
  3163 
  3165             if tr:
       
  3166                 tr.close()
       
  3167             if msgs:
  3164             if msgs:
  3168                 repo.savecommitmessage('\n* * *\n'.join(msgs))
  3165                 repo.savecommitmessage('\n* * *\n'.join(msgs))
  3169             if dsguard:
  3166         return ret
  3170                 dsguard.close()
       
  3171             return ret
       
  3172         finally:
       
  3173             if tr:
       
  3174                 tr.release()
       
  3175             release(lock, dsguard)
       
  3176 
  3167 
  3177 @command('incoming|in',
  3168 @command('incoming|in',
  3178     [('f', 'force', None,
  3169     [('f', 'force', None,
  3179      _('run even if remote repository is unrelated')),
  3170      _('run even if remote repository is unrelated')),
  3180     ('n', 'newest-first', None, _('show newest record first')),
  3171     ('n', 'newest-first', None, _('show newest record first')),