Skip to content

Commit 8652326

Browse files
committed
Renamed msg named parameter to logmsg, as it describes the purpose of the message much better
Added test for deletion of reflog file when the corresponding ref is deleted
1 parent c946bf2 commit 8652326

File tree

3 files changed

+27
-30
lines changed

3 files changed

+27
-30
lines changed

‎refs/reference.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ def __init__(self, repo, path):
3737
def __str__(self):
3838
return self.name
3939

40-
def set_object(self, object, msg = None):
40+
def set_object(self, object, logmsg = None):
4141
"""Special version which checks if the head-log needs an update as well"""
4242
oldbinsha = None
43-
if msg is not None:
43+
if logmsg is not None:
4444
head = self.repo.head
4545
if not head.is_detached and head.ref == self:
4646
oldbinsha = self.commit.binsha
4747
#END handle commit retrieval
4848
#END handle message is set
4949

50-
super(Reference, self).set_object(object, msg)
50+
super(Reference, self).set_object(object, logmsg)
5151

5252
if oldbinsha is not None:
5353
# /* from refs.c in git-source
@@ -62,7 +62,7 @@ def set_object(self, object, msg = None):
6262
# * check with HEAD only which should cover 99% of all usage
6363
# * scenarios (even 100% of the default ones).
6464
# */
65-
self.repo.head.log_append(oldbinsha, msg)
65+
self.repo.head.log_append(oldbinsha, logmsg)
6666
#END check if the head
6767

6868
# NOTE: Don't have to overwrite properties as the will only work without a the log

‎refs/symbolic.py

+16-16
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ def _get_commit(self):
172172
#END handle type
173173
return obj
174174

175-
def set_commit(self, commit, msg = None):
175+
def set_commit(self, commit, logmsg = None):
176176
"""As set_object, but restricts the type of object to be a Commit
177177
:raise ValueError: If commit is not a Commit object or doesn't point to
178178
a commit
@@ -196,18 +196,18 @@ def set_commit(self, commit, msg = None):
196196
#END handle raise
197197

198198
# we leave strings to the rev-parse method below
199-
self.set_object(commit, msg)
199+
self.set_object(commit, logmsg)
200200

201201
return self
202202

203203

204-
def set_object(self, object, msg = None):
204+
def set_object(self, object, logmsg = None):
205205
"""Set the object we point to, possibly dereference our symbolic reference first.
206206
If the reference does not exist, it will be created
207207
208208
:param object: a refspec, a SymbolicReference or an Object instance. SymbolicReferences
209209
will be dereferenced beforehand to obtain the object they point to
210-
:param msg: If not None, the message will be used in the reflog entry to be
210+
:param logmsg: If not None, the message will be used in the reflog entry to be
211211
written. Otherwise the reflog is not altered
212212
:note: plain SymbolicReferences may not actually point to objects by convention
213213
:return: self"""
@@ -223,10 +223,10 @@ def set_object(self, object, msg = None):
223223
# END handle non-existing ones
224224

225225
if is_detached:
226-
return self.set_reference(object, msg)
226+
return self.set_reference(object, logmsg)
227227

228228
# set the commit on our reference
229-
return self._get_reference().set_object(object, msg)
229+
return self._get_reference().set_object(object, logmsg)
230230

231231
commit = property(_get_commit, set_commit, doc="Query or set commits directly")
232232
object = property(_get_object, set_object, doc="Return the object our ref currently refers to")
@@ -240,7 +240,7 @@ def _get_reference(self):
240240
raise TypeError("%s is a detached symbolic reference as it points to %r" % (self, sha))
241241
return self.from_path(self.repo, target_ref_path)
242242

243-
def set_reference(self, ref, msg = None):
243+
def set_reference(self, ref, logmsg = None):
244244
"""Set ourselves to the given ref. It will stay a symbol if the ref is a Reference.
245245
Otherwise an Object, given as Object instance or refspec, is assumed and if valid,
246246
will be set which effectively detaches the refererence if it was a purely
@@ -249,7 +249,7 @@ def set_reference(self, ref, msg = None):
249249
:param ref: SymbolicReference instance, Object instance or refspec string
250250
Only if the ref is a SymbolicRef instance, we will point to it. Everthiny
251251
else is dereferenced to obtain the actual object.
252-
:param msg: If set to a string, the message will be used in the reflog.
252+
:param logmsg: If set to a string, the message will be used in the reflog.
253253
Otherwise, a reflog entry is not written for the changed reference.
254254
The previous commit of the entry will be the commit we point to now.
255255
@@ -282,7 +282,7 @@ def set_reference(self, ref, msg = None):
282282
#END verify type
283283

