Deduplicate some more code

fsck_repo is used in both files, so move it to utils. push_to_gerrit is
only used in manage-projects and sync_upstream is only used in
track-upstream.

Change-Id: Ia81c8a54023d5f0cac6443a6e28475b0d2243aa0
diff --git a/jeepyb/cmd/manage_projects.py b/jeepyb/cmd/manage_projects.py
index c549141..256cae3 100644
--- a/jeepyb/cmd/manage_projects.py
+++ b/jeepyb/cmd/manage_projects.py
@@ -339,16 +339,6 @@
     return None
 
 
-def fsck_repo(repo_path):
-    rc, out = u.git_command_output(repo_path, 'fsck --full')
-    # Check for non zero return code or warnings which should
-    # be treated as errors. In this case zeroPaddedFilemodes
-    # will not be accepted by Gerrit/jgit but are accepted by C git.
-    if rc != 0 or 'zeroPaddedFilemode' in out:
-        log.error('git fsck of %s failed:\n%s' % (repo_path, out))
-        raise Exception('git fsck failed not importing')
-
-
 def push_to_gerrit(repo_path, project, push_string, remote_url, ssh_env):
     try:
         u.git_command(repo_path, push_string % remote_url, env=ssh_env)
@@ -358,42 +348,6 @@
             "Error pushing %s to Gerrit." % project)
 
 
-def sync_upstream(repo_path, project, ssh_env, upstream_prefix):
-    u.git_command(
-        repo_path,
-        "remote update upstream --prune", env=ssh_env)
-    # Any branch that exists in the upstream remote, we want
-    # a local branch of, optionally prefixed with the
-    # upstream prefix value
-    for branch in u.git_command_output(
-            repo_path, "branch -a")[1].split('\n'):
-        if not branch.strip().startswith("remotes/upstream"):
-            continue
-        if "->" in branch:
-            continue
-        local_branch = branch.split()[0][len('remotes/upstream/'):]
-        if upstream_prefix:
-            local_branch = "%s/%s" % (
-                upstream_prefix, local_branch)
-
-        # Check out an up to date copy of the branch, so that
-        # we can push it and it will get picked up below
-        u.git_command(repo_path, "checkout -B %s %s" % (
-            local_branch, branch))
-
-    try:
-        # Push all of the local branches to similarly named
-        # Branches on gerrit. Also, push all of the tags
-        u.git_command(
-            repo_path,
-            "push origin refs/heads/*:refs/heads/*",
-            env=ssh_env)
-        u.git_command(repo_path, 'push origin --tags', env=ssh_env)
-    except Exception:
-        log.exception(
-            "Error pushing %s to Gerrit." % project)
-
-
 def process_acls(acl_config, project, ACL_DIR, section,
                  remote_url, repo_path, ssh_env, gerrit, GERRIT_GITID):
     if not os.path.isfile(acl_config):
@@ -556,7 +510,7 @@
                         find_description_override(repo_path)
                         or description)
 
-                    fsck_repo(repo_path)
+                    u.fsck_repo(repo_path)
 
                     if push_string:
                         push_to_gerrit(
diff --git a/jeepyb/cmd/track_upstream.py b/jeepyb/cmd/track_upstream.py
index 24e6245..65751b7 100644
--- a/jeepyb/cmd/track_upstream.py
+++ b/jeepyb/cmd/track_upstream.py
@@ -104,25 +104,6 @@
     u.git_command(repo_path, "checkout -B master origin/master")
 
 
-def fsck_repo(repo_path):
-    rc, out = u.git_command_output(repo_path, 'fsck --full')
-    # Check for non zero return code or warnings which should
-    # be treated as errors. In this case zeroPaddedFilemodes
-    # will not be accepted by Gerrit/jgit but are accepted by C git.
-    if rc != 0 or 'zeroPaddedFilemode' in out:
-        log.error('git fsck of %s failed:\n%s' % (repo_path, out))
-        raise Exception('git fsck failed not importing')
-
-
-def push_to_gerrit(repo_path, project, push_string, remote_url, ssh_env):
-    try:
-        u.git_command(repo_path, push_string % remote_url, env=ssh_env)
-        u.git_command(repo_path, "push --tags %s" % remote_url, env=ssh_env)
-    except Exception:
-        log.exception(
-            "Error pushing %s to Gerrit." % project)
-
-
 def sync_upstream(repo_path, project, ssh_env, upstream_prefix):
     u.git_command(
         repo_path,
@@ -235,7 +216,7 @@
                     update_local_copy(
                         repo_path, track_upstream, git_opts, ssh_env)
 
-                fsck_repo(repo_path)
+                u.fsck_repo(repo_path)
                 sync_upstream(repo_path, project, ssh_env, upstream_prefix)
 
             except Exception:
diff --git a/jeepyb/utils.py b/jeepyb/utils.py
index f79257d..f0b0265 100644
--- a/jeepyb/utils.py
+++ b/jeepyb/utils.py
@@ -154,6 +154,16 @@
         return "push %s HEAD:refs/heads/master"
 
 
+def fsck_repo(repo_path):
+    rc, out = git_command_output(repo_path, 'fsck --full')
+    # Check for non zero return code or warnings which should
+    # be treated as errors. In this case zeroPaddedFilemodes
+    # will not be accepted by Gerrit/jgit but are accepted by C git.
+    if rc != 0 or 'zeroPaddedFilemode' in out:
+        log.error('git fsck of %s failed:\n%s' % (repo_path, out))
+        raise Exception('git fsck failed not importing')
+
+
 class ProjectsRegistry(object):
     """read config from ini or yaml file.