##// END OF EJS Templates
import: allow processing of extra part header during import...
Pierre-Yves David -
r26561:1f14920a default
parent child Browse files
Show More
@@ -831,6 +831,22 b' def service(opts, parentfn=None, initfn='
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
@@ -949,12 +965,15 b' def tryimportone(ui, repo, hunk, parents'
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()
@@ -1505,3 +1505,43 b' Importing multiple failing patches:'
1505 $ hg status -c .
1505 $ hg status -c .
1506 C a
1506 C a
1507 C b
1507 C b
1508
1509 Importing some extra header
1510 ===========================
1511
1512 $ cat > $TESTTMP/parseextra.py <<EOF
1513 > import mercurial.patch
1514 > import mercurial.cmdutil
1515 >
1516 > def processfoo(repo, data, extra, opts):
1517 > if 'foo' in data:
1518 > extra['foo'] = data['foo']
1519 >
1520 > mercurial.patch.patchheadermap.append(('Foo', 'foo'))
1521 > mercurial.cmdutil.extrapreimport.append('foo')
1522 > mercurial.cmdutil.extrapreimportmap['foo'] = processfoo
1523 > EOF
1524 $ printf "[extensions]\nparseextra=$TESTTMP/parseextra.py" >> $HGRCPATH
1525 $ hg up -C tip
1526 0 files updated, 0 files merged, 0 files removed, 0 files unresolved
1527 $ cat > $TESTTMP/foo.patch <<EOF
1528 > # HG changeset patch
1529 > # User Rataxes
1530 > # Date 0 0
1531 > # Thu Jan 01 00:00:00 1970 +0000
1532 > # Foo bar
1533 > height
1534 >
1535 > --- a/a Thu Jan 01 00:00:00 1970 +0000
1536 > +++ b/a Wed Oct 07 09:17:44 2015 +0000
1537 > @@ -5,3 +5,4 @@
1538 > five
1539 > six
1540 > seven
1541 > +heigt
1542 > EOF
1543 $ hg import $TESTTMP/foo.patch
1544 applying $TESTTMP/foo.patch
1545 $ hg log --debug -r . | grep extra
1546 extra: branch=default
1547 extra: foo=bar
General Comments 0
You need to be logged in to leave comments. Login now