From 968ffb2c2e5c6066a2b01ad2a0833c2800880d46 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 24 Nov 2010 21:33:36 +0100 Subject: Adjusted all Head.create calls to set a logmessage similar to the one git uses --- objects/commit.py | 18 +++++++++++++++--- objects/submodule/root.py | 8 ++------ 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'objects') diff --git a/objects/commit.py b/objects/commit.py index 9c7e66a3..883d6a6c 100644 --- a/objects/commit.py +++ b/objects/commit.py @@ -350,12 +350,12 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): # as well ... import git.refs try: - repo.head.commit = new_commit + repo.head.set_commit(new_commit, logmsg="commit: %s" % message) except ValueError: # head is not yet set to the ref our HEAD points to # Happens on first commit import git.refs - master = git.refs.Head.create(repo, repo.head.ref, commit=new_commit) + master = git.refs.Head.create(repo, repo.head.ref, commit=new_commit, logmsg="commit (initial): %s" % message) repo.head.reference = master # END handle empty repositories # END advance head handling @@ -382,7 +382,12 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): self.authored_date, altz_to_utctz_str(self.author_tz_offset))) - write(fmt % ("committer", c.name, c.email, + # encode committer + aname = c.name + if isinstance(aname, unicode): + aname = aname.encode(self.encoding) + # END handle unicode in name + write(fmt % ("committer", aname, c.email, self.committed_date, altz_to_utctz_str(self.committer_tz_offset))) @@ -440,6 +445,13 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): print >> sys.stderr, "Failed to decode author name '%s' using encoding %s" % (self.author.name, self.encoding) # END handle author's encoding + # decode committer name + try: + self.committer.name = self.committer.name.decode(self.encoding) + except UnicodeDecodeError: + print >> sys.stderr, "Failed to decode committer name '%s' using encoding %s" % (self.committer.name, self.encoding) + # END handle author's encoding + # a stream from our data simply gives us the plain message # The end of our message stream is marked with a newline that we strip self.message = stream.read() diff --git a/objects/submodule/root.py b/objects/submodule/root.py index d194cd5b..ca51b34e 100644 --- a/objects/submodule/root.py +++ b/objects/submodule/root.py @@ -207,12 +207,8 @@ class RootModule(Submodule): smm = sm.module() smmr = smm.remotes try: - tbr = git.Head.create(smm, sm.branch_name) - except git.GitCommandError, e: - if e.status != 128: - raise - #END handle something unexpected - + tbr = git.Head.create(smm, sm.branch_name, logmsg='branch: Created from HEAD') + except OSError: # ... or reuse the existing one tbr = git.Head(smm, sm.branch_path) #END assure tracking branch exists -- cgit v1.2.3 From b81273e70c9c31ae02cb0a2d6e697d7a4e2b683a Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 24 Nov 2010 22:05:05 +0100 Subject: Adjusted remaining usages of set_reference and set_commit to set a logmessage --- objects/commit.py | 2 +- objects/submodule/base.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'objects') diff --git a/objects/commit.py b/objects/commit.py index 883d6a6c..69a3adc4 100644 --- a/objects/commit.py +++ b/objects/commit.py @@ -356,7 +356,7 @@ class Commit(base.Object, Iterable, Diffable, Traversable, Serializable): # Happens on first commit import git.refs master = git.refs.Head.create(repo, repo.head.ref, commit=new_commit, logmsg="commit (initial): %s" % message) - repo.head.reference = master + repo.head.set_reference(master, logmsg='commit: Switching to %s' % master) # END handle empty repositories # END advance head handling diff --git a/objects/submodule/base.py b/objects/submodule/base.py index 5d32d600..36b48d78 100644 --- a/objects/submodule/base.py +++ b/objects/submodule/base.py @@ -344,7 +344,7 @@ class Submodule(util.IndexObject, Iterable, Traversable): # END initial checkout + branch creation # make sure HEAD is not detached - mrepo.head.ref = local_branch + mrepo.head.set_reference(local_branch, logmsg="submodule: attaching head to %s" % local_branch) mrepo.head.ref.set_tracking_branch(remote_branch) except IndexError: print >> sys.stderr, "Warning: Failed to checkout tracking branch %s" % self.branch_path -- cgit v1.2.3 From 7da101ba9a09a22a85c314a8909fd23468ae66f0 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Wed, 24 Nov 2010 22:23:47 +0100 Subject: submodule.update: previous_commit is now set according to the stored reflog value, and is not using ORIG_HEAD anymore --- objects/submodule/root.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'objects') diff --git a/objects/submodule/root.py b/objects/submodule/root.py index ca51b34e..753c6df4 100644 --- a/objects/submodule/root.py +++ b/objects/submodule/root.py @@ -68,19 +68,15 @@ class RootModule(Submodule): ################## cur_commit = repo.head.commit if previous_commit is None: - symref = repo.head.orig_head() try: - previous_commit = symref.commit - except Exception: - pcommits = cur_commit.parents - if pcommits: - previous_commit = pcommits[0] - else: - # in this special case, we just diff against ourselve, which - # means exactly no change - previous_commit = cur_commit - # END handle initial commit - # END no ORIG_HEAD + previous_commit = repo.commit(repo.head.log_entry(-1).oldhexsha) + if previous_commit.binsha == previous_commit.NULL_BIN_SHA: + raise IndexError + #END handle initial commit + except IndexError: + # in new repositories, there is no previous commit + previous_commit = cur_commit + #END exception handling else: previous_commit = repo.commit(previous_commit) # obtain commit object # END handle previous commit -- cgit v1.2.3