Просмотр исходного кода

When writing manifest, set the dest-branch attribute for projects

When generating a revision locked manifest, we need to know what
ref to push changes to when doing 'repo upload'.  This information
is lost when we lock the revision attribute to a particular commit
hash, so we need to expose it through the dest-branch attribute.

Bug: https://crbug.com/1005103
Test: manual execution
Change-Id: Ib31fd77ad8c9379759c4181dac1ea97de43eec35
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/263572
Tested-by: Sean McAllister <smcallis@google.com>
Reviewed-by: Mike Frysinger <vapier@google.com>
Sean McAllister 5 лет назад
Родитель
Сommit
af908cb543
2 измененных файлов с 17 добавлено и 3 удалено
  1. 8 1
      manifest_xml.py
  2. 9 2
      subcmds/manifest.py

+ 8 - 1
manifest_xml.py

@@ -284,7 +284,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
   def _ParseGroups(self, groups):
   def _ParseGroups(self, groups):
     return [x for x in re.split(r'[,\s]+', groups) if x]
     return [x for x in re.split(r'[,\s]+', groups) if x]
 
 
-  def Save(self, fd, peg_rev=False, peg_rev_upstream=True, groups=None):
+  def Save(self, fd, peg_rev=False, peg_rev_upstream=True, peg_rev_dest_branch=True, groups=None):
     """Write the current manifest out to the given file descriptor.
     """Write the current manifest out to the given file descriptor.
     """
     """
     mp = self.manifestProject
     mp = self.manifestProject
@@ -389,6 +389,13 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md
             # Only save the origin if the origin is not a sha1, and the default
             # Only save the origin if the origin is not a sha1, and the default
             # isn't our value
             # isn't our value
             e.setAttribute('upstream', p.revisionExpr)
             e.setAttribute('upstream', p.revisionExpr)
+
+        if peg_rev_dest_branch:
+          if p.dest_branch:
+            e.setAttribute('dest-branch', p.dest_branch)
+          elif value != p.revisionExpr:
+            e.setAttribute('dest-branch', p.revisionExpr)
+
       else:
       else:
         revision = self.remotes[p.remote.orig_name].revision or d.revisionExpr
         revision = self.remotes[p.remote.orig_name].revision or d.revisionExpr
         if not revision or revision != p.revisionExpr:
         if not revision or revision != p.revisionExpr:

+ 9 - 2
subcmds/manifest.py

@@ -38,7 +38,8 @@ The -r option can be used to generate a manifest file with project
 revisions set to the current commit hash.  These are known as
 revisions set to the current commit hash.  These are known as
 "revision locked manifests", as they don't follow a particular branch.
 "revision locked manifests", as they don't follow a particular branch.
 In this case, the 'upstream' attribute is set to the ref we were on
 In this case, the 'upstream' attribute is set to the ref we were on
-when the manifest was generated.
+when the manifest was generated.  The 'dest-branch' attribute is set
+to indicate the remote ref to push changes to via 'repo upload'.
 """
 """
 
 
   @property
   @property
@@ -62,6 +63,11 @@ when the manifest was generated.
                  help='If in -r mode, do not write the upstream field.  '
                  help='If in -r mode, do not write the upstream field.  '
                  'Only of use if the branch names for a sha1 manifest are '
                  'Only of use if the branch names for a sha1 manifest are '
                  'sensitive.')
                  'sensitive.')
+    p.add_option('--suppress-dest-branch', dest='peg_rev_dest_branch',
+                 default=True, action='store_false',
+                 help='If in -r mode, do not write the dest-branch field.  '
+                 'Only of use if the branch names for a sha1 manifest are '
+                 'sensitive.')
     p.add_option('-o', '--output-file',
     p.add_option('-o', '--output-file',
                  dest='output_file',
                  dest='output_file',
                  default='-',
                  default='-',
@@ -79,7 +85,8 @@ when the manifest was generated.
       fd = open(opt.output_file, 'w')
       fd = open(opt.output_file, 'w')
     self.manifest.Save(fd,
     self.manifest.Save(fd,
                        peg_rev=opt.peg_rev,
                        peg_rev=opt.peg_rev,
-                       peg_rev_upstream=opt.peg_rev_upstream)
+                       peg_rev_upstream=opt.peg_rev_upstream,
+                       peg_rev_dest_branch=opt.peg_rev_dest_branch)
     fd.close()
     fd.close()
     if opt.output_file != '-':
     if opt.output_file != '-':
       print('Saved manifest to %s' % opt.output_file, file=sys.stderr)
       print('Saved manifest to %s' % opt.output_file, file=sys.stderr)