This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Trailing Whitespace


As I've tried, .

I have my editor set to trim all trailing whitespace, because trailing
whitespace is never desirable.

However, since other people have in times past committed code that
*does* contain trailing whitespace, this creates noise when I'm trying
to create a patch.

Therefore, I suggest that someone create a commit that removes all the
trailing whitespace. The pressing need is to apply this to gdb/ but
there is no reason it couldn't be applied to other parts if need be.

A commit that does nothing besides change trailing whitespace is *not*
harmful to the history, because git-blame and other tools can all
ignore whitespace.

Therefore, the only consideration is whether this will cause problems
for people with changes that are not yet committed in the main repo.
The script at the end of this message demonstrates how to avoid
problems with all 4 of the local branch strategies that I know about.

But first, the script to clean up after it:

#!/bin/bash -eu
# clean.sh
# Make the directory effectively empty
read -p 'Press enter to rm a bunch of directories, ^C to cancel'
rm -rf remote
rm -rf init
rm -rf whitespace
for repo in retv args
do
    rm -rf $repo
    for strategy in merge rebase git_patch dumb_patch
    do
        rm -rf $repo-$strategy
    done
done



#!/bin/bash -eu
# dirty.sh
# Run from an effectively empty directory
! test -f remote
! test -f init
! test -f whitespace
for repo in retv args
do
    ! test -f $repo
    for strategy in merge rebase git_patch dumb_patch
    do
        ! test -f $repo-$strategy
    done
done

# first set up the repo and contents
git init --bare remote
git clone remote init
cd init
echo 'int main() {  ' > file.c
echo '    return 0;' >> file.c
echo '}'             >> file.c
git add file.c
git commit -m 'init'
git push origin master
cd ..

# Two different cases representing people's non-committed changes.
# one is diff on the same line and one is on a nearby line
git clone remote retv
cd retv
sed 's/0/1/' -i file.c
git add -u
git commit -m retv
git branch retv # for backup
cd ..

git clone remote args
cd args
sed 's/()/(int argc, char **argv)/' -i file.c
git commit -a -m args
git branch args # for backup
cd ..

# Then make the whitespace change
git clone remote whitespace
cd whitespace
sed 's/[[:space:]]\+$//' -i file.c
git commit -a -m 'whitespace'
git push
cd ..

strategy_merge() {
    # cannot be used until we ditch changelogs
    # preferred strategy for many projects
    git pull -X ignore-space-at-eol --no-edit
}

strategy_rebase() {
    # best approach given changelogs
    # preferred strategy for many projects
    git pull --rebase -X ignore-space-at-eol
}

strategy_git_patch() {
    # historical approach from when patches had to be mailed around
    # still works fairly well
    git format-patch HEAD^
    git fetch
    git reset --hard origin/master
    git am --ignore-whitespace 0001-$repo.patch
}

strategy_dumb_patch() {
    # not recommended - no advantages, several disadvantages over git_patch
    git show > dumb.diff
    git fetch
    git reset --hard origin/master
    patch --ignore-whitespace -p1 < dumb.diff
    git add -u
    git commit -m $repo
}

for repo in retv args
do
    for strategy in merge rebase git_patch dumb_patch
    do
        echo in $repo, using $strategy
        cp -a $repo $repo-$strategy
        cd $repo-$strategy
        strategy_$strategy
        cd ..
    done
done
echo Done


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]