[MediaWiki-commits] [Gerrit] operations/puppet[production]: git-sync-upstream: formatting and comment tweaks

2017-10-27 Thread Andrew Bogott (Code Review)
Andrew Bogott has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/386763 )

Change subject: git-sync-upstream: formatting and comment tweaks
..


git-sync-upstream: formatting and comment tweaks

* Use logging for all output
* Add timestamp to log messages
* Add a few comments
* Pedantic bd808 code style changes

Change-Id: I05beeb3bd323d00b57ebcba1afcc674470531487
---
M modules/puppetmaster/files/git-sync-upstream
1 file changed, 59 insertions(+), 36 deletions(-)

Approvals:
  Andrew Bogott: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/modules/puppetmaster/files/git-sync-upstream 
b/modules/puppetmaster/files/git-sync-upstream
index 16993fb..1b490dc 100755
--- a/modules/puppetmaster/files/git-sync-upstream
+++ b/modules/puppetmaster/files/git-sync-upstream
@@ -1,5 +1,8 @@
 #!/usr/bin/python3
-
+# Fetch new git changes from upstream repos and rebase local changes on top.
+# Rebase step is done in a temporary git clone that shares objects with the
+# repo being rebased. This helps avoid consumers of the clone seeing partial
+# application of local changes do to non-atomic operations.
 import datetime
 import logging
 import os
@@ -9,12 +12,24 @@
 # Send all git output to stdout
 # This has to be set before git is imported.
 os.environ["GIT_PYTHON_TRACE"] = 'full'
-logging.basicConfig(level=logging.INFO)
+logging.basicConfig(
+level=logging.INFO,
+format='%(asctime)s %(levelname)-8s %(name)s: %(message)s',
+datefmt='%Y-%m-%dT%H:%M:%SZ'
+)
+logging.captureWarnings(True)
+logger = logging.getLogger('sync-upstream')
 
 import git
 
 
 def rebase_repo(repo_path, track_branch):
+"""Rebase the current HEAD of the given clone on top of the given tracking
+branch of it's origin repo.
+
+:param repo_path: git clone to rebase
+:param track_branch: origin branch to track
+"""
 datestring = datetime.datetime.now().strftime('%Y%m%d%H%M')
 branchname = "oot-branch-%s" % datestring
 tagname = "snapshot-%s" % datestring
@@ -27,7 +42,7 @@
 
 # diff index against working copy
 if repo.index.diff(None):
-print("Local diffs detected.  Commit your changes!")
+logger.error("Local diffs detected.  Commit your changes!")
 return False
 
 repo.remotes.origin.fetch()
@@ -38,70 +53,78 @@
 latest_merged_commit = repo.git.merge_base(upstream_branch, "HEAD")
 
 if latest_upstream_commit == latest_merged_commit:
-print("Up-to-date: %s" % repo_path)
+logger.info("Up-to-date: %s" % repo_path)
 return True
 try:
-# Rebase in a tempdir to avoid changing the state of the current 
workdir.
-#  (Rebasing in place causes an occasional puppet race)
+# Perform rebase in a temporary workdir to avoid altering the state of
+# the current workdir. Rebasing in place can lead to Puppet using
+# files after the update but before local patches are re-applied.
 #
 # This next bit is largely cribbed from
-#  https://github.com/encukou/bin/blob/master/oot-rebase
-#
+# https://github.com/encukou/bin/blob/master/oot-rebase
 os.makedirs(tempdir)
 
 tmprepo = git.Repo.init(tempdir)
 
-# This bit of magic should prevent us from needing to create a full 
duplicate
-#  of all the objects in repo_path
-with open(os.path.join(tempdir,".git/objects/info/alternates"), "w") 
as alternates:
+# This bit of magic should prevent us from needing to create a full
+# duplicate of all the objects in repo_path.
+# See: https://git-scm.com/docs/gitrepository-layout
+alt_file = os.path.join(tempdir,".git/objects/info/alternates")
+with open(alt_file, "w") as alternates:
 alternates.write("%s/.git/objects" % repo_path)
 
 # Get ready to rebase in tmprepo:  fetch from upstream, and create and
-#  check out a branch 'oot-rebase' that matches the state of the
-#  main repo in repo_path:
-tmprepo.git.fetch("-n", repo_path,
-  "%s:oot-rebase/%s" % (current_branch, 
current_branch),
-  "%s:oot-rebase/%s" % (upstream_branch, 
upstream_branch))
+# check out a branch 'oot-rebase' that matches the state of the main
+# repo in repo_path:
+tmprepo.git.fetch(
+"-n", repo_path,
+"%s:oot-rebase/%s" % (current_branch, current_branch),
+"%s:oot-rebase/%s" % (upstream_branch, upstream_branch))
 tmprepo.git.checkout("oot-rebase/%s" % current_branch)
 
 # And... rebase.
-tmprepo.git.rebase("--preserve-merges",
-   "--stat",
-   "--strategy=recursive",
-   "--strategy-option=patience",
-   "oot-rebase/%s" % upstream_branch)
+

