summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2020-10-02 10:57:28 +0200
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2020-10-09 18:41:55 +0200
commit4cc62eb73e99c9c274753faad7df472358c5fb3b (patch)
tree649fb11029a377e4ce5feda7946a6c3ead347f11
parente7a43f40dfd7bc2cec25e719e9a39e83d2bd0cb7 (diff)
downloadvendor_replicant-scripts-4cc62eb73e99c9c274753faad7df472358c5fb3b.tar.gz
vendor_replicant-scripts-4cc62eb73e99c9c274753faad7df472358c5fb3b.tar.bz2
vendor_replicant-scripts-4cc62eb73e99c9c274753faad7df472358c5fb3b.zip
replicant_prepare_patch.py: Add -C option to run it in a given directory
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rwxr-xr-xpatches/replicant_prepare_patch.py39
1 files changed, 28 insertions, 11 deletions
diff --git a/patches/replicant_prepare_patch.py b/patches/replicant_prepare_patch.py
index 5ed3311..57f8d6c 100755
--- a/patches/replicant_prepare_patch.py
+++ b/patches/replicant_prepare_patch.py
@@ -36,8 +36,10 @@ git show {commit}
"""
def usage(progname):
- print('{} <git_revision> [nr_patches] <patches_serie_revision>'.format(
+ print('Usage:\n\t{} [-C <directory>] <git_revision> [nr_patches] <patches_serie_revision>'.format(
progname))
+ print('Options:')
+ print('\t-C <directory>\t\tRun as if it was started in the given git directory')
sys.exit(1)
def get_config():
@@ -90,15 +92,20 @@ def get_config():
return config
class GitRepo(object):
- def __init__(self, config):
+ def __init__(self, config, directory):
self.config = config
+ self.directory = re.sub('/+$', '', directory)
+ if self.directory:
+ self.git = sh.git.bake("-C", self.directory)
+ else:
+ self.git = sh.git.bake()
def get_repo_url(self):
- output = sh.git('remote', 'get-url', self.config['local']['git_remote'])
+ output = self.git('remote', 'get-url', self.config['local']['git_remote'])
return output
def get_repo_name(self):
- output = sh.git('remote', 'get-url', config['local']['git_remote'])
+ output = self.git('remote', 'get-url', config['local']['git_remote'])
output = os.path.basename(str(output))
output = re.sub(os.linesep, '', output)
output = re.sub('\.git', '', output)
@@ -144,11 +151,16 @@ class GitRepo(object):
if patches_revision != None:
git_arguments.append('-v{}'.format(patches_revision))
- patches = sh.git(*git_arguments).split(os.linesep)
-
+ patches = self.git(*git_arguments).split(os.linesep)
patches.remove('')
- return patches
+ if self.directory:
+ results = []
+ for patch in patches:
+ results.append(self.directory + os.sep + patch)
+ return results
+ else:
+ return patches
def generate_cover_mail_text(self, commit, nr_patches, repo):
cgit_url = 'https://git.replicant.us'
@@ -186,8 +198,8 @@ class GitRepo(object):
return command
def get_git_revision(self, git_revision):
- output = sh.git('--no-pager', 'log', '--oneline', git_revision, '-1',
- '--format=%H')
+ output = self.git('--no-pager', 'log', '--oneline', git_revision, '-1',
+ '--format=%H')
revision = re.sub(os.linesep, '', str(output))
return revision
@@ -195,10 +207,15 @@ class GitRepo(object):
if __name__ == '__main__':
nr_patches = 1
patches_revision = None
+ directory = None
- if len(sys.argv) not in [2, 3, 4]:
+ if len(sys.argv) not in [2, 3, 4, 5, 6]:
usage(sys.argv[0])
+ if sys.argv[1] == '-C':
+ sys.argv.pop(1)
+ directory = sys.argv.pop(1)
+
if len (sys.argv) >= 3:
nr_patches = int(sys.argv[2])
@@ -211,7 +228,7 @@ if __name__ == '__main__':
print('Failed to find a configuration file')
sys.exit(1)
- repo = GitRepo(config)
+ repo = GitRepo(config, directory)
git_revision = repo.get_git_revision(sys.argv[1])
patches = repo.generate_patches(git_revision, nr_patches, patches_revision)