From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org, Junio C Hamano <gitster@pobox.com>,
Kevin Ballard <kevin@sb.org>, Yann Dirson <dirson@bertin.fr>,
Jeff King <peff@peff.net>, Jakub Narebski <jnareb@gmail.com>
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH 2/2] get_sha1: support ref^{/regex} syntax
Date: Wed, 8 Dec 2010 21:58:39 +0700 [thread overview]
Message-ID: <1291820319-12455-3-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1291820319-12455-1-git-send-email-pclouds@gmail.com>
This works like :/ syntax, but only limited to one ref.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
Documentation/revisions.txt | 7 +++++++
sha1_name.c | 26 ++++++++++++++++++++++----
2 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt
index 3d4b79c..fbe6245 100644
--- a/Documentation/revisions.txt
+++ b/Documentation/revisions.txt
@@ -106,6 +106,13 @@ the `$GIT_DIR/refs` directory or from the `$GIT_DIR/packed-refs` file.
and dereference the tag recursively until a non-tag object is
found.
+* A suffix '{caret}' to a revision parameter followed by a brace
+ pair that contains a text led by a slash (e.g. `HEAD^{/fix nasty bug}`):
+ this names a commit whose commit message matches the specified
+ regular expression. This name returns the youngest matching commit
+ which is reachable from the dereferenced commit. The leading '!'
+ in the text is treated especially like in `:/` syntax below.
+
* A colon, followed by a slash, followed by a text (e.g. `:/fix nasty bug`): this names
a commit whose commit message matches the specified regular expression.
This name returns the youngest matching commit which is
diff --git a/sha1_name.c b/sha1_name.c
index f4ccdc5..00e52b0 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -527,6 +527,7 @@ struct object *peel_to_type(const char *name, int namelen,
}
}
+static int get_sha1_oneline(const char *, unsigned char *, struct commit_list *);
static int peel_onion(const char *name, int len, unsigned char *sha1)
{
unsigned char outer[20];
@@ -562,6 +563,11 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
expected_type = OBJ_BLOB;
else if (sp[0] == '}')
expected_type = OBJ_NONE;
+ else if (sp[0] == '/') {
+ if (sp[1] == '}')
+ return -1;
+ expected_type = OBJ_COMMIT;
+ }
else
return -1;
@@ -584,11 +590,23 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
* barf.
*/
o = peel_to_type(name, len, o, expected_type);
- if (o) {
- hashcpy(sha1, o->sha1);
- return 0;
+ if (!o)
+ return -1;
+
+ hashcpy(sha1, o->sha1);
+ if (sp[0] == '/') { /* ^{/foo} */
+ struct commit_list *list = NULL;
+ char *prefix;
+ int ret;
+
+ commit_list_insert((struct commit *)o, &list);
+ prefix = xstrndup(sp + 1, name + len - 1 - (sp + 1));
+ ret = get_sha1_oneline(prefix, sha1, list);
+ free(prefix);
+ free_commit_list(list);
+ return ret;
}
- return -1;
+ return 0;
}
return 0;
}
--
1.7.3.2.316.gda8b3
next prev parent reply other threads:[~2010-12-08 15:00 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-08 14:58 [PATCH 0/2] [RFD] Using gitrevisions :/search style with other operators Nguyễn Thái Ngọc Duy
2010-12-08 14:58 ` [PATCH 1/2] get_sha1_oneline: allow to input commit_list Nguyễn Thái Ngọc Duy
2010-12-08 15:11 ` Thiago Farina
2010-12-08 14:58 ` Nguyễn Thái Ngọc Duy [this message]
2010-12-08 22:50 ` [PATCH 2/2] get_sha1: support ref^{/regex} syntax Junio C Hamano
2010-12-08 18:06 ` [PATCH 0/2] [RFD] Using gitrevisions :/search style with other operators Jonathan Nieder
2010-12-08 19:51 ` Jakub Narebski
2010-12-09 1:28 ` Nguyen Thai Ngoc Duy
2010-12-09 1:54 ` Jakub Narebski
2010-12-09 1:59 ` Jonathan Nieder
2010-12-09 2:02 ` Kevin Ballard
2010-12-09 2:06 ` Nguyen Thai Ngoc Duy
2010-12-09 2:11 ` Jonathan Nieder
2010-12-09 6:22 ` Junio C Hamano
2010-12-09 11:38 ` Jakub Narebski
2010-12-10 13:25 ` Nguyen Thai Ngoc Duy
2010-12-10 19:03 ` Jonathan Nieder
2010-12-10 19:26 ` Jakub Narebski
2010-12-10 21:21 ` Kevin Ballard
2010-12-10 21:30 ` Jeff King
2010-12-10 23:08 ` Junio C Hamano
2010-12-10 23:11 ` Kevin Ballard
2010-12-10 23:36 ` Junio C Hamano
2010-12-09 5:15 ` Junio C Hamano
2010-12-08 19:47 ` Jakub Narebski
2010-12-08 20:40 ` Jonathan Nieder
2010-12-09 0:30 ` Nguyen Thai Ngoc Duy
2010-12-09 0:44 ` Jakub Narebski
2010-12-09 1:42 ` Nguyen Thai Ngoc Duy
2010-12-09 1:46 ` Kevin Ballard
2010-12-09 11:43 ` Jakub Narebski
2010-12-09 11:53 ` Nguyen Thai Ngoc Duy
-- strict thread matches above, loose matches on Subject: below --
2010-12-12 10:56 [PATCH 1/2] get_sha1_oneline: allow to input commit_list Nguyễn Thái Ngọc Duy
2010-12-12 10:56 ` [PATCH 2/2] get_sha1: support ref^{/regex} syntax Nguyễn Thái Ngọc Duy
2010-12-12 17:38 ` Jonathan Nieder
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=1291820319-12455-3-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=dirson@bertin.fr \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jnareb@gmail.com \
--cc=kevin@sb.org \
--cc=peff@peff.net \
/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.