Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 26561:1f14920a892c
import: allow processing of extra part header during 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 points to alter the changeset
(especially extra) before we commit. There would be more to do for a full
featured hooking, but this currently fit my needs.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Tue, 06 Oct 2015 09:51:24 -0700 |
parents | b9be8ab6e628 |
children | dd2f5e014806 |
comparison
equal
deleted
inserted
replaced
26560:75d448d56a9d | 26561:1f14920a892c |
---|---|
829 os.close(logfilefd) | 829 os.close(logfilefd) |
830 | 830 |
831 if runfn: | 831 if runfn: |
832 return runfn() | 832 return runfn() |
833 | 833 |
834 ## facility to let extension process additional data into an import patch | |
835 # list of identifier to be executed in order | |
836 extrapreimport = [] # run before commit | |
837 # mapping from identifier to actual import function | |
838 # | |
839 # 'preimport' are run before the commit is made and are provided the following | |
840 # arguments: | |
841 # - repo: the localrepository instance, | |
842 # - patchdata: data extracted from patch header (cf m.patch.patchheadermap), | |
843 # - extra: the future extra dictionnary of the changeset, please mutate it, | |
844 # - opts: the import options. | |
845 # 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 # there. | |
848 extrapreimportmap = {} | |
849 | |
834 def tryimportone(ui, repo, hunk, parents, opts, msgs, updatefunc): | 850 def tryimportone(ui, repo, hunk, parents, opts, msgs, updatefunc): |
835 """Utility function used by commands.import to import a single patch | 851 """Utility function used by commands.import to import a single patch |
836 | 852 |
837 This function is explicitly defined here to help the evolve extension to | 853 This function is explicitly defined here to help the evolve extension to |
838 wrap this part of the import logic. | 854 wrap this part of the import logic. |
947 if opts.get('exact'): | 963 if opts.get('exact'): |
948 editor = None | 964 editor = None |
949 else: | 965 else: |
950 editor = getcommiteditor(editform=editform, **opts) | 966 editor = getcommiteditor(editform=editform, **opts) |
951 allowemptyback = repo.ui.backupconfig('ui', 'allowemptycommit') | 967 allowemptyback = repo.ui.backupconfig('ui', 'allowemptycommit') |
968 extra = {} | |
969 for idfunc in extrapreimport: | |
970 extrapreimportmap[idfunc](repo, extractdata, extra, opts) | |
952 try: | 971 try: |
953 if partial: | 972 if partial: |
954 repo.ui.setconfig('ui', 'allowemptycommit', True) | 973 repo.ui.setconfig('ui', 'allowemptycommit', True) |
955 n = repo.commit(message, opts.get('user') or user, | 974 n = repo.commit(message, opts.get('user') or user, |
956 opts.get('date') or date, match=m, | 975 opts.get('date') or date, match=m, |
957 editor=editor) | 976 editor=editor, extra=extra) |
958 finally: | 977 finally: |
959 repo.ui.restoreconfig(allowemptyback) | 978 repo.ui.restoreconfig(allowemptyback) |
960 dsguard.close() | 979 dsguard.close() |
961 else: | 980 else: |
962 if opts.get('exact') or opts.get('import_branch'): | 981 if opts.get('exact') or opts.get('import_branch'): |