Re: [PATCH] Remove perl dependency from git-submodule.sh
- From
Johannes Sixt <j.sixt@viscovery.net>
- Date
- May 31, 2012, 09:19 UTC
- Message-ID
- <4FC73788.6070805@viscovery.net>
- In-Reply-To
- <1338454126-30441-1-git-send-email-iveqy@iveqy.com>
Am 5/31/2012 10:48, schrieb Fredrik Gustafsson:
> Rewrote a perl section in sh.
> The code may be a bit slower (doing grep on strings instead of using > perl-lists).
"A lot" would be more correct on Windows :-) But it can be avoided, I think.
Show 23 quoted lines
> module_list()
> {
> + unmerged=
> + null_sha1=0000000000000000000000000000000000000000
> git ls-files --error-unmatch --stage -- "$@" |
> - perl -e '
> - my %unmerged = ();
> - my ($null_sha1) = ("0" x 40);
> - while (<STDIN>) {
> - chomp;
> - my ($mode, $sha1, $stage, $path) =
> - /^([0-7]+) ([0-9a-f]{40}) ([0-3])\t(.*)$/;
> - next unless $mode eq "160000";
> - if ($stage ne "0") {
> - if (!$unmerged{$path}++) {
> - print "$mode $null_sha1 U\t$path\n";
> - }
> - next;
> - }
> - print "$_\n";
> - }
> - '
> + while read mode sha1 stage pathBe prepared for backslashes in the path name:
while read -r mode sha1 stage path
> + do > + if test $mode -eq 160000
$mode is not a number, but a string: test "$mode" = 160000
> + then > + if test $stage -ne 0
That $stage looks like a number is of no importance, either.
Show 6 quoted lines
> + then > + if test -z "$(echo $unmerged | grep "|$path|")" > + then > + echo "$mode $null_sha1 U\t$path" > + fi > + unmerged="$unmerged|$path|"
IIUC, the purpose of $unmerged and this check is to avoid that an unmerged path is dumped for each stage that is listed by ls-files. Therefore it should be sufficient to just check that the current path is different from the last path.
Show 8 quoted lines
> + else > + echo "$mode $sha1 $stage\t$path" > + fi > + fi > + done > } > > #
-- Hannes