[projects/git-slug: 23/170] Allow for multiple branch patterns

glen glen at pld-linux.org
Mon Sep 21 21:40:44 CEST 2015


commit 6127c1a424072672c335f805c50b155bfc338f12
Author: Kacper Kornet <draenog at pld-linux.org>
Date:   Mon Sep 19 02:37:30 2011 +0100

    Allow for multiple branch patterns
    
    Multiple -b options are accepted. For example ./slug -b master -b devel
    will fetch both master and devel branches. Any of this argument can be
    an fnmatch pattern: ./slug -b 'AC*' -b  '*devel'.
    
    In config file the patterns should be separated by space:
    [PLD]
        branch = master devel

 git_slug/refsdata.py |  4 ++--
 slug.py              | 17 +++++++++++++++--
 2 files changed, 17 insertions(+), 4 deletions(-)
---
diff --git a/git_slug/refsdata.py b/git_slug/refsdata.py
index 237b0a5..41f45fe 100644
--- a/git_slug/refsdata.py
+++ b/git_slug/refsdata.py
@@ -12,12 +12,12 @@ class RemoteRefsError(Exception):
 class RemoteRefsData:
     def __init__(self, stream, pattern, dirpattern='*'):
         self.heads = collections.defaultdict(lambda: collections.defaultdict(lambda: EMPTYSHA1))
-        pattern = os.path.join('refs/heads', pattern)
+        refpatterns = list(os.path.join('refs/heads', p) for p in pattern)
         for line in stream.readlines():
             if isinstance(line, bytes):
                 line = line.decode("utf-8")
             (sha1, ref, repo) = line.split()
-            if fnmatch.fnmatchcase(ref, pattern) and fnmatch.fnmatchcase(repo, dirpattern):
+            if any(fnmatch.fnmatchcase(ref, p) for p in refpatterns) and fnmatch.fnmatchcase(repo, dirpattern):
                 self.heads[repo][ref] = sha1
 
     def put(self, repo, data):
diff --git a/slug.py b/slug.py
index 80c8303..9c5d35d 100755
--- a/slug.py
+++ b/slug.py
@@ -1,5 +1,6 @@
 #!/usr/bin/python3
 
+import copy
 import glob
 import sys
 import os
@@ -17,6 +18,16 @@ from git_slug.gitconst import GITSERVER, GIT_REPO, GIT_REPO_PUSH, REMOTEREFS
 from git_slug.gitrepo import GitRepo, GitRepoError
 from git_slug.refsdata import GitRemoteRefsData, RemoteRefsError
 
+class DelAppend(argparse._AppendAction):
+    def __call__(self, parser, namespace, values, option_string=None):
+        item = copy.copy(getattr(namespace, self.dest, None)) if getattr(namespace, self.dest, None) is not None else []
+        try:
+            self._firstrun
+        except AttributeError:
+            self._firstrun = True
+            del item[:]
+        item.append(values)
+        setattr(namespace, self.dest, item)
 
 class ThreadFetch(threading.Thread):
     def __init__(self, queue, dir, depth=0):
@@ -42,9 +53,11 @@ def readconfig(path):
     for option in ('newpkgs', 'prune'):
         if config.has_option('PLD',option):
             optionslist[option] = config.getboolean('PLD', option)
-    for option in ('branch', 'depth', 'dirpattern', 'packagesdir', 'remoterefs'):
+    for option in ('depth', 'dirpattern', 'packagesdir', 'remoterefs'):
         if config.has_option('PLD',option):
             optionslist[option] = config.get('PLD', option)
+    if config.has_option('PLD','branch'):
+        optionslist['branch'] = config.get('PLD', 'branch').split()
     for option in ('j'):
         if config.has_option('PLD',option):
             optionslist[option] = config.getint('PLD', option)
@@ -137,7 +150,7 @@ parser = argparse.ArgumentParser(description='PLD tool for interaction with git
 subparsers = parser.add_subparsers(help='sub-command help')
 clone = subparsers.add_parser('update', help='fetch repositories', parents=[common_options],
         formatter_class=argparse.ArgumentDefaultsHelpFormatter)
-clone.add_argument('-b', '--branch', help='branch to fetch', default = 'master')
+clone.add_argument('-b', '--branch', help='branch to fetch', action=DelAppend, default=['master'])
 clone.add_argument('-P', '--prune', help='prune git repositories that do no exist upstream',
         action='store_true')
 clone.add_argument('-j', help='number of threads to use', default=4, type=int)
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/git-slug.git/commitdiff/4ed64f73960519a2f4fd04c42950b2c96ae795c5



More information about the pld-cvs-commit mailing list