What you can throw (on a Friday)

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

 



@ Junio C Hamano <gitster@xxxxxxxxx> wrote (2011-08-04 21:34+0200):
> Noe Rubinstein <nrubinstein@xxxxxxxxxxxxxxxxx> writes: [...]
> If a user fat-fingers an unnecessary [...]

Heh.  Note that one of the first mails i've received from this
list was the one which transported the annoyed gasp from
the-one-who-was-born-right-next-door-to-where-the-elks-live.
About scattered non-breaking spaces (U+A0).

Unfortunately that patch series has been thrown away!  And so
i think you underestimate the problem.  On my german keyboard,
f.e., i need to press ALT for all of these: []|{} (ALT + [5-9]).
!!!  Well, there *are* days where my thumb is fast enough to leave
ALT before i hit SPC ...  (But today it yet caused distress.)

After the second scissor i'll append my current pre-commit (and
thus pre-applypatch) (for nothing except to show that it's
a problem people really have to deal with).  But i already thought
about resurrecting your patch-series and reduce it to only the
whitespace check.  Because, being able to say

    exec git diff-index --check --cached $against --

instead would be much easier, because then you could simply state
and request from contributors "please adhere to the whitespace
policy of this project:"

    whitespace = trailing-space,tabwidth=4,tab-in-indent,yell-on-nbsp

> Hmm?

Well and while fooling around and getting more familiar with
git(1) i stumbled over some things which might be caused by bad
control flow instead of being desired behaviour.  After the first
scissor there is a test shell script which reproduces them.

Thanks for git(1) beside that, plastic dishes also break ...
Nice weekend all of you.

--Steffen
Ciao, sdaoden(*)(gmail.com)
ASCII ribbon campaign           ( ) More nuclear fission plants
  against HTML e-mail            X    can serve more coloured
    and proprietary attachments / \     and sounding animations

-- >8 --
#!/bin/sh

error() {
	echo >&2 Error: $*
}

add_file() {
    local f=$1
    echo $f > $f
    git add $f
    git commit -qm $f
}

origin() {
    rm -rf origin
    mkdir origin
    cd origin
    git init -q
    add_file eins
    add_file zwei
    add_file drei
    add_file vier
    add_file fuenf
    git checkout -qb devel
    add_file devel-one
    add_file devel-two
    git checkout -q master
    git tag -m vT1 vT1 HEAD
    cd ..
}

badbad_tagopt() {
    echo
    echo
    echo '1. echo git fetch will --prune away branches if --tags is set'
    echo '   (even if done so through remote.XY.tagopt config).'
    echo '   But nice: it works well again if --all is also given.'
    echo
	work() {
        echo - Am using fetch -q --prune $1 $2
		rm -rf tr1
		mkdir tr1
		cd tr1
		git init -q
		git remote add -t master -t devel -m master origin ../origin

		git fetch -q --prune $1 $2

		git branch -a | grep -F 'origin/master' || error no master branch
		git branch -a | grep -F 'origin/devel' || error no devel branch
		cd ..
		rm -rf tr1
	}


	work '' ''
	work '--tags' ''
    work '--tags' '--all'
}

lazy_ref() {
    echo
    echo
    echo 2. If you do drop/there is no remote.XY.fetch of a branch,
    echo '   but configure the remote.XY.push entry, then after'
    echo '   git push the local ref is not updated, even though'
    echo '   the push succeeded and correctly updated the target repo.'
    echo
	work() {
        echo - remote.origin.fetch will include devel branch: $#
        cp -R origin origin.save
		rm -rf tr1
		mkdir tr1
		cd tr1
		git init -q
		git remote add -t master -m master -t devel origin ../origin
        git config --local remote.origin.push \
                           +refs/heads/master:refs/heads/master
        git config --local --add remote.origin.push \
                            +refs/heads/devel:refs/heads/devel
		git fetch -q --prune
        git checkout -q master
        git checkout -q devel
        add_file test-repo-devel-branch-file

        test $# == 0 &&
            git config --local --replace-all remote.origin.fetch \
                                 +refs/heads/master:refs/remotes/origin/master
        git push -q origin

        x=$(git show-ref --hash devel | sort -u | awk '{++l} END {print l}')
        test $x == 1 || error 'local-ref mismatch'
		cd ..
		rm -rf tr1 origin
        mv origin.save origin
	}

	work YesPlease
	work
}

cd $TMPDIR
mkdir workdir
cd workdir

origin

badbad_tagopt
lazy_ref

cd ..
rm -rf workdir
exit 0
-- >8 --
#!/bin/sh
#@ git(1) pre-commit hook for dummies

#if git rev-parse --verify HEAD >/dev/null 2>&1
#then
    against=HEAD
#else
    # Initial commit: diff against an empty tree object
#   against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
#fi

# Oh no, unfortunately not: exec git diff-index --check --cached $against --
git diff --cached $against | perl -e '
    # XXX 1st version, may not be able to swallow all possible diff output yet
    my ($estat, $l, $fname) = (0, undef, undef);

    for (;;) { last if stdin() =~ /^diff/o; }
    for (;;) { head(); hunk(); }

    sub stdin {
        $l = <STDIN>;
        exit($estat) unless $l;
        chomp($l);
        return $l;
    }

    sub head {
        # Skip anything, including options and entire rename and delete diffs,
        # until we see the ---/+++ line pair
        for (;;) {
            last if $l =~ /^---/o;
            stdin();
        }

        stdin();
        die "head, 1.: cannot parse diff!" unless $l =~ /^\+\+\+ /o;
        $fname = substr($l, 4);
        $fname = substr($fname, 2) if $fname =~ /^b\//o;
    }

    sub hunk() {
        stdin();
        die "hunk, 1.: cannot parse diff!" unless $l =~ /^@@ /o;
JHUNK:
        # regex shamelessly stolen from git(1), and modified
        $l =~ /^@@ -\d+(?:,\d+)? \+(\d+)(?:,\d+)? @@/;
        my $lno = $1 - 1;

        for (;;) {
            stdin();
            return if $l =~ /^diff/o;       # Different file?
            goto JHUNK if $l =~ /^@@ /o;    # Same file, different hunk?
            next if $l =~ /^-/o;            # Ignore removals

            ++$lno;
            next if $l =~ /^ /o;
            $l = substr($l, 1);

            if (index($l, "\xA0") != -1) {
                $estat = 1;
                print "$fname:$lno: non-breaking space (NBSP, U+A0).\n";
            }
            if ($l =~ /\s+$/o) {
                $estat = 1;
                print "$fname:$lno: trailing whitespace.\n";
            }
            if ($l =~ /^(\s+)/o && $1 =~ /\x09/o) {
                $estat = 1;
                print "$fname:$lno: tabulator in indent.\n";
            }
        }
    }
    '
--
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]