git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yann Dirson <ydirson@altern.org>
To: Catalin Marinas <catalin.marinas@gmail.com>
Cc: git@vger.kernel.org
Subject: [StGIT PATCH] Recognize refs under remotes/ as parent branch on stack creation.
Date: Mon, 02 Jul 2007 23:37:44 +0200	[thread overview]
Message-ID: <20070702213744.3014.793.stgit@gandelf.nowhere.earth> (raw)

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>
---

 stgit/commands/branch.py |   37 +++++++++++++++++++++++--------------
 1 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/stgit/commands/branch.py b/stgit/commands/branch.py
index c22e143..e45bcee 100644
--- a/stgit/commands/branch.py
+++ b/stgit/commands/branch.py
@@ -122,27 +122,36 @@ 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
 
-            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()

                 reply	other threads:[~2007-07-02 21:38 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070702213744.3014.793.stgit@gandelf.nowhere.earth \
    --to=ydirson@altern.org \
    --cc=catalin.marinas@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).