[GRASS-dev] Code re-indentation: done.

Developers,

GRASS 6.4.svn and 7.0.svn re-indentation is done in SVN.
It took longer than expected but now it's done.

Steps to do (read carefully):
a) if you don't have local, unsubmitted changes: svn up

b) if you have local, unsubmitted changes:
    - first run:
           tools/grass_indent.sh <file.c>
       and/or
           tools/grass_indent.sh <file.h>
      on *each* file with local changes.
    - then: svn up

Hope it works out all easy for you.
Now code changes can be submitted again.

Happy hacking,
Markus

I have discovered that we overlooked
lib/external/*
to be taken out from reformatting.

Is there an easy way to revert a set of files to their respective
previous versions?
svn revert only works with unsubmitted changes.
Didn't find any other useful reference...

Thanks
Markus

Hi,

2008/8/5 Markus Neteler <neteler@osgeo.org>:

I have discovered that we overlooked
lib/external/*
to be taken out from reformatting.

Is there an easy way to revert a set of files to their respective
previous versions?
svn revert only works with unsubmitted changes.
Didn't find any other useful reference...

svn cat -r PREV [file] > [file]

?

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa *

Markus Neteler wrote:

I have discovered that we overlooked
lib/external/*
to be taken out from reformatting.

Is there an easy way to revert a set of files to their respective
previous versions?
svn revert only works with unsubmitted changes.
Didn't find any other useful reference...

  find lib/external -type f -name '*.[ch]' | \
  while read file ; do
    svn merge -c -32526 $file
  done

Here, 32526 is the revision corresponding to the indenting of the
trunk. Passing a negative revision to "svn merge -c" will "unmerge"
that change.

That's how I reverted the Togl changes. There is quite a lot of
preprocessor use in Togl, and some of it confuses indent. Also,
retaining the original formatting may make it easier to update to a
future version.

Another thing which seemed to confuse indent is initialising an array
of structures, like the following from raster/r.series/main.c:

  struct menu
  {
  ....
  } menu = {
      {c_ave, 0, "average", "average value"},
      {c_count, 1, "count", "count of non-NULL cells"},
  ...
  };

For some reason, it reformatted it like:

      {
      c_ave, 0, "average", "average value"}, {
      c_count, 1, "count", "count of non-NULL cells"}, {
  ...

I'm sure that we'll encounter a few more idiosyncrasies over time. It
wouldn't have been realistic to verify ~3500 C source files manually
before committing.

--
Glynn Clements <glynn@gclements.plus.com>

Hi,

2008/8/5 Glynn Clements <glynn@gclements.plus.com>:

[...]

I'm sure that we'll encounter a few more idiosyncrasies over time. It
wouldn't have been realistic to verify ~3500 C source files manually
before committing.

btw what to do with message indent e.g.

G_message(_

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa *

Hi,

2008/8/5 Martin Landa <landa.martin@gmail.com>:

[...]

sorry, here is complete message

---

btw what to do with messages indented like

G_message(_
                  (...));

manually fix when fixing/updating code to?

G_message(_(...));

Martin

--
Martin Landa <landa.martin gmail.com> * http://gama.fsv.cvut.cz/~landa *

Martin Landa wrote:

btw what to do with messages indented like

G_message(_
                  (...));

Damn; I thought that not specifying -l would prevent this from
happening.

manually fix when fixing/updating code to?

G_message(_(...));

We can fix them automatically:

  find . -type f -name '*.c' | xargs grep -l '(_$' | \
  while read file ; do sed -i -e '/(_$/{;N;s/\n[ \t]*//;}' $file ; done

[Note: using \t in a character set is a GNU extension; other versions
of sed need a literal tab character.]

--
Glynn Clements <glynn@gclements.plus.com>

Martin Landa wrote:

> btw what to do with messages indented like
> G_message(_
> (...));

Glynn:

Damn; I thought that not specifying -l would prevent this
from happening.

> manually fix when fixing/updating code to?
>
> G_message(_(...));

We can fix them automatically:

  find . -type f -name '*.c' | xargs grep -l '(_$' | \
  while read file ; do sed -i -e '/(_$/{;N;s/\n[
\t]*//;}' $file ; done

[Note: using \t in a character set is a GNU extension;
other versions of sed need a literal tab character.]

see also
http://article.gmane.org/gmane.comp.gis.grass.devel/27382
http://article.gmane.org/gmane.comp.gis.grass.devel/27387

Hamish

On Tue, Aug 5, 2008 at 9:11 PM, Glynn Clements <glynn@gclements.plus.com> wrote:

Markus Neteler wrote:

