public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] contrib: git gcc-descr defaulting to print hash
@ 2021-10-08 11:01 Martin Liška
  2021-10-08 11:12 ` Jakub Jelinek
  0 siblings, 1 reply; 15+ messages in thread
From: Martin Liška @ 2021-10-08 11:01 UTC (permalink / raw)
  To: gcc-patches; +Cc: Martin Jambor, Jakub Jelinek, Jonathan Wakely

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(-)

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'
-- 
2.33.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] contrib: git gcc-descr defaulting to print hash
  2021-10-08 11:01 [PATCH] contrib: git gcc-descr defaulting to print hash Martin Liška
@ 2021-10-08 11:12 ` Jakub Jelinek
  2021-10-11 12:32   ` [RFC] Port git gcc-descr to Python Martin Liška
  0 siblings, 1 reply; 15+ messages in thread
From: Jakub Jelinek @ 2021-10-08 11:12 UTC (permalink / raw)
  To: Martin Liška; +Cc: gcc-patches, Martin Jambor, Jonathan Wakely

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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [RFC] Port git gcc-descr to Python
  2021-10-08 11:12 ` Jakub Jelinek
@ 2021-10-11 12:32   ` Martin Liška
  2021-10-12  8:59     ` Martin Liška
  0 siblings, 1 reply; 15+ messages in thread
From: Martin Liška @ 2021-10-11 12:32 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, Martin Jambor, Jonathan Wakely

