[X2Go-Commits] [maintenancescripts] 01/01: git/hooks/update-script._irkerhook.py_: merge in upstream changes.

git-admin at x2go.org git-admin at x2go.org
Sun Aug 20 14:50:34 CEST 2017


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository maintenancescripts.

commit 0ae3e41ccad0c25ac97119ed9ee02ed74d0d429c
Author: Mihai Moldovan <ionic at ionic.de>
Date:   Sun Aug 20 14:47:14 2017 +0200

    git/hooks/update-script._irkerhook.py_: merge in upstream changes.
---
 git/hooks/update-script._irkerhook.py_ | 43 ++++++++++++++++++++++++----------
 1 file changed, 31 insertions(+), 12 deletions(-)

diff --git a/git/hooks/update-script._irkerhook.py_ b/git/hooks/update-script._irkerhook.py_
index 889dbd4..672fc95 100755
--- a/git/hooks/update-script._irkerhook.py_
+++ b/git/hooks/update-script._irkerhook.py_
@@ -16,6 +16,8 @@
 
 # The default location of the irker proxy, if the project configuration
 # does not override it.
+#
+# SPDX-License-Identifier: BSD-2-Clause
 default_server = "ionic.de"
 IRKER_PORT = 10614
 
@@ -30,24 +32,31 @@ urlprefixmap = {
     "cgit": "http://%(host)s/cgi-bin/cgit.cgi/%(repo)s/commit/?id=",
     }
 
-# By default, ship to the freenode #commits channel
+# By default, ship to the freenode #commits list
 default_channels = "irc://chat.freenode.net/#x2go"
 
 #
 # No user-serviceable parts below this line:
 #
 
-version = "2.11"
+version = "2.17"
 
-import os, sys, commands, socket, urllib, subprocess, locale, datetime, re
+import os, sys, socket, urllib2, subprocess, locale, datetime, re
 from pipes import quote as shellquote
+
 try:
-    import simplejson as json   # Faster, also makes us Python-2.5-compatible
+    import simplejson as json	# Faster, also makes us Python-2.5-compatible
 except ImportError:
     import json
 
+try:
+    getstatusoutput = subprocess.getstatusoutput
+except AttributeError:
+    import commands
+    getstatusoutput = commands.getstatusoutput
+
 def do(command):
-    return unicode(commands.getstatusoutput(command)[1], locale.getlocale()[1] or 'UTF-8').encode(locale.getlocale()[1] or 'UTF-8')
+    return unicode(getstatusoutput(command)[1], locale.getlocale()[1] or 'UTF-8').encode(locale.getlocale()[1] or 'UTF-8')
 
 class Commit:
     def __init__(self, extractor, commit):
@@ -71,13 +80,13 @@ class Commit:
             urlprefix = urlprefixmap.get(self.urlprefix, self.urlprefix)
             webview = (urlprefix % self.__dict__) + self.commit
             try:
-                if urllib.urlopen(webview).getcode() == 404:
-                    raise IOError
+                # See it the url is accessible
+                res = urllib2.urlopen(webview)
                 if self.tinyifier and self.tinyifier.lower() != "none":
                     try:
-                        # Didn't get a retrieval error or 404 on the web
+                        # Didn't get a retrieval error on the web
                         # view, so try to tinyify a reference to it.
-                        self.url = open(urllib.urlretrieve(self.tinyifier + webview)[0]).read()
+                        self.url = urllib2.urlopen(self.tinyifier + webview).read()
                         try:
                             self.url = self.url.decode('UTF-8')
                         except UnicodeError:
@@ -86,9 +95,15 @@ class Commit:
                         self.url = webview
                 else:
                     self.url = webview
+            except urllib2.HTTPError as e:
+                if e.code == 401:
+                    # Authentication error, so we assume the view is valid
+                    self.url = webview
+                else:
+                    self.url = ""
             except IOError as e:
-                print "IOError: {0}:{1}".format(e.errno, e.strerror)
                 self.url = ""
+                print "IOError: {0}:{1}".format(e.errno, e.strerror)
         res = self.template % self.__dict__
         return unicode(res, 'UTF-8') if not isinstance(res, unicode) else res
 
@@ -277,7 +292,11 @@ class GitExtractor(GenericExtractor):
         else: # self.revformat == 'describe'
             commit.rev = do("git describe %s 2>/dev/null" % shellquote(commit.commit))
         if not commit.rev:
-            commit.rev = commit.commit[:12]
+            # Query git for the abbreviated hash
+            commit.rev = do("git log -1 '--pretty=format:%h' " + shellquote(commit.commit))
+            if self.urlprefix in ('gitweb', 'cgit'):
+                # Also truncate the commit used for the announced urls
+                commit.commit = commit.rev
         # Extract the meta-information for the commit
         parent = ''
         if self.rebase == '':
@@ -452,7 +471,7 @@ def ship(extractor, commit, debug):
                          shellquote(json.dumps(metadata.__dict__)))
         data = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout.read()
         try:
-            metadata.__dict__.update(json.loads(data), encoding='utf-8')
+            metadata.__dict__.update(json.loads(data))
         except ValueError:
             sys.stderr.write("irkerhook.py: could not decode JSON: %s\n" % data)
             raise SystemExit(1)

--
Alioth's /srv/git/code.x2go.org/maintenancescripts.git//..//_hooks_/post-receive-email on /srv/git/code.x2go.org/maintenancescripts.git


More information about the x2go-commits mailing list