file patterns, globbing, sparse, etc

Hollis Blanchard hollis_blanchard at mentor.com
Tue Dec 12 20:26:57 EST 2017


The plethora of Mercurial's file pattern behaviors are really confusing. 
It's only through carefully trying to compose this email for over an 
hour that I'm even starting to understand it, and that complexity is a 
barrier to adoption.

    hblancha at aurora:base.hg$ tree
    .
    ├── dir
    │   ├── dir.txt
    │   └── subdir
    │       └── subdir.txt
    ├── file.txt
    └── top.txt

    hblancha at aurora:base.hg$ echo dir/*
    dir/dir.txt dir/subdir

I want shell globbing, as seen in that 'echo' command. Except hg doesn't 
track directories, so I expect hg's shell globbing will only list dir.txt.

    hblancha at aurora:base.hg$ hg files 'dir/*'
    hblancha at aurora:base.hg$

Nope. Nothing at all. (Oops, it's a "fileset"! Certainly not what I 
expected.)

    hblancha at aurora:base.hg$ hg files --include 'dir/*'
    dir/dir.txt
    dir/subdir/subdir.txt

If I use "--include", now I get radically different behavior. I had no 
idea that would happen, but now I get my shell globs!

Except it's still not what I expected, because subdir.txt ended up 
there. (Yes, I see the fine print in 'hg help patterns' that says "For 
"-I" and "-X" options, "glob:" will match directories recursively." 
Again, not what I expected.)

    hblancha at aurora:base.hg$ hg files 'glob:dir/*'
    dir/dir.txt

Finally, here's my glob! Even though 'hg help files' said I could only 
use "filenames or filesets", not patterns, it turns out I could use 
patterns after all...

Now I just have to remember which of these three very similar methods 
I'm supposed to use, and explain it to my comrades who didn't invest the 
effort to experiment for themselves and hope they care to remember.






Now I think I've figured out how file globbing/patterns/etc works. But 
wait, it gets worse:

    hblancha at aurora:base.hg$ hg sparse --reset; hg sparse -I 'dir/subdir'; tree
    .
    └── dir
         ├──*dir.txt*
         └── subdir
             └── subdir.txt

    hblancha at aurora:base.hg$ hg sparse --reset; hg sparse -I 'glob:dir/subdir'; tree
    .
    └── dir
         └── subdir
             └── subdir.txt

We can see that 'dir/subdir' is not the same as 'glob:dir/subdir', even 
though the documentation claims it should be. Also, neither should 
display *dir.txt* (as far as I understand, from my experimentation this 
evening), so there seems to be a sparse bug here.




Also, remember how I got the glob I wanted above? Well I can't do that 
with sparse, because I can /only/ use --include, and that gets me the 
behavior I didn't want.

    hblancha at aurora:base.hg$ hg files 'glob:dir/*'
    dir/dir.txt
    hblancha at aurora:base.hg$ hg sparse --reset; hg sparse --include 'rootfilesin:dir'; tree
    .
    └── dir
         └── dir.txt
    hblancha at aurora:base.hg$ hg files 'rootfilesin:dir'
    dir/dir.txt

So now I have to use "rootfilesin:" prefix, which I've never heard of 
and have no muscle memory for, and is more annoying to type. At least it 
works in both commands, though I don't know if I'll ever want to type 
that unless I have no other choice.




I guess, in summary, my complaint is that we shouldn't have to conduct 
all these experiments to figure out how to use a fundamental technique 
like shell globbing in Mercurial. At best that slows us down; at worst 
it makes us look elsewhere, and I really don't want that. Thanks for 
listening.

-- 
Hollis Blanchard <hollis_blanchard at mentor.com>
Mentor Graphics Emulation Division

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.mercurial-scm.org/pipermail/mercurial-devel/attachments/20171212/73bb8f62/attachment.html>


More information about the Mercurial-devel mailing list