diff mbox series

contrib: git gcc-descr defaulting to print hash

Message ID 7e803eb3-d9df-99de-490d-823c1ffe29d7@suse.cz
State New
Headers show
Series contrib: git gcc-descr defaulting to print hash | expand

Commit Message

Martin Liška Oct. 8, 2021, 11:01 a.m. UTC
Hello.

I'm sending a patch originally written by Martin Jambor.
The patch changes the behavior in the following way:

$ git gcc-descr HEAD~

r12-4245-gdb3d7270b42fe2

$ git gcc-descr --short HEAD~

r12-4245

$ git gcc-undescr r12-4245-gdb3d7270b42fe2

db3d7270b42fe27fb05664c4fdf524ab7ad13a75

while right now, one gets:
$ git gcc-descr

r12-4090

$ git gcc-undescr r12-4245-gdb3d7270b42fe2
Invalid id r12-4245-gdb3d7270b42fe2

Thoughts?
Martin

contrib/ChangeLog:

	* gcc-git-customization.sh: Remove --full option and add --short
	one. By default, gcc-descr prints 14 characters of hash.
	gcc-undescr supports r$number-$number-$hash format.
---
  contrib/gcc-git-customization.sh | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Jakub Jelinek Oct. 8, 2021, 11:12 a.m. UTC | #1
On Fri, Oct 08, 2021 at 01:01:33PM +0200, Martin Liška wrote:
> I'm sending a patch originally written by Martin Jambor.
> The patch changes the behavior in the following way:
> 
> $ git gcc-descr HEAD~
> 
> r12-4245-gdb3d7270b42fe2
> 
> $ git gcc-descr --short HEAD~
> 
> r12-4245

I think changing the default is ok, but dropping --full is not,
it should stay and behave the way it did before (i.e. print
r12-4245-gdb3d7270b42fe27fb05664c4fdf524ab7ad13a75
same thing as the new default except for full hash instead of
first 14 chars from it).

> $ git gcc-undescr r12-4245-gdb3d7270b42fe2
> 
> db3d7270b42fe27fb05664c4fdf524ab7ad13a75

I don't understand this.  Why do you want to make this work?
That is clearly a noop, you can use r12-4245-gdb3d7270b42fe2
directly in git commands, and if you for whatever strange reason
don't want the r12-4245-g prefix before it, just copy'n'paste
what is after it.

	Jakub
Martin Liška Oct. 11, 2021, 12:32 p.m. UTC | #2
On 10/8/21 13:12, Jakub Jelinek wrote:
> I think changing the default is ok, but dropping --full is not,
> it should stay and behave the way it did before (i.e. print
> r12-4245-gdb3d7270b42fe27fb05664c4fdf524ab7ad13a75
> same thing as the new default except for full hash instead of
> first 14 chars from it).

All right, makes sense, but updating the git alias doesn't work for me.
Thus I'm suggesting a Python replacement of it, which does:

$ ./describe.py basepoints/gcc-11

r11-0-g50ee04838efc16


$ ./describe.py

r12-4285-g07dd3bcda17f97


$ ./describe.py --short

r12-4285


$ ./describe.py --full

r12-4285-g07dd3bcda17f97cf5476c3d6f2f2501c1e0712e6


Motivation behind usage of Python:
- the script can be put to contrib and nobody would have to re-run contrib/gcc-git-customization.sh locally
- it's not a single line script and one doesn't have to do bash escaping in the contrib/gcc-git-customization.sh script
- positional argument support

Thoughts?

Note I can port the same way the counterpart script.
One another note:

$ git gcc-descr basepoints/gcc-11

r11-0


seems to me like bogus.

Cheers,
Martin
Martin Liška Oct. 12, 2021, 8:59 a.m. UTC | #3
Hello.

There's a complete patch that implements both git gcc-descr and gcc-undesrc
and sets corresponding git aliases to use them.

Ready to be installed?
Thanks,
Martin
Tobias Burnus Oct. 14, 2021, 9:06 a.m. UTC | #4
Hi Martin,

