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

Re: [PATCH] checkout: add a test for creating a new branch with regexp as a starting point

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 2, 2010, 21:04 UTC
Message-ID
<7v1vaglo9w.fsf@alter.siamese.dyndns.org>
In-Reply-To
<201007300136.13501.trast@student.ethz.ch>
Thomas Rast <trast@student.ethz.ch> writes:
Show 13 quoted lines
>> > +test_expect_success checkout '
>> > +       git checkout -b new_branch :/first
>> > +'
>> > +
>> > +test_done
>> 
>> ...it looks like this can just be added to the end of
>> t2018-checkout-branch.sh instead of creating a new test. Creating a
>> new file just for a single test for such a simple feature is a bit of
>> an overkill.
>
> It should also use test_expect_failure unless you expect to have a fix
> soon, otherwise it would stop the test suite from running through.

I think this is an ancient bug from the very beginning of the ":/" notation. Because it temporarily uses one bit in the object flags, but the get_sha1_oneline() parser can be called multiple times, it tries to clear the flag bits it smudged at the end, but fails.

The basic pattern for traversing the ancestry while avoiding duplication is:

    prepare commits you traverse from in "list";
    while (list) {
        commit = pop_most_recent_commit(&list, MARK);
        try to use commit;
    }

pop_most_recent_commit() removes a commit from the list, pushes parents of the commit that are _not_ marked with any of the bits in the MARK to the given list, and returns that commit.

While introducing the feature ':/', however, 28a4d94 (object name: introduce ':/<oneline prefix>' notation, 2007-02-24) wanted to avoid leaving the mark used in the loop before leaving the function (which is a right thing to do), by doing this:

    prepare commits you traverse from in "list";
+   keep a copy of "list" in "backup";
    while (list) {
        commit = pop_most_recent_commit(&list, MARK);
        try to use commit;
    }
+   for (commit in backup)
+       clear_commit_marks(commit, MARK);

which is wrong, as clear_commit_marks() will ignore if the starting commit does not have the MARK.

I think the fix should be just as simple as this. Essentially, X_SEEN mark means "we have marked and placed this item on the list (so do not put it again back on the list when it appears as a parent of some other item)" so marking commits we initially put on the list with the bit should be the right thing to do regardless of this clean-up business.

 sha1_name.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/sha1_name.c b/sha1_name.c
index 4f2af8d..b935688 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -704,8 +704,10 @@ static int get_sha1_oneline(const char *prefix, unsigned char *sha1)
 		die("Invalid search pattern: %s", prefix);
 
 	for_each_ref(handle_one_ref, &list);
-	for (l = list; l; l = l->next)
+	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;
Previous: Dmitry V. Levin
Message 17 of 17 in “checkout: add a test for creating a new branch with regexp as a starting point”
  1. checkout: add a test for creating a new branch with regexp as a starting pointDmitry V. Levin, Jul 29, 2010
  2. Ævar Arnfjörð BjarmasonJul 29, 2010
  3. Thomas RastJul 29, 2010
  4. Dmitry V. LevinJul 30, 2010
  5. Ævar Arnfjörð BjarmasonJul 30, 2010
  6. When to use test_commit (Re: [PATCH] checkout: add a test for creating a new branch with regexp as a starting point)Jonathan Nieder, Jul 30, 2010
  7. Ævar Arnfjörð BjarmasonJul 30, 2010
  8. 1/2 test-lib.sh: introduce 4th argument to test_commit() specifying a tag nameDmitry V. Levin, Jul 31, 2010
  9. Ævar Arnfjörð BjarmasonJul 31, 2010
  10. 1/2 test-lib.sh: introduce 4th argument to test_commit() specifying a tag nameDmitry V. Levin, Jul 31, 2010
  11. Ævar Arnfjörð BjarmasonJul 31, 2010
  12. 2/2 checkout: add a test for creating a new branch with regexp as a starting pointDmitry V. Levin, Jul 31, 2010
  13. Ævar Arnfjörð BjarmasonJul 31, 2010
  14. 2/2 checkout: add a test for creating a new branch with regexp as a starting pointDmitry V. Levin, Jul 31, 2010
  15. Ævar Arnfjörð BjarmasonJul 31, 2010
  16. Dmitry V. LevinAug 5, 2010
  17. Junio C HamanoAug 2, 2010

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.