Bug 1344316 Add Commit Date to libyuv README draft
authorTom Ritter <tom@mozilla.com>
Fri, 03 Mar 2017 13:02:04 -0600
changeset 493274 04f1474dbef10d67b643e2cb26045ae087f70535
parent 490570 9b668cf096aafb0d245113e319592974d2f79b33
child 494132 38360f2cf0e80f87217c2b9f1ad66699a0688682
push id47714
push userbmo:tom@mozilla.com
push dateFri, 03 Mar 2017 19:02:41 +0000
bugs1344316
milestone54.0a1
Bug 1344316 Add Commit Date to libyuv README MozReview-Commit-ID: 6EVZR6ZilH1
media/libyuv/README_MOZILLA
media/libyuv/update.py
--- a/media/libyuv/README_MOZILLA
+++ b/media/libyuv/README_MOZILLA
@@ -4,9 +4,9 @@ The source in this directory was copied 
 update.py script from media/libyuv. Any changes made relative to upstream
 should be reflected in that script, e.g. by applying patch files after the
 copy step.
 
 The upstream repository is https://chromium.googlesource.com/libyuv/libyuv
 Updates before this file was added were done manually; the last import was
 r1602 (svn).
 
-The git commit ID last used to import was 054ec37f8e31e6131c8f19eb74395d29009d6604
+The git commit ID last used to import was 054ec37f8e31e6131c8f19eb74395d29009d6604 (2017-02-21 23:59:57)
--- a/media/libyuv/update.py
+++ b/media/libyuv/update.py
@@ -2,54 +2,63 @@
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 import argparse
 import os
 import re
 import shutil
 import sys
+import datetime
 import subprocess
 import tarfile
 import urllib
 from pprint import pprint
 from StringIO import StringIO
 
 def prepare_upstream(prefix, commit=None):
     upstream_url = 'https://chromium.googlesource.com/libyuv/libyuv'
     shutil.rmtree(os.path.join(base, 'libyuv/'))
     print(upstream_url + '/+archive/' + commit + '.tar.gz')
     urllib.urlretrieve(upstream_url + '/+archive/' + commit + '.tar.gz', 'libyuv.tar.gz')
     tarfile.open('libyuv.tar.gz').extractall(path='libyuv')
     os.remove(os.path.join(base, 'libyuv.tar.gz'))
     os.chdir(base)
     return commit
 
+def get_commit_date(prefix, commit=None):
+    upstream_url = 'https://chromium.googlesource.com/libyuv/libyuv/+/' + commit
+    text = urllib.urlopen(upstream_url).readlines()
+    text = "".join(text)
+    regex = '<tr><th class="Metadata-title">committer</th><td>.+</td><td>[^\s]+ ([0-9a-zA-Z: ]+)\s*\+*[0-9]*</td></tr>'
+    date = re.search(regex, text).groups(0)[0]
+    return datetime.datetime.strptime(date, "%b %d %H:%M:%S %Y")
+
 def cleanup_upstream():
     os.remove(os.path.join(base, 'libyuv/.gitignore'))
 
 def apply_patches():
     # Patch to update gyp build files
     os.system("patch -p3 < update_gyp.patch")
     # Patch to fix build errors
     os.system("patch -p3 < fix_build_errors.patch")
     # Patch to make mjpeg printfs optional at build time
     os.system("patch -p3 < make_mjpeg_printfs_optional.patch")
     # Patch to allow disabling of inline ASM and AVX2 code
     os.system("patch -p3 < allow_disabling_asm_avx2.patch")
     # Patch to add H444ToARGB() variant
     os.system("patch -p3 < add_H444ToARGB.patch")
 
-def update_readme(commit):
+def update_readme(commit, commitdate):
     with open('README_MOZILLA') as f:
         readme = f.read()
 
     if 'The git commit ID last used to import was ' in readme:
-        new_readme = re.sub('The git commit ID last used to import was [v\.a-f0-9]+',
-            'The git commit ID last used to import was %s' % commit, readme)
+        new_readme = re.sub('The git commit ID last used to import was [v\.a-f0-9]+ \(.+\)',
+            'The git commit ID last used to import was %s (%s)' % (commit, commitdate), readme)
     else:
         new_readme = "%s\n\nThe git commit ID last used to import was %s\n" % (readme, commit)
 
     if readme != new_readme:
         with open('README_MOZILLA', 'w') as f:
             f.write(new_readme)
 
 if __name__ == '__main__':
@@ -61,15 +70,16 @@ if __name__ == '__main__':
 
     commit = args.commit
     DEBUG = args.debug
 
     base = os.path.abspath(os.curdir)
     prefix = os.path.join(base, 'libyuv/')
 
     commit = prepare_upstream(prefix, commit)
+    commitdate = get_commit_date(prefix, commit)
 
     apply_patches()
-    update_readme(commit)
+    update_readme(commit, commitdate)
 
     print('Patches applied; run "hg addremove --similarity 70 libyuv" before committing changes')
 
     cleanup_upstream()