[PATCH 14/20] list_tags: Stop executing a command

Mathieu Bridon bochecha at fedoraproject.org
Wed Oct 29 12:57:12 UTC 2014


From: Mathieu Bridon <bochecha at daitauha.fr>

We have a Git API, let's use it, instead of constantly running commands
in subprocesses.

This even results in simpler code!

In addition, it makes the method actually testable. Without this, the
tag list was printed in the stdout **of the subprocess**, which is
unaccessible to the parent process, and as such to the tests. The tests
couldn't even verify what the library had done!
---
 src/pyrpkg/__init__.py | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/src/pyrpkg/__init__.py b/src/pyrpkg/__init__.py
index 03fb493..9070ac0 100644
--- a/src/pyrpkg/__init__.py
+++ b/src/pyrpkg/__init__.py
@@ -1381,19 +1381,21 @@ class Commands(object):
         os.chdir(oldpath)
         return(uploadfiles)
 
-    def list_tag(self, tagname=None):
+    def list_tag(self, tagname='*'):
         """Create a list of all tags in the repository which match a given tagname.
 
-        The optional `tagname` argument may contain a '*' glob.
+        The optional `tagname` argument may be a shell glob (it is matched
+        with fnmatch).
 
         """
 
-        cmd = ['git', 'tag']
-        cmd.extend(['-l'])
-        if tagname and tagname != '*':
-            cmd.extend([tagname])
-        # make it so
-        self._run_command(cmd)
+        tags = map(lambda t: t.name, self.repo.tags)
+
+        if tagname is not '*':
+            tags = filter(lambda t: fnmatch.fnmatch(t, tagname), tags)
+
+        for tag in tags:
+            print(tag)
 
     def new(self):
         """Return changes in a repo since the last tag"""
-- 
2.1.0



More information about the rel-eng mailing list