| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -297,7 +297,10 @@ Access objects and add/remove entries. Commit the changes:: | |||
| 297 | 297 | # Access the entries directly | |
| 298 | 298 | index.add(['my_new_file']) # add a new file to the index | |
| 299 | 299 | index.remove(['dir/existing_file']) | |
| 300 | - new_commit = index.commit("my commit message") | ||
| 300 | + new_commit = index.commit("my commit message") # commit by commit message first | ||
| 301 | + my_author = Actor("An author", "author@example.com") | ||
| 302 | + my_committer = Actor("A committer", "committer@example.com") | ||
| 303 | + next_commit = index.commit("my commit message", author=my_author, commiter=my_committer) # commit by commit message and author and committer | ||
| 301 | 304 | ||
| 302 | 305 | Create new indices from other trees or as result of a merge. Write that result to a new index file:: | |
| 303 | 306 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -358,7 +358,7 @@ def create_from_tree(cls, repo, tree, message, parent_commits=None, head=False, | |||
| 358 | 358 | # as well ... | |
| 359 | 359 | import git.refs | |
| 360 | 360 | try: | |
| 361 | - repo.head.set_commit(new_commit, logmsg="commit: %s" % message) | ||
| 361 | + repo.head.set_commit(new_commit, logmsg=message) | ||
| 362 | 362 | except ValueError: | |
| 363 | 363 | # head is not yet set to the ref our HEAD points to | |
| 364 | 364 | # Happens on first commit | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,6 +18,7 @@ | |||
| 18 | 18 | altz_to_utctz_str, | |
| 19 | 19 | ) | |
| 20 | 20 | from git.compat import ( | |
| 21 | + PY3, | ||
| 21 | 22 | xrange, | |
| 22 | 23 | string_types, | |
| 23 | 24 | defenc | |
@@ -32,16 +33,30 @@ | |||
| 32 | 33 | class RefLogEntry(tuple): | |
| 33 | 34 | ||
| 34 | 35 | """Named tuple allowing easy access to the revlog data fields""" | |
| 35 | - _fmt = "%s %s %s <%s> %i %s\t%s\n" | ||
| 36 | 36 | _re_hexsha_only = re.compile('^[0-9A-Fa-f]{40}$') | |
| 37 | 37 | __slots__ = tuple() | |
| 38 | 38 | ||
| 39 | 39 | def __repr__(self): | |
| 40 | 40 | """Representation of ourselves in git reflog format""" | |
| 41 | + res = self.format() | ||
| 42 | + if PY3: | ||
| 43 | + return res | ||
| 44 | + else: | ||
| 45 | + # repr must return a string, which it will auto-encode from unicode using the default encoding. | ||
| 46 | + # This usually fails, so we encode ourselves | ||
| 47 | + return res.encode(defenc) | ||
| 48 | + | ||
| 49 | + def format(self): | ||
| 50 | + """:return: a string suitable to be placed in a reflog file""" | ||
| 41 | 51 | act = self.actor | |
| 42 | 52 | time = self.time | |
| 43 | - return self._fmt % (self.oldhexsha, self.newhexsha, act.name, act.email, | ||
| 44 | - time[0], altz_to_utctz_str(time[1]), self.message) | ||
| 53 | + return u"{0} {1} {2} <{3}> {4!s} {5}\t{6}\n".format(self.oldhexsha, | ||
| 54 | + self.newhexsha, | ||
| 55 | + act.name, | ||
| 56 | + act.email, | ||
| 57 | + time[0], | ||
| 58 | + altz_to_utctz_str(time[1]), | ||
| 59 | + self.message) | ||
| 45 | 60 | ||
| 46 | 61 | @property | |
| 47 | 62 | def oldhexsha(self): | |
@@ -267,10 +282,9 @@ def append_entry(cls, config_reader, filepath, oldbinsha, newbinsha, message): | |||
| 267 | 282 | ||
| 268 | 283 | lf = LockFile(filepath) | |
| 269 | 284 | lf._obtain_lock_or_raise() | |
| 270 | - | ||
| 271 | 285 | fd = open(filepath, 'ab') | |
| 272 | 286 | try: | |
| 273 | - fd.write(repr(entry).encode(defenc)) | ||
| 287 | + fd.write(entry.format().encode(defenc)) | ||
| 274 | 288 | finally: | |
| 275 | 289 | fd.close() | |
| 276 | 290 | lf._release_lock() | |
@@ -295,7 +309,7 @@ def _serialize(self, stream): | |||
| 295 | 309 | ||
| 296 | 310 | # write all entries | |
| 297 | 311 | for e in self: | |
| 298 | - write(repr(e).encode(defenc)) | ||
| 312 | + write(e.format().encode(defenc)) | ||
| 299 | 313 | # END for each entry | |
| 300 | 314 | ||
| 301 | 315 | def _deserialize(self, stream): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,4 @@ | |||
| 1 | + #-*-coding:utf-8-*- | ||
| 1 | 2 | # test_index.py | |
| 2 | 3 | # Copyright (C) 2008, 2009 Michael Trier (mtrier@gmail.com) and contributors | |
| 3 | 4 | # | |
@@ -10,6 +11,7 @@ | |||
| 10 | 11 | fixture, | |
| 11 | 12 | with_rw_repo | |
| 12 | 13 | ) | |
| 14 | + from git.util import Actor | ||
| 13 | 15 | from git import ( | |
| 14 | 16 | IndexFile, | |
| 15 | 17 | BlobFilter, | |
@@ -432,7 +434,7 @@ def mixed_iterator(): | |||
| 432 | 434 | # TEST COMMITTING | |
| 433 | 435 | # commit changed index | |
| 434 | 436 | cur_commit = cur_head.commit | |
| 435 | - commit_message = "commit default head" | ||
| 437 | + commit_message = u"commit default head by Frèderic Çaufl€" | ||
| 436 | 438 | ||
| 437 | 439 | new_commit = index.commit(commit_message, head=False) | |
| 438 | 440 | assert cur_commit != new_commit | |
@@ -445,6 +447,23 @@ def mixed_iterator(): | |||
| 445 | 447 | assert len(new_commit.parents) == 1 | |
| 446 | 448 | assert cur_head.commit == cur_commit | |
| 447 | 449 | ||
| 450 | + # commit with other actor | ||
| 451 | + cur_commit = cur_head.commit | ||
| 452 | + | ||
| 453 | + my_author = Actor(u"Frèderic Çaufl€", "author@example.com") | ||
| 454 | + my_committer = Actor(u"Committing Frèderic Çaufl€", "committer@example.com") | ||
| 455 | + commit_actor = index.commit(commit_message, author=my_author, committer=my_committer) | ||
| 456 | + assert cur_commit != commit_actor | ||
| 457 | + assert commit_actor.author.name == u"Frèderic Çaufl€" | ||
| 458 | + assert commit_actor.author.email == "author@example.com" | ||
| 459 | + assert commit_actor.committer.name == u"Committing Frèderic Çaufl€" | ||
| 460 | + assert commit_actor.committer.email == "committer@example.com" | ||
| 461 | + assert commit_actor.message == commit_message | ||
| 462 | + assert commit_actor.parents[0] == cur_commit | ||
| 463 | + assert len(new_commit.parents) == 1 | ||
| 464 | + assert cur_head.commit == commit_actor | ||
| 465 | + assert cur_head.log()[-1].actor == my_committer | ||
| 466 | + | ||
| 448 | 467 | # same index, no parents | |
| 449 | 468 | commit_message = "index without parents" | |
| 450 | 469 | commit_no_parents = index.commit(commit_message, parent_commits=list(), head=True) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -328,7 +328,7 @@ def __str__(self): | |||
| 328 | 328 | return self.name | |
| 329 | 329 | ||
| 330 | 330 | def __repr__(self): | |
| 331 | - return '<git.Actor "%s <%s>">' % (self.name, self.email) | ||
| 331 | + return u'<git.Actor "%s <%s>">' % (self.name, self.email) | ||
| 332 | 332 | ||
| 333 | 333 | @classmethod | |
| 334 | 334 | def _from_string(cls, string): | |
| Back | FazBrowse Home | New Git URL |
0 commit comments