git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[StGIT PATCH v2] Recognize refs under remotes/ as parent branch on stack creation.

From
Yann Dirson <ydirson@altern.org>
Date
Jul 3, 2007, 22:12 UTC
Message-ID
<20070703220920.30696.3240.stgit@gandelf.nowhere.earth>

Also remove the "relaxed" parentbranch detecting logic (accepting anything with an embedded slash as a parent branch name), which was never invoked because of a bug, and looks like a bad idea anyway. Better add sensible namespaces when we feel a need for them, rather than accepting anything by default, with potentially unwanted results.

Signed-off-by: Yann Dirson <ydirson@altern.org>
---

For some reason I had omitted to run the testsuite on the final version of this patch. Here is a version that also works when the branchpoint is a stgit-only ref ("base" in the testsuite).

 stgit/commands/branch.py |   39 +++++++++++++++++++++++++--------------
 1 files changed, 25 insertions(+), 14 deletions(-)
diff --git a/stgit/commands/branch.py b/stgit/commands/branch.py
index c22e143..2fb5f59 100644
--- a/stgit/commands/branch.py
+++ b/stgit/commands/branch.py
@@ -122,27 +122,38 @@ def func(parser, options, args):
 
         tree_id = None
         if len(args) >= 2:
+            parentbranch = None
             try:
-                if git.rev_parse(args[1]) == git.rev_parse('refs/heads/' + args[1]):
-                    # we are for sure referring to a branch
-                    parentbranch = 'refs/heads/' + args[1]
-                    out.info('Recording "%s" as parent branch' % parentbranch)
-                elif git.rev_parse(args[1]) and re.search('/', args[1]):
-                    # FIXME: should the test be more strict ?
-                    parentbranch = args[1]
-                else:
-                    # Note: this includes refs to StGIT patches
-                    out.info('Don\'t know how to determine parent branch'
-                             ' from "%s"' % args[1])
-                    parentbranch = None
+                branchpoint = git.rev_parse(args[1])
+
+                # first, look for branchpoint in well-known branch namespaces
+                for namespace in ('refs/heads/', 'remotes/'):
+                    # check if branchpoint exists in namespace
+                    try:
+                        maybehead = git.rev_parse(namespace + args[1])
+                    except git.GitException:
+                        maybehead = None
+
+                    # check if git resolved branchpoint to this namespace
+                    if maybehead and branchpoint == maybehead:
+                        # we are for sure referring to a branch
+                        parentbranch = namespace + args[1]
+
             except git.GitException:
                 # should use a more specific exception to catch only
                 # non-git refs ?
                 out.info('Don\'t know how to determine parent branch'
                          ' from "%s"' % args[1])
-                parentbranch = None
+                # exception in branch = rev_parse() leaves branchpoint unbound
+                branchpoint = None
 
-            tree_id = git_id(args[1])
+            tree_id = branchpoint or git_id(args[1])
+
+            if parentbranch:
+                out.info('Recording "%s" as parent branch' % parentbranch)
+            else:
+                out.info('Don\'t know how to determine parent branch'
+                         ' from "%s"' % args[1])                
         else:
             # branch stack off current branch
             parentbranch = git.get_head_file()
Message 1 of 1 in “Recognize refs under remotes/ as parent branch on stack creation.”
  1. Recognize refs under remotes/ as parent branch on stack creation.Yann Dirson, Jul 3, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.