Implementation of manifest defined githooks

When working within a team or corporation it is often
useful/required to use predefined git templates. This
change teaches repo to use a per-remote git hook template
structure.

The implementation is done as a continuation of the
existing projecthook functionality. The terminology is
therefore defined as projecthooks.

The downloaded projecthooks are stored in the .repo
directory as a metaproject separating them from the users
project forest.

The projecthooks are downloaded and set up when doing a
repo init and updated for each new repo init.

When downloading a mirror the projecthooks gits are
not added to the bare forest since the intention is to
ensure that the latest are used (allows for company policy
enforcement).

The projecthooks are defined in the manifest file in the
remote element as a subnode, the name refers to the
project name on the server referred to in the remote.
<remote name="myremote ..>
   <projecthook name="myprojecthookgit" revision="myrevision"/>
</remote>

The hooks found in the projecthook revision supersede
the stock hooks found in repo. This removes the need for
updating the projecthook gits for repo stock hook changes.

Change-Id: I6796b7b0342c1f83c35f4b3e46782581b069a561
Signed-off-by: Patrik Ryd <patrik.ryd@stericsson.com>
Signed-off-by: Ian Kumlien <ian.kumlien@gmail.com>
diff --git a/manifest_xml.py b/manifest_xml.py
index 890c954..9472a08 100644
--- a/manifest_xml.py
+++ b/manifest_xml.py
@@ -64,7 +64,9 @@
                fetch=None,
                manifestUrl=None,
                review=None,
-               revision=None):
+               revision=None,
+               projecthookName=None,
+               projecthookRevision=None):
     self.name = name
     self.fetchUrl = fetch
     self.manifestUrl = manifestUrl
@@ -72,6 +74,8 @@
     self.reviewUrl = review
     self.revision = revision
     self.resolvedFetchUrl = self._resolveFetchUrl()
+    self.projecthookName = projecthookName
+    self.projecthookRevision = projecthookRevision
 
   def __eq__(self, other):
     return self.__dict__ == other.__dict__
@@ -167,6 +171,11 @@
       e.setAttribute('review', r.reviewUrl)
     if r.revision is not None:
       e.setAttribute('revision', r.revision)
+    if r.projecthookName is not None:
+      ph = doc.createElement('projecthook')
+      ph.setAttribute('name', r.projecthookName)
+      ph.setAttribute('revision', r.projecthookRevision)
+      e.appendChild(ph)
 
   def _ParseGroups(self, groups):
     return [x for x in re.split(r'[,\s]+', groups) if x]
@@ -629,7 +638,13 @@
     if revision == '':
       revision = None
     manifestUrl = self.manifestProject.config.GetString('remote.origin.url')
-    return _XmlRemote(name, alias, fetch, manifestUrl, review, revision)
+    projecthookName = None
+    projecthookRevision = None
+    for n in node.childNodes:
+      if n.nodeName == 'projecthook':
+        projecthookName, projecthookRevision = self._ParseProjectHooks(n)
+        break
+    return _XmlRemote(name, alias, fetch, manifestUrl, review, revision, projecthookName, projecthookRevision)
 
   def _ParseDefault(self, node):
     """
@@ -933,3 +948,8 @@
       diff['added'].append(toProjects[proj])
 
     return diff
+
+  def _ParseProjectHooks(self, node):
+    name = self._reqatt(node, 'name')
+    revision = self._reqatt(node, 'revision')
+    return name, revision