I have discovered that we overlooked
lib/external/*
to be taken out from reformatting.

Is there an easy way to revert a set of files to their respective
previous versions?
svn revert only works with unsubmitted changes.
Didn't find any other useful reference...

       find lib/external -type f -name '*.[ch]' | \
       while read file ; do
               svn merge -c -32526 $file
       done

Here, 32526 is the revision corresponding to the indenting of the
trunk. Passing a negative revision to "svn merge -c" will "unmerge"
that change.

It didn't work like this:

[neteler@markus grass70]$ find lib/external -type f -name '*.[ch]' | \

while read file ; do
      svn merge -c -32526 $file
done

svn: REPORT request failed on '/grass/!svn/vcc/default'
svn: Cannot replace a directory from within
svn: REPORT request failed on '/grass/!svn/vcc/default'
svn: Cannot replace a directory from within
svn: REPORT request failed on '/grass/!svn/vcc/default'
svn: Cannot replace a directory from within
svn: REPORT request failed on '/grass/!svn/vcc/default'
svn: Cannot replace a directory from within

AFAIK because https://svn.osgeo.org/grass/grass/trunk is lacking.
I tried some other ways to yet no avail.

Markus

Markus Neteler wrote:

>> I have discovered that we overlooked
>> lib/external/*
>> to be taken out from reformatting.
>>
>> Is there an easy way to revert a set of files to their respective
>> previous versions?
>> svn revert only works with unsubmitted changes.
>> Didn't find any other useful reference...
>
> find lib/external -type f -name '*.[ch]' | \
> while read file ; do
> svn merge -c -32526 $file
> done
>
> Here, 32526 is the revision corresponding to the indenting of the
> trunk. Passing a negative revision to "svn merge -c" will "unmerge"
> that change.

It didn't work like this:

[neteler@markus grass70]$ find lib/external -type f -name '*.[ch]' | \
> while read file ; do
> svn merge -c -32526 $file
> done
svn: REPORT request failed on '/grass/!svn/vcc/default'
svn: Cannot replace a directory from within

Oops; it needs to be done from within the directory:

  find lib/external -type f -name '*.[ch]' | \
  while read file ; do
    ( cd ${file%/*} && svn merge -c -32526 ${file##*/} )
  done

But that's likely to be inefficient; in this case, you can just use:

  cd lib/external/shapelib
  svn merge -c -32526 .

[BWidget is Tcl/Tk; there are no C source files.]

--
Glynn Clements <glynn@gclements.plus.com>

On Tue, Aug 5, 2008 at 11:17 PM, Glynn Clements
<glynn@gclements.plus.com> wrote:

Martin Landa wrote:

btw what to do with messages indented like

G_message(_
                  (...));

Damn; I thought that not specifying -l would prevent this from
happening.

manually fix when fixing/updating code to?

G_message(_(...));

We can fix them automatically:

       find . -type f -name '*.c' | xargs grep -l '(_$' | \
       while read file ; do sed -i -e '/(_$/{;N;s/\n[ \t]*//;}' $file ; done

[Note: using \t in a character set is a GNU extension; other versions
of sed need a literal tab character.]

Excellent.
Fixed in 6.4.svn and 7.0.svn.

Also lib/external/shapelib formatting is reverted.

@ALL: please update asap from SVN to avoid local conflicts.

Markus

On Tue, Aug 5, 2008 at 11:17 PM, Glynn Clements
<glynn@gclements.plus.com> wrote:

Martin Landa wrote:

btw what to do with messages indented like

G_message(_
                  (...));

Damn; I thought that not specifying -l would prevent this from
happening.

manually fix when fixing/updating code to?

G_message(_(...));

We can fix them automatically:

       find . -type f -name '*.c' | xargs grep -l '(_$' | \
       while read file ; do sed -i -e '/(_$/{;N;s/\n[ \t]*//;}' $file ; done

[Note: using \t in a character set is a GNU extension; other versions
of sed need a literal tab character.]

I have added this gettext polishing trick to
tools/grass_indent.sh

Using this script you can format easily the file indentation to the new standard
before submitting to SVN.

Markus

Markus Neteler wrote:

>> btw what to do with messages indented like
>>
>> G_message(_
>> (...));
>
> Damn; I thought that not specifying -l would prevent this from
> happening.
>
>> manually fix when fixing/updating code to?
>>
>> G_message(_(...));
>
> We can fix them automatically:
>
> find . -type f -name '*.c' | xargs grep -l '(_$' | \
> while read file ; do sed -i -e '/(_$/{;N;s/\n[ \t]*//;}' $file ; done
>
> [Note: using \t in a character set is a GNU extension; other versions
> of sed need a literal tab character.]

I have added this gettext polishing trick to
tools/grass_indent.sh

However, this only catches some of the cases; there are also cases
where the underscore isn't preceded by a left parenthesis, e.g. the
->description fields of parser options.

A more general solution, is:

  find . -type f -name '*.c' | xargs grep -l '\<_$' | \
  while read file ; do sed -i -e '/[( \t]_$/{;N;s/\n[ \t]*//;}' $file ; done

[Almost the same as before, but with different regexps.]

I have made this change to grass_indent.sh, and also committed the
fixed files.

--
Glynn Clements <glynn@gclements.plus.com>

On Tue, Aug 12, 2008 at 2:09 AM, Glynn Clements
<glynn@gclements.plus.com> wrote:

Markus Neteler wrote:

...

I have added this gettext polishing trick to
tools/grass_indent.sh

However, this only catches some of the cases; there are also cases
where the underscore isn't preceded by a left parenthesis, e.g. the
->description fields of parser options.

A more general solution, is:

       find . -type f -name '*.c' | xargs grep -l '\<_$' | \
       while read file ; do sed -i -e '/[( \t]_$/{;N;s/\n[ \t]*//;}' $file ; done

[Almost the same as before, but with different regexps.]

I have made this change to grass_indent.sh, and also committed the
fixed files.

Great.
I have fixed 6.4.svn accordingly. Please all update...

Markus
(who wonders why we didn't invent tools/grass_indent.sh some years ago)