Re: Trouble writing a simple symbol transformer

Markus Schöpflin <[email protected]> Mon, 17 Dec 2012 09:31:04 +0100
Newsgroups gmane.comp.version-control.subversion.cvs2svn.user
Message-ID <[email protected]>
Am 15.12.2012 06:41, schrieb Michael Haggerty:
> On 12/14/2012 03:37 PM, Markus Schöpflin wrote:

[...]

>> Can anyone tell me what to do about this, as I have no idea what could be wrong.
>
> Technical explanation: The problem is that the symbol transforms are
> pickled in pass1 then unpickled in later passes.  (Pickling is a Python
> mechanism for storing objects to a file.)  Class instances can only be
> unpickled if the class can be imported at the time of unpickling.  Your
> class is not, because it is defined in the options file, which is loaded
> using execfile(), not by being imported.
>
> Short answer: define your class in a separate file and import that file
> into your options file:
>
> mysymboltransform.py:
>
>>      class MySymbolTransform:
>>          def __init__(self):
>>              self.mapping = {"foo" : "bar"}
>>
>>       def transform(self, cvs_file, symbol_name, revision):
>>           return self.mapping.get(symbol_name, "CVS_%s" % symbol_name)
>
> cvs2svn.options:
>
>> from mysymboltransform import MySymbolTransform
>> [...]
>> run_options.set_project(
>>       ...
>>       symbol_transforms=[
>>           MySymbolTransform(),
>>           ReplaceSubstringsSymbolTransform('\\','/'),
>>           NormalizePathsSymbolTransform(),
>>           ],
>
> This is pretty subtle and needs to be added to the FAQ.
>

Thank you very much for your help, this worked like a charm.

Markus

------------------------------------------------------
http://cvs2svn.tigris.org/ds/viewMessage.do?dsForumId=1670&dsMessageId=3036417

To unsubscribe from this discussion, e-mail: [[email protected]].