From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: kevin@sb.org, "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 3/5] sha1_name: move interpret_nth_prior_checkout closer to interpret_branch_name
Date: Fri, 24 Dec 2010 21:07:47 +0700 [thread overview]
Message-ID: <1293199669-19016-4-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1293199669-19016-1-git-send-email-pclouds@gmail.com>
interpret_nth_prior_checkout() is a subfunction of
interpret_branch_name(). So it's better to let them be close together
(i.e. not letting get_sha1_mb() stays in between).
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
sha1_name.c | 84 +++++++++++++++++++++++++++++-----------------------------
1 files changed, 42 insertions(+), 42 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 3a98a50..dcdf1e6 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -883,6 +883,48 @@ static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,
return 0;
}
+int get_sha1_mb(const char *name, unsigned char *sha1)
+{
+ struct commit *one, *two;
+ struct commit_list *mbs;
+ unsigned char sha1_tmp[20];
+ const char *dots;
+ int st;
+
+ dots = strstr(name, "...");
+ if (!dots)
+ return get_sha1(name, sha1);
+ if (dots == name)
+ st = get_sha1("HEAD", sha1_tmp);
+ else {
+ struct strbuf sb;
+ strbuf_init(&sb, dots - name);
+ strbuf_add(&sb, name, dots - name);
+ st = get_sha1(sb.buf, sha1_tmp);
+ strbuf_release(&sb);
+ }
+ if (st)
+ return st;
+ one = lookup_commit_reference_gently(sha1_tmp, 0);
+ if (!one)
+ return -1;
+
+ if (get_sha1(dots[3] ? (dots + 3) : "HEAD", sha1_tmp))
+ return -1;
+ two = lookup_commit_reference_gently(sha1_tmp, 0);
+ if (!two)
+ return -1;
+ mbs = get_merge_bases(one, two, 1);
+ if (!mbs || mbs->next)
+ st = -1;
+ else {
+ st = 0;
+ hashcpy(sha1, mbs->item->object.sha1);
+ }
+ free_commit_list(mbs);
+ return st;
+}
+
/*
* Parse @{-N} syntax, return the number of characters parsed
* if successful; otherwise signal an error with negative value.
@@ -931,48 +973,6 @@ release_return:
return retval;
}
-int get_sha1_mb(const char *name, unsigned char *sha1)
-{
- struct commit *one, *two;
- struct commit_list *mbs;
- unsigned char sha1_tmp[20];
- const char *dots;
- int st;
-
- dots = strstr(name, "...");
- if (!dots)
- return get_sha1(name, sha1);
- if (dots == name)
- st = get_sha1("HEAD", sha1_tmp);
- else {
- struct strbuf sb;
- strbuf_init(&sb, dots - name);
- strbuf_add(&sb, name, dots - name);
- st = get_sha1(sb.buf, sha1_tmp);
- strbuf_release(&sb);
- }
- if (st)
- return st;
- one = lookup_commit_reference_gently(sha1_tmp, 0);
- if (!one)
- return -1;
-
- if (get_sha1(dots[3] ? (dots + 3) : "HEAD", sha1_tmp))
- return -1;
- two = lookup_commit_reference_gently(sha1_tmp, 0);
- if (!two)
- return -1;
- mbs = get_merge_bases(one, two, 1);
- if (!mbs || mbs->next)
- st = -1;
- else {
- st = 0;
- hashcpy(sha1, mbs->item->object.sha1);
- }
- free_commit_list(mbs);
- return st;
-}
-
/*
* This reads short-hand syntax that not only evaluates to a commit
* object name, but also can act as if the end user spelled the name
--
1.7.3.3.476.g10a82
next prev parent reply other threads:[~2010-12-24 14:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-24 14:07 [PATCH 0/5] Custom extended SHA-1 syntax Nguyễn Thái Ngọc Duy
2010-12-24 14:07 ` [PATCH 1/5] alias: add functions to do param substitution and alias running Nguyễn Thái Ngọc Duy
2010-12-24 14:07 ` [PATCH 2/5] get_sha1: allow custom SHA-1 mapping with $SHA1^{~alias} syntax Nguyễn Thái Ngọc Duy
2010-12-24 14:07 ` Nguyễn Thái Ngọc Duy [this message]
2010-12-24 14:07 ` [PATCH 4/5] interpret_branch_name: takes @{u} code out and reorder the function Nguyễn Thái Ngọc Duy
2010-12-24 14:07 ` [PATCH 5/5] get_sha1: allow custom ref mapping with $ref@{~alias} syntax Nguyễn Thái Ngọc Duy
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=1293199669-19016-4-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=kevin@sb.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.