Ignore merge point candidates that create crosses

In OBS you can create submit requests for revisions that are behind
the last merge point, in git you can't - so we ignore them.

Fixes #14
This commit is contained in:
Stephan Kulow 2022-11-03 15:03:41 +01:00
parent ef7755c771
commit f2019db8ff
6 changed files with 20 additions and 11 deletions

View File

@ -31,6 +31,7 @@ class DBRevision:
self.rev = float(self.rev) self.rev = float(self.rev)
self._files = None self._files = None
self.db = db self.db = db
self.git_commit = None
def short_string(self): def short_string(self):
return f"{self.project}/{self.package}/{self.rev}" return f"{self.project}/{self.package}/{self.rev}"

View File

@ -107,10 +107,12 @@ class GitExporter:
if flat.parent1: if flat.parent1:
if not self.branch_fits_parent1(flat, branch_state): if not self.branch_fits_parent1(flat, branch_state):
logging.info(f"Reset {flat.branch} onto {flat.parent1.short_string()}") logging.info(f"Reset {flat.branch} onto {flat.parent1.short_string()}")
assert flat.parent1.git_commit
self.git.set_branch_head(flat.branch, flat.parent1.git_commit) self.git.set_branch_head(flat.branch, flat.parent1.git_commit)
self.git.checkout(flat.branch) self.git.checkout(flat.branch)
parents.append(flat.parent1.git_commit) parents.append(flat.parent1.git_commit)
if flat.parent2: if flat.parent2:
assert flat.parent2.git_commit
parents.append(flat.parent2.git_commit) parents.append(flat.parent2.git_commit)
# Overwrite ".gitattributes" with the # Overwrite ".gitattributes" with the

View File

@ -104,14 +104,23 @@ class TreeBuilder:
"""For a given revision in the target, find the node in the source chain """For a given revision in the target, find the node in the source chain
that matches the files""" that matches the files"""
node = source_chain node = source_chain
candidates = []
while node: while node:
# exclude reverts happening after the merge # exclude reverts happening after the merge
if ( if (
node.revision.commit_time <= revision.commit_time node.revision.commit_time <= revision.commit_time
and node.revision.files_hash == revision.files_hash and node.revision.files_hash == revision.files_hash
): ):
return node candidates.append(node)
if node.merged_into:
# we can't have candidates that are crossing previous merges
# see https://gitea.opensuse.org/importers/git-importer/issues/14
candidates = []
node = node.parent node = node.parent
if candidates:
# the assert is here to see if we have more hot cases
assert len(candidates) == 1
return candidates[0]
def add_merge_points(self, factory_revisions): def add_merge_points(self, factory_revisions):
"""For all target revisions that accepted a request, look up the merge """For all target revisions that accepted a request, look up the merge

View File