[-- Attachment #1: Type: text/plain, Size: 1120 bytes --]

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

[-- Attachment #2: describe.py --]
[-- Type: text/x-python, Size: 1848 bytes --]

#!/usr/bin/env python3

import argparse
import subprocess
import sys

DEFAULT_REV = 'master'
PREFIX = 'basepoints/gcc-'
hash_length = 14


def run_git(cmd):
    return subprocess.run(cmd, shell=True, encoding='utf8',
                          stdout=subprocess.PIPE, stderr=subprocess.PIPE)


parser = argparse.ArgumentParser(description='Describe a GCC git commit.')
parser.add_argument('revision', nargs='?', default=DEFAULT_REV,
                    help=f'Described revision ("{DEFAULT_REV}" by default)')
parser.add_argument('--full', '-f', action='store_true',
                    help='Print complete git hash')
parser.add_argument('--short', '-s', action='store_true',
                    help='Shorten described revision')
args = parser.parse_args()

if args.full:
    hash_length = 40

r = run_git(f'git describe --all --match {PREFIX}[0-9]* '
            f'{args.revision} --abbrev={hash_length}')
if r.returncode != 0:
    print(r.stderr, end='')
    sys.exit(1)

# produces e.g. r12-4285-g07dd3bcda17f97
descr = r.stdout.strip()
assert PREFIX in descr
descr = 'r' + descr[descr.find(PREFIX) + len(PREFIX):]

# handle basepoints
if '-' not in descr:
    r = run_git(f'git rev-parse {args.revision}')
    descr += '-0-g' + r.stdout.strip()[:hash_length]

parts = descr.split('-')
assert len(parts) == 3

if args.short:
    descr = '-'.join(parts[:-1])

# verify common ancestor
r = run_git('git config --get gcc-config.upstream')
upstream = r.stdout.strip() if r.returncode else 'origin'
gcc_branch = parts[0][1:]

r = run_git(f'git rev-parse --quiet --verify origin/releases/gcc-{gcc_branch}')
branch = f'releases/gcc-{gcc_branch}' if r.returncode == 0 else 'master'

r = run_git(f'git merge-base --is-ancestor {args.revision} '
            f'{upstream}/{branch}')
if r.returncode != 0:
    print(r.stderr)
    sys.exit(2)

print(descr)

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC] Port git gcc-descr to Python
  2021-10-11 12:32   ` [RFC] Port git gcc-descr to Python Martin Liška
@ 2021-10-12  8:59     ` Martin Liška
  2021-10-14  9:06       ` Tobias Burnus
  2021-10-18  9:01       ` Martin Liška
  0 siblings, 2 replies; 15+ messages in thread
From: Martin Liška @ 2021-10-12  8:59 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, Jonathan Wakely, Martin Jambor

[-- Attachment #1: Type: text/plain, Size: 170 bytes --]

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

[-- Attachment #2: 0001-Port-git-gcc-un-descr-to-Python.patch --]
[-- Type: text/x-patch, Size: 7304 bytes --]

From bf46024d03d00edf09d804449acbc5ff17690127 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Mon, 11 Oct 2021 14:36:19 +0200
Subject: [PATCH] Port git gcc-{,un}descr to Python.

contrib/ChangeLog:

	* gcc-git-customization.sh: Use the new python implementation.
	* describe_common.py: New file.
	* git-describe.py: New file.
	* git-undescribe.py: New file.
---
 contrib/describe_common.py       | 27 +++++++++++++++
 contrib/gcc-git-customization.sh |  5 ++-
 contrib/git-describe.py          | 56 ++++++++++++++++++++++++++++++++
 contrib/git-undescribe.py        | 39 ++++++++++++++++++++++
 4 files changed, 124 insertions(+), 3 deletions(-)
 create mode 100644 contrib/describe_common.py
 create mode 100755 contrib/git-describe.py
 create mode 100755 contrib/git-undescribe.py

diff --git a/contrib/describe_common.py b/contrib/describe_common.py
new file mode 100644
index 00000000000..ff48bccc71c
--- /dev/null
+++ b/contrib/describe_common.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python3
+
+import subprocess
+
+BASE_PREFIX = 'basepoints/gcc-'
+
+
+def run_git(cmd):
+    return subprocess.run(cmd, shell=True, encoding='utf8',
+                          stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+
+def get_upstream():
+    r = run_git('git config --get gcc-config.upstream')
+    upstream = r.stdout.strip() if r.returncode else 'origin'
+    return upstream
+
+
+def get_branch_for_version(version):
+    r = run_git('git rev-parse --quiet --verify '
+                f'origin/releases/gcc-{version}')
+    return f'releases/gcc-{version}' if r.returncode == 0 else 'master'
+
+
+def get_description(revision, options=''):
+    return run_git(f'git describe --all --match {BASE_PREFIX}[0-9]* '
+                   f'{revision} ' + options)
diff --git a/contrib/gcc-git-customization.sh b/contrib/gcc-git-customization.sh
index aca61b781ff..1cc0a5abc34 100755
--- a/contrib/gcc-git-customization.sh
+++ b/contrib/gcc-git-customization.sh
@@ -22,9 +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() { "`git rev-parse --show-toplevel`/contrib/git-describe.py" $@; } ; f'
+git config alias.gcc-undescr '!f() { "`git rev-parse --show-toplevel`/contrib/git-undescribe.py" $@; } ; 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'
 git config alias.gcc-mklog '!f() { "`git rev-parse --show-toplevel`/contrib/mklog.py" $@; } ; f'
diff --git a/contrib/git-describe.py b/contrib/git-describe.py
new file mode 100755
index 00000000000..db2d229a31d
--- /dev/null
+++ b/contrib/git-describe.py
@@ -0,0 +1,56 @@
+#!/usr/bin/env python3
+
+import argparse
+import sys
+
+from describe_common import BASE_PREFIX, get_branch_for_version
+from describe_common import get_description, get_upstream, run_git
+
+DEFAULT_REV = 'master'
+hash_length = 14
+
+parser = argparse.ArgumentParser(description='Describe a GCC git commit.')
+parser.add_argument('revision', nargs='?', default=DEFAULT_REV,
+                    help=f'Described revision ("{DEFAULT_REV}" by default)')
+parser.add_argument('--full', '-f', action='store_true',
+                    help='Print complete git hash')
+parser.add_argument('--short', '-s', action='store_true',
+                    help='Shorten described revision')
+args = parser.parse_args()
+
+if args.full:
+    hash_length = 40
+
+r = get_description(args.revision, f'--abbrev={hash_length}')
+if r.returncode != 0:
+    print(r.stderr, end='')
+    sys.exit(1)
+
+# produces e.g. r12-4285-g07dd3bcda17f97
+descr = r.stdout.strip()
+assert BASE_PREFIX in descr
+descr = 'r' + descr[descr.find(BASE_PREFIX) + len(BASE_PREFIX):]
+
+# handle basepoints
+if '-' not in descr:
+    r = run_git(f'git rev-parse {args.revision}')
+    descr += '-0-g' + r.stdout.strip()[:hash_length]
+
+parts = descr.split('-')
+assert len(parts) == 3
+
+if args.short:
+    descr = '-'.join(parts[:-1])
+
+# verify common ancestor
+upstream = get_upstream()
+version = parts[0][1:]
+branch = get_branch_for_version(version)
+
+r = run_git(f'git merge-base --is-ancestor {args.revision} '
+            f'{upstream}/{branch}')
+if r.returncode != 0:
+    print(r.stderr)
+    sys.exit(2)
+
+print(descr)
diff --git a/contrib/git-undescribe.py b/contrib/git-undescribe.py
new file mode 100755
index 00000000000..430e30a90d6
--- /dev/null
+++ b/contrib/git-undescribe.py
@@ -0,0 +1,39 @@
+#!/usr/bin/env python3
+
+import argparse
+import re
+import sys
+
+from describe_common import get_branch_for_version
+from describe_common import get_description, get_upstream, run_git
+
+
+FORMAT = re.compile(r'r(?P<version>[0-9]+)-(?P<revs>[0-9]+)')
+
+parser = argparse.ArgumentParser(description='Undescribe a GCC git commit.')
+parser.add_argument('revision', help='A revision to undescribe')
+args = parser.parse_args()
+
+match = FORMAT.match(args.revision)
+if not match:
+    print(f'Invalid id {args.revision}')
+    sys.exit(1)
+
+version = int(match.group('version'))
+revs = int(match.group('revs'))
+
+branch = get_branch_for_version(version)
+upstream = get_upstream()
+
+r = run_git(f'git rev-parse --verify --quiet {upstream}/{branch}')
+assert r.returncode == 0
+tip = r.stdout.strip()
+
+r = get_description(tip)
+assert r.returncode == 0
+
+# Example parsing: get 4346 from tags/basepoints/gcc-12-4346-geb92cd57a1e
+tip_steps = int(r.stdout.strip().split('-')[-2])
+
+r = run_git(f'git rev-parse {tip}~{tip_steps - revs}')
+print(r.stdout.strip())
-- 
2.33.0


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC] Port git gcc-descr to Python
  2021-10-12  8:59     ` Martin Liška
@ 2021-10-14  9:06       ` Tobias Burnus
  2021-10-14  9:19         ` Jakub Jelinek
  2021-10-18  9:01       ` Martin Liška
  1 sibling, 1 reply; 15+ messages in thread
From: Tobias Burnus @ 2021-10-14  9:06 UTC (permalink / raw)
  To: Martin Liška, Jakub Jelinek; +Cc: Jonathan Wakely, gcc-patches

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC] Port git gcc-descr to Python
  2021-10-14  9:06       ` Tobias Burnus
@ 2021-10-14  9:19         ` Jakub Jelinek
  0 siblings, 0 replies; 15+ messages in thread
From: Jakub Jelinek @ 2021-10-14  9:19 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: Martin Liška, Jonathan Wakely, gcc-patches

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


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC] Port git gcc-descr to Python
  2021-10-12  8:59     ` Martin Liška
  2021-10-14  9:06       ` Tobias Burnus
@ 2021-10-18  9:01       ` Martin Liška
  2022-01-19 11:01         ` Martin Liška
  1 sibling, 1 reply; 15+ messages in thread
From: Martin Liška @ 2021-10-18  9:01 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, Jonathan Wakely, Martin Jambor

On 10/12/21 10:59, Martin Liška wrote:
> 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

All right, so Jakub told me at IRC that we doesn't support porting to Python.
However, he promised supporting the changes I made in the original shell script.

Cheers,
Martin

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC] Port git gcc-descr to Python
  2021-10-18  9:01       ` Martin Liška
@ 2022-01-19 11:01         ` Martin Liška
  2022-01-19 12:49           ` Martin Jambor
  0 siblings, 1 reply; 15+ messages in thread
From: Martin Liška @ 2022-01-19 11:01 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Jonathan Wakely, gcc-patches, Martin Jambor

On 10/18/21 11:01, Martin Liška wrote:
> On 10/12/21 10:59, Martin Liška wrote:
>> 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
> 
> All right, so Jakub told me at IRC that we doesn't support porting to Python.
> However, he promised supporting the changes I made in the original shell script.

@Jakub: May I remind this, please?

Thanks,
Martin

> 
> Cheers,
> Martin


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC] Port git gcc-descr to Python
  2022-01-19 11:01         ` Martin Liška
