Bug 882101 - toggle trailing whitespace in client.py update_nss/nspr must be based on old state, r=wtc
authorKai Engert <kaie@kuix.de>
Mon, 24 Jun 2013 16:39:22 +0200
changeset 136285 0b06da71de7e
parent 136255 8a9410b02e6e
child 136286 fcb5b279f477
push id24880
push userphilringnalda@gmail.com
push dateTue, 25 Jun 2013 04:54:35 +0000
treeherdermozilla-central@bc569033125a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerswtc
bugs882101
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 882101 - toggle trailing whitespace in client.py update_nss/nspr must be based on old state, r=wtc
client.py
--- a/client.py
+++ b/client.py
@@ -90,16 +90,41 @@ def toggle_trailing_blank_line(depname):
 
   if not lines[-1].strip():
       # trailing line is blank, removing it
       open(depname, "wb").writelines(lines[:-1])
   else:
       # adding blank line
       open(depname, "ab").write("\n")
 
+def get_trailing_blank_line_state(depname):
+  lines = open(depname, "r").readlines()
+  if not lines:
+      print >>sys.stderr, "unexpected short file"
+      return "no blank line"
+
+  if not lines[-1].strip():
+      return "has blank line"
+  else:
+      return "no blank line"
+
+def update_nspr_or_nss(tag, depfile, destination, hgpath):
+  print "reverting to HG version of %s to get its blank line state" % depfile
+  check_call_noisy([options.hg, 'revert', depfile])
+  old_state = get_trailing_blank_line_state(depfile)
+  print "old state of %s is: %s" % (depfile, old_state)
+  do_hg_replace(destination, hgpath, tag, HG_EXCLUSIONS, options.hg)
+  new_state = get_trailing_blank_line_state(depfile)
+  print "new state of %s is: %s" % (depfile, new_state)
+  if old_state == new_state:
+    print "toggling blank line in: ", depfile
+    toggle_trailing_blank_line(depfile)
+  tag_file = destination + "/TAG-INFO"
+  print >>file(tag_file, "w"), tag
+
 o = OptionParser(usage="client.py [options] update_nspr tagname | update_nss tagname | update_libffi tagname | update_webidlparser tagname")
 o.add_option("--skip-mozilla", dest="skip_mozilla",
              action="store_true", default=False,
              help="Obsolete")
 
 o.add_option("--cvs", dest="cvs", default=os.environ.get('CVS', 'cvs'),
              help="The location of the cvs binary")
 o.add_option("--cvsroot", dest="cvsroot",
@@ -114,26 +139,22 @@ except IndexError:
     o.print_help()
     sys.exit(2)
 
 if action in ('checkout', 'co'):
     print >>sys.stderr, "Warning: client.py checkout is obsolete."
     pass
 elif action in ('update_nspr'):
     tag, = args[1:]
-    do_hg_replace('nsprpub', 'https://hg.mozilla.org/projects/nspr',
-	              tag, HG_EXCLUSIONS, options.hg)
-    print >>file("nsprpub/TAG-INFO", "w"), tag
-    toggle_trailing_blank_line("nsprpub/config/prdepend.h")
+    depfile = "nsprpub/config/prdepend.h"
+    update_nspr_or_nss(tag, depfile, 'nsprpub', 'https://hg.mozilla.org/projects/nspr')
 elif action in ('update_nss'):
     tag, = args[1:]
-    do_hg_replace('security/nss', 'https://hg.mozilla.org/projects/nss',
-	              tag, HG_EXCLUSIONS, options.hg)
-    print >>file("security/nss/TAG-INFO", "w"), tag
-    toggle_trailing_blank_line("security/nss/coreconf/coreconf.dep")
+    depfile = "security/nss/coreconf/coreconf.dep"
+    update_nspr_or_nss(tag, depfile, 'security/nss', 'https://hg.mozilla.org/projects/nss')
 elif action in ('update_libffi'):
     tag, = args[1:]
     if not options.cvsroot:
         options.cvsroot = CVSROOT_LIBFFI
     do_cvs_export(LIBFFI_DIRS, tag, options.cvsroot, options.cvs)
 elif action in ('update_webidlparser'):
     tag, = args[1:]
     do_hg_replace(WEBIDLPARSER_DIR, WEBIDLPARSER_REPO, tag, WEBIDLPARSER_EXCLUSIONS, options.hg)