forked from importers/git-importer
Include all the devel commits
If commits in devel are younger than factory, we should probalby export them too....
This commit is contained in:
@@ -37,7 +37,7 @@ class GitExporter:
|
||||
def set_gc_interval(self, gc):
|
||||
self.gc_interval = gc
|
||||
|
||||
def check_repo_state(self, flats, branch_state):
|
||||
def check_repo_state(self, flats, branch_state, branch):
|
||||
state_data = dict()
|
||||
if os.path.exists(self.state_file):
|
||||
with open(self.state_file) as f:
|
||||
@@ -47,32 +47,36 @@ class GitExporter:
|
||||
left_to_commit = []
|
||||
for flat in reversed(flats):
|
||||
found_state = False
|
||||
for branch in ["factory"]:
|
||||
if flat.commit.dbid == state_data.get(branch):
|
||||
branch_state[branch] = flat.commit
|
||||
flat.commit.git_commit = self.git.branch_head(branch)
|
||||
logging.debug(
|
||||
f"Found {self.git.path}'s {branch} branch in state {flat}"
|
||||
)
|
||||
left_to_commit = []
|
||||
found_state = True
|
||||
if flat.commit.dbid == state_data.get(branch):
|
||||
branch_state[branch] = flat.commit
|
||||
flat.commit.git_commit = self.git.branch_head(branch)
|
||||
logging.debug(
|
||||
f"Found {self.git.path}'s {branch} branch in state {flat}"
|
||||
)
|
||||
left_to_commit = []
|
||||
found_state = True
|
||||
if not found_state:
|
||||
left_to_commit.append(flat)
|
||||
return left_to_commit
|
||||
|
||||
def devel_rev(self, tree):
|
||||
for flat in tree:
|
||||
if flat.branch == "devel":
|
||||
return flat
|
||||
return None
|
||||
|
||||
def export_as_git(self):
|
||||
if os.getenv("CHECK_ALL_LFS"):
|
||||
LFSOid.check_all(self.db, self.package)
|
||||
tree = TreeBuilder(self.db).build(self.project, self.package)
|
||||
added_commits = False
|
||||
|
||||
if tree == None: # eg. python-M2Crypto errors
|
||||
return
|
||||
flats = tree.as_flat_list()
|
||||
|
||||
branch_state = {"factory": None, "devel": None}
|
||||
left_to_commit = self.check_repo_state(flats, branch_state)
|
||||
|
||||
if not left_to_commit:
|
||||
return
|
||||
self.check_repo_state(flats, branch_state, "devel") # used to set branch_state only
|
||||
left_to_commit = self.check_repo_state(flats, branch_state, "factory")
|
||||
|
||||
logging.info(f"Commiting into {self.git.path}")
|
||||
self.run_gc()
|
||||
@@ -87,13 +91,38 @@ class GitExporter:
|
||||
self.run_gc()
|
||||
logging.debug(f"Committing {flat}")
|
||||
self.commit_flat(flat, branch_state)
|
||||
added_commits = True
|
||||
|
||||
# export the devel_tree head commits based on the devel branch
|
||||
if self.project == "openSUSE:Factory":
|
||||
devel_head = self.devel_rev(flats)
|
||||
flat_devel = None
|
||||
if devel_head is not None:
|
||||
flat_devel = TreeBuilder(self.db).revisions_chain(devel_head.commit.project, self.package).as_flat_list()
|
||||
for f in flat_devel:
|
||||
f.branch = "devel"
|
||||
|
||||
left_to_commit = self.check_repo_state(flat_devel, branch_state, "devel")
|
||||
print(branch_state)
|
||||
logging.debug(f"appending {len(left_to_commit)} items on top of devel")
|
||||
for flat in left_to_commit:
|
||||
if flat.commit.userid not in users:
|
||||
users[flat.commit.userid] = User.find(self.db, flat.commit.userid)
|
||||
flat.user = users[flat.commit.userid]
|
||||
self.gc_cnt -= 1
|
||||
if self.gc_cnt <= 0 and self.gc_interval:
|
||||
self.run_gc()
|
||||
logging.debug(f"Committing {flat}")
|
||||
self.commit_flat(flat, branch_state)
|
||||
added_commits = True
|
||||
|
||||
# make sure that we create devel branch
|
||||
if not branch_state["devel"]:
|
||||
logging.debug("force creating devel")
|
||||
self.git.set_branch_head("devel", self.git.branch_head("factory"))
|
||||
|
||||
self.git.push(force=True)
|
||||
if added_commits:
|
||||
self.git.push(force=True)
|
||||
|
||||
def run_gc(self):
|
||||
self.gc_cnt = self.gc_interval
|
||||
|
Reference in New Issue
Block a user