@ 2022-01-19 12:49           ` Martin Jambor
  2022-01-19 13:17             ` Martin Liška
  2022-01-27 15:06             ` [PATCH] contrib: Put gcc-descr and gcc-undescr to file Martin Liška
  0 siblings, 2 replies; 15+ messages in thread
From: Martin Jambor @ 2022-01-19 12:49 UTC (permalink / raw)
  To: Martin Liška, Jakub Jelinek; +Cc: Jonathan Wakely, gcc-patches

Hi,

On Wed, Jan 19 2022, Martin Liška wrote:
> On 10/18/21 11:01, Martin Liška wrote:
>> On 10/12/21 10:59, Martin Liška wrote:
>>> 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
>> 
>> All right, so Jakub told me at IRC that we doesn't support porting to Python.
>> However, he promised supporting the changes I made in the original shell script.
>
> @Jakub: May I remind this, please?

putting the following line in ..git/config seems to do the trick?

	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'); elif 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'); 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"

Derived from the following before squashing all the new lines:

    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');
    elif test ${1:-no} = --long; then
	c=${2:-master};
	r=$(git describe --all --abbrev=40 --match 'basepoints/gcc-[0-9]*' $c | sed -n 's,^\\(tags/\\)\\?basepoints/gcc-,r,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;


(And if you wanted to ask then no, I am not touching
contrib/gcc-git-customization.sh, not even with a long pole, it scares
me :-)

Martin


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC] Port git gcc-descr to Python
  2022-01-19 12:49           ` Martin Jambor
