Simplify author and committer argument passing
authorGuido Günther <agx@sigxcpu.org>
Wed, 9 Feb 2011 20:19:23 +0000 (21:19 +0100)
committerGuido Günther <agx@sigxcpu.org>
Wed, 9 Feb 2011 20:25:40 +0000 (21:25 +0100)
to reduce the number of function arguments.

Git-Dch: Ignore

debian/rules
gbp/git.py
git-import-dsc

index b0c44e6..ae680c6 100755 (executable)
@@ -29,7 +29,7 @@ POD_MANPAGES=docs/git-pbuilder.1
 MANPAGES=$(SGML_MANPAGES) $(POD_MANPAGES)
 MANUAL=docs/manual-html
 PYCHECKS=$(patsubst %,%.py,$(COMMANDS))
-PYCHECKER_ARGS=--maxlines=200 --maxargs=12 -boptparse --no-override --no-shadowbuiltin
+PYCHECKER_ARGS=--maxlines=200 -boptparse --no-override --no-shadowbuiltin
 GBP_VERSION=gbp/gbp_version.py
 VERSION_ENT=docs/version.ent
 
index 04fef6a..f9defd5 100644 (file)
@@ -369,23 +369,15 @@ class GitRepository(object):
             args = [ '-m', msg ] + args
         GitCommand("update-ref")(args)
 
-    def commit_tree(self, tree, msg, parents, author=None, email=None,
-                    date=None, committer_name=None, committer_email=None,
-                    committer_date=None):
+    def commit_tree(self, tree, msg, parents, author={}, committer={}):
         """Commit a tree with commit msg 'msg' and parents 'parents'"""
         extra_env = {}
-        if author:
-            extra_env['GIT_AUTHOR_NAME'] = author
-        if email:
-            extra_env['GIT_AUTHOR_EMAIL'] = email
-        if date:
-            extra_env['GIT_AUTHOR_DATE'] = date
-        if committer_name:
-            extra_env['GIT_COMMITTER_NAME'] = committer_name
-        if committer_email:
-            extra_env['GIT_COMMITTER_EMAIL'] = committer_email
-        if committer_date:
-            extra_env['GIT_COMMITTER_DATE'] = committer_date
+        for key, val in author.items():
+            if val:
+                extra_env['GIT_AUTHOR_%s' % key.upper()] = val
+        for key, val in committer.items():
+            if val:
+                extra_env['GIT_COMMITTER_%s' % key.upper()] = val
 
         args = [ tree ]
         for parent in parents:
@@ -394,20 +386,17 @@ class GitRepository(object):
         return sha1
 
     def commit_dir(self, unpack_dir, msg, branch, other_parents=None,
-                   author = None, email = None, date = None,
-                   committer_name = None, committer_email = None,
-                   committer_date = None):
+                   author={}, committer={}):
         """Replace the current tip of branch 'branch' with the contents from 'unpack_dir'
            @param unpack_dir: content to add
            @param msg: commit message to use
            @param branch: branch to add the contents of unpack_dir to
            @param parents: additional parents of this commit
-           @param author: commit with author name 'author'
-           @param email: commit with author email 'email'
-           @param date: set author date to 'date'
-           @param committer_author: commit with committer name 'commiter_name'
-           @param committer_email: commit with committer email 'commiter_email'
-           @param committer_date: set commit date to 'date'"""
+           @param author: commit with author information from author
+           @type author: dict with keys 'name', 'email', 'date'
+           @param committer_author: commit with committer information from committer
+           @type comitter: dict with keys 'name', 'email', 'date'"""
+
         self.__check_path()
         git_index_file = os.path.join(self.path, '.git', 'gbp_index')
         try:
@@ -436,10 +425,7 @@ class GitRepository(object):
                     parents += [ sha ]
 
         commit = self.commit_tree(tree=tree, msg=msg, parents=parents,
-                                  author=author, email=email, date=date,
-                                  committer_name=committer_name,
-                                  committer_email=committer_email,
-                                  committer_date=committer_date)
+                                  author=author, committer=committer)
         if not commit:
             raise GbpError, "Failed to commit tree"
         self.update_ref("refs/heads/%s" % branch, commit, cur)
index 2a6ef00..4c774ac 100755 (executable)
@@ -107,12 +107,10 @@ def apply_debian_patch(repo, unpack_dir, src, options, parents):
                                  "Imported Debian patch %s" % version,
                                  branch = options.debian_branch,
                                  other_parents = parents,
-                                 author = author,
-                                 email = email,
-                                 date = date,
-                                 committer_date = [None, date][options.author_committer_date],
-                                 committer_name = [None, author][options.author_committer],
-                                 committer_email = [None, email][options.author_committer],)
+                                 author=dict(name=author, email = email, date = date),
+                                 committer=dict(name=[None, author][options.author_committer],
+                                                email=[None, email][options.author_committer],
+                                                date=[None, date][options.author_committer_date]))
 
         gitTag(build_tag(options.debian_tag, version),
                msg="Debian release %s" % version, commit=commit)