Skip to contentSkip to conversation

Add support for merge-friendly branches

RFC PATCH In review Catalin Marinas 4 participants 12 messages Jun 15, 2016 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 Add support for merge-friendly branches

The main issue with publishing StGit branches is that the Git history represented by patches is volatile, making it difficult for people wanting to merge such branch. One solution is for all the downstream developers to always rebase but that's not always desirable. Another solution is provided by tools like TopGit but the visible Git history becomes complicated, especially with repeated reordering.

The patch proposes a new StGit command called "publish". This command allows one to develop patches normally on a StGit branch but publish the stack changes to a separate, merge-friendly branch whose history is not re-writable.

More about its behaviour can be found in the command description in this patch.

---
 stgit/commands/common.py  |   26 ++++++++
 stgit/commands/new.py     |   22 -------
 stgit/commands/publish.py |  139 +++++++++++++++++++++++++++++++++++++++++++++
 stgit/lib/git.py          |    5 ++
 t/t4100-publish.sh        |  129 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 300 insertions(+), 21 deletions(-)
 create mode 100644 stgit/commands/publish.py
 create mode 100755 t/t4100-publish.sh
stgit/commands/common.py +26 -0
index e46412e..04314f3 100644
@@ -447,6 +447,32 @@ def readonly_constant_property(f):
         return getattr(self, n)
     return property(new_f)
 
+def update_commit_data(cd, options, allow_edit = False):
+    """Return a new CommitData object updated according to the command line
+    options."""
+    # Set the commit message from commandline.
+    if options.message != None:
+        cd = cd.set_message(options.message)
+
+    # Modify author data.
+    cd = cd.set_author(options.author(cd.author))
+
+    # Add Signed-off-by: or similar.
+    if options.sign_str != None:
+        sign_str = options.sign_str
+    else:
+        sign_str = config.get("stgit.autosign")
+    if sign_str != None:
+        cd = cd.set_message(
+            add_sign_line(cd.message, sign_str,
+                          cd.committer.name, cd.committer.email))
+
+    # Let user edit the commit message manually.
+    if allow_edit and not options.message:
+        cd = cd.set_message(edit_string(cd.message, '.stgit-new.txt'))
+
+    return cd
+
 class DirectoryException(StgException):
     pass
 
stgit/commands/new.py +1 -21
index 2c98431..9fd51c3 100644
@@ -67,32 +67,12 @@ def func(parser, options, args):
     cd = gitlib.CommitData(
         tree = stack.head.data.tree, parents = [stack.head], message = '',
         author = gitlib.Person.author(), committer = gitlib.Person.committer())
-
-    # Set patch commit message from commandline.
-    if options.message != None:
-        cd = cd.set_message(options.message)
-
-    # Modify author data.
-    cd = cd.set_author(options.author(cd.author))
-
-    # Add Signed-off-by: or similar.
-    if options.sign_str != None:
-        sign_str = options.sign_str
-    else:
-        sign_str = config.get("stgit.autosign")
-
-    if sign_str != None:
-        cd = cd.set_message(
-            utils.add_sign_line(cd.message, sign_str,
-                                cd.committer.name, cd.committer.email))
+    cd = common.update_commit_data(cd, options, allow_edit = True)
 
     if options.save_template:
         options.save_template(cd.message)
         return utils.STGIT_SUCCESS
 
-    # Let user edit the commit message manually.
-    if not options.message:
-        cd = cd.set_message(utils.edit_string(cd.message, '.stgit-new.txt'))
     if name == None:
         name = utils.make_patch_name(cd.message,
                                      lambda name: stack.patches.exists(name))
stgit/commands/publish.py new file +139 -0

139 lines not on this page · raw message

stgit/lib/git.py +5 -0
index 6f2c977..4a17c8a 100644
@@ -609,6 +609,11 @@ class Repository(RunWithEnv):
             raise DetachedHeadException()
     def set_head_ref(self, ref, msg):
         self.run(['git', 'symbolic-ref', '-m', msg, 'HEAD', ref]).no_output()