@ 2022-01-19 13:17             ` Martin Liška
  2022-01-19 16:54               ` Eric Gallager
  2022-01-27 15:06             ` [PATCH] contrib: Put gcc-descr and gcc-undescr to file Martin Liška
  1 sibling, 1 reply; 15+ messages in thread
From: Martin Liška @ 2022-01-19 13:17 UTC (permalink / raw)
  To: Martin Jambor, Jakub Jelinek; +Cc: Jonathan Wakely, gcc-patches

On 1/19/22 13:49, Martin Jambor wrote:
> Hi,
> 
> On Wed, Jan 19 2022, Martin Liška wrote:
>> On 10/18/21 11:01, Martin Liška wrote:
>>> On 10/12/21 10:59, Martin Liška wrote:
>>>> 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
>>>
>>> All right, so Jakub told me at IRC that we doesn't support porting to Python.
>>> However, he promised supporting the changes I made in the original shell script.
>>
>> @Jakub: May I remind this, please?
> 
> putting the following line in ..git/config seems to do the trick?
> 
> 	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'); elif 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'); 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"
> 
> Derived from the following before squashing all the new lines:
> 
>      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');
>      elif test ${1:-no} = --long; then
> 	c=${2:-master};
> 	r=$(git describe --all --abbrev=40 --match 'basepoints/gcc-[0-9]*' $c | sed -n 's,^\\(tags/\\)\\?basepoints/gcc-,r,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;

Anyway, can we please put the nicely formatted bash script to contrib/git-describe.sh (contrib/git-undescribe.sh), having that squashed
to one line is just crazy.

Martin, can you please do that?

> 
> 
> (And if you wanted to ask then no, I am not touching
> contrib/gcc-git-customization.sh, not even with a long pole, it scares
> me :-)

Sure, I can then adjust it if we end up with an outlined version where to code
sits in proper .sh files.

Martin

> 
> Martin
> 


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [RFC] Port git gcc-descr to Python
  2022-01-19 13:17             ` Martin Liška
