Mercurial > hg
view tests/test-duplicateoptions.py @ 30660:1f21a6835604
convert: add config option to copy extra keys from Git commits
Git commit objects support storing arbitrary key-value metadata. While
there is no user-facing mechanism in Git to record these values, some
tools do record data here.
Currently, `hg convert` only handles the "author," "committer," and
"parent" keys in Git commit objects. All other keys are ignored. This
means that any custom keys are lost when converting Git repos to
Mercurial.
This patch implements support for copying a whitelist of extra keys
from Git commit objects to the "extras" dict of the destination. As
the added tests demonstate, this allows extra metadata to be preserved
during the conversion process.
This patch stops short of converting all metadata to "extras." We could
potentially implement this via `convert.git.extrakeys=*` or similar.
But copying everything by default is a bit dangerous because if Git
adds new keys to commit objects, we could find ourselves copying
things that shouldn't be copied!
This patch also assumes the source key is the same as the destination
key. We could implement support for prefixing the output key to
distinguish it as coming from Git. But until this feature is needed,
I'm inclined to hold off implementing it.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Thu, 22 Dec 2016 23:28:11 -0700 |
parents | d83ca854fa21 |
children | bd872f64a8ba |
line wrap: on
line source
from __future__ import absolute_import, print_function import os from mercurial import ( commands, extensions, ui as uimod, ) ignore = set(['highlight', 'win32text', 'factotum']) if os.name != 'nt': ignore.add('win32mbcs') disabled = [ext for ext in extensions.disabled().keys() if ext not in ignore] hgrc = open(os.environ["HGRCPATH"], 'w') hgrc.write('[extensions]\n') for ext in disabled: hgrc.write(ext + '=\n') hgrc.close() u = uimod.ui.load() extensions.loadall(u) globalshort = set() globallong = set() for option in commands.globalopts: option[0] and globalshort.add(option[0]) option[1] and globallong.add(option[1]) for cmd, entry in commands.table.iteritems(): seenshort = globalshort.copy() seenlong = globallong.copy() for option in entry[1]: if (option[0] and option[0] in seenshort) or \ (option[1] and option[1] in seenlong): print("command '" + cmd + "' has duplicate option " + str(option)) seenshort.add(option[0]) seenlong.add(option[1])