From 00ce31ad308ff4c7ef874d2fa64374f47980c85c Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Mon, 15 Nov 2010 16:53:12 +0100 Subject: Objects: Constructor now manually checks and sets the input arguments to the local cache - previously a procedural approach was used, which was less code, but slower too. Especially in case of CommitObjects unrolling the loop manually makes a difference. Submodule: Implemented query methods and did a bit of testing. More is to come, but the test works for now. As special addition, the submodule implementation uses the section name as submodule ID even though it seems to be just the path. This allows to make renames easier --- lib/git/objects/commit.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'lib/git/objects/commit.py') diff --git a/lib/git/objects/commit.py b/lib/git/objects/commit.py index 58c82da2..ae22fb76 100644 --- a/lib/git/objects/commit.py +++ b/lib/git/objects/commit.py @@ -108,7 +108,26 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): super(Commit,self).__init__(repo, binsha) if tree is not None: assert isinstance(tree, Tree), "Tree needs to be a Tree instance, was %s" % type(tree) - self._set_self_from_args_(locals()) + if tree is not None: + self.tree = tree + if author is not None: + self.author = author + if authored_date is not None: + self.authored_date = authored_date + if author_tz_offset is not None: + self.author_tz_offset = author_tz_offset + if committer is not None: + self.committer = committer + if committed_date is not None: + self.committed_date = committed_date + if committer_tz_offset is not None: + self.committer_tz_offset = committer_tz_offset + if message is not None: + self.message = message + if parents is not None: + self.parents = parents + if encoding is not None: + self.encoding = encoding @classmethod def _get_intermediate_items(cls, commit): @@ -434,7 +453,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): try: self.author.name = self.author.name.decode(self.encoding) except UnicodeDecodeError: - print >> sys.stderr, "Failed to decode author name: %s" % self.author.name + print >> sys.stderr, "Failed to decode author name '%s' using encoding %s" % (self.author.name, self.encoding) # END handle author's encoding # a stream from our data simply gives us the plain message @@ -443,7 +462,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): try: self.message = self.message.decode(self.encoding) except UnicodeDecodeError: - print >> sys.stderr, "Failed to decode message: %s" % self.message + print >> sys.stderr, "Failed to decode message '%s' using encoding %s" % (self.message, self.encoding) # END exception handling return self -- cgit v1.2.1 From 7a320abc52307b4d4010166bd899ac75024ec9a7 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 18 Nov 2010 09:20:15 +0100 Subject: commit: when creating a new commit and advancing the head, it will now write the ORIG_HEAD reference as well --- lib/git/objects/commit.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/git/objects/commit.py') diff --git a/lib/git/objects/commit.py b/lib/git/objects/commit.py index ae22fb76..1aedaabf 100644 --- a/lib/git/objects/commit.py +++ b/lib/git/objects/commit.py @@ -365,7 +365,13 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): new_commit.binsha = istream.binsha if head: + # need late import here, importing git at the very beginning throws + # as well ... + import git.refs try: + cur_commit = repo.head.commit + # Adjust the original head reference - force it + git.refs.SymbolicReference.create(repo, 'ORIG_HEAD', cur_commit, force=True) repo.head.commit = new_commit except ValueError: # head is not yet set to the ref our HEAD points to -- cgit v1.2.1 From 82849578e61a7dfb47fc76dcbe18b1e3b6a36951 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 18 Nov 2010 10:40:16 +0100 Subject: ORIG_HEAD handling is now implemented in the ref-class itself, instead of being a special case of the commit method; includes tests util: Fixed iterable lists, which broke due to an incorrectly implemented __contains__ method --- lib/git/objects/commit.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'lib/git/objects/commit.py') diff --git a/lib/git/objects/commit.py b/lib/git/objects/commit.py index 1aedaabf..a2b6c554 100644 --- a/lib/git/objects/commit.py +++ b/lib/git/objects/commit.py @@ -369,9 +369,6 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): # as well ... import git.refs try: - cur_commit = repo.head.commit - # Adjust the original head reference - force it - git.refs.SymbolicReference.create(repo, 'ORIG_HEAD', cur_commit, force=True) repo.head.commit = new_commit except ValueError: # head is not yet set to the ref our HEAD points to -- cgit v1.2.1