@ 2022-01-19 16:54               ` Eric Gallager
  0 siblings, 0 replies; 15+ messages in thread
From: Eric Gallager @ 2022-01-19 16:54 UTC (permalink / raw)
  To: Martin Liška
  Cc: Martin Jambor, Jakub Jelinek, Jonathan Wakely, gcc-patches

On Wed, Jan 19, 2022 at 8:18 AM Martin Liška <mliska@suse.cz> wrote:
>
> On 1/19/22 13:49, Martin Jambor wrote:
> > Hi,
> >
> > On Wed, Jan 19 2022, Martin Liška wrote:
> >> On 10/18/21 11:01, Martin Liška wrote:
> >>> On 10/12/21 10:59, Martin Liška wrote:
> >>>> 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
> >>>
> >>> All right, so Jakub told me at IRC that we doesn't support porting to Python.
> >>> However, he promised supporting the changes I made in the original shell script.
> >>
> >> @Jakub: May I remind this, please?
> >
> > putting the following line in ..git/config seems to do the trick?
> >
> >       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'); elif 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'); 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"
> >
> > Derived from the following before squashing all the new lines:
> >
> >      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');
> >      elif test ${1:-no} = --long; then
> >       c=${2:-master};
> >       r=$(git describe --all --abbrev=40 --match 'basepoints/gcc-[0-9]*' $c | sed -n 's,^\\(tags/\\)\\?basepoints/gcc-,r,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;
>
> Anyway, can we please put the nicely formatted bash script to contrib/git-describe.sh (contrib/git-undescribe.sh), having that squashed
> to one line is just crazy.
>
> Martin, can you please do that?
>
> >
> >
> > (And if you wanted to ask then no, I am not touching
> > contrib/gcc-git-customization.sh, not even with a long pole, it scares
> > me :-)
>
> Sure, I can then adjust it if we end up with an outlined version where to code
> sits in proper .sh files.
>
> Martin
>
> >
> > Martin
> >
>

Hi, while people are modifying contrib/gcc-git-customization.sh, could
I get someone to take a look at bug 102644, too?
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102664
Thanks,
Eric

^ permalink raw reply	[flat|nested] 15+ messages in thread

* [PATCH] contrib: Put gcc-descr and gcc-undescr to file.
  2022-01-19 12:49           ` Martin Jambor
  2022-01-19 13:17             ` Martin Liška
@ 2022-01-27 15:06             ` Martin Liška
  2022-01-27 15:35               ` Jakub Jelinek
  2022-01-27 15:51               ` Jonathan Wakely
  1 sibling, 2 replies; 15+ messages in thread
From: Martin Liška @ 2022-01-27 15:06 UTC (permalink / raw)
  To: Martin Jambor, Jakub Jelinek; +Cc: Jonathan Wakely, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 513 bytes --]

Hello.

I've finished Martin's work and put the 2 aliases into files. The git-undescr.sh is basically
unchanged, while I added better option parsing for git-descr.sh script so that it supports:

$ git gcc-descr
r12-6895-g14f339894db6ca

$ git gcc-descr HEAD~10
r12-6886-geaa59070343326

$ git gcc-descr HEAD~10 --long
r12-6886-geaa5907034332649c918f0579da805b6e786aa47

$ git gcc-descr --short HEAD~10 --long
r12-6886

$ git gcc-descr --short --short --long HEAD~10
r12-6886

Ready to be installed?
Thanks,
Martin

[-- Attachment #2: 0001-contrib-Put-gcc-descr-and-gcc-undescr-to-file.patch --]
[-- Type: text/x-patch, Size: 5405 bytes --]

From feb3f83724cd0764f7ad3fbd1504c0d43266c88a Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Thu, 27 Jan 2022 16:01:55 +0100
Subject: [PATCH] contrib: Put gcc-descr and gcc-undescr to file.

contrib/ChangeLog:

	* git-descr.sh: New file.
	* git-undescr.sh: New file.
	Support optional arguments --long, --short and default
	to 14 characters of git hash.

contrib/ChangeLog:

	* gcc-git-customization.sh: Use the created files.
	* git-descr.sh: New file.
	* git-undescr.sh: New file.

Co-Authored-By: Martin Jambor <mjambor@suse.cz>
---
 contrib/gcc-git-customization.sh |  4 ++--
 contrib/git-descr.sh             | 37 ++++++++++++++++++++++++++++++++
 contrib/git-undescr.sh           | 13 +++++++++++
 3 files changed, 52 insertions(+), 2 deletions(-)
 create mode 100755 contrib/git-descr.sh
 create mode 100755 contrib/git-undescr.sh

diff --git a/contrib/gcc-git-customization.sh b/contrib/gcc-git-customization.sh
index 2eec17937af..b24948d9874 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() { "`git rev-parse --show-toplevel`/contrib/git-descr.sh" $@; } ; f'
+git config alias.gcc-undescr '!f() { "`git rev-parse --show-toplevel`/contrib/git-undescr.sh" $@; } ; 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'
diff --git a/contrib/git-descr.sh b/contrib/git-descr.sh
new file mode 100755
index 00000000000..0d3e42940b3
--- /dev/null
+++ b/contrib/git-descr.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+# Script to describe a GCC revision based on git hash
+
+short=no
+long=no
+c=master
+
+for arg in "$@"
+do
+    case "$arg" in
+      --short) short=yes
+	;;
+      --long) long=yes
+	;;
+      *) c=$arg
+    esac
+done
+
+if test x$short = xyes; then
+    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');
+elif test x$long = xyes; then
+    r=$(git describe --all --abbrev=40 --match 'basepoints/gcc-[0-9]*' $c | sed -n 's,^\(tags/\)\?basepoints/gcc-,r,p')
+else
+    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 $c);
+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;
diff --git a/contrib/git-undescr.sh b/contrib/git-undescr.sh
new file mode 100755
index 00000000000..7d2efe1a8e7
--- /dev/null
+++ b/contrib/git-undescr.sh
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+# Script to undescribe a GCC revision
+
+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);
-- 
2.34.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] contrib: Put gcc-descr and gcc-undescr to file.
  2022-01-27 15:06             ` [PATCH] contrib: Put gcc-descr and gcc-undescr to file Martin Liška
@ 2022-01-27 15:35               ` Jakub Jelinek
  2022-01-27 17:44                 ` Martin Liška
  2022-01-27 15:51               ` Jonathan Wakely
  1 sibling, 1 reply; 15+ messages in thread
