public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/c++-coroutines] git_update_version: add --current argument.
@ 2020-06-11 20:08 Iain D Sandoe
  0 siblings, 0 replies; only message in thread
From: Iain D Sandoe @ 2020-06-11 20:08 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:be11812eef33786f77676327667bf3885c1f33e8

commit be11812eef33786f77676327667bf3885c1f33e8
Author: Martin Liska <mliska@suse.cz>
Date:   Thu Jun 11 13:34:53 2020 +0200

    git_update_version: add --current argument.
    
    The argument can be useful to update arbitrary branch, the changes
    are added to git index and user is supposed to make a commit.
    
    contrib/ChangeLog:
    
            * gcc-changelog/git_update_version.py: Add --curent argument.

Diff:
---
 contrib/gcc-changelog/git_update_version.py | 106 ++++++++++++++++------------
 1 file changed, 59 insertions(+), 47 deletions(-)

diff --git a/contrib/gcc-changelog/git_update_version.py b/contrib/gcc-changelog/git_update_version.py
index 6b6ccf68a5e..733a1a0f14a 100755
--- a/contrib/gcc-changelog/git_update_version.py
+++ b/contrib/gcc-changelog/git_update_version.py
@@ -66,60 +66,72 @@ parser.add_argument('-d', '--dry-mode',
                     help='Generate patch for ChangeLog entries and do it'
                          ' even if DATESTAMP is unchanged; folder argument'
                          ' is expected')
+parser.add_argument('-c', '--current', action='store_true',
+                    help='Modify current branch (--push argument is ignored)')
 args = parser.parse_args()
 
 repo = Repo(args.git_path)
 origin = repo.remotes['origin']
 
-for ref in origin.refs:
-    assert ref.name.startswith('origin/')
-    name = ref.name[len('origin/'):]
-    if name in active_refs:
-        if name in repo.branches:
-            branch = repo.branches[name]
+
+def update_current_branch():
+    commit = repo.head.commit
+    commit_count = 1
+    while commit:
+        if (commit.author.email == 'gccadmin@gcc.gnu.org'
+                and commit.message.strip() == 'Daily bump.'):
+            break
+        commit = commit.parents[0]
+        commit_count += 1
+
+    print('%d revisions since last Daily bump' % commit_count)
+    datestamp_path = os.path.join(args.git_path, 'gcc/DATESTAMP')
+    if (read_timestamp(datestamp_path) != current_timestamp
+            or args.dry_mode or args.current):
+        commits = parse_git_revisions(args.git_path, '%s..HEAD'
+                                      % commit.hexsha)
+        for git_commit in reversed(commits):
+            prepend_to_changelog_files(repo, args.git_path, git_commit,
+                                       not args.dry_mode)
+        if args.dry_mode:
+            diff = repo.git.diff('HEAD')
+            patch = os.path.join(args.dry_mode,
+                                 branch.name.split('/')[-1] + '.patch')
+            with open(patch, 'w+') as f:
+                f.write(diff)
+            print('branch diff written to %s' % patch)
+            repo.git.checkout(force=True)
         else:
-            branch = repo.create_head(name, ref).set_tracking_branch(ref)
-        print('=== Working on: %s ===' % branch, flush=True)
-        origin.pull(rebase=True)
-        branch.checkout()
-        print('branch pulled and checked out')
-        assert not repo.index.diff(None)
-        commit = branch.commit
-        commit_count = 1
-        while commit:
-            if (commit.author.email == 'gccadmin@gcc.gnu.org'
-                    and commit.message.strip() == 'Daily bump.'):
-                break
-            commit = commit.parents[0]
-            commit_count += 1
-
-        print('%d revisions since last Daily bump' % commit_count)
-        datestamp_path = os.path.join(args.git_path, 'gcc/DATESTAMP')
-        if (read_timestamp(datestamp_path) != current_timestamp
-                or args.dry_mode):
-            commits = parse_git_revisions(args.git_path, '%s..HEAD'
-                                          % commit.hexsha)
-            for git_commit in reversed(commits):
-                prepend_to_changelog_files(repo, args.git_path, git_commit,
-                                           not args.dry_mode)
-            if args.dry_mode:
-                diff = repo.git.diff('HEAD')
-                patch = os.path.join(args.dry_mode,
-                                     branch.name.split('/')[-1] + '.patch')
-                with open(patch, 'w+') as f:
-                    f.write(diff)
-                print('branch diff written to %s' % patch)
-                repo.git.checkout(force=True)
-            else:
-                # update timestamp
-                print('DATESTAMP will be changed:')
-                with open(datestamp_path, 'w+') as f:
-                    f.write(current_timestamp)
-                repo.git.add(datestamp_path)
+            # update timestamp
+            print('DATESTAMP will be changed:')
+            with open(datestamp_path, 'w+') as f:
+                f.write(current_timestamp)
+            repo.git.add(datestamp_path)
+            if not args.current:
                 repo.index.commit('Daily bump.')
                 if args.push:
                     repo.git.push('origin', branch)
                     print('branch is pushed')
-        else:
-            print('DATESTAMP unchanged')
-        print('branch is done\n', flush=True)
+    else:
+        print('DATESTAMP unchanged')
+
+
+if args.current:
+    print('=== Working on the current branch ===', flush=True)
+    update_current_branch()
+else:
+    for ref in origin.refs:
+        assert ref.name.startswith('origin/')
+        name = ref.name[len('origin/'):]
+        if name in active_refs:
+            if name in repo.branches:
+                branch = repo.branches[name]
+            else:
+                branch = repo.create_head(name, ref).set_tracking_branch(ref)
+            print('=== Working on: %s ===' % branch, flush=True)
+            origin.pull(rebase=True)
+            branch.checkout()
+            print('branch pulled and checked out')
+            update_current_branch()
+            assert not repo.index.diff(None)
+            print('branch is done\n', flush=True)


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-06-11 20:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-11 20:08 [gcc/devel/c++-coroutines] git_update_version: add --current argument Iain D Sandoe

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