[MediaWiki-commits] [Gerrit] operations/puppet[production]: git-sync-upstream: formatting and comment tweaks

2017-10-26 Thread BryanDavis (Code Review)
BryanDavis has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/386763 )

Change subject: git-sync-upstream: formatting and comment tweaks
..

git-sync-upstream: formatting and comment tweaks

* Use logging for all output
* Add timestamp to log messages
* Add a few comments
* Pedantic bd808 code style changes

Change-Id: I05beeb3bd323d00b57ebcba1afcc674470531487
---
M modules/puppetmaster/files/git-sync-upstream
1 file changed, 59 insertions(+), 36 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/operations/puppet 
refs/changes/63/386763/1

diff --git a/modules/puppetmaster/files/git-sync-upstream 
b/modules/puppetmaster/files/git-sync-upstream
index 16993fb..1b490dc 100755
--- a/modules/puppetmaster/files/git-sync-upstream
+++ b/modules/puppetmaster/files/git-sync-upstream
@@ -1,5 +1,8 @@
 #!/usr/bin/python3
-
+# Fetch new git changes from upstream repos and rebase local changes on top.
+# Rebase step is done in a temporary git clone that shares objects with the
+# repo being rebased. This helps avoid consumers of the clone seeing partial
+# application of local changes do to non-atomic operations.
 import datetime
 import logging
 import os
@@ -9,12 +12,24 @@
 # Send all git output to stdout
 # This has to be set before git is imported.
 os.environ["GIT_PYTHON_TRACE"] = 'full'
-logging.basicConfig(level=logging.INFO)
+logging.basicConfig(
+level=logging.INFO,
+format='%(asctime)s %(levelname)-8s %(name)s: %(message)s',
+datefmt='%Y-%m-%dT%H:%M:%SZ'
+)
+logging.captureWarnings(True)
+logger = logging.getLogger('sync-upstream')
 
 import git
 
 
 def rebase_repo(repo_path, track_branch):
+"""Rebase the current HEAD of the given clone on top of the given tracking
+branch of it's origin repo.
+
+:param repo_path: git clone to rebase
+:param track_branch: origin branch to track
+"""
 datestring = datetime.datetime.now().strftime('%Y%m%d%H%M')
 branchname = "oot-branch-%s" % datestring
 tagname = "snapshot-%s" % datestring
@@ -27,7 +42,7 @@
 
 # diff index against working copy
 if repo.index.diff(None):
-print("Local diffs detected.  Commit your changes!")
+logger.error("Local diffs detected.  Commit your changes!")
 return False
 
 repo.remotes.origin.fetch()
@@ -38,70 +53,78 @@
 latest_merged_commit = repo.git.merge_base(upstream_branch, "HEAD")
 
 if latest_upstream_commit == latest_merged_commit:
-print("Up-to-date: %s" % repo_path)
+logger.info("Up-to-date: %s" % repo_path)
 return True
 try:
-# Rebase in a tempdir to avoid changing the state of the current 
workdir.
-#  (Rebasing in place causes an occasional puppet race)
+# Perform rebase in a temporary workdir to avoid altering the state of
+# the current workdir. Rebasing in place can lead to Puppet using
+# files after the update but before local patches are re-applied.
 #
 # This next bit is largely cribbed from
-#  https://github.com/encukou/bin/blob/master/oot-rebase
-#
+# https://github.com/encukou/bin/blob/master/oot-rebase
 os.makedirs(tempdir)
 
 tmprepo = git.Repo.init(tempdir)
 
-# This bit of magic should prevent us from needing to create a full 
duplicate
-#  of all the objects in repo_path
-with open(os.path.join(tempdir,".git/objects/info/alternates"), "w") 
as alternates:
+# This bit of magic should prevent us from needing to create a full
+# duplicate of all the objects in repo_path.
+# See: https://git-scm.com/docs/gitrepository-layout
+alt_file = os.path.join(tempdir,".git/objects/info/alternates")
+with open(alt_file, "w") as alternates:
 alternates.write("%s/.git/objects" % repo_path)
 
 # Get ready to rebase in tmprepo:  fetch from upstream, and create and
-#  check out a branch 'oot-rebase' that matches the state of the
-#  main repo in repo_path:
-tmprepo.git.fetch("-n", repo_path,
-  "%s:oot-rebase/%s" % (current_branch, 
current_branch),
-  "%s:oot-rebase/%s" % (upstream_branch, 
upstream_branch))
+# check out a branch 'oot-rebase' that matches the state of the main
+# repo in repo_path:
+tmprepo.git.fetch(
+"-n", repo_path,
+"%s:oot-rebase/%s" % (current_branch, current_branch),
+"%s:oot-rebase/%s" % (upstream_branch, upstream_branch))
 tmprepo.git.checkout("oot-rebase/%s" % current_branch)
 
 # And... rebase.
-tmprepo.git.rebase("--preserve-merges",
-   "--stat",
-   "--strategy=recursive",
-   "--strategy-option=patience",
-   "oot-rebase/%s" % upstream_branch)
+tmprepo.git.rebase(