On 12.10.21 10:59, Martin Liška wrote:
> There's a complete patch that implements both git gcc-descr and
> gcc-undesrc
> and sets corresponding git aliases to use them.

When invoking ./contrib/git-describe.py directly, I get the error:
fatal: Not a valid object name /master

I think you need something like:
-   upstream = r.stdout.strip() if r.returncode else 'origin'
+   upstream = r.stdout.strip() if r.returncode == 0 else 'origin'

  * * *

Additionally, I observe the following (independent of the conversion):
For 7433458d871f6bfe2169b9d7d04fec64bb142924, I get:
    r0-80854-g7433458d871f6b
The question is whether we are happy that only reversions since
basepoints/gcc-5 have a version number or whether we want to
use releases/gcc-x.y.0 -> x.y as fallback when basepoint does not
exist or back-added more basepoints? Admittedly, this will add '.',
thus, maybe the answer is 'no'?

Tobias

-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
Jakub Jelinek Oct. 14, 2021, 9:19 a.m. UTC | #5
On Thu, Oct 14, 2021 at 11:06:55AM +0200, Tobias Burnus wrote:
> Additionally, I observe the following (independent of the conversion):
> For 7433458d871f6bfe2169b9d7d04fec64bb142924, I get:
>    r0-80854-g7433458d871f6b
> The question is whether we are happy that only reversions since
> basepoints/gcc-5 have a version number or whether we want to
> use releases/gcc-x.y.0 -> x.y as fallback when basepoint does not
> exist or back-added more basepoints? Admittedly, this will add '.',
> thus, maybe the answer is 'no'?

Yes, everything older than basepoints/gcc-5 is r0-NNNNN-gNNNNNN
by design.  Digits aren't allowed there and while we could use say
underscore, it doesn't seem to be worth it for such old history,
and all the bugzilla highlighting, web redirection etc. handles just
r number - number - g hexnumber
or
r number - number
formats.  It is more common to refer to the old commits through svn
revisions anyway.

	Jakub
diff mbox series

Patch

diff --git a/contrib/gcc-git-customization.sh b/contrib/gcc-git-customization.sh
index aca61b781ff..b63c4c80935 100755
--- a/contrib/gcc-git-customization.sh
+++ b/contrib/gcc-git-customization.sh
@@ -22,8 +22,8 @@  git config alias.svn-rev '!f() { rev=$1; shift; git log --all --grep="^From-SVN:
  
  # Add git commands to convert git commit to monotonically increasing revision number
  # and vice versa
