From 8a2a21d7995b3dd28f31525d6bdd2d562427495a Mon Sep 17 00:00:00 2001 From: Henning Schild Date: Tue, 20 Aug 2019 12:48:56 +0200 Subject: [PATCH] repos: change the way we apply patches Switch to applying all patches with "patch" and later do a " add; commit". Also iterate over quilt series files ourselfs and apply the patches one by one. This means we can apply patches on mercurial as well as on git. Signed-off-by: Henning Schild Signed-off-by: Jan Kiszka --- kas/repos.py | 69 ++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/kas/repos.py b/kas/repos.py index 215ff26..2d363ba 100644 --- a/kas/repos.py +++ b/kas/repos.py @@ -250,6 +250,8 @@ class RepoImpl(Repo): if self.operations_disabled: return 0 + my_patches = [] + for patch in self._patches: other_repo = get_context().config.repo_dict.get(patch['repo'], None) @@ -267,9 +269,18 @@ class RepoImpl(Repo): cmd = [] if os.path.isfile(path): - cmd = self.apply_patches_file_cmd(path) - elif os.path.isdir(path): - cmd = self.apply_patches_quilt_cmd(path) + my_patches.append(path) + elif (os.path.isdir(path) + and os.path.isfile(os.path.join(path, 'series'))): + with open(os.path.join(path, 'series')) as f: + for line in f: + if line.startswith('#'): + continue + p = os.path.join(path, line.split(' #')[0].rstrip()) + if os.path.isfile(p): + my_patches.append(p) + else: + raise FileNotFoundError(p) else: logging.error('Could not find patch. ' '(patch path: %s, repo: %s, patch entry: %s)', @@ -278,6 +289,11 @@ class RepoImpl(Repo): patch['id']) return 1 + if len(my_patches) == 0: + return 0 + + for path in my_patches: + cmd = ['patch', '-p', '1', '-i', path] (retc, output) = yield from run_cmd_async(cmd, cwd=self.path, fail=False) @@ -291,6 +307,27 @@ class RepoImpl(Repo): logging.info('Patch applied. ' '(patch path: %s, repo: %s, patch entry: %s)', path, self.name, patch['id']) + + cmd = self.add_cmd() + (retc, output) = yield from run_cmd_async(cmd, + cwd=self.path, + fail=False) + if retc: + logging.error('Could not add patched files. ' + 'repo: %s, vcs output: %s)', + self.name, output) + return 1 + + cmd = self.commit_cmd() + (retc, output) = yield from run_cmd_async(cmd, + cwd=self.path, + fail=False) + if retc: + logging.error('Could not commit patch changes. ' + 'repo: %s, vcs output: %s)', + self.name, output) + return 1 + return 0 @@ -299,12 +336,19 @@ class GitRepo(RepoImpl): Provides the git functionality for a Repo. """ + def add_cmd(self): + return ['git', 'add', '-A'] + def clone_cmd(self, gitsrcdir): cmd = ['git', 'clone', '-q', self.effective_url, self.path] if get_context().kas_repo_ref_dir and os.path.exists(gitsrcdir): cmd.extend(['--reference', gitsrcdir]) return cmd + def commit_cmd(self): + return ['git', 'commit', '-a', '--author', 'kas ', + '-m', 'msg'] + def contains_refspec_cmd(self): return ['git', 'cat-file', '-t', self.refspec] @@ -321,13 +365,6 @@ class GitRepo(RepoImpl): return ['git', 'checkout', '-q', '{refspec}'.format(refspec=self.refspec)] - def apply_patches_file_cmd(self, path): - return ['git', 'am', '-q', path] - - def apply_patches_quilt_cmd(self, path): - return ['git', 'quiltimport', '--author', 'kas ', - '--patches', path] - def set_remote_url_cmd(self): return ['git', 'remote', 'set-url', 'origin', self.effective_url] @@ -337,9 +374,15 @@ class MercurialRepo(RepoImpl): Provides the hg functionality for a Repo. """ + def add_cmd(self): + return ['hg', 'add'] + def clone_cmd(self, srcdir): return ['hg', 'clone', self.effective_url, self.path] + def commit_cmd(self): + return ['hg', 'commit', '--user', 'kas ', '-m', 'msg'] + def contains_refspec_cmd(self): return ['hg', 'log', '-r', self.refspec] @@ -355,11 +398,5 @@ class MercurialRepo(RepoImpl): def checkout_cmd(self): return ['hg', 'checkout', '{refspec}'.format(refspec=self.refspec)] - def apply_patches_file_cmd(self, path): - raise NotImplementedError() - - def apply_patches_quilt_cmd(self, path): - raise NotImplementedError() - def set_remote_url_cmd(self): raise NotImplementedError()