File tree 3 files changed +23
-10
lines changed
Filter options
3 files changed +23
-10
lines changed
Original file line number Diff line number Diff line change @@ -120,6 +120,7 @@ class GitConfigParser(cp.RawConfigParser, object):
120
120
# They must be compatible to the LockFile interface.
121
121
# A suitable alternative would be the BlockingLockFile
122
122
t_lock = LockFile
123
+ re_comment = re .compile ('^\s*[#;]' )
123
124
124
125
#} END configuration
125
126
@@ -211,16 +212,16 @@ def _read(self, fp, fpname):
211
212
break
212
213
lineno = lineno + 1
213
214
# comment or blank line?
214
- if line .strip () == '' or line [ 0 ] in '#;' :
215
+ if line .strip () == '' or self . re_comment . match ( line ) :
215
216
continue
216
217
if line .split (None , 1 )[0 ].lower () == 'rem' and line [0 ] in "rR" :
217
218
# no leading whitespace
218
219
continue
219
220
else :
220
221
# is it a section header?
221
- mo = self .SECTCRE .match (line )
222
+ mo = self .SECTCRE .match (line . strip () )
222
223
if mo :
223
- sectname = mo .group ('header' )
224
+ sectname = mo .group ('header' ). strip ()
224
225
if sectname in self ._sections :
225
226
cursect = self ._sections [sectname ]
226
227
elif sectname == cp .DEFAULTSECT :
@@ -332,6 +333,10 @@ def write(self):
332
333
close_fp = True
333
334
else :
334
335
fp .seek (0 )
336
+ # make sure we do not overwrite into an existing file
337
+ if hasattr (fp , 'truncate' ):
338
+ fp .truncate ()
339
+ #END
335
340
# END handle stream or file
336
341
337
342
# WRITE DATA
Original file line number Diff line number Diff line change 1
1
[core]
2
2
repositoryformatversion = 0
3
3
filemode = true
4
- bare = false
5
- logallrefupdates = true
4
+ bare = false
5
+ logallrefupdates = true
6
6
[remote "origin"]
7
7
fetch = +refs/heads/*:refs/remotes/origin/*
8
8
url = git://gitorious.org/~byron/git-python/byrons-clone.git
9
9
pushurl = git@gitorious.org:~byron/git-python/byrons-clone.git
10
- [branch "master"]
10
+ # a tab indented section header
11
+ [branch "master"]
11
12
remote = origin
12
13
merge = refs/heads/master
13
- [remote "mainline"]
14
+ # an space indented section header
15
+ [remote "mainline"]
16
+ # space indented comment
14
17
url = git://gitorious.org/git-python/mainline.git
15
18
fetch = +refs/heads/*:refs/remotes/mainline/*
19
+
16
20
[remote "MartinMarcher"]
21
+ # tab indented comment
17
22
url = git://gitorious.org/~martin.marcher/git-python/serverhorror.git
18
23
fetch = +refs/heads/*:refs/remotes/MartinMarcher/*
19
- [gui]
24
+ # can handle comments - the section name is supposed to be stripped
25
+ [ gui ]
20
26
geometry = 1316x820+219+243 207 192
21
27
[branch "mainline_performance"]
22
28
remote = mainline
Original file line number Diff line number Diff line change @@ -30,7 +30,9 @@ def test_read_write(self):
30
30
w_config .read () # enforce reading
31
31
assert w_config ._sections
32
32
w_config .write () # enforce writing
33
- assert file_obj .getvalue () == file_obj_orig .getvalue ()
33
+
34
+ # we stripped lines when reading, so the results differ
35
+ assert file_obj .getvalue () != file_obj_orig .getvalue ()
34
36
35
37
# creating an additional config writer must fail due to exclusive access
36
38
self .failUnlessRaises (IOError , GitConfigParser , file_obj , read_only = False )
@@ -56,10 +58,10 @@ def test_read_write(self):
56
58
57
59
file_obj .seek (0 )
58
60
r_config = GitConfigParser (file_obj , read_only = True )
61
+ #print file_obj.getvalue()
59
62
assert r_config .has_section (sname )
60
63
assert r_config .has_option (sname , oname )
61
64
assert r_config .get (sname , oname ) == val
62
-
63
65
# END for each filename
64
66
65
67
def test_base (self ):
You can’t perform that action at this time.
0 commit comments