+    def get_merge_base(self, commit1, commit2):
+        """Return the merge base of two commits."""
+        sha1 = self.run(['git', 'merge-base',
+                         commit1.sha1, commit2.sha1]).output_one_line()
+        return self.get_commit(sha1)
     def simple_merge(self, base, ours, theirs):
         index = self.temp_index()
         try:
t/t4100-publish.sh new file +129 -0

129 lines not on this page · raw message

#2 lore raw

RFC PATCH 1/1 Add support for merge-friendly branches

In reply to a message not in the archive

[Forwarded to vcs-pkg-discuss]

Hey vcs-pkg people,

This may be of interest, I don't have any time right now to check this out and don't remember StGit too well either.

I suggest that comments be fed back to the git mailing list, which has a Cc policy, so just reply to all.

I have put the list and Catalin and Karl on Cc so that they know that http://vcs-pkg.org has sighted this stuff. ;)

----- Forwarded message from Catalin Marinas <[email protected]> -----

Date: Thu, 28 May 2009 12:12:42 +0100
From: Catalin Marinas <[email protected]>
To: [email protected], Karl Hasselström <[email protected]>
Subject: [RFC][StGit PATCH] Add support for merge-friendly branches
Message-ID: <20090528111212.21925.45527.stgit-hhZApKj8DF/[email protected]>

The main issue with publishing StGit branches is that the Git history represented by patches is volatile, making it difficult for people wanting to merge such branch. One solution is for all the downstream developers to always rebase but that's not always desirable. Another solution is provided by tools like TopGit but the visible Git history becomes complicated, especially with repeated reordering.

The patch proposes a new StGit command called "publish". This command allows one to develop patches normally on a StGit branch but publish the stack changes to a separate, merge-friendly branch whose history is not re-writable.

More about its behaviour can be found in the command description in this patch.

---
 stgit/commands/common.py  |   26 ++++++++
 stgit/commands/new.py     |   22 -------
 stgit/commands/publish.py |  139 +++++++++++++++++++++++++++++++++++++++++++++
 stgit/lib/git.py          |    5 ++
 t/t4100-publish.sh        |  129 ++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 300 insertions(+), 21 deletions(-)
 create mode 100644 stgit/commands/publish.py
 create mode 100755 t/t4100-publish.sh
stgit/commands/common.py +26 -0
index e46412e..04314f3 100644
@@ -447,6 +447,32 @@ def readonly_constant_property(f):
         return getattr(self, n)
     return property(new_f)
 
+def update_commit_data(cd, options, allow_edit = False):
+    """Return a new CommitData object updated according to the command line
+    options."""
+    # Set the commit message from commandline.
+    if options.message != None:
+        cd = cd.set_message(options.message)
+
+    # Modify author data.
+    cd = cd.set_author(options.author(cd.author))
+
+    # Add Signed-off-by: or similar.
+    if options.sign_str != None:
+        sign_str = options.sign_str
+    else:
+        sign_str = config.get("stgit.autosign")
+    if sign_str != None:
+        cd = cd.set_message(
+            add_sign_line(cd.message, sign_str,
+                          cd.committer.name, cd.committer.email))
+
+    # Let user edit the commit message manually.
+    if allow_edit and not options.message:
+        cd = cd.set_message(edit_string(cd.message, '.stgit-new.txt'))
+
+    return cd
+
 class DirectoryException(StgException):
     pass
 
stgit/commands/new.py +1 -21
index 2c98431..9fd51c3 100644
@@ -67,32 +67,12 @@ def func(parser, options, args):
     cd = gitlib.CommitData(
         tree = stack.head.data.tree, parents = [stack.head], message = '',
         author = gitlib.Person.author(), committer = gitlib.Person.committer())
