comparison svnwrap/svn_swig_wrapper.py @ 75:cca31b6b1318

SubversionRepo: add optrev() to help generate client API revisions
author Patrick Mezard <pmezard@gmail.com>
date Sun, 09 Nov 2008 18:08:35 -0600
parents 450d5d9d3b80
children 6c62bd201785
comparison
equal deleted inserted replaced
74:450d5d9d3b80 75:cca31b6b1318
11 from svn import delta 11 from svn import delta
12 from svn import ra 12 from svn import ra
13 13
14 if (core.SVN_VER_MAJOR, core.SVN_VER_MINOR, core.SVN_VER_MICRO) < (1, 5, 0): #pragma: no cover 14 if (core.SVN_VER_MAJOR, core.SVN_VER_MINOR, core.SVN_VER_MICRO) < (1, 5, 0): #pragma: no cover
15 raise ImportError, 'You must have Subversion 1.5.0 or newer and matching SWIG bindings.' 15 raise ImportError, 'You must have Subversion 1.5.0 or newer and matching SWIG bindings.'
16
17 def optrev(revnum):
18 optrev = core.svn_opt_revision_t()
19 optrev.kind = core.svn_opt_revision_number
20 optrev.value.number = revnum
21 return optrev
16 22
17 svn_config = core.svn_config_get_config(None) 23 svn_config = core.svn_config_get_config(None)
18 class RaCallbacks(ra.Callbacks): 24 class RaCallbacks(ra.Callbacks):
19 def open_tmp_file(self, pool): #pragma: no cover 25 def open_tmp_file(self, pool): #pragma: no cover
20 (fd, fn) = tempfile.mkstemp() 26 (fd, fn) = tempfile.mkstemp()
369 # hot tip: the swig bridge doesn't like StringIO for these bad boys 375 # hot tip: the swig bridge doesn't like StringIO for these bad boys
370 out_path = os.path.join(tmpdir, 'diffout') 376 out_path = os.path.join(tmpdir, 'diffout')
371 error_path = os.path.join(tmpdir, 'differr') 377 error_path = os.path.join(tmpdir, 'differr')
372 out = open(out_path, 'w') 378 out = open(out_path, 'w')
373 err = open(error_path, 'w') 379 err = open(error_path, 'w')
374 rev_old = core.svn_opt_revision_t() 380 client.diff3([], url2, optrev(other_rev), url, optrev(revision),
375 rev_old.kind = core.svn_opt_revision_number 381 True, True, deleted, ignore_type, 'UTF-8', out, err,
376 rev_old.value.number = other_rev
377 rev_new = core.svn_opt_revision_t()
378 rev_new.kind = core.svn_opt_revision_number
379 rev_new.value.number = revision
380 client.diff3([], url2, rev_old, url, rev_new, True, True,
381 deleted, ignore_type, 'UTF-8', out, err,
382 self.client_context, self.pool) 382 self.client_context, self.pool)
383 out.close() 383 out.close()
384 err.close() 384 err.close()
385 assert len(open(error_path).read()) == 0 385 assert len(open(error_path).read()) == 0
386 diff = open(out_path).read() 386 diff = open(out_path).read()
401 raise 401 raise
402 data = out.getvalue() 402 data = out.getvalue()
403 return data 403 return data
404 404
405 def proplist(self, path, revision, recurse=False): 405 def proplist(self, path, revision, recurse=False):
406 rev = core.svn_opt_revision_t()
407 rev.kind = core.svn_opt_revision_number
408 rev.value.number = revision
409 if path[-1] == '/': 406 if path[-1] == '/':
410 path = path[:-1] 407 path = path[:-1]
411 if path[0] == '/': 408 if path[0] == '/':
412 path = path[1:] 409 path = path[1:]
410 rev = optrev(revision)
413 pl = dict(client.proplist2(self.svn_url+'/'+path, rev, rev, True, 411 pl = dict(client.proplist2(self.svn_url+'/'+path, rev, rev, True,
414 self.client_context, self.pool)) 412 self.client_context, self.pool))
415 pl2 = {} 413 pl2 = {}
416 for key, value in pl.iteritems(): 414 for key, value in pl.iteritems():
417 pl2[key[len(self.svn_url)+1:]] = value 415 pl2[key[len(self.svn_url)+1:]] = value
418 return pl2 416 return pl2
419 417
420 def fetch_all_files_to_dir(self, path, revision, checkout_path): 418 def fetch_all_files_to_dir(self, path, revision, checkout_path):
421 rev = core.svn_opt_revision_t() 419 rev = optrev(revision)
422 rev.kind = core.svn_opt_revision_number
423 rev.value.number = revision
424 client.export3(self.svn_url+'/'+path, checkout_path, rev, 420 client.export3(self.svn_url+'/'+path, checkout_path, rev,
425 rev, True, True, True, 'LF', # should be 'CRLF' on win32 421 rev, True, True, True, 'LF', # should be 'CRLF' on win32
426 self.client_context, self.pool) 422 self.client_context, self.pool)
427 423
428 class SubversionRepoCanNotReplay(Exception): 424 class SubversionRepoCanNotReplay(Exception):