Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / common / hooks / pre-receive.hook
1 #!/usr/bin/env python
2 import sys
3 import os
4 import subprocess
5
6 # This server-side pre-receive hook is to be put and activated in all modules
7 # that depend on the common submodule.
8 #
9 # It will check whether any modifications to the common 'submodule file' has a
10 # a valid commit SHA1 that exists in the common module.
11
12 def commit_exists(sha1, gitdir):
13     """Returns True if the sha1 is a valid commit in the given
14     git directory"""
15     # FIXME: We're using 'git show' for the time being, but there's a small
16     # risk that there might be a valid SHA1 for a non-commit object.
17     env = os.environ.copy()
18     env["GIT_DIR"] = gitdir
19     sub = subprocess.Popen(["git", "show", sha1], env=env,
20                            stdout=subprocess.PIPE,
21                            stderr=subprocess.PIPE)
22     while True:
23         res = sub.poll()
24         if res != None:
25             return res == 0
26
27 # location of the common git module
28 COMMON_GIT_DIR = "/git/gstreamer/common.git"
29
30 pushvalid = True
31 error_badcommon = False
32 error_badcommit = False
33
34 print "=> Checking for integrity of common submodule changes"
35 print
36
37 for line in sys.stdin.readlines():
38     # ref is the ref to be modified
39     # old is the old commit it was pointing to
40     # new is the new commit it was pointing to
41     old, new, ref = line.split(' ', 2)
42
43     # 1. Get the latest change to common (if there was any changes)
44     sub = subprocess.Popen(["git", "diff", "%s..%s" % (old, new, ), "--", "common"],
45                            stdout=subprocess.PIPE)
46     stdout, stderr = sub.communicate()
47     if stdout != "":
48         # Format of submodule special files
49         # Subproject commit <SHA1>
50
51         # we get a diff, therefore only grab the last line
52         lastline = stdout.strip().rsplit('\n',1)[-1]
53         if not lastline.startswith("+Subproject commit"):
54             # this is bad, it means the diff has changed to something completely
55             # different
56             continue
57         subsha1 = lastline.rsplit(' ', 1)[-1]
58         print "   Pack wants common to point to", subsha1
59         if not commit_exists(subsha1, COMMON_GIT_DIR):
60             print "   /!\\ Commit does not exist in common git module /!\\"
61             print "   /!\\ for ref", ref
62             pushvalid = False
63             break
64
65         # 2. Figure out if that commit exists in the common submodule
66         # (use GIT_DIR to execute commands in that directory)
67
68     # Get the commit message
69     sub = subprocess.Popen(["git", "log", "--format=%s",
70             "%s..%s" % (old, new, )], stdout=subprocess.PIPE)
71     stdout, stderr = sub.communicate()
72     if stdout != "":
73         for line in stdout.strip().rsplit('\n',1):
74             if line.startswith("!"):
75                 error_badcommit = True
76                 pushvalid = False
77                 break
78
79 if pushvalid:
80     print "   Incoming packet valid, proceeding to actual commit"
81     sys.exit(0)
82 else:
83     if error_badcommit:
84         print "   Attempting to push commits with commit messages that start"
85         print "   with '!'.  Commit messages starting with '!' are reserved"
86         print "   for private branches to prevent the commits from accidentally"
87         print "   getting to the main repository."
88     if error_badcommon:
89         print "   Attempting to push commits containing modifications to common"
90         print "   that have not been commited to the actuall common module."
91         print
92         print "   First push your changes to common/ before pushing the changes"
93         print "   to the module using it."
94     sys.exit(-1)
95