git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Mazo, Andrey" <amazo@checkvideo.com>
To: "git@vger.kernel.org" <git@vger.kernel.org>
Cc: "Mazo, Andrey" <amazo@checkvideo.com>,
	"Luke Diamand" <luke@diamand.org>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"George Vanburgh" <gvanburgh@bloomberg.net>,
	"Lars Schneider" <larsxschneider@gmail.com>,
	"Miguel Torroja" <miguel.torroja@gmail.com>,
	"Romain Merland" <merlorom@yahoo.fr>,
	"Vitor Antunes" <vitor.hda@gmail.com>,
	"Andrew Oakley" <aoakley@roku.com>,
	"SZEDER Gábor" <szeder.dev@gmail.com>,
	"Andrey Mazo" <ahippo@yandex.com>,
	"Junio C Hamano" <gitster@pobox.com>
Subject: [PATCH v3 1/8] git-p4: detect/prevent infinite loop in gitCommitByP4Change()
Date: Mon, 1 Apr 2019 18:02:17 +0000	[thread overview]
Message-ID: <bd009a5ca5679883f9366a58fbfbdcff1cf5f8fa.1554141338.git.amazo@checkvideo.com> (raw)
In-Reply-To: <cover.1554141338.git.amazo@checkvideo.com>

Under certain circumstances, gitCommitByP4Change() can enter an infinite
loop resulting in `git p4 sync` hanging forever.

The problem is that
`git rev-list --bisect <latest> ^<earliest>` can return `<latest>`,
which would result in reinspecting <latest> and potentially an infinite loop.

This can happen when importing just a subset of P4 repository
and/or with explicit "--changesfile" option.

A real-life example:
"""
    looking in ref refs/remotes/p4/mybranch for change 26894 using bisect...
    Reading pipe: git rev-parse refs/remotes/p4/mybranch
    trying: earliest  latest 4daff81c520a82678e1ef347f2b5e97258101ae1
    Reading pipe: git rev-list --bisect 4daff81c520a82678e1ef347f2b5e97258101ae1
    Reading pipe: git cat-file commit 147f5d3292af2e1cc4a56a7b96db845144c68486
    current change 25339
    trying: earliest ^147f5d3292af2e1cc4a56a7b96db845144c68486 latest 4daff81c520a82678e1ef347f2b5e97258101ae1
    Reading pipe: git rev-list --bisect 4daff81c520a82678e1ef347f2b5e97258101ae1 ^147f5d3292af2e1cc4a56a7b96db845144c68486
    Reading pipe: git cat-file commit 51db83df9d588010d0bd995641c85aa0408a5bb9
    current change 25420
    trying: earliest ^51db83df9d588010d0bd995641c85aa0408a5bb9 latest 4daff81c520a82678e1ef347f2b5e97258101ae1
    Reading pipe: git rev-list --bisect 4daff81c520a82678e1ef347f2b5e97258101ae1 ^51db83df9d588010d0bd995641c85aa0408a5bb9
    Reading pipe: git cat-file commit e8f83909ceb570f5a7e48c2853f3c5d8207cea52
    current change 25448
    trying: earliest ^e8f83909ceb570f5a7e48c2853f3c5d8207cea52 latest 4daff81c520a82678e1ef347f2b5e97258101ae1
    Reading pipe: git rev-list --bisect 4daff81c520a82678e1ef347f2b5e97258101ae1 ^e8f83909ceb570f5a7e48c2853f3c5d8207cea52
    Reading pipe: git cat-file commit 09a48eb7acd594dce52e06681be9c366e1844d66
    current change 25521
    trying: earliest ^09a48eb7acd594dce52e06681be9c366e1844d66 latest 4daff81c520a82678e1ef347f2b5e97258101ae1
    Reading pipe: git rev-list --bisect 4daff81c520a82678e1ef347f2b5e97258101ae1 ^09a48eb7acd594dce52e06681be9c366e1844d66
    Reading pipe: git cat-file commit 4daff81c520a82678e1ef347f2b5e97258101ae1
    current change 26907
    trying: earliest ^09a48eb7acd594dce52e06681be9c366e1844d66 latest 4daff81c520a82678e1ef347f2b5e97258101ae1
    Reading pipe: git rev-list --bisect 4daff81c520a82678e1ef347f2b5e97258101ae1 ^09a48eb7acd594dce52e06681be9c366e1844d66
    Reading pipe: git cat-file commit 4daff81c520a82678e1ef347f2b5e97258101ae1
    current change 26907
    trying: earliest ^09a48eb7acd594dce52e06681be9c366e1844d66 latest 4daff81c520a82678e1ef347f2b5e97258101ae1
    Reading pipe: git rev-list --bisect 4daff81c520a82678e1ef347f2b5e97258101ae1 ^09a48eb7acd594dce52e06681be9c366e1844d66
    Reading pipe: git cat-file commit 4daff81c520a82678e1ef347f2b5e97258101ae1
    current change 26907
    ...
"""

