mbox series

[0/1] git-gui: remove unused global declarations

Message ID 20191025013255.7367-1-me@yadavpratyush.com (mailing list archive)
Headers show
Series git-gui: remove unused global declarations | expand

Message

Pratyush Yadav Oct. 25, 2019, 1:32 a.m. UTC
A lot of places have unused global variables declared. Remove them.

It started as a couple of quick fixes and ended up in me writing an ugly
hacky script to catch all the instances of unused global declarations.
Lot more than I expected.

The script can be found at [0]. The script at [0] will only catch the
unused globals in 'proc's. But git-gui also has 'method's and
'constructor's. Just change '^proc' to '^constructor' or '^method'.

I manually checked each instance before removing just to be sure I'm not
doing something wrong. Still, a bit of testing would be appreciated.
Just apply this patch and go on about your business as usual. There
_should_ be no change in the behaviour. I tested some basic functions
like commit, push, etc, and they work fine for me.

[0] https://gist.github.com/prati0100/0f3ef903ad1658e76ea0b95f001b4865

Pratyush Yadav (1):
  git-gui: remove unused global declarations

 git-gui.sh                | 12 ++++--------
 lib/about.tcl             |  2 +-
 lib/blame.tcl             |  3 +--
 lib/branch_checkout.tcl   |  2 +-
 lib/branch_create.tcl     |  1 -
 lib/branch_delete.tcl     |  2 +-
 lib/browser.tcl           |  2 +-
 lib/checkout_op.tcl       |  4 +---
 lib/choose_font.tcl       |  2 +-
 lib/choose_repository.tcl |  6 +++---
 lib/class.tcl             |  1 -
 lib/commit.tcl            | 10 +++-------
 lib/console.tcl           |  2 +-
 lib/database.tcl          |  2 +-
 lib/diff.tcl              | 21 +++++++--------------
 lib/error.tcl             |  2 +-
 lib/index.tcl             |  9 ++++-----
 lib/line.tcl              |  2 +-
 lib/merge.tcl             |  5 ++---
 lib/mergetool.tcl         | 10 +++++-----
 lib/remote_add.tcl        |  5 ++---
 lib/search.tcl            |  4 ++--
 lib/sshkey.tcl            |  2 +-
 lib/tools_dlg.tcl         |  6 +++---
 24 files changed, 47 insertions(+), 70 deletions(-)

--
2.21.0

Comments

Johannes Schindelin Oct. 28, 2019, 1:15 p.m. UTC | #1
Hi Pratyush,

On Fri, 25 Oct 2019, Pratyush Yadav wrote:

> A lot of places have unused global variables declared. Remove them.
>
> It started as a couple of quick fixes and ended up in me writing an ugly
> hacky script to catch all the instances of unused global declarations.
> Lot more than I expected.
>
> The script can be found at [0].

Wouldn't it make more sense to integrate that script into a Makefile
target `check`, rather than hiding it in a gist (that might become
unavailable if GitHub goes away, as some of you seem to fear)?

> The script at [0] will only catch the unused globals in 'proc's. But
> git-gui also has 'method's and 'constructor's. Just change '^proc' to
> '^constructor' or '^method'.

Why not use `grep -E -n -e '^(proc|method)'`?

> I manually checked each instance before removing just to be sure I'm not
> doing something wrong. Still, a bit of testing would be appreciated.
> Just apply this patch and go on about your business as usual. There
> _should_ be no change in the behaviour. I tested some basic functions
> like commit, push, etc, and they work fine for me.

I would, if I used Git GUI regularly ;-)

Ciao,
Dscho

>
> [0] https://gist.github.com/prati0100/0f3ef903ad1658e76ea0b95f001b4865
>
> Pratyush Yadav (1):
>   git-gui: remove unused global declarations
>
>  git-gui.sh                | 12 ++++--------
>  lib/about.tcl             |  2 +-
>  lib/blame.tcl             |  3 +--
>  lib/branch_checkout.tcl   |  2 +-
>  lib/branch_create.tcl     |  1 -
>  lib/branch_delete.tcl     |  2 +-
>  lib/browser.tcl           |  2 +-
>  lib/checkout_op.tcl       |  4 +---
>  lib/choose_font.tcl       |  2 +-
>  lib/choose_repository.tcl |  6 +++---
>  lib/class.tcl             |  1 -
>  lib/commit.tcl            | 10 +++-------
>  lib/console.tcl           |  2 +-
>  lib/database.tcl          |  2 +-
>  lib/diff.tcl              | 21 +++++++--------------
>  lib/error.tcl             |  2 +-
>  lib/index.tcl             |  9 ++++-----
>  lib/line.tcl              |  2 +-
>  lib/merge.tcl             |  5 ++---
>  lib/mergetool.tcl         | 10 +++++-----
>  lib/remote_add.tcl        |  5 ++---
>  lib/search.tcl            |  4 ++--
>  lib/sshkey.tcl            |  2 +-
>  lib/tools_dlg.tcl         |  6 +++---
>  24 files changed, 47 insertions(+), 70 deletions(-)
>
> --
> 2.21.0
>
>
Pratyush Yadav Oct. 29, 2019, 7:09 p.m. UTC | #2
On 28/10/19 02:15PM, Johannes Schindelin wrote:
> Hi Pratyush,
> 
> On Fri, 25 Oct 2019, Pratyush Yadav wrote:
> 
> > A lot of places have unused global variables declared. Remove them.
> >
> > It started as a couple of quick fixes and ended up in me writing an ugly
> > hacky script to catch all the instances of unused global declarations.
> > Lot more than I expected.
> >
> > The script can be found at [0].
> 
> Wouldn't it make more sense to integrate that script into a Makefile
> target `check`, rather than hiding it in a gist (that might become
> unavailable if GitHub goes away, as some of you seem to fear)?

The idea of the script was just a quick hack to list as many instances 
as possible, and then I could manually verify them. It turned out to be 
pretty accurate. I linked it here so other people can know what I used 
to find these, and can suggest some cases I missed, if any. That's why I 
linked to the script in the cover letter, and not in the commit message.

It would probably be a better idea to use a linter/static analyzer. This 
would provide much better coverage than a script written for one-off 
usage.

I looked up some linters. There doesn't seem to be a lot of options, and 
most of them are not very good. One option I found is [0], but it gives 
more useless warnings than useful ones. Tcl being a really difficult 
language to lint doesn't help. So unless someone knows a good Tcl 
linter, maybe the best compromise would be to clean up the script and 
add it to our build process. But I'd really prefer a "proper" linter.
 
> > The script at [0] will only catch the unused globals in 'proc's. But
> > git-gui also has 'method's and 'constructor's. Just change '^proc' to
> > '^constructor' or '^method'.
> 
> Why not use `grep -E -n -e '^(proc|method)'`?

No particular reason. I just wrote it for 'proc', and then realized I 
might as well check 'method' and 'constructor'. Like I said, the aim of 
the script was use-and-throw.
 
> > I manually checked each instance before removing just to be sure I'm not
> > doing something wrong. Still, a bit of testing would be appreciated.
> > Just apply this patch and go on about your business as usual. There
> > _should_ be no change in the behaviour. I tested some basic functions
> > like commit, push, etc, and they work fine for me.
> 
> I would, if I used Git GUI regularly ;-)

[0] https://github.com/Xilinx/XilinxTclStore/blob/master/support/linter/tcl_lint.tcl