Merge branch 'jk/p4-locate-branch-point-optim'

"git p4" learned to find branch points more efficiently.

* jk/p4-locate-branch-point-optim:
  git-p4: speed up search for branch parent
  git-p4: ensure complex branches are cloned correctly
This commit is contained in:
Junio C Hamano 2021-05-14 08:26:08 +09:00
commit e289f681ed
2 changed files with 12 additions and 11 deletions

View file

@ -3600,19 +3600,18 @@ def importNewBranch(self, branch, maxChange):
return True return True
def searchParent(self, parent, branch, target): def searchParent(self, parent, branch, target):
parentFound = False targetTree = read_pipe(["git", "rev-parse",
for blob in read_pipe_lines(["git", "rev-list", "--reverse", "{}^{{tree}}".format(target)]).strip()
for line in read_pipe_lines(["git", "rev-list", "--format=%H %T",
"--no-merges", parent]): "--no-merges", parent]):
blob = blob.strip() if line.startswith("commit "):
if len(read_pipe(["git", "diff-tree", blob, target])) == 0: continue
parentFound = True commit, tree = line.strip().split(" ")
if tree == targetTree:
if self.verbose: if self.verbose:
print("Found parent of %s in commit %s" % (branch, blob)) print("Found parent of %s in commit %s" % (branch, commit))
break return commit
if parentFound: return None
return blob
else:
return None
def importChanges(self, changes, origin_revision=0): def importChanges(self, changes, origin_revision=0):
cnt = 1 cnt = 1

View file

@ -294,11 +294,13 @@ test_expect_success 'git p4 clone complex branches' '
test_path_is_file file3 && test_path_is_file file3 &&
grep update file2 && grep update file2 &&
git reset --hard p4/depot/branch4 && git reset --hard p4/depot/branch4 &&
git diff-tree --quiet HEAD &&
test_path_is_file file1 && test_path_is_file file1 &&
test_path_is_file file2 && test_path_is_file file2 &&
test_path_is_missing file3 && test_path_is_missing file3 &&
! grep update file2 && ! grep update file2 &&
git reset --hard p4/depot/branch5 && git reset --hard p4/depot/branch5 &&
git diff-tree --quiet HEAD &&
test_path_is_file file1 && test_path_is_file file1 &&
test_path_is_file file2 && test_path_is_file file2 &&
test_path_is_file file3 && test_path_is_file file3 &&