@ -44,8 +44,7 @@
- factory c:openSUSE:Factory/firewalld/53.0 p1:openSUSE:Factory/firewalld/52.0 p2:security:netfilter/firewalld/107.0 - factory c:openSUSE:Factory/firewalld/53.0 p1:openSUSE:Factory/firewalld/52.0 p2:security:netfilter/firewalld/107.0
- devel c:security:netfilter/firewalld/107.0 p1:security:netfilter/firewalld/106.0 - devel c:security:netfilter/firewalld/107.0 p1:security:netfilter/firewalld/106.0
- factory c:openSUSE:Factory/firewalld/52.0 p1:openSUSE:Factory/firewalld/51.0 - factory c:openSUSE:Factory/firewalld/52.0 p1:openSUSE:Factory/firewalld/51.0
- factory c:openSUSE:Factory/firewalld/51.0 p1:openSUSE:Factory/firewalld/50.0 p2:security:netfilter/firewalld/107.0 - factory c:openSUSE:Factory/firewalld/51.0 p1:openSUSE:Factory/firewalld/50.0
- devel c:security:netfilter/firewalld/107.0 p1:security:netfilter/firewalld/106.0
- factory c:openSUSE:Factory/firewalld/50.0 p1:openSUSE:Factory/firewalld/49.0 p2:security:netfilter/firewalld/106.0 - factory c:openSUSE:Factory/firewalld/50.0 p1:openSUSE:Factory/firewalld/49.0 p2:security:netfilter/firewalld/106.0
- devel c:security:netfilter/firewalld/106.0 p1:security:netfilter/firewalld/105.0 - devel c:security:netfilter/firewalld/106.0 p1:security:netfilter/firewalld/105.0
- factory c:openSUSE:Factory/firewalld/49.0 p1:openSUSE:Factory/firewalld/48.0 p2:security:netfilter/firewalld/105.0 - factory c:openSUSE:Factory/firewalld/49.0 p1:openSUSE:Factory/firewalld/48.0 p2:security:netfilter/firewalld/105.0
@ -89,13 +88,13 @@
- devel c:security:netfilter/firewalld/82.0 p1:security:netfilter/firewalld/81.0 - devel c:security:netfilter/firewalld/82.0 p1:security:netfilter/firewalld/81.0
- devel c:security:netfilter/firewalld/81.0 p1:security:netfilter/firewalld/80.0 - devel c:security:netfilter/firewalld/81.0 p1:security:netfilter/firewalld/80.0
- devel c:security:netfilter/firewalld/80.0 p1:security:netfilter/firewalld/79.0 - devel c:security:netfilter/firewalld/80.0 p1:security:netfilter/firewalld/79.0
- devel c:security:netfilter/firewalld/79.0 p1:security:netfilter/firewalld/78.0
- devel c:security:netfilter/firewalld/78.0 p1:security:netfilter/firewalld/77.0
- factory c:openSUSE:Factory/firewalld/34.0 p1:openSUSE:Factory/firewalld/33.0 p2:security:netfilter/firewalld/77.0 - factory c:openSUSE:Factory/firewalld/34.0 p1:openSUSE:Factory/firewalld/33.0 p2:security:netfilter/firewalld/77.0
- devel c:security:netfilter/firewalld/77.0 p1:security:netfilter/firewalld/76.0 - devel c:security:netfilter/firewalld/77.0 p1:security:netfilter/firewalld/76.0
- devel c:security:netfilter/firewalld/76.0 p1:security:netfilter/firewalld/75.0 - devel c:security:netfilter/firewalld/76.0 p1:security:netfilter/firewalld/75.0
- devel c:security:netfilter/firewalld/75.0 p1:security:netfilter/firewalld/74.0 - devel c:security:netfilter/firewalld/75.0 p1:security:netfilter/firewalld/74.0
- factory c:openSUSE:Factory/firewalld/33.0 p1:openSUSE:Factory/firewalld/32.0 p2:security:netfilter/firewalld/79.0 - factory c:openSUSE:Factory/firewalld/33.0 p1:openSUSE:Factory/firewalld/32.0
- devel c:security:netfilter/firewalld/79.0 p1:security:netfilter/firewalld/78.0
- devel c:security:netfilter/firewalld/78.0 p1:security:netfilter/firewalld/77.0
- factory c:openSUSE:Factory/firewalld/32.0 p1:openSUSE:Factory/firewalld/31.0 p2:security:netfilter/firewalld/74.0 - factory c:openSUSE:Factory/firewalld/32.0 p1:openSUSE:Factory/firewalld/31.0 p2:security:netfilter/firewalld/74.0
- devel c:security:netfilter/firewalld/74.0 p1:security:netfilter/firewalld/71.0 - devel c:security:netfilter/firewalld/74.0 p1:security:netfilter/firewalld/71.0
- factory c:openSUSE:Factory/firewalld/31.0 p1:openSUSE:Factory/firewalld/30.0 - factory c:openSUSE:Factory/firewalld/31.0 p1:openSUSE:Factory/firewalld/30.0

View File

@ -65,8 +65,6 @@
- security:netfilter/firewalld/107.0 - security:netfilter/firewalld/107.0
- commit: openSUSE:Factory/firewalld/52.0 - commit: openSUSE:Factory/firewalld/52.0
- commit: openSUSE:Factory/firewalld/51.0 - commit: openSUSE:Factory/firewalld/51.0
merged:
- security:netfilter/firewalld/107.0
- commit: openSUSE:Factory/firewalld/50.0 - commit: openSUSE:Factory/firewalld/50.0
merged: merged:
- security:netfilter/firewalld/106.0 - security:netfilter/firewalld/106.0
@ -126,15 +124,14 @@
- security:netfilter/firewalld/82.0 - security:netfilter/firewalld/82.0
- security:netfilter/firewalld/81.0 - security:netfilter/firewalld/81.0
- security:netfilter/firewalld/80.0 - security:netfilter/firewalld/80.0
- security:netfilter/firewalld/79.0
- security:netfilter/firewalld/78.0
- commit: openSUSE:Factory/firewalld/34.0 - commit: openSUSE:Factory/firewalld/34.0
merged: merged:
- security:netfilter/firewalld/77.0 - security:netfilter/firewalld/77.0
- security:netfilter/firewalld/76.0 - security:netfilter/firewalld/76.0
- security:netfilter/firewalld/75.0 - security:netfilter/firewalld/75.0
- commit: openSUSE:Factory/firewalld/33.0 - commit: openSUSE:Factory/firewalld/33.0
merged:
- security:netfilter/firewalld/79.0
- security:netfilter/firewalld/78.0
- commit: openSUSE:Factory/firewalld/32.0 - commit: openSUSE:Factory/firewalld/32.0
merged: merged:
- security:netfilter/firewalld/74.0 - security:netfilter/firewalld/74.0

View File

@ -71,5 +71,6 @@ class TestTreeMethods(unittest.TestCase):
def test_firewalld_tree(self): def test_firewalld_tree(self):
self.verify_package("firewalld") self.verify_package("firewalld")
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()