284284
oldbinsha = None
285-
if msg is not None:
285+
if logmsg is not None:
286286
try:
287287
oldbinsha = self.commit.binsha
288288
except ValueError:
@@ -299,8 +299,8 @@ def set_reference(self, ref, msg = None):
299299
lfd.commit()
300300

301301
# Adjust the reflog
302-
if msg is not None:
303-
self.log_append(oldbinsha, msg)
302+
if logmsg is not None:
303+
self.log_append(oldbinsha, logmsg)
304304
#END handle reflog
305305

306306
return self
@@ -426,7 +426,7 @@ def delete(cls, repo, path):
426426

427427

428428
@classmethod
429-
def _create(cls, repo, path, resolve, reference, force, msg=None):
429+
def _create(cls, repo, path, resolve, reference, force, logmsg=None):
430430
"""internal method used to create a new symbolic reference.
431431
If resolve is False, the reference will be taken as is, creating
432432
a proper symbolic reference. Otherwise it will be resolved to the
@@ -452,11 +452,11 @@ def _create(cls, repo, path, resolve, reference, force, msg=None):
452452
# END no force handling
453453

454454
ref = cls(repo, full_ref_path)
455-
ref.set_reference(target, msg)
455+
ref.set_reference(target, logmsg)
456456
return ref
457457

458458
@classmethod
459-
def create(cls, repo, path, reference='HEAD', force=False, msg=None):
459+
def create(cls, repo, path, reference='HEAD', force=False, logmsg=None):
460460
"""Create a new symbolic reference, hence a reference pointing to another reference.
461461
462462
:param repo:
@@ -473,7 +473,7 @@ def create(cls, repo, path, reference='HEAD', force=False, msg=None):
473473
if True, force creation even if a symbolic reference with that name already exists.
474474
Raise OSError otherwise
475475
476-
:param msg:
476+
:param logmsg:
477477
If not None, the message to append to the reflog. Otherwise no reflog
478478
entry is written.
479479
@@ -484,7 +484,7 @@ def create(cls, repo, path, reference='HEAD', force=False, msg=None):
484484
already exists.
485485
486486
:note: This does not alter the current HEAD, index or Working Tree"""
487-
return cls._create(repo, path, cls._resolve_ref_on_create, reference, force, msg)
487+
return cls._create(repo, path, cls._resolve_ref_on_create, reference, force, logmsg)
488488

489489
def rename(self, new_path, force=False):
490490
"""Rename self to a new path

‎test/test_refs.py

+7-10
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def test_heads(self, rwrepo):
102102
pcommit = cur_head.commit.parents[0].parents[0]
103103
hlog_len = len(head.log())
104104
blog_len = len(cur_head.log())
105-
head.set_reference(pcommit, 'detached head')
105+
assert head.set_reference(pcommit, 'detached head') is head
106106
# one new log-entry
107107
thlog = head.log()
108108
assert len(thlog) == hlog_len + 1
@@ -125,12 +125,12 @@ def test_heads(self, rwrepo):
125125

126126

127127
# with automatic dereferencing
128-
head.set_commit(cur_commit, 'change commit once again')
128+
assert head.set_commit(cur_commit, 'change commit once again') is head
129129
assert len(head.log()) == hlog_len+4
130130
assert len(cur_head.log()) == blog_len+2
131131

132132
# a new branch has just a single entry
133-
other_head = Head.create(rwrepo, 'mynewhead', pcommit, msg='new head created')
133+
other_head = Head.create(rwrepo, 'mynewhead', pcommit, logmsg='new head created')
134134
log = other_head.log()
135135
assert len(log) == 1
136136
assert log[0].oldhexsha == pcommit.NULL_HEX_SHA
@@ -237,7 +237,11 @@ def test_head_reset(self, rw_repo):
237237
tmp_head.rename(new_head, force=True)
238238
assert tmp_head == new_head and tmp_head.object == new_head.object
239239

240+
logfile = RefLog.path(tmp_head)
241+
assert os.path.isfile(logfile)
240242
Head.delete(rw_repo, tmp_head)
243+
# deletion removes the log as well
244+
assert not os.path.isfile(logfile)
241245
heads = rw_repo.heads
242246
assert tmp_head not in heads and new_head not in heads
243247
# force on deletion testing would be missing here, code looks okay though ;)
@@ -512,10 +516,3 @@ def test_dereference_recursive(self):
512516
def test_reflog(self):
513517
assert isinstance(self.rorepo.heads.master.log(), RefLog)
514518

515-
516-
def test_todo(self):
517-
# delete deletes the reflog
518-
# create creates a new entry
519-
# set_reference and set_commit and set_object use the reflog if message is given
520-
# if there is no actual head-change, don't do anything
521-
self.fail()

0 commit comments

Comments
 (0)