Patchwork D6265: narrow: also warn when not deleting untracked or ignored files

login
register
mail settings
Submitter phabricator
Date April 17, 2019, 5:59 p.m.
Message ID <differential-rev-PHID-DREV-7k3m7eirtmwmmnrt2gf5-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/39704/
State Superseded
Headers show

Comments

phabricator - April 17, 2019, 5:59 p.m.
martinvonz created this revision.
Herald added a reviewer: durin42.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6265

AFFECTED FILES
  mercurial/narrowspec.py
  tests/test-narrow-share.t

CHANGE DETAILS




To: martinvonz, durin42, #hg-reviewers
Cc: mercurial-devel
phabricator - April 17, 2019, 7:51 p.m.
rdamazio added inline comments.

INLINE COMMENTS

> narrowspec.py:310
> +    for f in sorted(trackeddirty + status.unknown + status.ignored):
> +        if f in unknownset:
> +            repo.ui.status(_('not deleting unknown file %s\n') % uipathfn(f))

Just do a loop for each one? You probably also don't need them to be sets.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6265

To: martinvonz, durin42, #hg-reviewers
Cc: rdamazio, mercurial-devel
phabricator - April 17, 2019, 9:16 p.m.
martinvonz added inline comments.

INLINE COMMENTS

> rdamazio wrote in narrowspec.py:310
> Just do a loop for each one? You probably also don't need them to be sets.

I did it that way at first. Then I changed it because I figured it might be a harder to read if dirty, untracked, and ignored files in single a directory were spread out in three places. OTOH, both `hg status` and `hg revert` already do it that way, so I guess we should follow them. I'll change it back here.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D6265

To: martinvonz, durin42, #hg-reviewers
Cc: rdamazio, mercurial-devel

Patch

diff --git a/tests/test-narrow-share.t b/tests/test-narrow-share.t
--- a/tests/test-narrow-share.t
+++ b/tests/test-narrow-share.t
@@ -28,6 +28,9 @@ 
   $ hg clone --narrow ssh://user@dummy/remote main -q \
   > --include d1 --include d3 --include d5 --include d7
 
+Ignore file called "ignored"
+  $ echo ignored > main/.hgignore
+
   $ hg share main share
   updating working directory
   4 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -55,15 +58,19 @@ 
 # Make d3/f dirty
   $ echo x >> main/d3/f
   $ echo y >> main/d3/g
+  $ touch main/d3/ignored
+  $ touch main/d3/untracked
   $ hg add main/d3/g
   $ hg -R main st
   M d3/f
   A d3/g
+  ? d3/untracked
 # Make d5/f not match the dirstate timestamp even though it's clean
   $ sleep 2
   $ hg -R main st
   M d3/f
   A d3/g
+  ? d3/untracked
   $ hg -R main debugdirstate --no-dates
   n 644          2 set                 d1/f
   n 644          2 set                 d3/f
@@ -90,6 +97,8 @@ 
   $ hg -R main tracked --update-working-copy
   not deleting possibly dirty file d3/f
   not deleting possibly dirty file d3/g
+  not deleting ignored file d3/ignored
+  not deleting unknown file d3/untracked
   not deleting possibly dirty file d5/f
 # d1/f, d3/f, d3/g and d5/f should no longer be reported
   $ hg -R main files
@@ -99,6 +108,8 @@ 
   $ find main/d* -type f | sort
   main/d3/f
   main/d3/g
+  main/d3/ignored
+  main/d3/untracked
   main/d5/f
   main/d7/f
 
@@ -131,6 +142,8 @@ 
   $ hg -R main st --all
   M d3/f
   ? d3/g
+  ? d3/untracked
+  I d3/ignored
   C d1/f
   C d7/f
 
diff --git a/mercurial/narrowspec.py b/mercurial/narrowspec.py
--- a/mercurial/narrowspec.py
+++ b/mercurial/narrowspec.py
@@ -293,8 +293,8 @@ 
     removedmatch = matchmod.differencematcher(oldmatch, newmatch)
 
     ds = repo.dirstate
-    lookup, status = ds.status(removedmatch, subrepos=[], ignored=False,
-                               clean=True, unknown=False)
+    lookup, status = ds.status(removedmatch, subrepos=[], ignored=True,
+                               clean=True, unknown=True)
     trackeddirty = status.modified + status.added
     clean = status.clean
     if assumeclean:
@@ -304,8 +304,16 @@ 
         trackeddirty.extend(lookup)
     _deletecleanfiles(repo, clean)
     uipathfn = scmutil.getuipathfn(repo)
-    for f in sorted(trackeddirty):
-        repo.ui.status(_('not deleting possibly dirty file %s\n') % uipathfn(f))
+    unknownset = set(status.unknown)
+    ignoredset = set(status.ignored)
+    for f in sorted(trackeddirty + status.unknown + status.ignored):
+        if f in unknownset:
+            repo.ui.status(_('not deleting unknown file %s\n') % uipathfn(f))
+        elif f in ignoredset:
+            repo.ui.status(_('not deleting ignored file %s\n') % uipathfn(f))
+        else:
+            repo.ui.status(_('not deleting possibly dirty file %s\n') %
+                           uipathfn(f))
     for f in clean + trackeddirty:
         ds.drop(f)