forked from adamm/git-importer
Don't calculate diffs ....
Instead of calculating diffs, just apply the revision to the branch as-is. If things don't match, update them. Done. Problems happens if there are devel project changes and histories are no longer linear and the diffs are not calculated properly. eg. trytond_stock_lot devel branch was imported incorrectly
This commit is contained in:
parent
574bc9aa10
commit
3d1684f01b
@ -2,6 +2,8 @@ import logging
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
from hashlib import md5
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
from lib.binary import is_binary_or_large
|
from lib.binary import is_binary_or_large
|
||||||
from lib.db import DB
|
from lib.db import DB
|
||||||
@ -133,6 +135,12 @@ class GitExporter:
|
|||||||
return True
|
return True
|
||||||
return flat.parent1 == branch_state[flat.branch]
|
return flat.parent1 == branch_state[flat.branch]
|
||||||
|
|
||||||
|
def file_md5(self, file):
|
||||||
|
m = md5()
|
||||||
|
with open(file, 'rb') as f:
|
||||||
|
m.update(f.read())
|
||||||
|
return m.hexdigest()
|
||||||
|
|
||||||
def commit_flat(self, flat, branch_state):
|
def commit_flat(self, flat, branch_state):
|
||||||
parents = []
|
parents = []
|
||||||
self.git.checkout(flat.branch)
|
self.git.checkout(flat.branch)
|
||||||
@ -151,11 +159,40 @@ class GitExporter:
|
|||||||
# create file if not existant
|
# create file if not existant
|
||||||
self.git.add_default_lfs_gitattributes(force=False)
|
self.git.add_default_lfs_gitattributes(force=False)
|
||||||
|
|
||||||
to_download, to_delete = flat.commit.calc_delta(branch_state[flat.branch])
|
new_files = flat.commit.files_list()
|
||||||
for file in to_delete:
|
cur_files = os.listdir(self.git.path)
|
||||||
self.git.remove(file)
|
for cf in cur_files:
|
||||||
for file, size, md5 in to_download:
|
if cf[0] == '.':
|
||||||
self.commit_file(flat, file, size, md5)
|
continue
|
||||||
|
found = False
|
||||||
|
for nf in new_files:
|
||||||
|
if nf['name'] == cf:
|
||||||
|
found = True
|
||||||
|
break
|
||||||
|
|
||||||
|
if found:
|
||||||
|
# check if file is modified
|
||||||
|
file_path = self.git.path.joinpath(cf)
|
||||||
|
stat = file_path.stat()
|
||||||
|
if stat.st_size != nf['size'] or self.file_md5(file_path) != nf['md5']:
|
||||||
|
logging.debug(f"updating {file_path.name}")
|
||||||
|
self.commit_file(flat, Path(cf), nf['size'], nf['md5'])
|
||||||
|
else:
|
||||||
|
logging.debug(f"leaving {file_path.name}")
|
||||||
|
else:
|
||||||
|
# file not exist in new commit
|
||||||
|
self.git.remove(Path(cf))
|
||||||
|
|
||||||
|
|
||||||
|
# new files?
|
||||||
|
for file in new_files:
|
||||||
|
found = False
|
||||||
|
for cf in cur_files:
|
||||||
|
if file['name'] == cf:
|
||||||
|
found = True
|
||||||
|
break
|
||||||
|
if not found:
|
||||||
|
self.commit_file(flat, Path(file['name']), file['size'], file['md5'])
|
||||||
|
|
||||||
commit = self.git.commit(
|
commit = self.git.commit(
|
||||||
flat.user.realname,
|
flat.user.realname,
|
||||||
|
Loading…
Reference in New Issue
Block a user