Show More
@@ -327,6 +327,12 b' def convert(ui, src, dest=None, revmapfi' | |||||
327 | ``convert.git.similarity`` is greater than 0. The default is |
|
327 | ``convert.git.similarity`` is greater than 0. The default is | |
328 | ``400``. |
|
328 | ``400``. | |
329 |
|
329 | |||
|
330 | :convert.git.extrakeys: list of extra keys from commit metadata to copy to | |||
|
331 | the destination. Some Git repositories store extra metadata in commits. | |||
|
332 | By default, this non-default metadata will be lost during conversion. | |||
|
333 | Setting this config option can retain that metadata. Some built-in | |||
|
334 | keys such as ``parent`` and ``branch`` are not allowed to be copied. | |||
|
335 | ||||
330 | :convert.git.remoteprefix: remote refs are converted as bookmarks with |
|
336 | :convert.git.remoteprefix: remote refs are converted as bookmarks with | |
331 | ``convert.git.remoteprefix`` as a prefix followed by a /. The default |
|
337 | ``convert.git.remoteprefix`` as a prefix followed by a /. The default | |
332 | is 'remote'. |
|
338 | is 'remote'. |
@@ -31,6 +31,18 b' class submodule(object):' | |||||
31 | def hgsubstate(self): |
|
31 | def hgsubstate(self): | |
32 | return "%s %s" % (self.node, self.path) |
|
32 | return "%s %s" % (self.node, self.path) | |
33 |
|
33 | |||
|
34 | # Keys in extra fields that should not be copied if the user requests. | |||
|
35 | bannedextrakeys = set([ | |||
|
36 | # Git commit object built-ins. | |||
|
37 | 'tree', | |||
|
38 | 'parent', | |||
|
39 | 'author', | |||
|
40 | 'committer', | |||
|
41 | # Mercurial built-ins. | |||
|
42 | 'branch', | |||
|
43 | 'close', | |||
|
44 | ]) | |||
|
45 | ||||
34 | class convert_git(common.converter_source, common.commandline): |
|
46 | class convert_git(common.converter_source, common.commandline): | |
35 | # Windows does not support GIT_DIR= construct while other systems |
|
47 | # Windows does not support GIT_DIR= construct while other systems | |
36 | # cannot remove environment variable. Just assume none have |
|
48 | # cannot remove environment variable. Just assume none have | |
@@ -92,6 +104,12 b' class convert_git(common.converter_sourc' | |||||
92 |
|
104 | |||
93 | self.catfilepipe = self.gitpipe('cat-file', '--batch') |
|
105 | self.catfilepipe = self.gitpipe('cat-file', '--batch') | |
94 |
|
106 | |||
|
107 | self.copyextrakeys = self.ui.configlist('convert', 'git.extrakeys') | |||
|
108 | banned = set(self.copyextrakeys) & bannedextrakeys | |||
|
109 | if banned: | |||
|
110 | raise error.Abort(_('copying of extra key is forbidden: %s') % | |||
|
111 | _(', ').join(sorted(banned))) | |||
|
112 | ||||
95 | def after(self): |
|
113 | def after(self): | |
96 | for f in self.catfilepipe: |
|
114 | for f in self.catfilepipe: | |
97 | f.close() |
|
115 | f.close() | |
@@ -279,6 +297,7 b' class convert_git(common.converter_sourc' | |||||
279 | l = c[:end].splitlines() |
|
297 | l = c[:end].splitlines() | |
280 | parents = [] |
|
298 | parents = [] | |
281 | author = committer = None |
|
299 | author = committer = None | |
|
300 | extra = {} | |||
282 | for e in l[1:]: |
|
301 | for e in l[1:]: | |
283 | n, v = e.split(" ", 1) |
|
302 | n, v = e.split(" ", 1) | |
284 | if n == "author": |
|
303 | if n == "author": | |
@@ -295,6 +314,8 b' class convert_git(common.converter_sourc' | |||||
295 | committer = self.recode(committer) |
|
314 | committer = self.recode(committer) | |
296 | if n == "parent": |
|
315 | if n == "parent": | |
297 | parents.append(v) |
|
316 | parents.append(v) | |
|
317 | if n in self.copyextrakeys: | |||
|
318 | extra[n] = v | |||
298 |
|
319 | |||
299 | if committer and committer != author: |
|
320 | if committer and committer != author: | |
300 | message += "\ncommitter: %s\n" % committer |
|
321 | message += "\ncommitter: %s\n" % committer | |
@@ -304,7 +325,8 b' class convert_git(common.converter_sourc' | |||||
304 |
|
325 | |||
305 | c = common.commit(parents=parents, date=date, author=author, |
|
326 | c = common.commit(parents=parents, date=date, author=author, | |
306 | desc=message, |
|
327 | desc=message, | |
307 |
rev=version |
|
328 | rev=version, | |
|
329 | extra=extra) | |||
308 | return c |
|
330 | return c | |
309 |
|
331 | |||
310 | def numcommits(self): |
|
332 | def numcommits(self): |
@@ -804,3 +804,127 b' test for safely passing paths to git (CV' | |||||
804 |
|
804 | |||
805 | #endif |
|
805 | #endif | |
806 |
|
806 | |||
|
807 | Conversion of extra commit metadata to extras works | |||
|
808 | ||||
|
809 | $ git init gitextras >/dev/null 2>/dev/null | |||
|
810 | $ cd gitextras | |||
|
811 | $ touch foo | |||
|
812 | $ git add foo | |||
|
813 | $ commit -m initial | |||
|
814 | $ echo 1 > foo | |||
|
815 | $ tree=`git write-tree` | |||
|
816 | ||||
|
817 | Git doesn't provider a user-facing API to write extra metadata into the | |||
|
818 | commit, so create the commit object by hand | |||
|
819 | ||||
|
820 | $ git hash-object -t commit -w --stdin << EOF | |||
|
821 | > tree ${tree} | |||
|
822 | > parent ba6b1344e977ece9e00958dbbf17f1f09384b2c1 | |||
|
823 | > author test <test@example.com> 1000000000 +0000 | |||
|
824 | > committer test <test@example.com> 1000000000 +0000 | |||
|
825 | > extra-1 extra-1 | |||
|
826 | > extra-2 extra-2 with space | |||
|
827 | > convert_revision 0000aaaabbbbccccddddeeee | |||
|
828 | > | |||
|
829 | > message with extras | |||
|
830 | > EOF | |||
|
831 | 8123727c8361a4117d1a2d80e0c4e7d70c757f18 | |||
|
832 | ||||
|
833 | $ git reset --hard 8123727c8361a4117d1a2d80e0c4e7d70c757f18 > /dev/null | |||
|
834 | ||||
|
835 | $ cd .. | |||
|
836 | ||||
|
837 | convert will not retain custom metadata keys by default | |||
|
838 | ||||
|
839 | $ hg convert gitextras hgextras1 | |||
|
840 | initializing destination hgextras1 repository | |||
|
841 | scanning source... | |||
|
842 | sorting... | |||
|
843 | converting... | |||
|
844 | 1 initial | |||
|
845 | 0 message with extras | |||
|
846 | updating bookmarks | |||
|
847 | ||||
|
848 | $ hg -R hgextras1 log --debug -r 1 | |||
|
849 | changeset: 1:e13a39880f68479127b2a80fa0b448cc8524aa09 | |||
|
850 | bookmark: master | |||
|
851 | tag: tip | |||
|
852 | phase: draft | |||
|
853 | parent: 0:dcb68977c55cd02cbd13b901df65c4b6e7b9c4b9 | |||
|
854 | parent: -1:0000000000000000000000000000000000000000 | |||
|
855 | manifest: 0:6a3df4de388f3c4f8e28f4f9a814299a3cbb5f50 | |||
|
856 | user: test <test@example.com> | |||
|
857 | date: Sun Sep 09 01:46:40 2001 +0000 | |||
|
858 | extra: branch=default | |||
|
859 | extra: convert_revision=8123727c8361a4117d1a2d80e0c4e7d70c757f18 | |||
|
860 | description: | |||
|
861 | message with extras | |||
|
862 | ||||
|
863 | ||||
|
864 | ||||
|
865 | Attempting to convert a banned extra is disallowed | |||
|
866 | ||||
|
867 | $ hg convert --config convert.git.extrakeys=tree,parent gitextras hgextras-banned | |||
|
868 | initializing destination hgextras-banned repository | |||
|
869 | abort: copying of extra key is forbidden: parent, tree | |||
|
870 | [255] | |||
|
871 | ||||
|
872 | Converting a specific extra works | |||
|
873 | ||||
|
874 | $ hg convert --config convert.git.extrakeys=extra-1 gitextras hgextras2 | |||
|
875 | initializing destination hgextras2 repository | |||
|
876 | scanning source... | |||
|
877 | sorting... | |||
|
878 | converting... | |||
|
879 | 1 initial | |||
|
880 | 0 message with extras | |||
|
881 | updating bookmarks | |||
|
882 | ||||
|
883 | $ hg -R hgextras2 log --debug -r 1 | |||
|
884 | changeset: 1:d40fb205d58597e6ecfd55b16f198be5bf436391 | |||
|
885 | bookmark: master | |||
|
886 | tag: tip | |||
|
887 | phase: draft | |||
|
888 | parent: 0:dcb68977c55cd02cbd13b901df65c4b6e7b9c4b9 | |||
|
889 | parent: -1:0000000000000000000000000000000000000000 | |||
|
890 | manifest: 0:6a3df4de388f3c4f8e28f4f9a814299a3cbb5f50 | |||
|
891 | user: test <test@example.com> | |||
|
892 | date: Sun Sep 09 01:46:40 2001 +0000 | |||
|
893 | extra: branch=default | |||
|
894 | extra: convert_revision=8123727c8361a4117d1a2d80e0c4e7d70c757f18 | |||
|
895 | extra: extra-1=extra-1 | |||
|
896 | description: | |||
|
897 | message with extras | |||
|
898 | ||||
|
899 | ||||
|
900 | ||||
|
901 | Converting multiple extras works | |||
|
902 | ||||
|
903 | $ hg convert --config convert.git.extrakeys=extra-1,extra-2 gitextras hgextras3 | |||
|
904 | initializing destination hgextras3 repository | |||
|
905 | scanning source... | |||
|
906 | sorting... | |||
|
907 | converting... | |||
|
908 | 1 initial | |||
|
909 | 0 message with extras | |||
|
910 | updating bookmarks | |||
|
911 | ||||
|
912 | $ hg -R hgextras3 log --debug -r 1 | |||
|
913 | changeset: 1:0105af33379e7b6491501fd34141b7af700fe125 | |||
|
914 | bookmark: master | |||
|
915 | tag: tip | |||
|
916 | phase: draft | |||
|
917 | parent: 0:dcb68977c55cd02cbd13b901df65c4b6e7b9c4b9 | |||
|
918 | parent: -1:0000000000000000000000000000000000000000 | |||
|
919 | manifest: 0:6a3df4de388f3c4f8e28f4f9a814299a3cbb5f50 | |||
|
920 | user: test <test@example.com> | |||
|
921 | date: Sun Sep 09 01:46:40 2001 +0000 | |||
|
922 | extra: branch=default | |||
|
923 | extra: convert_revision=8123727c8361a4117d1a2d80e0c4e7d70c757f18 | |||
|
924 | extra: extra-1=extra-1 | |||
|
925 | extra: extra-2=extra-2 with space | |||
|
926 | description: | |||
|
927 | message with extras | |||
|
928 | ||||
|
929 | ||||
|
930 |
@@ -268,6 +268,13 b'' | |||||
268 | computation on large projects. The option is only relevant |
|
268 | computation on large projects. The option is only relevant | |
269 | if "convert.git.similarity" is greater than 0. The default |
|
269 | if "convert.git.similarity" is greater than 0. The default | |
270 | is "400". |
|
270 | is "400". | |
|
271 | convert.git.extrakeys | |||
|
272 | list of extra keys from commit metadata to copy to the | |||
|
273 | destination. Some Git repositories store extra metadata in | |||
|
274 | commits. By default, this non-default metadata will be lost | |||
|
275 | during conversion. Setting this config option can retain | |||
|
276 | that metadata. Some built-in keys such as "parent" and | |||
|
277 | "branch" are not allowed to be copied. | |||
271 | convert.git.remoteprefix |
|
278 | convert.git.remoteprefix | |
272 | remote refs are converted as bookmarks with |
|
279 | remote refs are converted as bookmarks with | |
273 | "convert.git.remoteprefix" as a prefix followed by a /. The |
|
280 | "convert.git.remoteprefix" as a prefix followed by a /. The |
General Comments 0
You need to be logged in to leave comments.
Login now