Mercurial > hgsubversion
annotate hgsubversion/svnwrap/common.py @ 948:e2090fabc1a9
editor: use SimpleStringIO in apply_text()
The design is a little ugly as the data stored in _openfiles will be a
string or a SimpleStringIO depending on the file having been edited or
not but this is a simple way to avoid allocating large blocks of data.
This is also a bet the output stream passed to apply_text() is only
being written and never seeked or read.
author | Patrick Mezard <patrick@mezard.eu> |
---|---|
date | Wed, 26 Sep 2012 22:18:31 +0200 |
parents | e1dbd9646d6a |
children | 04f15d38a500 |
rev | line source |
---|---|
0
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
1 import cStringIO |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
2 import getpass |
531
cf4fe45bf8fd
Change all instantiations of IOError to set both errno and strerror.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
511
diff
changeset
|
3 import errno |
0
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
4 import os |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
5 import shutil |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
6 import sys |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
7 import tempfile |
235
2969a20e0eef
Add support for user:pass@url repositories to be hg-like
Daniel Tang <dytang@cs.purdue.edu>
parents:
234
diff
changeset
|
8 import urlparse |
238
e8b3ca865f93
Fix a boneheaded mistake I made when I touched up a previous patch.
Augie Fackler <durin42@gmail.com>
parents:
235
diff
changeset
|
9 import urllib |
300
4aba7542f6a9
Various cleanups, cosmetics and removal of superfluous assertions.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
298
diff
changeset
|
10 import collections |
911
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
11 import fnmatch |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
12 import ConfigParser |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
13 import sys |
0
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
14 |
89
edeec6829d80
SubversionRepo: remember svn.diff3() does not work
Patrick Mezard <pmezard@gmail.com>
parents:
87
diff
changeset
|
15 class SubversionRepoCanNotReplay(Exception): |
edeec6829d80
SubversionRepo: remember svn.diff3() does not work
Patrick Mezard <pmezard@gmail.com>
parents:
87
diff
changeset
|
16 """Exception raised when the svn server is too old to have replay. |
edeec6829d80
SubversionRepo: remember svn.diff3() does not work
Patrick Mezard <pmezard@gmail.com>
parents:
87
diff
changeset
|
17 """ |
edeec6829d80
SubversionRepo: remember svn.diff3() does not work
Patrick Mezard <pmezard@gmail.com>
parents:
87
diff
changeset
|
18 |
edeec6829d80
SubversionRepo: remember svn.diff3() does not work
Patrick Mezard <pmezard@gmail.com>
parents:
87
diff
changeset
|
19 class SubversionRepoCanNotDiff(Exception): |
edeec6829d80
SubversionRepo: remember svn.diff3() does not work
Patrick Mezard <pmezard@gmail.com>
parents:
87
diff
changeset
|
20 """Exception raised when the svn API diff3() command cannot be used |
edeec6829d80
SubversionRepo: remember svn.diff3() does not work
Patrick Mezard <pmezard@gmail.com>
parents:
87
diff
changeset
|
21 """ |
edeec6829d80
SubversionRepo: remember svn.diff3() does not work
Patrick Mezard <pmezard@gmail.com>
parents:
87
diff
changeset
|
22 |
611
b70f7c82b9b8
svncommands: fix layering violation & tweak error messages.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
609
diff
changeset
|
23 class SubversionConnectionException(Exception): |
b70f7c82b9b8
svncommands: fix layering violation & tweak error messages.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
609
diff
changeset
|
24 """Exception raised when a generic error occurs when connecting to a |
b70f7c82b9b8
svncommands: fix layering violation & tweak error messages.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
609
diff
changeset
|
25 repository. |
b70f7c82b9b8
svncommands: fix layering violation & tweak error messages.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
609
diff
changeset
|
26 """ |
b70f7c82b9b8
svncommands: fix layering violation & tweak error messages.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
609
diff
changeset
|
27 |
672
2cc1342d4476
svnwrap: factor out a common module
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
668
diff
changeset
|
28 # Default chunk size used in fetch_history_at_paths() and revisions(). |
668
6be7c9ace365
svnwrap: s/_chunk_size/chunk_size/
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
667
diff
changeset
|
29 chunk_size = 1000 |
301
79440ed81011
Allow specifying a revision to stop at using the -H flag.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
300
diff
changeset
|
30 |
467
3941d73c262e
svnwrappers: override svn+ssh credentials with supplied ones if any
Patrick Mezard <pmezard@gmail.com>
parents:
392
diff
changeset
|
31 def parse_url(url, user=None, passwd=None): |
235
2969a20e0eef
Add support for user:pass@url repositories to be hg-like
Daniel Tang <dytang@cs.purdue.edu>
parents:
234
diff
changeset
|
32 """Parse a URL and return a tuple (username, password, url) |
2969a20e0eef
Add support for user:pass@url repositories to be hg-like
Daniel Tang <dytang@cs.purdue.edu>
parents:
234
diff
changeset
|
33 """ |
2969a20e0eef
Add support for user:pass@url repositories to be hg-like
Daniel Tang <dytang@cs.purdue.edu>
parents:
234
diff
changeset
|
34 scheme, netloc, path, params, query, fragment = urlparse.urlparse(url) |
2969a20e0eef
Add support for user:pass@url repositories to be hg-like
Daniel Tang <dytang@cs.purdue.edu>
parents:
234
diff
changeset
|
35 if '@' in netloc: |
2969a20e0eef
Add support for user:pass@url repositories to be hg-like
Daniel Tang <dytang@cs.purdue.edu>
parents:
234
diff
changeset
|
36 userpass, netloc = netloc.split('@') |
467
3941d73c262e
svnwrappers: override svn+ssh credentials with supplied ones if any
Patrick Mezard <pmezard@gmail.com>
parents:
392
diff
changeset
|
37 if not user and not passwd: |
3941d73c262e
svnwrappers: override svn+ssh credentials with supplied ones if any
Patrick Mezard <pmezard@gmail.com>
parents:
392
diff
changeset
|
38 if ':' in userpass: |
3941d73c262e
svnwrappers: override svn+ssh credentials with supplied ones if any
Patrick Mezard <pmezard@gmail.com>
parents:
392
diff
changeset
|
39 user, passwd = userpass.split(':') |
3941d73c262e
svnwrappers: override svn+ssh credentials with supplied ones if any
Patrick Mezard <pmezard@gmail.com>
parents:
392
diff
changeset
|
40 else: |
3941d73c262e
svnwrappers: override svn+ssh credentials with supplied ones if any
Patrick Mezard <pmezard@gmail.com>
parents:
392
diff
changeset
|
41 user, passwd = userpass, '' |
3941d73c262e
svnwrappers: override svn+ssh credentials with supplied ones if any
Patrick Mezard <pmezard@gmail.com>
parents:
392
diff
changeset
|
42 user, passwd = urllib.unquote(user), urllib.unquote(passwd) |
3941d73c262e
svnwrappers: override svn+ssh credentials with supplied ones if any
Patrick Mezard <pmezard@gmail.com>
parents:
392
diff
changeset
|
43 if user and scheme == 'svn+ssh': |
832
e9af7eba88db
globally: clean up whitespace around operators and commas to conform with PEP8
Yonggang Luo <luoyonggang@gmail.com>
parents:
674
diff
changeset
|
44 netloc = '@'.join((user, netloc,)) |
235
2969a20e0eef
Add support for user:pass@url repositories to be hg-like
Daniel Tang <dytang@cs.purdue.edu>
parents:
234
diff
changeset
|
45 url = urlparse.urlunparse((scheme, netloc, path, params, query, fragment)) |
467
3941d73c262e
svnwrappers: override svn+ssh credentials with supplied ones if any
Patrick Mezard <pmezard@gmail.com>
parents:
392
diff
changeset
|
46 return (user or None, passwd or None, url) |
0
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
47 |
392
35993ba9d119
urls: Make sure we preserve username in urls given to ssh.
Augie Fackler <durin42@gmail.com>
parents:
361
diff
changeset
|
48 |
298
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
49 class Revision(tuple): |
0
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
50 """Wrapper for a Subversion revision. |
298
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
51 |
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
52 Derives from tuple in an attempt to minimise the memory footprint. |
0
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
53 """ |
298
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
54 def __new__(self, revnum, author, message, date, paths, strip_path=''): |
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
55 _paths = {} |
20
2953c867ca99
Minor fixes to the push command to make it more robust.
Augie Fackler <durin42@gmail.com>
parents:
10
diff
changeset
|
56 if paths: |
2953c867ca99
Minor fixes to the push command to make it more robust.
Augie Fackler <durin42@gmail.com>
parents:
10
diff
changeset
|
57 for p in paths: |
298
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
58 _paths[p[len(strip_path):]] = paths[p] |
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
59 return tuple.__new__(self, |
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
60 (revnum, author, message, date, _paths)) |
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
61 |
674
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
62 @property |
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
63 def revnum(self): |
298
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
64 return self[0] |
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
65 |
674
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
66 @property |
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
67 def author(self): |
298
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
68 return self[1] |
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
69 |
674
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
70 @property |
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
71 def message(self): |
298
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
72 return self[2] |
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
73 |
674
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
74 @property |
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
75 def date(self): |
298
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
76 return self[3] |
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
77 |
674
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
78 @property |
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
79 def paths(self): |
298
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
80 return self[4] |
0
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
81 |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
82 def __str__(self): |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
83 return 'r%d by %s' % (self.revnum, self.author) |
911
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
84 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
85 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
86 _svn_config_dir = None |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
87 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
88 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
89 class AutoPropsConfig(object): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
90 """Provides the subversion auto-props functionality |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
91 when pushing new files. |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
92 """ |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
93 def __init__(self, config_dir=None): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
94 config_file = config_file_path(config_dir) |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
95 self.config = ConfigParser.RawConfigParser() |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
96 self.config.read([config_file]) |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
97 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
98 def properties(self, file): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
99 """Returns a dictionary of the auto-props applicable for file. |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
100 Takes enable-auto-props into account. |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
101 """ |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
102 properties = {} |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
103 if self.autoprops_enabled(): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
104 for pattern,prop_list in self.config.items('auto-props'): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
105 if fnmatch.fnmatchcase(os.path.basename(file), pattern): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
106 properties.update(parse_autoprops(prop_list)) |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
107 return properties |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
108 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
109 def autoprops_enabled(self): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
110 return (self.config.has_option('miscellany', 'enable-auto-props') |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
111 and self.config.getboolean( 'miscellany', 'enable-auto-props') |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
112 and self.config.has_section('auto-props')) |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
113 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
114 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
115 def config_file_path(config_dir): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
116 if config_dir == None: |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
117 global _svn_config_dir |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
118 config_dir = _svn_config_dir |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
119 if config_dir == None: |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
120 if sys.platform == 'win32': |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
121 config_dir = os.path.join(os.environ['APPDATA'], 'Subversion') |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
122 else: |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
123 config_dir = os.path.join(os.environ['HOME'], '.subversion') |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
124 return os.path.join(config_dir, 'config') |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
125 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
126 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
127 def parse_autoprops(prop_list): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
128 """Parses a string of autoprops and returns a dictionary of |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
129 the results. |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
130 Emulates the parsing of core.auto_props_enumerator. |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
131 """ |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
132 def unquote(s): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
133 if len(s)>1 and s[0] in ['"', "'"] and s[0]==s[-1]: |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
134 return s[1:-1] |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
135 return s |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
136 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
137 properties = {} |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
138 for prop in prop_list.split(';'): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
139 if '=' in prop: |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
140 prop, value = prop.split('=',1) |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
141 value = unquote(value.strip()) |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
142 else: |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
143 value = '' |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
144 properties[prop.strip()] = value |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
145 return properties |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
146 |
931
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
147 class SimpleStringIO(object): |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
148 """SimpleStringIO can replace a StringIO in write mode. |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
149 |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
150 cStringIO reallocates and doubles the size of its internal buffer |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
151 when it needs to append new data which requires two large blocks for |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
152 large inputs. SimpleStringIO stores each individual blocks and joins |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
153 them once done. This might cause more memory fragmentation but |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
154 requires only one large block. In practice, ra.get_file() seems to |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
155 write in 16kB blocks (svn 1.7.5) which should be friendly to memory |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
156 allocators. |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
157 """ |
948
e2090fabc1a9
editor: use SimpleStringIO in apply_text()
Patrick Mezard <patrick@mezard.eu>
parents:
931
diff
changeset
|
158 def __init__(self, closing=True): |
931
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
159 self._blocks = [] |
948
e2090fabc1a9
editor: use SimpleStringIO in apply_text()
Patrick Mezard <patrick@mezard.eu>
parents:
931
diff
changeset
|
160 self._closing = closing |
931
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
161 |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
162 def write(self, s): |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
163 self._blocks.append(s) |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
164 |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
165 def getvalue(self): |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
166 return ''.join(self._blocks) |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
167 |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
168 def close(self): |
948
e2090fabc1a9
editor: use SimpleStringIO in apply_text()
Patrick Mezard <patrick@mezard.eu>
parents:
931
diff
changeset
|
169 if self._closing: |
e2090fabc1a9
editor: use SimpleStringIO in apply_text()
Patrick Mezard <patrick@mezard.eu>
parents:
931
diff
changeset
|
170 del self._blocks |
931
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
171 |