-
-    # Set patch commit message from commandline.
-    if options.message != None:
-        cd = cd.set_message(options.message)
-
-    # Modify author data.
-    cd = cd.set_author(options.author(cd.author))
-
-    # Add Signed-off-by: or similar.
-    if options.sign_str != None:
-        sign_str = options.sign_str
-    else:
-        sign_str = config.get("stgit.autosign")
-
-    if sign_str != None:
-        cd = cd.set_message(
-            utils.add_sign_line(cd.message, sign_str,
-                                cd.committer.name, cd.committer.email))
+    cd = common.update_commit_data(cd, options, allow_edit = True)
 
     if options.save_template:
         options.save_template(cd.message)
         return utils.STGIT_SUCCESS
 
-    # Let user edit the commit message manually.
-    if not options.message:
-        cd = cd.set_message(utils.edit_string(cd.message, '.stgit-new.txt'))
     if name == None:
         name = utils.make_patch_name(cd.message,
                                      lambda name: stack.patches.exists(name))
stgit/commands/publish.py new file +139 -0

139 lines not on this page · raw message

stgit/lib/git.py +5 -0
index 6f2c977..4a17c8a 100644
@@ -609,6 +609,11 @@ class Repository(RunWithEnv):
             raise DetachedHeadException()
     def set_head_ref(self, ref, msg):
         self.run(['git', 'symbolic-ref', '-m', msg, 'HEAD', ref]).no_output()
+    def get_merge_base(self, commit1, commit2):
+        """Return the merge base of two commits."""
+        sha1 = self.run(['git', 'merge-base',
+                         commit1.sha1, commit2.sha1]).output_one_line()
+        return self.get_commit(sha1)
     def simple_merge(self, base, ours, theirs):
         index = self.temp_index()
         try:
t/t4100-publish.sh new file +129 -0

129 lines not on this page · raw message

