* [PATCH 1/2] get_sha1_oneline: allow to input commit_list
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 ` Nguyễn Thái Ngọc Duy
2010-12-08 15:11 ` Thiago Farina
0 siblings, 1 reply; 7+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-12-08 14:58 UTC (permalink / raw)
To: git, Junio C Hamano, Kevin Ballard, Yann Dirson, Jeff King,
Jakub Narebski
Cc: Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
sha1_name.c | 19 ++++++++++++-------
1 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 2c3a5fb..f4ccdc5 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -686,13 +686,14 @@ static int handle_one_ref(const char *path,
if (object->type != OBJ_COMMIT)
return 0;
insert_by_date((struct commit *)object, list);
- object->flags |= ONELINE_SEEN;
return 0;
}
-static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
+static int get_sha1_oneline(const char *prefix,
+ unsigned char *sha1,
+ struct commit_list *list_)
{
- struct commit_list *list = NULL, *backup = NULL, *l;
+ struct commit_list *list = list_, *backup = NULL, *l;
int retval = -1;
char *temp_commit_buffer = NULL;
regex_t regex;
@@ -706,9 +707,12 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
if (regcomp(®ex, prefix, REG_EXTENDED))
die("Invalid search pattern: %s", prefix);
- for_each_ref(handle_one_ref, &list);
- for (l = list; l; l = l->next)
+ if (!list)
+ for_each_ref(handle_one_ref, &list);
+ for (l = list; l; l = l->next) {
commit_list_insert(l->item, &backup);
+ l->item->object.flags |= ONELINE_SEEN;
+ }
while (list) {
char *p;
struct commit *commit;
@@ -737,7 +741,8 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
}
regfree(®ex);
free(temp_commit_buffer);
- free_commit_list(list);
+ if (!list_)
+ free_commit_list(list);
for (l = backup; l; l = l->next)
clear_commit_marks(l->item, ONELINE_SEEN);
return retval;
@@ -1090,7 +1095,7 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1,
int pos;
if (namelen > 2 && name[1] == '/')
/* don't need mode for commit */
- return get_sha1_oneline(name + 2, sha1);
+ return get_sha1_oneline(name + 2, sha1, NULL);
if (namelen < 3 ||
name[2] != ':' ||
name[1] < '0' || '3' < name[1])
--
1.7.3.2.316.gda8b3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] get_sha1_oneline: allow to input commit_list
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
0 siblings, 0 replies; 7+ messages in thread
From: Thiago Farina @ 2010-12-08 15:11 UTC (permalink / raw)
To: Nguyễn Thái Ngọc Duy
Cc: git, Junio C Hamano, Kevin Ballard, Yann Dirson, Jeff King,
Jakub Narebski
2010/12/8 Nguyễn Thái Ngọc Duy <pclouds@gmail.com>:
>
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> -static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
> +static int get_sha1_oneline(const char *prefix,
> + unsigned char *sha1,
> + struct commit_list *list_)
> {
micronit: can we have a better name for |list_|, the suffix _ is very
ugly and uncommon :(
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] get_sha1_oneline: allow to input commit_list
@ 2010-12-12 10:56 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
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-12-12 10:56 UTC (permalink / raw)
To: git, Junio C Hamano
Cc: Kevin Ballard, Yann Dirson, Jeff King, Jakub Narebski,
Jonathan Niedier, Thiago Farina,
Nguyễn Thái Ngọc Duy
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
sha1_name.c | 13 ++++++++++---
1 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 2c3a5fb..c298285 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -690,7 +690,9 @@ static int handle_one_ref(const char *path,
return 0;
}
-static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
+static int get_sha1_oneline(const char *prefix,
+ unsigned char *sha1,
+ struct commit_list *original_list)
{
struct commit_list *list = NULL, *backup = NULL, *l;
int retval = -1;
@@ -706,7 +708,12 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
if (regcomp(®ex, prefix, REG_EXTENDED))
die("Invalid search pattern: %s", prefix);
- for_each_ref(handle_one_ref, &list);
+ for (l = original_list; l; l = l->next) {
+ commit_list_insert(l->item, &list);
+ l->item->object.flags |= ONELINE_SEEN;
+ }
+ if (!list)
+ for_each_ref(handle_one_ref, &list);
for (l = list; l; l = l->next)
commit_list_insert(l->item, &backup);
while (list) {
@@ -1090,7 +1097,7 @@ int get_sha1_with_context_1(const char *name, unsigned char *sha1,
int pos;
if (namelen > 2 && name[1] == '/')
/* don't need mode for commit */
- return get_sha1_oneline(name + 2, sha1);
+ return get_sha1_oneline(name + 2, sha1, NULL);
if (namelen < 3 ||
name[2] != ':' ||
name[1] < '0' || '3' < name[1])
--
1.7.3.3.476.g893a9
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/2] get_sha1: support ref^{/regex} syntax
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 ` Nguyễn Thái Ngọc Duy
2010-12-12 17:38 ` Jonathan Nieder
2010-12-12 17:34 ` [PATCH 1/2] get_sha1_oneline: allow to input commit_list Jonathan Nieder
2010-12-13 0:29 ` Junio C Hamano
2 siblings, 1 reply; 7+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2010-12-12 10:56 UTC (permalink / raw)
To: git, Junio C Hamano
Cc: Kevin Ballard, Yann Dirson, Jeff King, Jakub Narebski,
Jonathan Niedier, Thiago Farina,
Nguyễn Thái Ngọc Duy
This works like :/ syntax, but only limited to one ref.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
No fancy modifiers, but still useful.
Documentation/revisions.txt | 6 +++
sha1_name.c | 35 ++++++++++++++------
t/t1511-rev-parse-caret.sh | 73 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 103 insertions(+), 11 deletions(-)
create mode 100755 t/t1511-rev-parse-caret.sh
diff --git a/Documentation/revisions.txt b/Documentation/revisions.txt
index 3d4b79c..174fa8e 100644
--- a/Documentation/revisions.txt
+++ b/Documentation/revisions.txt
@@ -106,6 +106,12 @@ 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 is the same as `:/fix nasty bug` syntax below except that
+ it returns the youngest matching commit which is reachable from
+ the ref before '{caret}'.
+
* 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 c298285..f1a86d9 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,8 @@ 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] == '/')
+ expected_type = OBJ_COMMIT;
else
return -1;
@@ -576,19 +579,29 @@ static int peel_onion(const char *name, int len, unsigned char *sha1)
if (!o || (!o->parsed && !parse_object(o->sha1)))
return -1;
hashcpy(sha1, o->sha1);
+ return 0;
}
- else {
- /*
- * At this point, the syntax look correct, so
- * if we do not get the needed object, we should
- * barf.
- */
- o = peel_to_type(name, len, o, expected_type);
- if (o) {
- hashcpy(sha1, o->sha1);
- return 0;
- }
+
+ /*
+ * At this point, the syntax look correct, so if we do not get
+ * the needed object, we should barf.
+ */
+ o = peel_to_type(name, len, o, expected_type);
+ 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 0;
}
diff --git a/t/t1511-rev-parse-caret.sh b/t/t1511-rev-parse-caret.sh
new file mode 100755
index 0000000..5c8439c
--- /dev/null
+++ b/t/t1511-rev-parse-caret.sh
@@ -0,0 +1,73 @@
+#!/bin/sh
+
+test_description='tests for ref^{stuff}'
+
+. ./test-lib.sh
+
+test_expect_success 'setup' '
+ echo blob >a-blob &&
+ git tag -a -m blob blob-tag `git hash-object -w a-blob`
+ mkdir a-tree &&
+ echo moreblobs >a-tree/another-blob &&
+ git add . &&
+ TREE_SHA1=`git write-tree` &&
+ git tag -a -m tree tree-tag "$TREE_SHA1" &&
+ git commit -m Initial &&
+ git tag -a -m commit commit-tag &&
+ git branch ref &&
+ git checkout master &&
+ echo modified >>a-blob &&
+ git add -u &&
+ git commit -m Modified
+'
+
+test_expect_success 'ref^{non-existent}' '
+ test_must_fail git rev-parse ref^{non-existent}
+'
+
+test_expect_success 'ref^{}' '
+ git rev-parse ref >expected &&
+ git rev-parse ref^{} >actual &&
+ test_cmp expected actual &&
+ git rev-parse commit-tag^{} >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'ref^{commit}' '
+ git rev-parse ref >expected &&
+ git rev-parse ref^{commit} >actual &&
+ test_cmp expected actual &&
+ git rev-parse commit-tag^{commit} >actual &&
+ test_cmp expected actual &&
+ test_must_fail git rev-parse tree-tag^{commit} &&
+ test_must_fail git rev-parse blob-tag^{commit}
+'
+
+test_expect_success 'ref^{tree}' '
+ echo $TREE_SHA1 >expected &&
+ git rev-parse ref^{tree} >actual &&
+ test_cmp expected actual &&
+ git rev-parse commit-tag^{tree} >actual &&
+ test_cmp expected actual &&
+ git rev-parse tree-tag^{tree} >actual &&
+ test_cmp expected actual &&
+ test_must_fail git rev-parse blob-tag^{tree}
+'
+
+test_expect_success 'ref^{/}' '
+ git rev-parse master >expected &&
+ git rev-parse master^{/} >actual &&
+ test_cmp expected actual
+'
+
+test_expect_success 'ref^{/non-existent}' '
+ test_must_fail git rev-parse master^{/non-existent}
+'
+
+test_expect_success 'ref^{/Initial}' '
+ git rev-parse ref >expected &&
+ git rev-parse master^{/Initial} >actual &&
+ test_cmp expected actual
+'
+
+test_done
--
1.7.3.3.476.g893a9
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] get_sha1_oneline: allow to input commit_list
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:34 ` Jonathan Nieder
2010-12-13 0:29 ` Junio C Hamano
2 siblings, 0 replies; 7+ messages in thread
From: Jonathan Nieder @ 2010-12-12 17:34 UTC (permalink / raw)
To: Nguyễn Thái Ngọc Duy
Cc: git, Junio C Hamano, Kevin Ballard, Yann Dirson, Jeff King,
Jakub Narebski, Thiago Farina
Nguyễn Thái Ngọc Duy wrote:
> [Subject: get_sha1_oneline: allow to input commit_list]
Cryptic. Might be simpler to squash this with the next commit,
since the best explanation I can come up with is
prepare to extend :/foo syntax to start search at specified refs
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] get_sha1: support ref^{/regex} syntax
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
0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Nieder @ 2010-12-12 17:38 UTC (permalink / raw)
To: Nguyễn Thái Ngọc Duy
Cc: git, Junio C Hamano, Kevin Ballard, Yann Dirson, Jeff King,
Jakub Narebski, Thiago Farina
Nguyễn Thái Ngọc Duy wrote:
> This works like :/ syntax, but only limited to one ref.
Limited to the ancestors of one commit, not one ref, right?
> --- /dev/null
> +++ b/t/t1511-rev-parse-caret.sh
> @@ -0,0 +1,73 @@
Nice.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] get_sha1_oneline: allow to input commit_list
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:34 ` [PATCH 1/2] get_sha1_oneline: allow to input commit_list Jonathan Nieder
@ 2010-12-13 0:29 ` Junio C Hamano
2 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2010-12-13 0:29 UTC (permalink / raw)
To: Nguyễn Thái Ngọc Duy
Cc: git, Kevin Ballard, Yann Dirson, Jeff King, Jakub Narebski,
Jonathan Niedier, Thiago Farina
Nguyễn Thái Ngọc Duy <pclouds@gmail.com> writes:
> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
> ---
> sha1_name.c | 13 ++++++++++---
> 1 files changed, 10 insertions(+), 3 deletions(-)
>
> diff --git a/sha1_name.c b/sha1_name.c
> index 2c3a5fb..c298285 100644
> --- a/sha1_name.c
> +++ b/sha1_name.c
> @@ -690,7 +690,9 @@ static int handle_one_ref(const char *path,
> return 0;
> }
>
> -static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
> +static int get_sha1_oneline(const char *prefix,
> + unsigned char *sha1,
> + struct commit_list *original_list)
> {
> struct commit_list *list = NULL, *backup = NULL, *l;
> int retval = -1;
> @@ -706,7 +708,12 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
> if (regcomp(®ex, prefix, REG_EXTENDED))
> die("Invalid search pattern: %s", prefix);
>
> - for_each_ref(handle_one_ref, &list);
> + for (l = original_list; l; l = l->next) {
> + commit_list_insert(l->item, &list);
> + l->item->object.flags |= ONELINE_SEEN;
> + }
> + if (!list)
> + for_each_ref(handle_one_ref, &list);
Two-and-half yucks.
(1) "We work on the list you give us, if you give us one, but we work on
a list we come up with outselves in a magic way otherwise" is an API
designed with a bad taste. Why not make the original caller run
for-each-ref before calling this function?
(2) Why do you have to copy the list, using commit-list-insert, here?
(3) Even if the above extra copy turns out to be needed, do you need yet
another copy in "backup"?
Instead of this patch, I would suggest to go this route:
* Remove local varaible "list" and make it an input parameter.
* Stop calling for-each-ref from this function. Instead, have the
current caller run for-each-ref to prepare list and feed it to you;
* Stop marking commits with "ONELINE_SEEN" from handle-one-ref. Instead,
have the loop to copy list to backup do the marking.
That way, you make the purpose of the function much more clear. It gets a
list of one or more commits that are in date-order, and finds the most
recent commit reachable from them that match the given string, using
ONELINE_SEEN bit as a scratchpad (shouldn't we be using TMP_MARK here, by
the way?). The caller is responsible for giving you a sorted list, but
the caller shouldn't care about ONELINE_SEEN bit.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2010-12-13 0:29 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2010-12-12 17:34 ` [PATCH 1/2] get_sha1_oneline: allow to input commit_list Jonathan Nieder
2010-12-13 0:29 ` Junio C Hamano
-- strict thread matches above, loose matches on Subject: below --
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
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).