You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Charles Duffy <cd...@spamcop.net> on 2007/02/22 02:35:14 UTC

Of SWIG Python bindings and batons provided via void** arguments

Howdy, all.

I'm looking to use svn_ra_do_diff2() from the SWIG bindings, but I don't 
see how to do it: Even in trunk, this method's docstring indicates that 
it is just a direct passthrough to the C method:

{{{
def svn_ra_do_diff2(*args):
   """
     svn_ra_do_diff2(svn_ra_session_t session, svn_ra_reporter2_t reporter,
         void report_baton, svn_revnum_t revision,
         char diff_target, svn_boolean_t recurse, svn_boolean_t 
ignore_ancestry,
         svn_boolean_t text_deltas,
         char versus_url, svn_delta_editor_t diff_editor,
         void diff_baton, apr_pool_t pool) -> svn_error_t
     """
   return apply(_ra.svn_ra_do_diff2, args)
}}}

At issue here is the report_baton: What Python object can I pass in this 
spot (and then later use as a parameter to reporter->foo() methods)? 
There is no native type corresponding to a void*, at least that I'm 
aware of.

I'm interested only in copies, deletes and property changes -- not text 
diffs -- so the client.* bindings (and higher-level tools provided by 
pysvn) don't appear to be useful to me. I have code which does what I 
want using an editor driven by repos.dir_delta() [patterned off the 
useful example provided in svnlook.py]; my intent here is to add support 
for working against a remote URL, but it's appearing so far to be 
significantly more difficult than I've bargained for.

Any pointers as to approaches I've missed would be greatly appreciated. 
Thank you!

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Of SWIG Python bindings and batons provided via void** arguments

