hg status not showing empty dirs out of dirstate

Andrea Arcangeli andrea at suse.de
Mon Jun 5 23:35:24 CDT 2006


Hello,

hg status doesn't show the empty directories. This annoys me a bit
because I like strict behaviour and I like to see if there's some
garbage around (this makes life easier for people to write correct
distclean or setup.py clean -a procedures). So I'd prefer to change hg
status to show dirs by default (optionally would be ok too, but there's
no option to do that at the moment). This means 'hg status -nu | xargs
rm' won't be a clean command anymore if we make it by default. It'll
still work as good as before, but it will spawn some error too (but now
it will also show if you left dir garbage around).  The code in this
area happens to be a bit weird as well since there's a path in there
that can't ever trigger ("np can't be in dc"), I just dropped it and
coverted it for my basically opposite usage.

This does the trick for me:

diff -r fa4c11751367 -r 29842fde1aa3 mercurial/dirstate.py
--- a/mercurial/dirstate.py	Sun Jun 04 18:05:52 2006 +0100
+++ b/mercurial/dirstate.py	Tue Jun 06 06:28:36 2006 +0200
@@ -329,6 +329,9 @@ class dirstate(object):
     # 'm' the file was only in the dirstate and not in the tree
     # and st is the stat result if the file was found in the directory.
     #
+    # 'd' means the directory was found in the directory tree but it's not
+    # part of the dirstate.
+    #
     # dc is an optional arg for the current dirstate.  dc is not modified
     # directly by this function, but might be modified by your statmatch call.
     #
@@ -363,8 +366,8 @@ class dirstate(object):
                         ds = os.path.join(nd, f +'/')
                         if statmatch(ds, st):
                             work.append(p)
-                        if statmatch(np, st) and np in dc:
-                            yield 'm', np, st
+                        if statmatch(np, st) and not [ x for x in dc if ds in x ]:
+                            yield 'd', np, st
                     elif statmatch(np, st):
                         if self.supported_type(np, st):
                             yield 'f', np, st

The 'm' retval will allow for further extensions of the 'status' command
to only show unknown files and not directories. So for example you could
extend it to do 'hg status -unf | xargs rm; hg status -unF| xargs rmdir'
to make a clean command (though I wonder if it's really necessary since
'hg status -un | xargs rm; hg status -un| xargs rmdir' just works if you
ignore the cosmetics).

andrea at opteron:~/devel/python/network> mkdir x
andrea at opteron:~/devel/python/network> cd x
andrea at opteron:~/devel/python/network/x> hg init
andrea at opteron:~/devel/python/network/x> mkdir x
andrea at opteron:~/devel/python/network/x> hg status
? x
andrea at opteron:~/devel/python/network/x> 

Thanks.


More information about the Mercurial mailing list