[Treepkg-commits] r471 - trunk/treepkg

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Mon Nov 8 18:07:41 CET 2010


Author: bricks
Date: 2010-11-08 18:07:41 +0100 (Mon, 08 Nov 2010)
New Revision: 471

Modified:
   trunk/treepkg/git.py
Log:
add a tag detector for git


Modified: trunk/treepkg/git.py
===================================================================
--- trunk/treepkg/git.py	2010-11-08 16:40:19 UTC (rev 470)
+++ trunk/treepkg/git.py	2010-11-08 17:07:41 UTC (rev 471)
@@ -123,3 +123,46 @@
     def last_changed_revision(self):
         """Returns the last changed rev of the working copy"""
         return self.repository.last_changed_revision(self.localdir)
+
+    def list_tags(self, pattern):
+        output = run.capture_output(cmdexpand("git tag -l $pattern",
+            pattern=pattern), cwd=self.localdir)
+        return output.splitlines()
+
+    def get_revision(self, refname="HEAD"):
+        """Return the SHA1 sum of the latest commit"""
+        output = run.capture_output(cmdexpand("git rev-parse $id",
+            refname=refname), cwd=git_working_copy)
+        if output is None:
+            raise GitError("Cannot determine revision for %r"
+                           % git_working_copy)
+        return output.strip()
+
+class TagDetector:
+
+    """Class to detect tags from a git repository
+
+    The tags are found using the parameters:
+      url -- The url of the git repository to use
+      pattern -- A regular expression matching the tags
+    """
+
+    def __init__(self, url, pattern, localdir):
+        self.url = url
+        self.pattern = pattern
+        repo = GitRepository(url)
+        self.workingcopy = GitWorkingCopy(repo, localdir)
+
+    def newest_tag_revision(self):
+        self.workingcopy.update_or_checkout()
+        candidates = self.workingcopy.list_tags(self.pattern)
+        candidates = sorted(candidates)
+        urlrev = (None, None)
+        if candidates:
+            newest = candidates[-1]
+            try:
+                rev = self.workingcopy.get_revision(newest)
+                urlrev = (newest, rev)
+            except GitError:
+                pass
+        return urlrev



More information about the Treepkg-commits mailing list