3106 raise error.Abort(_('cannot use --exact with --edit')) |
3106 raise error.Abort(_('cannot use --exact with --edit')) |
3107 if opts.get('prefix'): |
3107 if opts.get('prefix'): |
3108 raise error.Abort(_('cannot use --exact with --prefix')) |
3108 raise error.Abort(_('cannot use --exact with --prefix')) |
3109 |
3109 |
3110 base = opts["base"] |
3110 base = opts["base"] |
3111 wlock = dsguard = lock = tr = None |
3111 dsguard = lock = tr = None |
3112 msgs = [] |
3112 msgs = [] |
3113 ret = 0 |
3113 ret = 0 |
3114 |
3114 |
3115 |
3115 with repo.wlock(): |
3116 try: |
3116 try: |
3117 wlock = repo.wlock() |
3117 if update: |
3118 |
3118 cmdutil.checkunfinished(repo) |
3119 if update: |
3119 if (exact or not opts.get('force')): |
3120 cmdutil.checkunfinished(repo) |
3120 cmdutil.bailifchanged(repo) |
3121 if (exact or not opts.get('force')): |
3121 |
3122 cmdutil.bailifchanged(repo) |
3122 if not opts.get('no_commit'): |
3123 |
3123 lock = repo.lock() |
3124 if not opts.get('no_commit'): |
3124 tr = repo.transaction('import') |
3125 lock = repo.lock() |
|
3126 tr = repo.transaction('import') |
|
3127 else: |
|
3128 dsguard = dirstateguard.dirstateguard(repo, 'import') |
|
3129 parents = repo[None].parents() |
|
3130 for patchurl in patches: |
|
3131 if patchurl == '-': |
|
3132 ui.status(_('applying patch from stdin\n')) |
|
3133 patchfile = ui.fin |
|
3134 patchurl = 'stdin' # for error message |
|
3135 else: |
3125 else: |
3136 patchurl = os.path.join(base, patchurl) |
3126 dsguard = dirstateguard.dirstateguard(repo, 'import') |
3137 ui.status(_('applying %s\n') % patchurl) |
3127 parents = repo[None].parents() |
3138 patchfile = hg.openpath(ui, patchurl) |
3128 for patchurl in patches: |
3139 |
3129 if patchurl == '-': |
3140 haspatch = False |
3130 ui.status(_('applying patch from stdin\n')) |
3141 for hunk in patch.split(patchfile): |
3131 patchfile = ui.fin |
3142 with patch.extract(ui, hunk) as patchdata: |
3132 patchurl = 'stdin' # for error message |
3143 msg, node, rej = cmdutil.tryimportone(ui, repo, patchdata, |
|
3144 parents, opts, |
|
3145 msgs, hg.clean) |
|
3146 if msg: |
|
3147 haspatch = True |
|
3148 ui.note(msg + '\n') |
|
3149 if update or exact: |
|
3150 parents = repo[None].parents() |
|
3151 else: |
3133 else: |
3152 parents = [repo[node]] |
3134 patchurl = os.path.join(base, patchurl) |
3153 if rej: |
3135 ui.status(_('applying %s\n') % patchurl) |
3154 ui.write_err(_("patch applied partially\n")) |
3136 patchfile = hg.openpath(ui, patchurl) |
3155 ui.write_err(_("(fix the .rej files and run " |
3137 |
3156 "`hg commit --amend`)\n")) |
3138 haspatch = False |
3157 ret = 1 |
3139 for hunk in patch.split(patchfile): |
3158 break |
3140 with patch.extract(ui, hunk) as patchdata: |
3159 |
3141 msg, node, rej = cmdutil.tryimportone(ui, repo, |
3160 if not haspatch: |
3142 patchdata, |
3161 raise error.Abort(_('%s: no diffs found') % patchurl) |
3143 parents, opts, |
3162 |
3144 msgs, hg.clean) |
3163 if tr: |
3145 if msg: |
3164 tr.close() |
3146 haspatch = True |
3165 if msgs: |
3147 ui.note(msg + '\n') |
3166 repo.savecommitmessage('\n* * *\n'.join(msgs)) |
3148 if update or exact: |
3167 if dsguard: |
3149 parents = repo[None].parents() |
3168 dsguard.close() |
3150 else: |
3169 return ret |
3151 parents = [repo[node]] |
3170 finally: |
3152 if rej: |
3171 if tr: |
3153 ui.write_err(_("patch applied partially\n")) |
3172 tr.release() |
3154 ui.write_err(_("(fix the .rej files and run " |
3173 release(lock, dsguard, wlock) |
3155 "`hg commit --amend`)\n")) |
|
3156 ret = 1 |
|
3157 break |
|
3158 |
|
3159 if not haspatch: |
|
3160 raise error.Abort(_('%s: no diffs found') % patchurl) |
|
3161 |
|
3162 if tr: |
|
3163 tr.close() |
|
3164 if msgs: |
|
3165 repo.savecommitmessage('\n* * *\n'.join(msgs)) |
|
3166 if dsguard: |
|
3167 dsguard.close() |
|
3168 return ret |
|
3169 finally: |
|
3170 if tr: |
|
3171 tr.release() |
|
3172 release(lock, dsguard) |
3174 |
3173 |
3175 @command('incoming|in', |
3174 @command('incoming|in', |
3176 [('f', 'force', None, |
3175 [('f', 'force', None, |
3177 _('run even if remote repository is unrelated')), |
3176 _('run even if remote repository is unrelated')), |
3178 ('n', 'newest-first', None, _('show newest record first')), |
3177 ('n', 'newest-first', None, _('show newest record first')), |