From: Jakub Jelinek @ 2022-01-27 15:35 UTC (permalink / raw)
  To: Martin Liška; +Cc: Martin Jambor, Jonathan Wakely, gcc-patches

On Thu, Jan 27, 2022 at 04:06:05PM +0100, Martin Liška wrote:
> I've finished Martin's work and put the 2 aliases into files. The git-undescr.sh is basically
> unchanged, while I added better option parsing for git-descr.sh script so that it supports:
> 
> $ git gcc-descr
> r12-6895-g14f339894db6ca
> 
> $ git gcc-descr HEAD~10
> r12-6886-geaa59070343326
> 
> $ git gcc-descr HEAD~10 --long
> r12-6886-geaa5907034332649c918f0579da805b6e786aa47
> 
> $ git gcc-descr --short HEAD~10 --long
> r12-6886
> 
> $ git gcc-descr --short --short --long HEAD~10
> r12-6886
> 
> Ready to be installed?

For backwards compatibility, I'd prefer --full to be an alias to --long,
and maybe the --short handling should short=yes; long=no and
similarly --long/--full handling should long=yes; short=no
so that --short --long is --long and --long --short is --short.

Otherwise LGTM.

> From feb3f83724cd0764f7ad3fbd1504c0d43266c88a Mon Sep 17 00:00:00 2001
> From: Martin Liska <mliska@suse.cz>
> Date: Thu, 27 Jan 2022 16:01:55 +0100
> Subject: [PATCH] contrib: Put gcc-descr and gcc-undescr to file.
> 
> contrib/ChangeLog:
> 
> 	* git-descr.sh: New file.
> 	* git-undescr.sh: New file.
> 	Support optional arguments --long, --short and default
> 	to 14 characters of git hash.
> 
> contrib/ChangeLog:
> 
> 	* gcc-git-customization.sh: Use the created files.
> 	* git-descr.sh: New file.
> 	* git-undescr.sh: New file.
> 
> Co-Authored-By: Martin Jambor <mjambor@suse.cz>
> ---
>  contrib/gcc-git-customization.sh |  4 ++--
>  contrib/git-descr.sh             | 37 ++++++++++++++++++++++++++++++++
>  contrib/git-undescr.sh           | 13 +++++++++++
>  3 files changed, 52 insertions(+), 2 deletions(-)
>  create mode 100755 contrib/git-descr.sh
>  create mode 100755 contrib/git-undescr.sh
> 
> diff --git a/contrib/gcc-git-customization.sh b/contrib/gcc-git-customization.sh
> index 2eec17937af..b24948d9874 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() { "`git rev-parse --show-toplevel`/contrib/git-descr.sh" $@; } ; f'
> +git config alias.gcc-undescr '!f() { "`git rev-parse --show-toplevel`/contrib/git-undescr.sh" $@; } ; 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'
> diff --git a/contrib/git-descr.sh b/contrib/git-descr.sh
> new file mode 100755
> index 00000000000..0d3e42940b3
> --- /dev/null
> +++ b/contrib/git-descr.sh
> @@ -0,0 +1,37 @@
> +#!/bin/sh
> +
> +# Script to describe a GCC revision based on git hash
> +
> +short=no
> +long=no
> +c=master
> +
> +for arg in "$@"
> +do
> +    case "$arg" in
> +      --short) short=yes
> +	;;
> +      --long) long=yes
> +	;;
> +      *) c=$arg
> +    esac
> +done
> +
> +if test x$short = xyes; then
> +    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');
> +elif test x$long = xyes; then
> +    r=$(git describe --all --abbrev=40 --match 'basepoints/gcc-[0-9]*' $c | sed -n 's,^\(tags/\)\?basepoints/gcc-,r,p')
> +else
> +    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 $c);
> +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;
> diff --git a/contrib/git-undescr.sh b/contrib/git-undescr.sh
> new file mode 100755
> index 00000000000..7d2efe1a8e7
> --- /dev/null
> +++ b/contrib/git-undescr.sh
> @@ -0,0 +1,13 @@
> +#!/bin/sh
> +
> +# Script to undescribe a GCC revision
> +
> +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);
> -- 
> 2.34.1
> 


	Jakub


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] contrib: Put gcc-descr and gcc-undescr to file.
  2022-01-27 15:06             ` [PATCH] contrib: Put gcc-descr and gcc-undescr to file Martin Liška
  2022-01-27 15:35               ` Jakub Jelinek
