Re: Filter-branch's "move tree to subdirectory" example fails with BSD sed?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Apr 14, 2012 at 09:25:05PM +0200, Johannes Sixt wrote:

> Am 14.04.2012 18:00, schrieb Christopher Tiwald:
> > The "Move tree to subdirectory" example in the 'git filter-branch'
> > manpage fails on Mac OSX 10.7.3, but succeeds on Ubuntu 10.04.
> 
> > git init "test"
> > cd "test"
> > mkdir -p subdirA/subdirB
> > echo content > subdirA/subdirB/file
> > git add .
> > git commit -m "initial commit"
> > git ls-files -s | sed "s-\t\"*-&newsubdir/-"
> > 
> > On Mac 10.7.3 the final command outputs:
> > 100644 d95f3ad14dee633a758d2e331151e950dd13e4ed 0	subdirA/subdirB/file
> > 
> > On Ubuntu 10.04:
> > 100644 d95f3ad14dee633a758d2e331151e950dd13e4ed 0	newsubdir/subdirA/subdirB/file
> 
> Perhaps a literal TAB instead of \t makes the example work?

Yes, I suspect that is the problem, too.

> It would be difficult, though, to write this down in the manual in an
> unambiguous way.

Maybe it would be simpler to just use perl:

 git filter-branch --index-filter '
   git ls-files -s |
     perl -pe "s{\t\"?}{$&newsubdir/}" |
     GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&
   mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE
 ' HEAD

I also think tweaking the indentation and line breaks as I did above
makes it a little more readable. If we are using perl, we could
also just use "-z" to get rid of the funny quote handling.

I wish we could also get rid of the temporary index. It exists solely
for the side effect of removing the existing entries (otherwise, you get
both "foo" and "newsubdir/foo" in the resulting history). It would be
nice if there was some flag to update-index to say "before you do
anything, clear the existing index" (or I guess, "don't bother reading
the existing index"). And then result could look like:

  git filter-branch --index-filter '
    git ls-files -sz |
    perl -0pe "s{\t}{\tnewsubdir/}" |
    git update-index --from-scratch -z --index-info
  ' HEAD

which is IMHO much easier to read and understand.

-Peff
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]