vcssync: rename variables so it is clear they store paths; r?glob draft
authorGregory Szorc <gps@mozilla.com>
Mon, 17 Apr 2017 17:23:54 -0700
changeset 10798 8a1f0c4b45932781071c48f1f2a996d4ecd63a7c
parent 10797 e8fcccfbd3cefd4d0ec23dabaaa109d489955c02
child 10799 08cb3b648e641ab10de634f45a6e1a7f2bada316
child 10800 748d03c60c713d0fd4aaf64e41addee9a1c23b04
push id1628
push userbmo:gps@mozilla.com
push dateTue, 18 Apr 2017 00:56:14 +0000
reviewersglob
vcssync: rename variables so it is clear they store paths; r?glob An upcoming commit will introduce a dulwich.repo.Repo into this function. To reduce confusion as to what variables refer to, this commit explicitly adds "path" to variables that hold paths. MozReview-Commit-ID: FNCXOjX06yT
vcssync/mozvcssync/git2hg.py
--- a/vcssync/mozvcssync/git2hg.py
+++ b/vcssync/mozvcssync/git2hg.py
@@ -15,17 +15,17 @@ import hglib
 from .gitrewrite.linearize import (
     linearize_git_repo,
 )
 
 
 logger = logging.getLogger(__name__)
 
 
-def linearize_git_repo_to_hg(git_source_url, ref, git_repo, hg_repo,
+def linearize_git_repo_to_hg(git_source_url, ref, git_repo_path, hg_repo_path,
                              git_push_url=None,
                              hg_push_url=None,
                              move_to_subdir=None,
                              find_copies_harder=False,
                              skip_submodules=False,
                              similarity=50,
                              shamap_s3_upload_url=None,
                              **kwargs):
@@ -39,17 +39,17 @@ def linearize_git_repo_to_hg(git_source_
 
     This function will perform such a conversion.
 
     The source Git repository to convert is specified by ``git_source_url``
     and ``ref``, where ``git_source_url`` is a URL understood by ``git
     clone`` and ``ref`` is a Git ref, like ``master``. Only converting
     a single ref is allowed.
 
-    The source Git repository is locally cloned to the path ``git_repo``.
+    The source Git repository is locally cloned to the path ``git_repo_path``.
     This directory will be created if necessary.
 
     If ``git_push_url`` is specified, the local clone (including converted
     commits) will be pushed to that URL.
 
     If ``hg_push_url`` is specified, the converted Mercurial repo will be
     pushed to that URL.
 
@@ -74,50 +74,50 @@ def linearize_git_repo_to_hg(git_source_
        SHA-1 of ``tip`` Mercurial changeset before conversion. 40 0's if the
        repo was empty.
     hg_after_tip_rev
        Numeric revision of ``tip`` Mercurial changeset before conversion.
     hg_after_tip_node
        SHA-1 of ``tip`` Mercurial changeset after conversion.
     """
     # Many processes execute with cwd=/ so normalize to absolute paths.
-    git_repo = os.path.abspath(git_repo)
-    hg_repo = os.path.abspath(hg_repo)
+    git_repo_path = os.path.abspath(git_repo_path)
+    hg_repo_path = os.path.abspath(hg_repo_path)
 
     # Create Git repo, if necessary.
-    if not os.path.exists(git_repo):
-        subprocess.check_call([b'git', b'init', b'--bare', git_repo])
+    if not os.path.exists(git_repo_path):
+        subprocess.check_call([b'git', b'init', b'--bare', git_repo_path])
         # We don't need to set up a remote because we use an explicit refspec
         # during fetch.
 
     subprocess.check_call([b'git', b'fetch', b'--no-tags', git_source_url,
                            b'heads/%s:heads/%s' % (ref, ref)],
-                          cwd=git_repo)
+                          cwd=git_repo_path)
 
     if git_push_url:
         subprocess.check_call([b'git', b'push', b'--mirror', git_push_url],
-                              cwd=git_repo)
+                              cwd=git_repo_path)
 
     git_state = linearize_git_repo(
-        git_repo,
+        git_repo_path,
         b'heads/%s' % ref,
         source_repo=git_source_url,
         **kwargs)
 
     if git_push_url:
         subprocess.check_call([b'git', b'push', b'--mirror', git_push_url],
-                              cwd=git_repo)
+                              cwd=git_repo_path)
 
-    rev_map = os.path.join(hg_repo, b'.hg', b'shamap')
+    rev_map = os.path.join(hg_repo_path, b'.hg', b'shamap')
 
     def maybe_push_hg():
         if not hg_push_url:
             return
 
-        with hglib.open(hg_repo) as hrepo:
+        with hglib.open(hg_repo_path) as hrepo:
             logger.warn('checking for outgoing changesets to %s' % hg_push_url)
             outgoing = hrepo.outgoing(path=hg_push_url)
             if not outgoing:
                 logger.warn('all changesets already in remote; no push '
                             'necessary')
                 return
 
             # We may want to add force=True and newbranch=True here. But
@@ -164,25 +164,25 @@ def linearize_git_repo_to_hg(git_source_
         b'convert.git.similarity=%d' % similarity,
     ]
 
     if find_copies_harder:
         hg_config.append(b'convert.git.findcopiesharder=true')
     if skip_submodules:
         hg_config.append(b'convert.git.skipsubmodules=true')
 
-    if not os.path.exists(hg_repo):
-        hglib.init(hg_repo)
+    if not os.path.exists(hg_repo_path):
+        hglib.init(hg_repo_path)
 
-    with hglib.open(hg_repo) as hrepo:
+    with hglib.open(hg_repo_path) as hrepo:
         tip = hrepo[b'tip']
         before_hg_tip_rev = tip.rev()
         before_hg_tip_node = tip.node()
 
-    shamap_path = os.path.join(hg_repo, b'.hg', b'shamap')
+    shamap_path = os.path.join(hg_repo_path, b'.hg', b'shamap')
     def get_shamap_hash():
         if not os.path.exists(shamap_path):
             return None
 
         with open(shamap_path, 'rb') as fh:
             return hashlib.sha256(fh.read()).digest()
 
     old_shamap_hash = get_shamap_hash()
@@ -199,27 +199,27 @@ def linearize_git_repo_to_hg(git_source_
     with tempfile.NamedTemporaryFile('wb') as tf:
         if move_to_subdir:
             tf.write(b'rename . %s\n' % move_to_subdir)
 
         tf.flush()
 
         args.extend([b'--filemap', tf.name])
 
-        args.extend([git_repo, hg_repo, rev_map])
+        args.extend([git_repo_path, hg_repo_path, rev_map])
 
         # hglib doesn't appear to stream output very well. So just invoke
         # `hg` directly.
         env = dict(os.environ)
         env[b'HGPLAIN'] = b'1'
         env[b'HGENCODING'] = b'utf-8'
 
         subprocess.check_call(args, cwd='/', env=env)
 
-    with hglib.open(hg_repo) as hrepo:
+    with hglib.open(hg_repo_path) as hrepo:
         tip = hrepo[b'tip']
         after_hg_tip_rev = tip.rev()
         after_hg_tip_node = tip.node()
 
     if before_hg_tip_rev == -1:
         convert_count = after_hg_tip_rev + 1
     else:
         convert_count = after_hg_tip_rev - before_hg_tip_rev