Skip to content

Commit 3203cd7

Browse files
committed
Fixed doc strings, improved error checking on RefLog.write method
1 parent 98a3133 commit 3203cd7

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

refs/log.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ def entry_at(cls, filepath, index):
182182
specifiy an entry counted from the end of the list
183183
184184
:raise IndexError: If the entry didn't exist
185+
185186
.. note:: This method is faster as it only parses the entry at index, skipping
186187
all other lines. Nonetheless, the whole file has to be read if
187188
the index is negative
@@ -224,6 +225,7 @@ def to_file(self, filepath):
224225
@classmethod
225226
def append_entry(cls, config_reader, filepath, oldbinsha, newbinsha, message):
226227
"""Append a new log entry to the revlog at filepath.
228+
227229
:param config_reader: configuration reader of the repository - used to obtain
228230
user information. May be None
229231
:param filepath: full path to the log file
@@ -255,8 +257,13 @@ def append_entry(cls, config_reader, filepath, oldbinsha, newbinsha, message):
255257
return entry
256258

257259
def write(self):
258-
"""Write this instance's data to the file we are originating from"""
259-
return self.to_file(self._path)
260+
"""Write this instance's data to the file we are originating from
261+
:return: self"""
262+
if self._path is None:
263+
raise ValueError("Instance was not initialized with a path, use to_file(...) instead")
264+
#END assert path
265+
self.to_file(self._path)
266+
return self
260267

261268
#} END interface
262269

refs/symbolic.py

+2
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ def _get_commit(self):
174174

175175
def set_commit(self, commit, logmsg = None):
176176
"""As set_object, but restricts the type of object to be a Commit
177+
177178
:raise ValueError: If commit is not a Commit object or doesn't point to
178179
a commit
179180
:return: self"""
@@ -345,6 +346,7 @@ def log(self):
345346

346347
def log_append(self, oldbinsha, message, newbinsha=None):
347348
"""Append a logentry to the logfile of this ref
349+
348350
:param oldbinsha: binary sha this ref used to point to
349351
:param message: A message describing the change
350352
:param newbinsha: The sha the ref points to now. If None, our current commit sha

test/test_reflog.py

+3
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ def test_base(self):
5656
self.failUnlessRaises(ValueError, RefLog.from_file, fixture_path(pp+suffix))
5757
#END for each invalid file
5858

59+
# cannot write an uninitialized reflog
60+
self.failUnlessRaises(ValueError, RefLog().write)
5961

6062
# test serialize and deserialize - results must match exactly
6163
binsha = chr(255)*20
@@ -65,6 +67,7 @@ def test_base(self):
6567
reflog = RefLog.from_file(rlp)
6668
tfile = os.path.join(tdir, os.path.basename(rlp))
6769
reflog.to_file(tfile)
70+
assert reflog.write() is reflog
6871

6972
# parsed result must match ...
7073
treflog = RefLog.from_file(tfile)

util.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ def to_native_path_linux(path):
6969
to_native_path = to_native_path_linux
7070

7171
def join_path_native(a, *p):
72-
"""As join path, but makes sure an OS native path is returned. This is only
73-
needed to play it safe on my dear windows and to assure nice paths that only
74-
use '\'"""
72+
"""
73+
As join path, but makes sure an OS native path is returned. This is only
74+
needed to play it safe on my dear windows and to assure nice paths that only
75+
use '\'"""
7576
return to_native_path(join_path(a, *p))
7677

7778
def assure_directory_exists(path, is_file=False):
@@ -187,10 +188,11 @@ def _main_actor(cls, env_name, env_email, config_reader=None):
187188

188189
@classmethod
189190
def committer(cls, config_reader=None):
190-
""":return: Actor instance corresponding to the configured committer. It behaves
191-
similar to the git implementation, such that the environment will override
192-
configuration values of config_reader. If no value is set at all, it will be
193-
generated
191+
"""
192+
:return: Actor instance corresponding to the configured committer. It behaves
193+
similar to the git implementation, such that the environment will override
194+
configuration values of config_reader. If no value is set at all, it will be
195+
generated
194196
:param config_reader: ConfigReader to use to retrieve the values from in case
195197
they are not set in the environment"""
196198
return cls._main_actor(cls.env_committer_name, cls.env_committer_email, config_reader)

0 commit comments

Comments
 (0)