@ 2022-01-27 15:51               ` Jonathan Wakely
  1 sibling, 0 replies; 15+ messages in thread
From: Jonathan Wakely @ 2022-01-27 15:51 UTC (permalink / raw)
  To: Martin Liška; +Cc: Martin Jambor, Jakub Jelinek, gcc-patches

On Thu, 27 Jan 2022, 15:06 Martin Liška, <mliska@suse.cz> wrote:

> Hello.
>
> I've finished Martin's work and put the 2 aliases into files. The
> git-undescr.sh is basically
> unchanged, while I added better option parsing for git-descr.sh script so
> that it supports:
>
> $ git gcc-descr
> r12-6895-g14f339894db6ca
>
> $ git gcc-descr HEAD~10
> r12-6886-geaa59070343326
>
> $ git gcc-descr HEAD~10 --long
> r12-6886-geaa5907034332649c918f0579da805b6e786aa47
>
> $ git gcc-descr --short HEAD~10 --long
> r12-6886
>
> $ git gcc-descr --short --short --long HEAD~10
> r12-6886
>
> Ready to be installed?
>

> +    expr match ${r:-no} '^r[0-9]\+$' >/dev/null && r=${r}-0-g$(git
rev-parse $c);


Please remove the ^ from the 'expr' regex. The regex for an expr match can
only match at the beginning, so the ^ is implicit, but some implementations
ignore it (e.g. on Linux) and others march it as a normal character (e.g.
macOS).

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [PATCH] contrib: Put gcc-descr and gcc-undescr to file.
  2022-01-27 15:35               ` Jakub Jelinek
@ 2022-01-27 17:44                 ` Martin Liška
  0 siblings, 0 replies; 15+ messages in thread
From: Martin Liška @ 2022-01-27 17:44 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Martin Jambor, Jonathan Wakely, gcc-patches

On 1/27/22 16:35, Jakub Jelinek wrote:
> For backwards compatibility, I'd prefer --full to be an alias to --long,
> and maybe the --short handling should short=yes; long=no and
> similarly --long/--full handling should long=yes; short=no
> so that --short --long is --long and --long --short is --short.

I like the suggestions, applied that!

Similarly to Jonathan's comment, thank for it.

I've just pushed that to master.

Martin

> 
> Otherwise LGTM.


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2022-01-27 17:44 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-08 11:01 [PATCH] contrib: git gcc-descr defaulting to print hash Martin Liška
2021-10-08 11:12 ` Jakub Jelinek
2021-10-11 12:32   ` [RFC] Port git gcc-descr to Python Martin Liška
2021-10-12  8:59     ` Martin Liška
2021-10-14  9:06       ` Tobias Burnus
2021-10-14  9:19         ` Jakub Jelinek
2021-10-18  9:01       ` Martin Liška
2022-01-19 11:01         ` Martin Liška
2022-01-19 12:49           ` Martin Jambor
2022-01-19 13:17             ` Martin Liška
2022-01-19 16:54               ` Eric Gallager
2022-01-27 15:06             ` [PATCH] contrib: Put gcc-descr and gcc-undescr to file Martin Liška
2022-01-27 15:35               ` Jakub Jelinek
2022-01-27 17:44                 ` Martin Liška
2022-01-27 15:51               ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).