Posted by "C. Michael Pilato" <cm...@collab.net>.
Charles Duffy wrote:
> C. Michael Pilato wrote:
>> It's possible (likely, even) that we've not yet done the hand-coding
>> magic
>> required to help SWIG do something sane with that reporter/report_baton
>> pair.  (In other words, it ain't gonna work.)
>>   
> 
> Is this legitimate grounds for filing a bug? (If so, would it be FEATURE
> or ENHANCEMENT?)

Yes (and as a DEFECT).

-- 
C. Michael Pilato <cm...@collab.net>
CollabNet   <>   www.collab.net   <>   Distributed Development On Demand


Re: Of SWIG Python bindings and batons provided via void** arguments

Posted by "C. Michael Pilato" <cm...@collab.net>.
Charles Duffy wrote:
> Howdy, all.
> 
> I'm looking to use svn_ra_do_diff2() from the SWIG bindings, but I don't
> see how to do it: Even in trunk, this method's docstring indicates that
> it is just a direct passthrough to the C method:
> 
> {{{
> def svn_ra_do_diff2(*args):
>   """
>     svn_ra_do_diff2(svn_ra_session_t session, svn_ra_reporter2_t reporter,
>         void report_baton, svn_revnum_t revision,
>         char diff_target, svn_boolean_t recurse, svn_boolean_t
> ignore_ancestry,
>         svn_boolean_t text_deltas,
>         char versus_url, svn_delta_editor_t diff_editor,
>         void diff_baton, apr_pool_t pool) -> svn_error_t
>     """
>   return apply(_ra.svn_ra_do_diff2, args)
> }}}
> 
> At issue here is the report_baton: What Python object can I pass in this
> spot (and then later use as a parameter to reporter->foo() methods)?
> There is no native type corresponding to a void*, at least that I'm
> aware of.

It's possible (likely, even) that we've not yet done the hand-coding magic
required to help SWIG do something sane with that reporter/report_baton
pair.  (In other words, it ain't gonna work.)

> I'm interested only in copies, deletes and property changes -- not text
> diffs -- so the client.* bindings (and higher-level tools provided by
> pysvn) don't appear to be useful to me. I have code which does what I
> want using an editor driven by repos.dir_delta() [patterned off the
> useful example provided in svnlook.py]; my intent here is to add support
> for working against a remote URL, but it's appearing so far to be
> significantly more difficult than I've bargained for.

In a pinch, you could always write your program in C.  Or, compromise --
hand-code a Python module (in C) which does the nasty reporter/baton stuff,
and call it from a Python script which handles all the not-so-nasty stuff.

Less performant (and far more complex) would be to have your script use the
svn_ra_get_logs() interface (which I know for sure works in Python) across
the range of revisions, tracking what changed in each and how they changed.

-- 
C. Michael Pilato <cm...@collab.net>
CollabNet   <>   www.collab.net   <>   Distributed Development On Demand


Re: Of SWIG Python bindings and batons provided via void** arguments

Posted by Charles Duffy <cd...@spamcop.net>.
David James wrote:
> For a more complete example, see the test_do_diff2 test, which I just
> added to 
> http://svn.collab.net/repos/svn/trunk/subversion/bindings/swig/python/tests/ra.py 

Thank you -- that helps a great deal.

What I don't see it doing, however, is filling out the callback 
structure. In particular, I'm a little unclear on how open_tmp_file is 
supposed to be populated; running without it results in a segfault when 
svn tries to dereference the pointer, and trying to assign a Python 
method fails as follows:

   File "./propcache.py", line 263, in _transform_to_revision
     callbacks.open_tmp_file = open_tmp_file
   File "/usr/lib64/python2.4/site-packages/libsvn/ra.py", line 240, in 
__setattr__
     return _swig_setattr(self, self.__class__, name, value)
   File "/usr/lib64/python2.4/site-packages/libsvn/ra.py", line 22, in 
_swig_setattr
     return _swig_setattr_nondynamic(self,class_type,name,value,0)
   File "/usr/lib64/python2.4/site-packages/libsvn/ra.py", line 15, in 
_swig_setattr_nondynamic
     if method: return method(self,value)
TypeError: argument number 2: a 'svn_error_t *(*)(apr_file_t **,void 
*,apr_pool_t *)' is expected, 'function(<function open_tmp_file at 
0x2addf7f4ccf8>)' is received

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org

Re: Of SWIG Python bindings and batons provided via void** arguments

Posted by David James <ja...@cs.toronto.edu>.
On 2/21/07, Charles Duffy <cd...@spamcop.net> wrote:
> Howdy, all.
>
> I'm looking to use svn_ra_do_diff2() from the SWIG bindings, but I don't
> see how to do it: Even in trunk, this method's docstring indicates that
> it is just a direct passthrough to the C method:

These docstrings are autogenerated by SWIG, and can be quite
misleading. If we can't find a way to fix them, we might end up
turning them off because they tend to be confusing. You're better off
looking at the original documentation from
http://svn.collab.net/repos/svn/trunk/subversion/include/, following
the guidelines at
http://svn.collab.net/repos/svn/trunk/subversion/bindings/swig/python/README


>
> {{{
> def svn_ra_do_diff2(*args):
>    """
>      svn_ra_do_diff2(svn_ra_session_t session, svn_ra_reporter2_t reporter,
>          void report_baton, svn_revnum_t revision,
>          char diff_target, svn_boolean_t recurse, svn_boolean_t
> ignore_ancestry,
>          svn_boolean_t text_deltas,
>          char versus_url, svn_delta_editor_t diff_editor,
>          void diff_baton, apr_pool_t pool) -> svn_error_t
>      """
>    return apply(_ra.svn_ra_do_diff2, args)
> }}}
>
> At issue here is the report_baton: What Python object can I pass in this
> spot (and then later use as a parameter to reporter->foo() methods)?
> There is no native type corresponding to a void*, at least that I'm
> aware of.

Actually, you don't need to pass in a report baton at all -- contrary
to this misleading docstring, the "reporter" and "reporter_baton" are
actually returned to you from the method.

Here's an example:
   e_ptr, e_baton = delta.make_editor(editor)

   reporter, reporter_baton = ra.do_diff2(self.ra_ctx, fs_revnum,
REPOS_URL + "/trunk/README.txt", 0, 0, 1, REPOS_URL +
"/trunk/README.txt", e_ptr, e_baton)

  reporter.set_path(reporter_baton, "", fs_revnum, True, None)

  reporter.finish_report(reporter_baton)

For a more complete example, see the test_do_diff2 test, which I just
added to http://svn.collab.net/repos/svn/trunk/subversion/bindings/swig/python/tests/ra.py

Cheers,

David

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org