public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: Martin Jambor <mjambor@suse.cz>, Jakub Jelinek <jakub@redhat.com>
Cc: Jonathan Wakely <jwakely.gcc@gmail.com>, gcc-patches@gcc.gnu.org
Subject: [PATCH] contrib: Put gcc-descr and gcc-undescr to file.
Date: Thu, 27 Jan 2022 16:06:05 +0100	[thread overview]
Message-ID: <28f9be5c-c9a7-9e33-1ba0-49579695c912@suse.cz> (raw)
In-Reply-To: <ri6sftjriv7.fsf@suse.cz>

[-- 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


  parent reply	other threads:[~2022-01-27 15:06 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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             ` Martin Liška [this message]
2022-01-27 15:35               ` [PATCH] contrib: Put gcc-descr and gcc-undescr to file Jakub Jelinek
2022-01-27 17:44                 ` Martin Liška
2022-01-27 15:51               ` Jonathan Wakely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=28f9be5c-c9a7-9e33-1ba0-49579695c912@suse.cz \
    --to=mliska@suse.cz \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=jwakely.gcc@gmail.com \
    --cc=mjambor@suse.cz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).