Explorar o código

repo download: add --revert option

BZ: 4779
Allows to revert a gerrit patch
This patch is necessary for the on-demand creation of
engineering builds using buildbot

You can now use:
repo download [--revert|-r project changeid/patchnumber

This is useful to automate reverting of a patch
in the context of build automation, and regression bisection

Change-Id: I3985e80e4b2a230f83526191ea1379765a54bdcf
Signed-off-by: Erwan Mahe <erwan.mahe@intel.com>
Signed-off-by: Pierre Tardy <pierre.tardy@intel.com>
Erwan Mahe %!s(int64=14) %!d(string=hai) anos
pai
achega
a94f162b9f
Modificáronse 2 ficheiros con 15 adicións e 1 borrados
  1. 9 0
      project.py
  2. 6 1
      subcmds/download.py

+ 9 - 0
project.py

@@ -1645,6 +1645,15 @@ class Project(object):
       if self._allrefs:
       if self._allrefs:
         raise GitError('%s cherry-pick %s ' % (self.name, rev))
         raise GitError('%s cherry-pick %s ' % (self.name, rev))
 
 
+  def _Revert(self, rev, quiet=False):
+    cmd = ['revert']
+    cmd.append('--no-edit')
+    cmd.append(rev)
+    cmd.append('--')
+    if GitCommand(self, cmd).Wait() != 0:
+      if self._allrefs:
+        raise GitError('%s revert %s ' % (self.name, rev))
+
   def _ResetHard(self, rev, quiet=True):
   def _ResetHard(self, rev, quiet=True):
     cmd = ['reset', '--hard']
     cmd = ['reset', '--hard']
     if quiet:
     if quiet:

+ 6 - 1
subcmds/download.py

@@ -36,6 +36,9 @@ makes it available in your project's local working directory.
     p.add_option('-c','--cherry-pick',
     p.add_option('-c','--cherry-pick',
                  dest='cherrypick', action='store_true',
                  dest='cherrypick', action='store_true',
                  help="cherry-pick instead of checkout")
                  help="cherry-pick instead of checkout")
+    p.add_option('-r','--revert',
+                 dest='revert', action='store_true',
+                 help="revert instead of checkout")
 
 
   def _ParseChangeIds(self, args):
   def _ParseChangeIds(self, args):
     if not args:
     if not args:
@@ -68,7 +71,7 @@ makes it available in your project's local working directory.
           % (project.name, change_id, ps_id)
           % (project.name, change_id, ps_id)
         sys.exit(1)
         sys.exit(1)
 
 
-      if not dl.commits:
+      if not opt.revert and not dl.commits:
         print >>sys.stderr, \
         print >>sys.stderr, \
           '[%s] change %d/%d has already been merged' \
           '[%s] change %d/%d has already been merged' \
           % (project.name, change_id, ps_id)
           % (project.name, change_id, ps_id)
@@ -82,5 +85,7 @@ makes it available in your project's local working directory.
           print >>sys.stderr, '  %s' % (c)
           print >>sys.stderr, '  %s' % (c)
       if opt.cherrypick:
       if opt.cherrypick:
         project._CherryPick(dl.commit)
         project._CherryPick(dl.commit)
+      elif opt.revert:
+        project._Revert(dl.commit)
       else:
       else:
         project._Checkout(dl.commit)
         project._Checkout(dl.commit)