@@ -1673,10 +1673,6 @@ EXAMPLES
1673
1673
"useful in determining what to filter in a subsequent run. "
1674
1674
"Will not modify your repo." ))
1675
1675
1676
- refs = parser .add_argument_group (title = _ ("Git References" ))
1677
- refs .add_argument ('--refs' , nargs = '*' , default = ['--all' ],
1678
- help = argparse .SUPPRESS )
1679
-
1680
1676
path = parser .add_argument_group (title = _ ("Filtering based on paths "
1681
1677
"(see also --filename-callback)" ))
1682
1678
path .add_argument ('--invert-paths' , action = 'store_false' , dest = 'inclusive' ,
@@ -1846,9 +1842,10 @@ EXAMPLES
1846
1842
"CALLBACKS section below." ))
1847
1843
1848
1844
desc = _ (
1849
- "Specifying alternate source or target locations will disable some \n "
1850
- "auxiliary steps such as disconnecting the origin remote, and avoiding\n "
1851
- "mixing new and old history." )
1845
+ "Specifying alternate source or target locations implies --partial,\n "
1846
+ "except that the normal default for --replace-refs is used. However,\n "
1847
+ "unlike normal uses of --partial, this doesn't risk mixing old and new\n "
1848
+ "history since the old and new histories are in different repositories." )
1852
1849
location = parser .add_argument_group (title = _ ("Location to filter from/to" ),
1853
1850
description = desc )
1854
1851
location .add_argument ('--source' , type = os .fsencode ,
@@ -1862,6 +1859,29 @@ EXAMPLES
1862
1859
misc .add_argument ('--force' , '-f' , action = 'store_true' ,
1863
1860
help = _ ("Rewrite history even if the current repo does not look "
1864
1861
"like a fresh clone." ))
1862
+ misc .add_argument ('--partial' , action = 'store_true' ,
1863
+ help = _ ("Do a partial history rewrite, resulting in the mixture of "
1864
+ "old and new history. This implies a default of "
1865
+ "update-no-add for --replace-refs, disables rewriting "
1866
+ "refs/remotes/origin/* to refs/heads/*, disables removing "
1867
+ "of the 'origin' remote, disables removing unexported refs, "
1868
+ "disables expiring the reflog, and disables the automatic "
1869
+ "post-filter gc. Also, this modifies --tag-rename and "
1870
+ "--refname-callback options such that instead of replacing "
1871
+ "old refs with new refnames, it will instead create new "
1872
+ "refs and keep the old ones around. Use with caution." ))
1873
+ # WARNING: --refs presents a problem with become-degenerate pruning:
1874
+ # * Excluding a commit also excludes its ancestors so when some other
1875
+ # commit has an excluded ancestor as a parent we have no way of
1876
+ # knowing what it is an ancestor of without doing a special
1877
+ # full-graph walk.
1878
+ misc .add_argument ('--refs' , nargs = '+' ,
1879
+ help = _ ("Limit history rewriting to the specified refs. Implies "
1880
+ "--partial. In addition to the normal caveats of --partial "
1881
+ "(mixing old and new history, no automatic remapping of "
1882
+ "refs/remotes/origin/* to refs/heads/*, etc.), this also may "
1883
+ "cause problems for pruning of degenerate empty merge "
1884
+ "commits when negative revisions are specified." ))
1865
1885
1866
1886
misc .add_argument ('--dry-run' , action = 'store_true' ,
1867
1887
help = _ ("Do not change the repository. Run `git fast-export` and "
@@ -2065,6 +2085,12 @@ EXAMPLES
2065
2085
args .strip_blobs_with_ids = set (f .read ().split ())
2066
2086
else :
2067
2087
args .strip_blobs_with_ids = set ()
2088
+ if (args .partial or args .refs ) and not args .replace_refs :
2089
+ args .replace_refs = 'update-no-add'
2090
+ if args .refs or args .source or args .target :
2091
+ args .partial = True
2092
+ if not args .refs :
2093
+ args .refs = ['--all' ]
2068
2094
return args
2069
2095
2070
2096
class RepoAnalyze (object ):
@@ -3475,8 +3501,6 @@ class RepoFilter(object):
3475
3501
.format (decode (self ._fe_filt )))
3476
3502
3477
3503
def _migrate_origin_to_heads (self ):
3478
- if self ._args .dry_run or self ._args .source or self ._args .target :
3479
- return
3480
3504
refs_to_migrate = set (x for x in self ._orig_refs
3481
3505
if x .startswith (b'refs/remotes/origin/' ))
3482
3506
if not refs_to_migrate :
@@ -3532,7 +3556,7 @@ class RepoFilter(object):
3532
3556
# Remove unused refs
3533
3557
exported_refs , imported_refs = self .get_exported_and_imported_refs ()
3534
3558
refs_to_nuke = exported_refs - imported_refs
3535
- if self ._args .source or self . _args . target :
3559
+ if self ._args .partial :
3536
3560
refs_to_nuke = set ()
3537
3561
if refs_to_nuke and self ._args .debug :
3538
3562
print ("[DEBUG] Deleting the following refs:\n " +
@@ -3690,7 +3714,8 @@ class RepoFilter(object):
3690
3714
start = time .time ()
3691
3715
if not self ._input and not self ._output :
3692
3716
self ._run_sanity_checks ()
3693
- self ._migrate_origin_to_heads ()
3717
+ if not self ._args .dry_run and not self ._args .partial :
3718
+ self ._migrate_origin_to_heads ()
3694
3719
self ._setup_input (use_done_feature = True )
3695
3720
self ._setup_output ()
3696
3721
assert self ._sanity_checks_handled
@@ -3725,7 +3750,7 @@ class RepoFilter(object):
3725
3750
self ._save_marks_files ()
3726
3751
3727
3752
# Notify user how long it took, before doing a gc and such
3728
- repack = (not self ._args .source and not self . _args . target )
3753
+ repack = (not self ._args .partial )
3729
3754
msg = "New history written in {:.2f} seconds..."
3730
3755
if repack :
3731
3756
msg = "New history written in {:.2f} seconds; now repacking/cleaning..."
@@ -3749,7 +3774,7 @@ class RepoFilter(object):
3749
3774
# Write out data about run
3750
3775
self ._record_metadata (self .results_tmp_dir (), self ._orig_refs )
3751
3776
3752
- # Nuke the reflogs and repack
3777
+ # If repack, then nuke the reflogs and repack. If reset, do a reset --hard
3753
3778
reset = not GitUtils .is_repository_bare (target_working_dir )
3754
3779
RepoFilter .cleanup (target_working_dir , repack , reset ,
3755
3780
run_quietly = self ._args .quiet ,
0 commit comments