On Friday October 28 2005 03:04, Matt Mackall wrote:
> hg cp a x -> x/a (with children, aka cp -r a x)
Assuming that x exists, otherwise we get a -> x (with children),
right?
> hg cp a b c x -> x/{a,b,c} (with all children, aka cp -r a b c
And here x must exist, OK.
> x) hg cp a/b x -> x/b (with all children)
Yes, similar to case 1).
> hg cp "regex:.*\.c" x -> all .c files under x
> hg cp "glob:a/*" x -> children of a under x
> hg cp "glob:a/**" x -> children of a under x, flattened
Here I am not sure to follow you. As I understand it, the walk code
matches files but not directories so "glob:a/*" will match only the
files directly under a while "glob:a/**" will match all the files in
the subtree rooted at a.
If we have d1, d2, d1/d11, d1/d12, d1/f11, d1/d11/f111 and
d1/d12/f121:
a) "hg cp d1/* d2" is equivalent to "hg cp d1/d11 d1/d12 d1/f11 d2"
provided that the shell expands '*' before it passes the line to
Mercurial. So in the docopy() function we can recursively copy of
the directories.
b) With "hg cp 'glob:d1/*' d2", docopy() (not finding a directory
named 'glob:d1/*', hopefully) passes the pattern to the walk code
which yields d1/f11 only.
c) "hg cp 'glob:d1/**' d2" -> d2/d11, d2/f111, d2/f121
So my impression is that if we drop --parents then copy/rename can
preserve the subtree structure of a directory passed in argument but
not for file or Mercurial pattern arguments.
> So something like:
>
> pats, dest = args[:-1], args[-1]
> for p in matching_files_or_dirs(pats):
> recursive_copy(p, dest)
>
> ..should cover all the possibilities.
Do you suggest here that docopy() should use a file system traversal
that includes directories in the matchable names rather than relying
on dirstate.walk()? That would work for most pattern types I guess
but how do we handle 'glob:d1/**' so that it flattens the subtrees
under d1? Wouldn't it match any directory directly under d1 and thus
yield the same result as 'glob:d1/*' (I am assuming that when a
pattern matches a directory, the traversal does not descend into
this directory)?
> > > > "hg cp --parents 'glob:d1/**' d2" -> (this is the
> > > > complicated case) copy everything under d1 to d2 while
> > > > replicating the nested tree structure under d1.
> > >
> > > And I'd rather do this without the strange --parents flag.
> >
> > Agreed.
>
> Don't we really want 'glob:d1/*' here?
It was more an attempt to make explicit what 'glob:blah**fu' would
do.
> > But we still might want to be able to do say "hg mv d1/* d2" to
> > move the everything under d1 to d2/ (directories and their
> > children included) which we currently cannot, I think.
>
> Why not?
Because the patch I originally proposed only handles the special
case where there is one source and it is a directory. If there are
more sources, they will be flattened at the destination.
Robin
|