forked from adamm/git-importer
Use proper user info in commits
This commit is contained in:
@@ -7,8 +7,9 @@ from lib.binary import is_binary_or_large
|
||||
from lib.db import DB
|
||||
from lib.git import Git
|
||||
from lib.obs import OBS
|
||||
from lib.proxy_sha256 import ProxySHA256, md5
|
||||
from lib.proxy_sha256 import ProxySHA256
|
||||
from lib.tree_builder import TreeBuilder
|
||||
from lib.user import User
|
||||
|
||||
|
||||
class GitExporter:
|
||||
@@ -31,12 +32,7 @@ class GitExporter:
|
||||
def set_gc_interval(self, gc):
|
||||
self.gc_interval = gc
|
||||
|
||||
def export_as_git(self):
|
||||
db = DB()
|
||||
tree = TreeBuilder(db).build(self.project, self.package)
|
||||
flats = tree.as_flat_list()
|
||||
|
||||
branch_state = {"factory": None, "devel": None}
|
||||
def check_repo_state(self, flats, branch_state):
|
||||
state_data = dict()
|
||||
if os.path.exists(self.state_file):
|
||||
with open(self.state_file, "r") as f:
|
||||
@@ -57,19 +53,38 @@ class GitExporter:
|
||||
found_state = True
|
||||
if not found_state:
|
||||
left_to_commit.append(flat)
|
||||
return left_to_commit
|
||||
|
||||
def export_as_git(self):
|
||||
db = DB()
|
||||
tree = TreeBuilder(db).build(self.project, self.package)
|
||||
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
|
||||
|
||||
logging.info(f"Commiting into {self.git.path}")
|
||||
self.run_gc()
|
||||
users = dict()
|
||||
|
||||
gc_cnt = self.gc_interval
|
||||
if len(left_to_commit) > 0:
|
||||
logging.info(f"Commiting into {self.git.path}")
|
||||
self.git.gc()
|
||||
for flat in left_to_commit:
|
||||
gc_cnt -= 1
|
||||
if gc_cnt <= 0 and self.gc_interval:
|
||||
self.git.gc()
|
||||
gc_cnt = self.gc_interval
|
||||
if flat.commit.userid not in users:
|
||||
users[flat.commit.userid] = User(db, flat.commit.userid)
|
||||
flat.user = users[flat.commit.userid]
|
||||
logging.debug(f"USER {flat.user}")
|
||||
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)
|
||||
|
||||
def run_gc(self):
|
||||
self.gc_cnt = self.gc_interval
|
||||
self.git.gc()
|
||||
|
||||
def commit_file(self, flat, file, size, md5):
|
||||
# have such files been detected as text mimetype before?
|
||||
is_text = self.proxy_sha256.is_text(flat.commit.package, file.name)
|
||||
@@ -107,7 +122,7 @@ class GitExporter:
|
||||
|
||||
if flat.parent1:
|
||||
if not self.branch_fits_parent1(flat, branch_state):
|
||||
logging.info(f"Reset {flat.branch} onto {flat.parent1.short_string()}")
|
||||
logging.debug(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.checkout(flat.branch)
|
||||
@@ -126,12 +141,11 @@ class GitExporter:
|
||||
self.commit_file(flat, file, size, md5)
|
||||
|
||||
commit = self.git.commit(
|
||||
f"OBS User {flat.commit.userid}",
|
||||
"null@suse.de",
|
||||
flat.user.realname,
|
||||
flat.user.email,
|
||||
flat.commit.commit_time,
|
||||
# TODO: Normalize better the commit message
|
||||
f"{flat.commit.comment}\n\n{flat.commit}",
|
||||
allow_empty=True,
|
||||
parents=parents,
|
||||
)
|
||||
flat.commit.git_commit = commit
|
||||
|
Reference in New Issue
Block a user