-git config alias.gcc-descr \!"f() { if test \${1:-no} = --full; then c=\${2:-master}; r=\$(git describe --all --abbrev=40 --match 'basepoints/gcc-[0-9]*' \$c | sed -n 's,^\\(tags/\\)\\?basepoints/gcc-,r,p'); expr match \${r:-no} '^r[0-9]\\+\$' >/dev/null && r=\${r}-0-g\$(git rev-parse \${2:-master}); else c=\${1:-master}; r=\$(git describe --all --match 'basepoints/gcc-[0-9]*' \$c | sed -n 's,^\\(tags/\\)\\?basepoints/gcc-\\([0-9]\\+\\)-\\([0-9]\\+\\)-g[0-9a-f]*\$,r\\2-\\3,p;s,^\\(tags/\\)\\?basepoints/gcc-\\([0-9]\\+\\)\$,r\\2-0,p'); fi; if test -n \$r; then o=\$(git config --get gcc-config.upstream); rr=\$(echo \$r | sed -n 's,^r\\([0-9]\\+\\)-[0-9]\\+\\(-g[0-9a-f]\\+\\)\\?\$,\\1,p'); if git rev-parse --verify --quiet \${o:-origin}/releases/gcc-\$rr >/dev/null; then m=releases/gcc-\$rr; else m=master; fi; git merge-base --is-ancestor \$c \${o:-origin}/\$m && \echo \${r}; fi; }; f"
-git config alias.gcc-undescr \!"f() { o=\$(git config --get gcc-config.upstream); r=\$(echo \$1 | sed -n 's,^r\\([0-9]\\+\\)-[0-9]\\+\$,\\1,p'); n=\$(echo \$1 | sed -n 's,^r[0-9]\\+-\\([0-9]\\+\\)\$,\\1,p'); test -z \$r && echo Invalid id \$1 && exit 1; h=\$(git rev-parse --verify --quiet \${o:-origin}/releases/gcc-\$r); test -z \$h && h=\$(git rev-parse --verify --quiet \${o:-origin}/master); p=\$(git describe --all --match 'basepoints/gcc-'\$r \$h | sed -n 's,^\\(tags/\\)\\?basepoints/gcc-[0-9]\\+-\\([0-9]\\+\\)-g[0-9a-f]*\$,\\2,p;s,^\\(tags/\\)\\?basepoints/gcc-[0-9]\\+\$,0,p'); git rev-parse --verify \$h~\$(expr \$p - \$n); }; f"
+git config alias.gcc-descr \!"f() { if test \${1:-no} = --short; then c=\${2:-master}; r=\$(git describe --all --match 'basepoints/gcc-[0-9]*' \$c | sed -n 's,^\\(tags/\\)\\?basepoints/gcc-\\([0-9]\\+\\)-\\([0-9]\\+\\)-g[0-9a-f]*\$,r\\2-\\3,p;s,^\\(tags/\\)\\?basepoints/gcc-\\([0-9]\\+\\)\$,r\\2-0,p'); else c=\${1:-master}; r=\$(git describe --all --abbrev=14 --match 'basepoints/gcc-[0-9]*' \$c | sed -n 's,^\\(tags/\\)\\?basepoints/gcc-,r,p'); expr match \${r:-no} '^r[0-9]\\+\$' >/dev/null && r=\${r}-0-g\$(git rev-parse \${2:-master}); fi; if test -n \$r; then o=\$(git config --get gcc-config.upstream); rr=\$(echo \$r | sed -n 's,^r\\([0-9]\\+\\)-[0-9]\\+\\(-g[0-9a-f]\\+\\)\\?\$,\\1,p'); if git rev-parse --verify --quiet \${o:-origin}/releases/gcc-\$rr >/dev/null; then m=releases/gcc-\$rr; else m=master; fi; git merge-base --is-ancestor \$c \${o:-origin}/\$m && \\echo \${r}; fi; }; f"
+git config alias.gcc-undescr \!"f() { o=\$(git config --get gcc-config.upstream); r=\$(echo \$1 | sed 's/\\([^-]*-[^-]*\\)-.*/\\1/' | sed -n 's,^r\\([0-9]\\+\\)-[0-9]\\+\$,\\1,p'); n=\$(echo \$1 | sed 's/\\([^-]*-[^-]*\\)-.*/\\1/' | sed -n 's,^r[0-9]\\+-\\([0-9]\\+\\)\$,\\1,p'); test -z \$r && echo Invalid id \$1 && exit 1; h=\$(git rev-parse --verify --quiet \${o:-origin}/releases/gcc-\$r); test -z \$h && h=\$(git rev-parse --verify --quiet \${o:-origin}/master); p=\$(git describe --all --match 'basepoints/gcc-'\$r \$h | sed -n 's,^\\(tags/\\)\\?basepoints/gcc-[0-9]\\+-\\([0-9]\\+\\)-g[0-9a-f]*\$,\\2,p;s,^\\(tags/\\)\\?basepoints/gcc-[0-9]\\+\$,0,p'); git rev-parse --verify \$h~\$(expr \$p - \$n); }; f"
  
  git config alias.gcc-verify '!f() { "`git rev-parse --show-toplevel`/contrib/gcc-changelog/git_check_commit.py" $@; } ; f'
  git config alias.gcc-backport '!f() { "`git rev-parse --show-toplevel`/contrib/git-backport.py" $@; } ; f'