comparison mercurial/cmdutil.py @ 26562:dd2f5e014806

import: allow processing of extra part header after import As we have a way for extension to add more header, we need a way for them to actually process them. We add a basic hook point to do extra work after the import have been committed.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Wed, 07 Oct 2015 13:05:25 -0700
parents 1f14920a892c
children 8bd2759f1fa7
comparison
equal deleted inserted replaced
26561:1f14920a892c 26562:dd2f5e014806
832 return runfn() 832 return runfn()
833 833
834 ## facility to let extension process additional data into an import patch 834 ## facility to let extension process additional data into an import patch
835 # list of identifier to be executed in order 835 # list of identifier to be executed in order
836 extrapreimport = [] # run before commit 836 extrapreimport = [] # run before commit
837 extrapostimport = [] # run after commit
837 # mapping from identifier to actual import function 838 # mapping from identifier to actual import function
838 # 839 #
839 # 'preimport' are run before the commit is made and are provided the following 840 # 'preimport' are run before the commit is made and are provided the following
840 # arguments: 841 # arguments:
841 # - repo: the localrepository instance, 842 # - repo: the localrepository instance,
844 # - opts: the import options. 845 # - opts: the import options.
845 # XXX ideally, we would just pass an ctx ready to be computed, that would allow 846 # XXX ideally, we would just pass an ctx ready to be computed, that would allow
846 # mutation of in memory commit and more. Feel free to rework the code to get 847 # mutation of in memory commit and more. Feel free to rework the code to get
847 # there. 848 # there.
848 extrapreimportmap = {} 849 extrapreimportmap = {}
850 # 'postimport' are run after the commit is made and are provided the following
851 # argument:
852 # - ctx: the changectx created by import.
853 extrapostimportmap = {}
849 854
850 def tryimportone(ui, repo, hunk, parents, opts, msgs, updatefunc): 855 def tryimportone(ui, repo, hunk, parents, opts, msgs, updatefunc):
851 """Utility function used by commands.import to import a single patch 856 """Utility function used by commands.import to import a single patch
852 857
853 This function is explicitly defined here to help the evolve extension to 858 This function is explicitly defined here to help the evolve extension to
972 if partial: 977 if partial:
973 repo.ui.setconfig('ui', 'allowemptycommit', True) 978 repo.ui.setconfig('ui', 'allowemptycommit', True)
974 n = repo.commit(message, opts.get('user') or user, 979 n = repo.commit(message, opts.get('user') or user,
975 opts.get('date') or date, match=m, 980 opts.get('date') or date, match=m,
976 editor=editor, extra=extra) 981 editor=editor, extra=extra)
982 for idfunc in extrapostimport:
983 extrapostimportmap[idfunc](repo[n])
977 finally: 984 finally:
978 repo.ui.restoreconfig(allowemptyback) 985 repo.ui.restoreconfig(allowemptyback)
979 dsguard.close() 986 dsguard.close()
980 else: 987 else:
981 if opts.get('exact') or opts.get('import_branch'): 988 if opts.get('exact') or opts.get('import_branch'):