The fix is two-fold:
 * detect an infinite loop and die right away
   instead of looping forever;
 * make sure, `git rev-list --bisect` can't return "latestCommit" again
   by excluding it from the rev-list range explicitly.

Signed-off-by: Andrey Mazo <amazo@checkvideo.com>
---

Notes:
    I don't have a simple test-case for this yet,
    and I was able to perform a few complex initial `git p4 sync` runs
    without hitting this problem.
    
    I suspect, I had somehow messed up with branch definitions
    and --changesfile option at some point.

 git-p4.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/git-p4.py b/git-p4.py
index 5b79920f46..c0a3068b6f 100755
--- a/git-p4.py
+++ b/git-p4.py
@@ -3323,11 +3323,13 @@ def gitCommitByP4Change(self, ref, change):
                 return next
 
             if currentChange < change:
                 earliestCommit = "^%s" % next
             else:
-                latestCommit = "%s" % next
+                if next == latestCommit:
+                    die("Infinite loop while looking in ref %s for change %s. Check your branch mappings" % (ref, change))
+                latestCommit = "%s^@" % next
 
         return ""
 
     def importNewBranch(self, branch, maxChange):
         # make fast-import flush all changes to disk and update the refs using the checkpoint
-- 
2.19.2


  reply	other threads:[~2019-04-01 18:02 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-04 17:34 [PATCH 0/5] git-p4: a few assorted fixes for branches, excludes Mazo, Andrey
2019-03-04 17:34 ` [PATCH 1/5] git-p4: detect/prevent infinite loop in gitCommitByP4Change() Mazo, Andrey
2019-03-04 17:34 ` [PATCH 2/5] git-p4: match branches case insensitively if configured Mazo, Andrey
2019-03-04 17:34 ` [PATCH 3/5] git-p4: don't groom exclude path list on every commit Mazo, Andrey
2019-03-04 17:34 ` [PATCH 4/5] git-p4: add failing test for "don't exclude other files with same prefix" Mazo, Andrey
2019-03-04 17:34 ` [PATCH 5/5] git-p4: don't exclude other files with same prefix Mazo, Andrey
2019-03-21 22:32 ` [PATCH v2 0/7] git-p4: a few assorted fixes for branches, excludes Mazo, Andrey
2019-03-21 22:32   ` [PATCH v2 1/7] git-p4: detect/prevent infinite loop in gitCommitByP4Change() Mazo, Andrey
2019-03-21 22:32   ` [PATCH v2 2/7] git-p4: match branches case insensitively if configured Mazo, Andrey
2019-03-23  9:15     ` Luke Diamand
2019-03-25 17:20       ` Mazo, Andrey
2019-03-21 22:32   ` [PATCH v2 3/7] git-p4: don't groom exclude path list on every commit Mazo, Andrey
2019-03-21 22:33   ` [PATCH v2 4/7] git-p4: add failing test for "don't exclude other files with same prefix" Mazo, Andrey
2019-03-21 22:33   ` [PATCH v2 5/7] git-p4: don't exclude other files with same prefix Mazo, Andrey
2019-03-21 22:33   ` [PATCH v2 6/7] git-p4: add failing test for "git-p4: respect excluded paths when detecting branches" Mazo, Andrey
2019-03-21 22:33   ` [PATCH v2 7/7] git-p4: respect excluded paths when detecting branches Mazo, Andrey
2019-03-22 19:54   ` [RFC PATCH 0/2] git-p4: "alien" branches and load changelist info from file Mazo, Andrey
2019-03-22 19:54     ` [RFC PATCH 1/2] git-p4: introduce alien branch mappings Mazo, Andrey
2019-03-23  9:08       ` Luke Diamand
2019-03-26 18:43         ` Mazo, Andrey
2019-03-27 23:08           ` [RFC PATCH 1/1] git-p4: inexact label detection Mazo, Andrey
2019-03-22 19:54     ` [RFC PATCH 2/2] git-p4: support loading changelist descriptions from files Mazo, Andrey
2019-03-23  8:44       ` Luke Diamand
2019-03-25 17:46         ` [RFC PATCH 2/2] git-p4: support loading changelist descriptions Mazo, Andrey
2019-04-01 18:02   ` [PATCH v3 0/8] git-p4: a few assorted fixes for branches, excludes Mazo, Andrey
2019-04-01 18:02     ` Mazo, Andrey [this message]
2019-04-01 18:02     ` [PATCH v3 2/8] git-p4: add failing test for "git-p4: match branches case insensitively if configured" Mazo, Andrey
2019-04-02 12:05       ` SZEDER Gábor
2019-04-02 17:13         ` Mazo, Andrey
2019-04-03  7:10         ` Junio C Hamano
2019-04-01 18:02     ` [PATCH v3 3/8] git-p4: match branches case insensitively if configured Mazo, Andrey
2019-04-01 18:02     ` [PATCH v3 4/8] git-p4: don't groom exclude path list on every commit Mazo, Andrey
2019-04-01 18:02     ` [PATCH v3 5/8] git-p4: add failing test for "don't exclude other files with same prefix" Mazo, Andrey
2019-04-01 18:02     ` [PATCH v3 6/8] git-p4: don't exclude other files with same prefix Mazo, Andrey
2019-04-01 18:02     ` [PATCH v3 7/8] git-p4: add failing test for "git-p4: respect excluded paths when detecting branches" Mazo, Andrey
2019-04-01 18:02     ` [PATCH v3 8/8] git-p4: respect excluded paths when detecting branches Mazo, Andrey
2019-04-01 19:54     ` [PATCH v3 0/8] git-p4: a few assorted fixes for branches, excludes Mazo, Andrey
2019-04-02  0:13     ` [RFC PATCH v2 0/2] git-p4: inexact labels and load changelist description from file Mazo, Andrey
2019-04-02  0:13       ` [RFC PATCH v2 1/2] git-p4: inexact label detection Mazo, Andrey
2019-04-02  0:13       ` [RFC PATCH v2 2/2] git-p4: support loading changelist descriptions from files Mazo, Andrey

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=bd009a5ca5679883f9366a58fbfbdcff1cf5f8fa.1554141338.git.amazo@checkvideo.com \
    --to=amazo@checkvideo.com \
    --cc=ahippo@yandex.com \
    --cc=aoakley@roku.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=gvanburgh@bloomberg.net \
    --cc=larsxschneider@gmail.com \
    --cc=luke@diamand.org \
    --cc=merlorom@yahoo.fr \
    --cc=miguel.torroja@gmail.com \
    --cc=sunshine@sunshineco.com \
    --cc=szeder.dev@gmail.com \
    --cc=vitor.hda@gmail.com \
    /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.
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).