vcssync: pass exclude_dirs to linearize_git_repo (
bug 1363635); r?gps
exclude_dirs was accidentally dropped during a refactor.
MozReview-Commit-ID: 92fQuk6KiJF
--- a/vcssync/mozvcssync/cli.py
+++ b/vcssync/mozvcssync/cli.py
@@ -188,17 +188,18 @@ def linearize_git_to_hg():
args.hg_repo_path,
git_push_url=args.git_push_url,
hg_push_url=args.hg_push_url,
move_to_subdir=args.move_to_subdir,
find_copies_harder=args.find_copies_harder,
skip_submodules=args.skip_submodules,
similarity=args.similarity,
shamap_s3_upload_url=args.shamap_s3_upload_url,
- git_commit_rewriter_args=rewriter_args)
+ git_commit_rewriter_args=rewriter_args,
+ exclude_dirs=args.exclude_dirs)
except RewriteError as e:
logger.error('abort: %s' % str(e))
sys.exit(1)
except subprocess.CalledProcessError:
sys.exit(1)
def overlay_hg_repos_cli():
--- a/vcssync/mozvcssync/git2hg.py
+++ b/vcssync/mozvcssync/git2hg.py
@@ -27,17 +27,18 @@ logger = logging.getLogger(__name__)
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,
- git_commit_rewriter_args=None):
+ git_commit_rewriter_args=None,
+ exclude_dirs=None):
"""Linearize a Git repo to an hg repo by squashing merges.
Many Git repositories (especially those on GitHub) have an excessive
number of merge commits and don't practice "every commit is
good/bisectable." When converting these repositories to Mercurial, it is
often desirable to ignore the non-first-parent ancestry so the result has
more readable history.
@@ -108,17 +109,18 @@ def linearize_git_repo_to_hg(git_source_
rewriter = commit_metadata_rewriter(git_repo,
source_repo=git_source_url,
**git_commit_rewriter_args)
git_state = linearize_git_repo(
git_repo,
b'heads/%s' % ref,
- commit_rewriter=rewriter)
+ commit_rewriter=rewriter,
+ exclude_dirs=exclude_dirs)
if git_push_url:
subprocess.check_call([b'git', b'push', b'--mirror', git_push_url],
cwd=git_repo_path)
rev_map = os.path.join(hg_repo_path, b'.hg', b'shamap')
def maybe_push_hg():
new file mode 100644
--- /dev/null
+++ b/vcssync/tests/test-linearize-git-to-hg-exclude-dirs.t
@@ -0,0 +1,115 @@
+#require hg41+
+
+ $ . $TESTDIR/vcssync/tests/helpers.sh
+
+ $ standardgitrepo grepo > /dev/null 2>&1
+ $ linearize-git-to-hg file://$TESTTMP/grepo master grepo-source grepo-dest > /dev/null 2>&1
+
+Directories can be excluded when linearizing
+
+ $ cd grepo
+ $ mkdir dir1
+ $ echo 0 > dir1/dir1_file0
+ $ echo 1 > dir1/dir1_file1
+ $ git add --all
+ $ git commit -m ignore > /dev/null
+ $ cd ..
+
+ $ linearize-git-to-hg file://$TESTTMP/grepo master grepo-source grepo-dest --exclude-dir dir1
+ From file://$TESTTMP/grepo
+ a447b9b..ad3f6b5 master -> master
+ linearizing 1 commits from heads/master (ad3f6b56f7320d386c2ce2574b0573d1ad88773b to ad3f6b56f7320d386c2ce2574b0573d1ad88773b)
+ 1/1 ad3f6b56f7320d386c2ce2574b0573d1ad88773b ignore
+ dropping ad3f6b56f7320d386c2ce2574b0573d1ad88773b because no tree changes
+ 0 commits from heads/master converted; original: ad3f6b56f7320d386c2ce2574b0573d1ad88773b; rewritten: aea30981234cf6848489e0ccf541fbf902b27aca
+ all Git commits have already been converted; not doing anything
+ $ cd grepo-dest
+ $ hg co tip > /dev/null
+ $ ls
+ bar
+ file0-copied-with-move
+ file0-copy0
+ file0-copy1
+ file0-copy2
+ file0-moved-with-copy
+ file1
+ file1-20
+ file1-50
+ file1-80
+ foo
+ $ cd ..
+
+--exclude-dir works multiple times
+
+ $ cd grepo
+ $ mkdir dir2
+ $ echo 0 > dir2/file0
+ $ git add --all
+ $ git commit -m ignore-multi > /dev/null
+ $ cd ..
+
+ $ linearize-git-to-hg file://$TESTTMP/grepo master grepo-source grepo-dest --exclude-dir dir1 --exclude-dir dir2
+ From file://$TESTTMP/grepo
+ ad3f6b5..04ac57d master -> master
+ linearizing 1 commits from heads/master (04ac57d95ed6dd954cceead6f95fcbb047c80760 to 04ac57d95ed6dd954cceead6f95fcbb047c80760)
+ 1/1 04ac57d95ed6dd954cceead6f95fcbb047c80760 ignore-multi
+ dropping 04ac57d95ed6dd954cceead6f95fcbb047c80760 because no tree changes
+ 0 commits from heads/master converted; original: 04ac57d95ed6dd954cceead6f95fcbb047c80760; rewritten: aea30981234cf6848489e0ccf541fbf902b27aca
+ all Git commits have already been converted; not doing anything
+ $ cd grepo-dest
+ $ hg co tip > /dev/null
+ $ ls
+ bar
+ file0-copied-with-move
+ file0-copy0
+ file0-copy1
+ file0-copy2
+ file0-moved-with-copy
+ file1
+ file1-20
+ file1-50
+ file1-80
+ foo
+ $ cd ..
+
+Excluding an intermediate directory works --exclude-dir ignore2/subdir0
+
+ $ cd grepo
+ $ mkdir -p dir3/subdir0
+ $ echo 0 > dir3/file0
+ $ echo 1 > dir3/subdir0/file1
+ $ git add --all
+ $ git commit -m ignore-multi > /dev/null
+ $ cd ..
+
+ $ linearize-git-to-hg file://$TESTTMP/grepo master grepo-source grepo-dest --exclude-dir dir1 --exclude-dir dir2 --exclude-dir dir3/subdir0
+ From file://$TESTTMP/grepo
+ 04ac57d..36d2de4 master -> master
+ linearizing 1 commits from heads/master (36d2de48325568c9bce9ff67d66ed6aca4c9b2e9 to 36d2de48325568c9bce9ff67d66ed6aca4c9b2e9)
+ 1/1 36d2de48325568c9bce9ff67d66ed6aca4c9b2e9 ignore-multi
+ 1 commits from heads/master converted; original: 36d2de48325568c9bce9ff67d66ed6aca4c9b2e9; rewritten: 95c25188f219f5c68497863faba183fbbbbfae04
+ converting 1 Git commits
+ scanning source...
+ sorting...
+ converting...
+ 0 ignore-multi
+ 1 Git commits converted to Mercurial; previous tip: 10:7d80acaa161029d9e746e3125e7cc0916406403f; current tip: 11:4c82e4e6f1944acf408939cee63fc5c078de73df
+ $ cd grepo-dest
+ $ hg co tip > /dev/null
+ $ ls -R
+ bar
+ dir3
+ file0-copied-with-move
+ file0-copy0
+ file0-copy1
+ file0-copy2
+ file0-moved-with-copy
+ file1
+ file1-20
+ file1-50
+ file1-80
+ foo
+
+ ./dir3:
+ file0
+ $ cd ..