changeset 46477:3c360ab2688d

narrow: add --no-backup option for narrowing Most of our users at Google use Mercurial on a file system that keeps backups of previous versions of all files, including those in `.hg/`. They therefore don't need a separate backup in the file system when narrowing their repo (which they typically do by running `hg tracked --auto-remove-includes`). Backups can be very slow. `hg strip` already has a `--no-backup` option. This patch adds the same option to `hg tracked --removeinclude/--addexclude`. Differential Revision: https://phab.mercurial-scm.org/D9951
author Martin von Zweigbergk <martinvonz@google.com>
date Wed, 03 Feb 2021 13:55:58 -0800
parents 4f5e9a77ff7a
children db9e33beb0fb
files hgext/narrow/narrowcommands.py tests/test-narrow-trackedcmd.t tests/test-narrow.t
diffstat 3 files changed, 28 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/narrow/narrowcommands.py	Fri Jan 29 15:23:07 2021 +0100
+++ b/hgext/narrow/narrowcommands.py	Wed Feb 03 13:55:58 2021 -0800
@@ -214,6 +214,7 @@
     newincludes,
     newexcludes,
     force,
+    backup,
 ):
     oldmatch = narrowspec.match(repo.root, oldincludes, oldexcludes)
     newmatch = narrowspec.match(repo.root, newincludes, newexcludes)
@@ -272,7 +273,7 @@
                 hg.clean(repo, urev)
             overrides = {(b'devel', b'strip-obsmarkers'): False}
             with ui.configoverride(overrides, b'narrow'):
-                repair.strip(ui, unfi, tostrip, topic=b'narrow')
+                repair.strip(ui, unfi, tostrip, topic=b'narrow', backup=backup)
 
         todelete = []
         for f, f2, size in repo.store.datafiles():
@@ -442,6 +443,12 @@
         ),
         (
             b'',
+            b'backup',
+            True,
+            _(b'back up local changes when narrowing'),
+        ),
+        (
+            b'',
             b'update-working-copy',
             False,
             _(b'update working copy when the store has changed'),
@@ -639,6 +646,7 @@
                 newincludes,
                 newexcludes,
                 opts[b'force_delete_local_changes'],
+                opts[b'backup'],
             )
             # _narrow() updated the narrowspec and _widen() below needs to
             # use the updated values as its base (otherwise removed includes
--- a/tests/test-narrow-trackedcmd.t	Fri Jan 29 15:23:07 2021 +0100
+++ b/tests/test-narrow-trackedcmd.t	Wed Feb 03 13:55:58 2021 -0800
@@ -110,6 +110,8 @@
       --clear                      whether to replace the existing narrowspec
       --force-delete-local-changes forces deletion of local changes when
                                    narrowing
+      --[no-]backup                back up local changes when narrowing
+                                   (default: on)
       --update-working-copy        update working copy when the store has
                                    changed
    -e --ssh CMD                    specify ssh command to use
--- a/tests/test-narrow.t	Fri Jan 29 15:23:07 2021 +0100
+++ b/tests/test-narrow.t	Wed Feb 03 13:55:58 2021 -0800
@@ -492,3 +492,20 @@
   searching for changes
   looking for unused includes to remove
   found no unused includes
+Test --no-backup
+  $ hg tracked --addinclude d0 --addinclude d2 -q
+  $ hg unbundle .hg/strip-backup/*-narrow.hg -q
+  $ rm .hg/strip-backup/*
+  $ hg tracked --auto-remove-includes --no-backup
+  comparing with ssh://user@dummy/master
+  searching for changes
+  looking for unused includes to remove
+  path:d0
+  path:d2
+  remove these unused includes (yn)? y
+  looking for local changes to affected paths
+  deleting data/d0/f.i
+  deleting data/d2/f.i
+  deleting meta/d0/00manifest.i (tree !)
+  deleting meta/d2/00manifest.i (tree !)
+  $ ls .hg/strip-backup/