Signature · 6 lines
 .''`.   martin f. krafft <[email protected]>      Related projects:
: :'  :  proud Debian developer               http://debiansystem.info
`. `'`   http://people.debian.org/~madduck    http://vcs-pkg.org
  `-  Debian - when you have better things to do than fixing systems
 
a farmer is a man outstanding in his field.

_______________________________________________
vcs-pkg-discuss mailing list vcs-pkg-discuss-XbBxUvOt3X2LieD7tvxI8l/[email protected]
http://lists.alioth.debian.org/mailman/listinfo/vcs-pkg-discuss

#3 lore raw
In reply to Catalin Marinas
Quoted 4 lines · Catalin Marinas

The patch proposes a new StGit command called "publish". This command allows one to develop patches normally on a StGit branch but publish the stack changes to a separate, merge-friendly branch whose history is not re-writable.

Hmm, interesting. I don't think I'd want to use a command like this myself, but I can see how it might be useful.

Quoted 4 lines
stgit/commands/publish.py new file +4 -0
+    # check for same tree (already up to date)
+    if public_tree.sha1 == stack.head.data.tree.sha1:
+        out.info('"%s" already up to date' % public_ref)
+        return

stgit/commands/publish.py line 115

Quoted 10 lines
stgit/commands/publish.py new file +10 -0
+
+    # check for rebased stack. In this case we emulate a merge with the stack
+    # base by setting two parents.
+    merge_base = repository.get_merge_base(public_head, stack.base)
+    if merge_base.sha1 != stack.base.sha1:
+        public_head = __create_commit(repository, stack.head.data.tree,
+                                      [public_head, stack.base], options)
+        repository.refs.set(public_ref, public_head, 'publish')
+        out.info('Merged the stack base into "%s"' % public_ref)
+        return

Hmm. Couldn't the merge base conceivably be higher up in the stack? Like, right at the beginning, don't we have public_head == stack.head? That would be caught by the "same tree" check" a bit earlier, but after adding another patch, don't we have public_head == stack.head^ ? Which would give merge_base == public_head.

stgit/lib/git.py class Repository(RunWithEnv): · line 616

Quoted 5 lines
stgit/lib/git.py +5 -0
+    def get_merge_base(self, commit1, commit2):
+        """Return the merge base of two commits."""
+        sha1 = self.run(['git', 'merge-base',
+                         commit1.sha1, commit2.sha1]).output_one_line()
+        return self.get_commit(sha1)

This funcion should probably return a list of zero or more merge bases. See the --all flag to git merge-base.

Signature · 2 lines
Karl Hasselström, [email protected]
      www.treskal.com/kalle
#4 lore raw

2009/5/28 Karl Hasselström <[email protected]>:

Quoted 9 lines · Catalin Marinas
Quoted 5 lines

The patch proposes a new StGit command called "publish". This command allows one to develop patches normally on a StGit branch but publish the stack changes to a separate, merge-friendly branch whose history is not re-writable.

Hmm, interesting. I don't think I'd want to use a command like this myself, but I can see how it might be useful.

For me it is useful. I publish a kernel tree with over 100 patches. Later I find that one patch is buggy. The current merge-friendly solution is to add another patch but I may want to just update the buggy patch as it's easier when time comes to submit upstream. This, however, rewrites the history. So with the "publish" command I just generate another commit on top of the public branch and I always end up with the same tree as on my stack.

Quoted 15 lines
Quoted 6 lines

+    # check for same tree (already up to date)
+    if public_tree.sha1 == stack.head.data.tree.sha1:
+        out.info('"%s" already up to date' % public_ref)
+        return
+
+    # check for rebased stack. In this case we emulate a merge with the stack

Quoted 8 lines

+    # base by setting two parents.
+    merge_base = repository.get_merge_base(public_head, stack.base)
+    if merge_base.sha1 != stack.base.sha1:
+        public_head = __create_commit(repository, stack.head.data.tree,
+                                      [public_head, stack.base], options)
+        repository.refs.set(public_ref, public_head, 'publish')
+        out.info('Merged the stack base into "%s"' % public_ref)
+        return

Quoted 5 lines

Hmm. Couldn't the merge base conceivably be higher up in the stack? Like, right at the beginning, don't we have public_head == stack.head? That would be caught by the "same tree" check" a bit earlier, but after adding another patch, don't we have public_head == stack.head^ ? Which would give merge_base == public_head.

We could have public_head == stack.head^... but that's not an issue. The merge_base above is checked against the base of the stack rather than the top as we assume that the base isn't volatile. So even if public_head is the same as some patch commit, the merge_base above would always be the base of the stack. Only if the stack base was updated, we get a different merge_base (equal to the previous stack base).

Quoted 8 lines
Quoted 5 lines

+    def get_merge_base(self, commit1, commit2):
+        """Return the merge base of two commits."""
+        sha1 = self.run(['git', 'merge-base',
+                         commit1.sha1, commit2.sha1]).output_one_line()
+        return self.get_commit(sha1)

This funcion should probably return a list of zero or more merge bases. See the --all flag to git merge-base.

OK, I'll add this and check the stack base against this set(list).

Signature · 1 line
Catalin
#5 lore raw
Quoted 12 lines · Catalin Marinas

2009/5/28 Karl Hasselström <[email protected]>:

Quoted 9 lines · Catalin Marinas
Quoted 5 lines

The patch proposes a new StGit command called "publish". This command allows one to develop patches normally on a StGit branch but publish the stack changes to a separate, merge-friendly branch whose history is not re-writable.

Hmm, interesting. I don't think I'd want to use a command like this myself, but I can see how it might be useful.

Quoted 7 lines

For me it is useful. I publish a kernel tree with over 100 patches. Later I find that one patch is buggy. The current merge-friendly solution is to add another patch but I may want to just update the buggy patch as it's easier when time comes to submit upstream. This, however, rewrites the history. So with the "publish" command I just generate another commit on top of the public branch and I always end up with the same tree as on my stack.

I think I would've kludged this by making --theirs merges from the StGit branch to the public branch. But "stg publish" should definitely make the kludge history less ugly.

Quoted 6 lines
Quoted 5 lines

Hmm. Couldn't the merge base conceivably be higher up in the stack? Like, right at the beginning, don't we have public_head == stack.head? That would be caught by the "same tree" check" a bit earlier, but after adding another patch, don't we have public_head == stack.head^ ? Which would give merge_base == public_head.

Quoted 7 lines

We could have public_head == stack.head^... but that's not an issue. The merge_base above is checked against the base of the stack rather than the top as we assume that the base isn't volatile. So even if public_head is the same as some patch commit, the merge_base above would always be the base of the stack. Only if the stack base was updated, we get a different merge_base (equal to the previous stack base).

The situation I described looks like this:

    B--o--o--o--o--o--P--T

Time goes from left to right. B is the stack base, P the head of the public branch, T the stack top. merge_base(P, T) is P, and not B.

Signature · 2 lines
Karl Hasselström, [email protected]
      www.treskal.com/kalle
#6 lore raw

2009/5/29 Karl Hasselström <[email protected]>:

Quoted 4 lines · Catalin Marinas

I think I would've kludged this by making --theirs merges from the StGit branch to the public branch. But "stg publish" should definitely make the kludge history less ugly.

That's what I'm trying to do, keep the public history clean. One advantage of merging the full StGit branch is that people could retrieve the latest patch version but for those interesting in cherry-picking you can just export the volatile StGit branch.

Regarding the resulting tree, rebasing a StGit stack is equivalent, on a linear history branch, to a merge of the new stack base into the linear branch. Rather than having to solve conflicts twice, the pubish command just fakes this merge and sets the resulting tree.

Quoted 14 lines
Quoted 6 lines
Quoted 5 lines

Hmm. Couldn't the merge base conceivably be higher up in the stack? Like, right at the beginning, don't we have public_head == stack.head? That would be caught by the "same tree" check" a bit earlier, but after adding another patch, don't we have public_head == stack.head^ ? Which would give merge_base == public_head.

Quoted 7 lines

We could have public_head == stack.head^... but that's not an issue. The merge_base above is checked against the base of the stack rather than the top as we assume that the base isn't volatile. So even if public_head is the same as some patch commit, the merge_base above would always be the base of the stack. Only if the stack base was updated, we get a different merge_base (equal to the previous stack base).

Quoted 6 lines

The situation I described looks like this:

   B--o--o--o--o--o--P--T

Time goes from left to right. B is the stack base, P the head of the public branch, T the stack top. merge_base(P, T) is P, and not B.

I don't check merge_base(P, T) but merge_base(P, B) to avoid the issues you described. So that's always B.

Signature · 1 line
Catalin
#7 lore raw
Quoted 4 lines · Catalin Marinas

2009/5/29 Karl Hasselström <[email protected]>:

Quoted 2 lines

The situation I described looks like this:

Quoted 8 lines
Quoted 5 lines

   B--o--o--o--o--o--P--T

Time goes from left to right. B is the stack base, P the head of the public branch, T the stack top. merge_base(P, T) is P, and not B.

I don't check merge_base(P, T) but merge_base(P, B) to avoid the issues you described. So that's always B.

Ah, so that's where I got myself confused. Thanks.

Signature · 2 lines
Karl Hasselström, [email protected]
      www.treskal.com/kalle
#8 lore raw
In reply to Catalin Marinas

2009/5/28 Catalin Marinas <[email protected]>:

Quoted 8 lines

2009/5/28 Karl Hasselström <[email protected]>:

Quoted 7 lines · Catalin Marinas
Quoted 5 lines

+    def get_merge_base(self, commit1, commit2):
+        """Return the merge base of two commits."""
+        sha1 = self.run(['git', 'merge-base',
+                         commit1.sha1, commit2.sha1]).output_one_line()
+        return self.get_commit(sha1)

Quoted 4 lines
Quoted 2 lines

This funcion should probably return a list of zero or more merge bases. See the --all flag to git merge-base.

OK, I'll add this and check the stack base against this set(list).

What about this change to the original patch (it's faster to just return the sha1 refs than building the Commit objects):

stgit/commands/publish.py +2 -2
index 06c32d0..ce08a19 100644
@@ -106,8 +106,8 @@ def func(parser, options, args):
 
     # check for rebased stack. In this case we emulate a merge with the stack
     # base by setting two parents.
-    merge_base = repository.get_merge_base(public_head, stack.base)
-    if merge_base.sha1 != stack.base.sha1:
+    merge_base = set(repository.get_merge_base_sha1(public_head, stack.base))
+    if not stack.base.sha1 in merge_base:
         public_head = __create_commit(repository, stack.head.data.tree,
                                       [public_head, stack.base], options)
         repository.refs.set(public_ref, public_head, 'publish')
stgit/lib/git.py +4 -5
index 4a17c8a..5bd4e4d 100644
@@ -609,11 +609,10 @@ class Repository(RunWithEnv):
             raise DetachedHeadException()
     def set_head_ref(self, ref, msg):
         self.run(['git', 'symbolic-ref', '-m', msg, 'HEAD', ref]).no_output()
-    def get_merge_base(self, commit1, commit2):
-        """Return the merge base of two commits."""
-        sha1 = self.run(['git', 'merge-base',
-                         commit1.sha1, commit2.sha1]).output_one_line()
-        return self.get_commit(sha1)
+    def get_merge_base_sha1(self, commit1, commit2):
+        """Return the merge base of two commits as a list of sha1 refs."""
+        return self.run(['git', 'merge-base', '--all',
+                         commit1.sha1, commit2.sha1]).output_lines()
     def simple_merge(self, base, ours, theirs):
         index = self.temp_index()
         try:
Signature · 1 line
Catalin
#9 lore raw
Quoted 11 lines · Catalin Marinas

2009/5/28 Catalin Marinas <[email protected]>:

Quoted 6 lines

2009/5/28 Karl Hasselström <[email protected]>:

Quoted 2 lines

This funcion should probably return a list of zero or more merge bases. See the --all flag to git merge-base.

OK, I'll add this and check the stack base against this set(list).

What about this change to the original patch (it's faster to just return the sha1 refs than building the Commit objects):

Creating Commit objects is really cheap---just look at the constructor. I made them that way on purpose, so that we'd never have to think twice about using Commit objects instead of passing sha1s around.

Also, you said "set", and I agree---the return value of get_mege_bases() should be a set. That's what it _is_, conceptually, and it makes little sense to obscure that fact.

Signature · 2 lines
Karl Hasselström, [email protected]
      www.treskal.com/kalle
#10 lore raw

2009/5/29 Karl Hasselström <[email protected]>:

Quoted 11 lines · Catalin Marinas
Quoted 10 lines

2009/5/28 Catalin Marinas <[email protected]>:

Quoted 6 lines

2009/5/28 Karl Hasselström <[email protected]>:

Quoted 2 lines

This funcion should probably return a list of zero or more merge bases. See the --all flag to git merge-base.

OK, I'll add this and check the stack base against this set(list).

Quoted 7 lines
Quoted 2 lines

What about this change to the original patch (it's faster to just return the sha1 refs than building the Commit objects):

Creating Commit objects is really cheap---just look at the constructor. I made them that way on purpose, so that we'd never have to think twice about using Commit objects instead of passing sha1s around.

I was worried it may invoke git to get the CommitData.

Quoted 3 lines

Also, you said "set", and I agree---the return value of get_mege_bases() should be a set. That's what it _is_, conceptually, and it makes little sense to obscure that fact.

If we return a set of commits, I suspect the Repository object guarantees that having the same sha1 value always returns the same Commit object and the code below is valid:

merge_bases = repository.get_merge_bases(public_head, stack.base) if not stack.base in merge_bases:
public_head = __create_commit(repository, stack.head.data.tree,
[public_head, stack.base], options)
repository.refs.set(public_ref, public_head, 'publish') out.info('Merged the stack base into "%s"' % public_ref) return

...

def get_merge_bases(self, commit1, commit2):
"""Return a set of merge bases of two commits.""" sha1_list = self.run(['git', 'merge-base', '--all',
commit1.sha1, commit2.sha1]).output_lines()
return set(self.get_commit(sha1) for sha1 in sha1_list)

Signature · 1 line
Catalin
#11 lore raw
Quoted 9 lines · Catalin Marinas

2009/5/29 Karl Hasselström <[email protected]>:

Quoted 7 lines · Catalin Marinas
Quoted 5 lines

2009/5/28 Catalin Marinas <[email protected]>:

What about this change to the original patch (it's faster to just return the sha1 refs than building the Commit objects):

Quoted 6 lines
Quoted 4 lines

Creating Commit objects is really cheap---just look at the constructor. I made them that way on purpose, so that we'd never have to think twice about using Commit objects instead of passing sha1s around.

I was worried it may invoke git to get the CommitData.

Only if you try to access it---it's evaluated lazily.

Quoted 7 lines
Quoted 3 lines

Also, you said "set", and I agree---the return value of get_mege_bases() should be a set. That's what it _is_, conceptually, and it makes little sense to obscure that fact.

If we return a set of commits, I suspect the Repository object guarantees that having the same sha1 value always returns the same Commit object

Yes, exactly. As long as you get all your Commit objects from the Repository object like you're supposed to, there'll be at most one Commit object for each sha1. In fact, the Commit objects don't have an __eq__ method on purpose---straight object comparison already does exactly what we want!

Quoted 1 line

and the code below is valid:

Yes, this is precisely what I meant.

Signature · 2 lines
Karl Hasselström, [email protected]
      www.treskal.com/kalle
#12 lore raw
In reply to Catalin Marinas

2009/5/29 Catalin Marinas <[email protected]>:

Quoted 7 lines

   merge_bases = repository.get_merge_bases(public_head, stack.base) if not stack.base in merge_bases:
       public_head = __create_commit(repository, stack.head.data.tree, [public_head, stack.base], options) repository.refs.set(public_ref, public_head, 'publish') out.info('Merged the stack base into "%s"' % public_ref) return

One minor improvement here, trying to guess what was merged:

stgit/commands/publish.py +5 -3
index fe7f7c6..401fbdf 100644
@@ -67,10 +67,10 @@ options = [
 
 directory = common.DirectoryHasRepositoryLib()
 
-def __create_commit(repository, tree, parents, options):
+def __create_commit(repository, tree, parents, options, message = ''):
     """Return a new Commit object."""
     cd = git.CommitData(
-        tree = tree, parents = parents, message = '',
+        tree = tree, parents = parents, message = message,
         author = git.Person.author(), committer = git.Person.committer())
     cd = common.update_commit_data(cd, options, allow_edit = True)
 
@@ -106,8 +106,10 @@ def func(parser, options, args):
     # base by setting two parents.
     merge_bases = repository.get_merge_bases(public_head, stack.base)
     if not stack.base in merge_bases:
+        message = 'Merge ' + repository.describe(stack.base)
         public_head = __create_commit(repository, stack.head.data.tree,
-                                      [public_head, stack.base], options)
+                                      [public_head, stack.base], options,
+                                      message)
         repository.refs.set(public_ref, public_head, 'publish')
         out.info('Merged the stack base into "%s"' % public_ref)
         return
stgit/lib/git.py +4 -0
index 3303eea..6e3bb4f 100644
@@ -614,6 +614,10 @@ class Repository(RunWithEnv):
         sha1_list = self.run(['git', 'merge-base', '--all',
                               commit1.sha1, commit2.sha1]).output_lines()
         return set(self.get_commit(sha1) for sha1 in sha1_list)
+    def describe(self, commit):
+        """Use git describe --all on the given commit."""
+        return self.run(['git', 'describe', '--all', commit.sha1]
+                       ).discard_stderr().discard_exitcode().raw_output()
     def simple_merge(self, base, ours, theirs):
         index = self.temp_index()
         try:
Signature · 1 line
Catalin