Skip to content

Commit 968ffb2

Browse files
committed
Adjusted all Head.create calls to set a logmessage similar to the one git uses
1 parent 3175b5b commit 968ffb2

File tree

5 files changed

+32
-14
lines changed

5 files changed

+32
-14
lines changed

doc/source/changes.rst

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,17 @@ Changelog
1717
* ``set_commit(...)`` method added (reflog support)
1818
* ``set_object(...)`` method added (reflog support)
1919

20-
* Intrusive Changes to ``Head`` type
20+
* **Intrusive Changes** to ``Head`` type
2121

2222
* ``create(...)`` method now supports the reflog, but will not raise ``GitCommandError`` anymore as it is a pure python implementation now. Instead, it raises ``OSError``.
23+
24+
* **Intrusive Changes** to ``Actor`` type
25+
26+
* the *name* field is now using unicode if ascii does not match
27+
28+
* **Intrusive Changes** to ``Repo`` type
29+
30+
* ``create_head(...)`` method does not support **kwargs anymore, instead it supports a logmsg parameter
2331
2432
* Repo.rev_parse now supports the [ref]@{n} syntax, where n is the number of steps to look into the reference's past
2533

objects/commit.py

+15-3
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,12 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False):
350350
# as well ...
351351
import git.refs
352352
try:
353-
repo.head.commit = new_commit
353+
repo.head.set_commit(new_commit, logmsg="commit: %s" % message)
354354
except ValueError:
355355
# head is not yet set to the ref our HEAD points to
356356
# Happens on first commit
357357
import git.refs
358-
master = git.refs.Head.create(repo, repo.head.ref, commit=new_commit)
358+
master = git.refs.Head.create(repo, repo.head.ref, commit=new_commit, logmsg="commit (initial): %s" % message)
359359
repo.head.reference = master
360360
# END handle empty repositories
361361
# END advance head handling
@@ -382,7 +382,12 @@ def _serialize(self, stream):
382382
self.authored_date,
383383
altz_to_utctz_str(self.author_tz_offset)))
384384

385-
write(fmt % ("committer", c.name, c.email,
385+
# encode committer
386+
aname = c.name
387+
if isinstance(aname, unicode):
388+
aname = aname.encode(self.encoding)
389+
# END handle unicode in name
390+
write(fmt % ("committer", aname, c.email,
386391
self.committed_date,
387392
altz_to_utctz_str(self.committer_tz_offset)))
388393

@@ -440,6 +445,13 @@ def _deserialize(self, stream):
440445
print >> sys.stderr, "Failed to decode author name '%s' using encoding %s" % (self.author.name, self.encoding)
441446
# END handle author's encoding
442447

448+
# decode committer name
449+
try:
450+
self.committer.name = self.committer.name.decode(self.encoding)
451+
except UnicodeDecodeError:
452+
print >> sys.stderr, "Failed to decode committer name '%s' using encoding %s" % (self.committer.name, self.encoding)
453+
# END handle author's encoding
454+
443455
# a stream from our data simply gives us the plain message
444456
# The end of our message stream is marked with a newline that we strip
445457
self.message = stream.read()

objects/submodule/root.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,8 @@ def update(self, previous_commit=None, recursive=True, force_remove=False, init=
207207
smm = sm.module()
208208
smmr = smm.remotes
209209
try:
210-
tbr = git.Head.create(smm, sm.branch_name)
211-
except git.GitCommandError, e:
212-
if e.status != 128:
213-
raise
214-
#END handle something unexpected
215-
210+
tbr = git.Head.create(smm, sm.branch_name, logmsg='branch: Created from HEAD')
211+
except OSError:
216212
# ... or reuse the existing one
217213
tbr = git.Head(smm, sm.branch_path)
218214
#END assure tracking branch exists

repo/base.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -274,12 +274,12 @@ def tag(self,path):
274274
:param path: path to the tag reference, i.e. 0.1.5 or tags/0.1.5 """
275275
return TagReference(self, path)
276276

277-
def create_head(self, path, commit='HEAD', force=False, **kwargs ):
277+
def create_head(self, path, commit='HEAD', force=False, logmsg=None ):
278278
"""Create a new head within the repository.
279279
For more documentation, please see the Head.create method.
280280
281281
:return: newly created Head Reference"""
282-
return Head.create(self, path, commit, force, **kwargs)
282+
return Head.create(self, path, commit, force, logmsg)
283283

284284
def delete_head(self, *heads, **kwargs):
285285
"""Delete the given heads

repo/fun.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ def rev_parse(repo, rev):
112112
for details
113113
:note: Currently there is no access to the rev-log, rev-specs may only contain
114114
topological tokens such ~ and ^.
115-
:raise BadObject: if the given revision could not be found"""
115+
:raise BadObject: if the given revision could not be found
116+
:raise ValueError: If rev couldn't be parsed
117+
:raise IndexError: If invalid reflog index is specified"""
116118

117119
# colon search mode ?
118120
if rev.startswith(':/'):
@@ -193,7 +195,7 @@ def rev_parse(repo, rev):
193195
try:
194196
entry = ref.log_entry(revlog_index)
195197
except IndexError:
196-
raise BadObject("Invalid revlog index: %i" % revlog_index)
198+
raise IndexError("Invalid revlog index: %i" % revlog_index)
197199
#END handle index out of bound
198200

199201
obj = Object.new_from_sha(repo, hex_to_bin(entry.newhexsha))

0 commit comments

Comments
 (0)