Mercurial > hgsubversion
annotate hgsubversion/svnwrap/common.py @ 1509:8c7dae2e0f54
svnwrap: don't add paths to revision outside of subdir
It prevents from closing the default branch on some occasional removal of
directory from outside of subdir in a single layout.
author | Ivan Lezhankin <ilezhankin@yandex-team.ru> |
---|---|
date | Tue, 23 May 2017 15:09:02 +0300 |
parents | 04f15d38a500 |
children | c5de1adc3092 |
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 """ |
1053
04f15d38a500
svnwrap: don't require Revision paths to be specified
Dan Villiom Podlaski Christiansen <dan@cabo.dk>
parents:
948
diff
changeset
|
54 def __new__(self, revnum, author, message, date, paths=None, strip_path=''): |
298
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: |
1509
8c7dae2e0f54
svnwrap: don't add paths to revision outside of subdir
Ivan Lezhankin <ilezhankin@yandex-team.ru>
parents:
1053
diff
changeset
|
58 if p.startswith(strip_path): |
8c7dae2e0f54
svnwrap: don't add paths to revision outside of subdir
Ivan Lezhankin <ilezhankin@yandex-team.ru>
parents:
1053
diff
changeset
|
59 _paths[p[len(strip_path):]] = paths[p] |
298
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
60 return tuple.__new__(self, |
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
61 (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
|
62 |
674
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
63 @property |
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
64 def revnum(self): |
298
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
65 return self[0] |
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
66 |
674
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
67 @property |
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
68 def author(self): |
298
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
69 return self[1] |
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
70 |
674
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
71 @property |
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
72 def message(self): |
298
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
73 return self[2] |
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
74 |
674
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
75 @property |
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
76 def date(self): |
298
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
77 return self[3] |
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
78 |
674
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
79 @property |
a51e50d943b2
svnwrap: use decorator syntax for properties.
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
672
diff
changeset
|
80 def paths(self): |
298
32d3f1716e66
Two minor optimisations/cleanups for svn_swig_wrapper:
Dan Villiom Podlaski Christiansen <danchr@gmail.com>
parents:
293
diff
changeset
|
81 return self[4] |
0
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
82 |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
83 def __str__(self): |
f2636cfed115
Initial import of hgsubversion into a public repository.
Augie Fackler <durin42@gmail.com>
parents:
diff
changeset
|
84 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
|
85 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
86 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
87 _svn_config_dir = None |
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 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
90 class AutoPropsConfig(object): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
91 """Provides the subversion auto-props functionality |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
92 when pushing new files. |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
93 """ |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
94 def __init__(self, config_dir=None): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
95 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
|
96 self.config = ConfigParser.RawConfigParser() |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
97 self.config.read([config_file]) |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
98 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
99 def properties(self, file): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
100 """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
|
101 Takes enable-auto-props into account. |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
102 """ |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
103 properties = {} |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
104 if self.autoprops_enabled(): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
105 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
|
106 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
|
107 properties.update(parse_autoprops(prop_list)) |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
108 return properties |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
109 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
110 def autoprops_enabled(self): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
111 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
|
112 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
|
113 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
|
114 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
115 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
116 def config_file_path(config_dir): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
117 if config_dir == None: |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
118 global _svn_config_dir |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
119 config_dir = _svn_config_dir |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
120 if config_dir == None: |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
121 if sys.platform == 'win32': |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
122 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
|
123 else: |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
124 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
|
125 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
|
126 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
127 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
128 def parse_autoprops(prop_list): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
129 """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
|
130 the results. |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
131 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
|
132 """ |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
133 def unquote(s): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
134 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
|
135 return s[1:-1] |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
136 return s |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
137 |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
138 properties = {} |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
139 for prop in prop_list.split(';'): |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
140 if '=' in prop: |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
141 prop, value = prop.split('=',1) |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
142 value = unquote(value.strip()) |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
143 else: |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
144 value = '' |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
145 properties[prop.strip()] = value |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
146 return properties |
772280aed751
Honor SVN auto-props (solves issue #186)
Ronny Voelker <ronny.voelker@googlemail.com>
parents:
832
diff
changeset
|
147 |
931
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
148 class SimpleStringIO(object): |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
149 """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
|
150 |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
151 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
|
152 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
|
153 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
|
154 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
|
155 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
|
156 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
|
157 allocators. |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
158 """ |
948
e2090fabc1a9
editor: use SimpleStringIO in apply_text()
Patrick Mezard <patrick@mezard.eu>
parents:
931
diff
changeset
|
159 def __init__(self, closing=True): |
931
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
160 self._blocks = [] |
948
e2090fabc1a9
editor: use SimpleStringIO in apply_text()
Patrick Mezard <patrick@mezard.eu>
parents:
931
diff
changeset
|
161 self._closing = closing |
931
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
162 |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
163 def write(self, s): |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
164 self._blocks.append(s) |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
165 |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
166 def getvalue(self): |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
167 return ''.join(self._blocks) |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
168 |
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
169 def close(self): |
948
e2090fabc1a9
editor: use SimpleStringIO in apply_text()
Patrick Mezard <patrick@mezard.eu>
parents:
931
diff
changeset
|
170 if self._closing: |
e2090fabc1a9
editor: use SimpleStringIO in apply_text()
Patrick Mezard <patrick@mezard.eu>
parents:
931
diff
changeset
|
171 del self._blocks |
931
e1dbd9646d6a
svnwrap: use custom StringIO class in get_file()
Patrick Mezard <patrick@mezard.eu>
parents:
911
diff
changeset
|
172 |