diff options
author | Conley Owens <cco3@android.com> | 2012-10-03 16:49:12 -0700 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2012-10-03 16:49:12 -0700 |
commit | 3ff9decfd4e2f1fed71658d0f78a17895f80ff5f (patch) | |
tree | 5ecf68da509291eaf368772f3f5c3571060651a8 | |
parent | 9779565abf06d2f1e48548197be350a06c1eab9b (diff) | |
parent | 14a6674e32b3000dbe8b7c96b0d1bb4fb0021720 (diff) | |
download | git-repo-3ff9decfd4e2f1fed71658d0f78a17895f80ff5f.tar.gz |
Merge "manifest: record the original revision when in -r mode."
-rw-r--r-- | manifest_xml.py | 19 | ||||
-rw-r--r-- | project.py | 45 | ||||
-rw-r--r-- | subcmds/manifest.py | 8 |
3 files changed, 55 insertions, 17 deletions
diff --git a/manifest_xml.py b/manifest_xml.py index 8be83cf9..a6364a77 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
@@ -124,7 +124,7 @@ class XmlManifest(object): | |||
124 | if r.reviewUrl is not None: | 124 | if r.reviewUrl is not None: |
125 | e.setAttribute('review', r.reviewUrl) | 125 | e.setAttribute('review', r.reviewUrl) |
126 | 126 | ||
127 | def Save(self, fd, peg_rev=False): | 127 | def Save(self, fd, peg_rev=False, peg_rev_upstream=True): |
128 | """Write the current manifest out to the given file descriptor. | 128 | """Write the current manifest out to the given file descriptor. |
129 | """ | 129 | """ |
130 | mp = self.manifestProject | 130 | mp = self.manifestProject |
@@ -198,11 +198,15 @@ class XmlManifest(object): | |||
198 | e.setAttribute('remote', p.remote.name) | 198 | e.setAttribute('remote', p.remote.name) |
199 | if peg_rev: | 199 | if peg_rev: |
200 | if self.IsMirror: | 200 | if self.IsMirror: |
201 | e.setAttribute('revision', | 201 | value = p.bare_git.rev_parse(p.revisionExpr + '^0') |
202 | p.bare_git.rev_parse(p.revisionExpr + '^0')) | ||
203 | else: | 202 | else: |
204 | e.setAttribute('revision', | 203 | value = p.work_git.rev_parse(HEAD + '^0') |
205 | p.work_git.rev_parse(HEAD + '^0')) | 204 | e.setAttribute('revision', value) |
205 | if peg_rev_upstream and value != p.revisionExpr: | ||
206 | # Only save the origin if the origin is not a sha1, and the default | ||
207 | # isn't our value, and the if the default doesn't already have that | ||
208 | # covered. | ||
209 | e.setAttribute('upstream', p.revisionExpr) | ||
206 | elif not d.revisionExpr or p.revisionExpr != d.revisionExpr: | 210 | elif not d.revisionExpr or p.revisionExpr != d.revisionExpr: |
207 | e.setAttribute('revision', p.revisionExpr) | 211 | e.setAttribute('revision', p.revisionExpr) |
208 | 212 | ||
@@ -574,6 +578,8 @@ class XmlManifest(object): | |||
574 | else: | 578 | else: |
575 | sync_c = sync_c.lower() in ("yes", "true", "1") | 579 | sync_c = sync_c.lower() in ("yes", "true", "1") |
576 | 580 | ||
581 | upstream = node.getAttribute('upstream') | ||
582 | |||
577 | groups = '' | 583 | groups = '' |
578 | if node.hasAttribute('groups'): | 584 | if node.hasAttribute('groups'): |
579 | groups = node.getAttribute('groups') | 585 | groups = node.getAttribute('groups') |
@@ -600,7 +606,8 @@ class XmlManifest(object): | |||
600 | revisionId = None, | 606 | revisionId = None, |
601 | rebase = rebase, | 607 | rebase = rebase, |
602 | groups = groups, | 608 | groups = groups, |
603 | sync_c = sync_c) | 609 | sync_c = sync_c, |
610 | upstream = upstream) | ||
604 | 611 | ||
605 | for n in node.childNodes: | 612 | for n in node.childNodes: |
606 | if n.nodeName == 'copyfile': | 613 | if n.nodeName == 'copyfile': |
@@ -484,7 +484,8 @@ class Project(object): | |||
484 | revisionId, | 484 | revisionId, |
485 | rebase = True, | 485 | rebase = True, |
486 | groups = None, | 486 | groups = None, |
487 | sync_c = False): | 487 | sync_c = False, |
488 | upstream = None): | ||
488 | self.manifest = manifest | 489 | self.manifest = manifest |
489 | self.name = name | 490 | self.name = name |
490 | self.remote = remote | 491 | self.remote = remote |
@@ -506,6 +507,7 @@ class Project(object): | |||
506 | self.rebase = rebase | 507 | self.rebase = rebase |
507 | self.groups = groups | 508 | self.groups = groups |
508 | self.sync_c = sync_c | 509 | self.sync_c = sync_c |
510 | self.upstream = upstream | ||
509 | 511 | ||
510 | self.snapshots = {} | 512 | self.snapshots = {} |
511 | self.copyfiles = [] | 513 | self.copyfiles = [] |
@@ -1373,6 +1375,16 @@ class Project(object): | |||
1373 | is_sha1 = False | 1375 | is_sha1 = False |
1374 | tag_name = None | 1376 | tag_name = None |
1375 | 1377 | ||
1378 | def CheckForSha1(): | ||
1379 | try: | ||
1380 | # if revision (sha or tag) is not present then following function | ||
1381 | # throws an error. | ||
1382 | self.bare_git.rev_parse('--verify', '%s^0' % self.revisionExpr) | ||
1383 | return True | ||
1384 | except GitError: | ||
1385 | # There is no such persistent revision. We have to fetch it. | ||
1386 | return False | ||
1387 | |||
1376 | if current_branch_only: | 1388 | if current_branch_only: |
1377 | if ID_RE.match(self.revisionExpr) is not None: | 1389 | if ID_RE.match(self.revisionExpr) is not None: |
1378 | is_sha1 = True | 1390 | is_sha1 = True |
@@ -1381,14 +1393,10 @@ class Project(object): | |||
1381 | tag_name = self.revisionExpr[len(R_TAGS):] | 1393 | tag_name = self.revisionExpr[len(R_TAGS):] |
1382 | 1394 | ||
1383 | if is_sha1 or tag_name is not None: | 1395 | if is_sha1 or tag_name is not None: |
1384 | try: | 1396 | if CheckForSha1(): |
1385 | # if revision (sha or tag) is not present then following function | ||
1386 | # throws an error. | ||
1387 | self.bare_git.rev_parse('--verify', '%s^0' % self.revisionExpr) | ||
1388 | return True | 1397 | return True |
1389 | except GitError: | 1398 | if is_sha1 and (not self.upstream or ID_RE.match(self.upstream)): |
1390 | # There is no such persistent revision. We have to fetch it. | 1399 | current_branch_only = False |
1391 | pass | ||
1392 | 1400 | ||
1393 | if not name: | 1401 | if not name: |
1394 | name = self.remote.name | 1402 | name = self.remote.name |
@@ -1453,7 +1461,7 @@ class Project(object): | |||
1453 | cmd.append('--update-head-ok') | 1461 | cmd.append('--update-head-ok') |
1454 | cmd.append(name) | 1462 | cmd.append(name) |
1455 | 1463 | ||
1456 | if not current_branch_only or is_sha1: | 1464 | if not current_branch_only: |
1457 | # Fetch whole repo | 1465 | # Fetch whole repo |
1458 | cmd.append('--tags') | 1466 | cmd.append('--tags') |
1459 | cmd.append((u'+refs/heads/*:') + remote.ToLocal('refs/heads/*')) | 1467 | cmd.append((u'+refs/heads/*:') + remote.ToLocal('refs/heads/*')) |
@@ -1462,15 +1470,23 @@ class Project(object): | |||
1462 | cmd.append(tag_name) | 1470 | cmd.append(tag_name) |
1463 | else: | 1471 | else: |
1464 | branch = self.revisionExpr | 1472 | branch = self.revisionExpr |
1473 | if is_sha1: | ||
1474 | branch = self.upstream | ||
1465 | if branch.startswith(R_HEADS): | 1475 | if branch.startswith(R_HEADS): |
1466 | branch = branch[len(R_HEADS):] | 1476 | branch = branch[len(R_HEADS):] |
1467 | cmd.append((u'+refs/heads/%s:' % branch) + remote.ToLocal('refs/heads/%s' % branch)) | 1477 | cmd.append((u'+refs/heads/%s:' % branch) + remote.ToLocal('refs/heads/%s' % branch)) |
1468 | 1478 | ||
1469 | ok = False | 1479 | ok = False |
1470 | for i in range(2): | 1480 | for i in range(2): |
1471 | if GitCommand(self, cmd, bare=True, ssh_proxy=ssh_proxy).Wait() == 0: | 1481 | ret = GitCommand(self, cmd, bare=True, ssh_proxy=ssh_proxy).Wait() |
1482 | if ret == 0: | ||
1472 | ok = True | 1483 | ok = True |
1473 | break | 1484 | break |
1485 | elif current_branch_only and is_sha1 and ret == 128: | ||
1486 | # Exit code 128 means "couldn't find the ref you asked for"; if we're in sha1 | ||
1487 | # mode, we just tried sync'ing from the upstream field; it doesn't exist, thus | ||
1488 | # abort the optimization attempt and do a full sync. | ||
1489 | break | ||
1474 | time.sleep(random.randint(30, 45)) | 1490 | time.sleep(random.randint(30, 45)) |
1475 | 1491 | ||
1476 | if initial: | 1492 | if initial: |
@@ -1480,6 +1496,15 @@ class Project(object): | |||
1480 | else: | 1496 | else: |
1481 | os.remove(packed_refs) | 1497 | os.remove(packed_refs) |
1482 | self.bare_git.pack_refs('--all', '--prune') | 1498 | self.bare_git.pack_refs('--all', '--prune') |
1499 | |||
1500 | if is_sha1 and current_branch_only and self.upstream: | ||
1501 | # We just synced the upstream given branch; verify we | ||
1502 | # got what we wanted, else trigger a second run of all | ||
1503 | # refs. | ||
1504 | if not CheckForSha1(): | ||
1505 | return self._RemoteFetch(name=name, current_branch_only=False, | ||
1506 | initial=False, quiet=quiet, alt_dir=alt_dir) | ||
1507 | |||
1483 | return ok | 1508 | return ok |
1484 | 1509 | ||
1485 | def _ApplyCloneBundle(self, initial=False, quiet=False): | 1510 | def _ApplyCloneBundle(self, initial=False, quiet=False): |
diff --git a/subcmds/manifest.py b/subcmds/manifest.py index cd196531..43887654 100644 --- a/subcmds/manifest.py +++ b/subcmds/manifest.py | |||
@@ -48,6 +48,11 @@ in a Git repository for use during future 'repo init' invocations. | |||
48 | p.add_option('-r', '--revision-as-HEAD', | 48 | p.add_option('-r', '--revision-as-HEAD', |
49 | dest='peg_rev', action='store_true', | 49 | dest='peg_rev', action='store_true', |
50 | help='Save revisions as current HEAD') | 50 | help='Save revisions as current HEAD') |
51 | p.add_option('--suppress-upstream-revision', dest='peg_rev_upstream', | ||
52 | default=True, action='store_false', | ||
53 | help='If in -r mode, do not write the upstream field. ' | ||
54 | 'Only of use if the branch names for a sha1 manifest are ' | ||
55 | 'sensitive.') | ||
51 | p.add_option('-o', '--output-file', | 56 | p.add_option('-o', '--output-file', |
52 | dest='output_file', | 57 | dest='output_file', |
53 | default='-', | 58 | default='-', |
@@ -60,7 +65,8 @@ in a Git repository for use during future 'repo init' invocations. | |||
60 | else: | 65 | else: |
61 | fd = open(opt.output_file, 'w') | 66 | fd = open(opt.output_file, 'w') |
62 | self.manifest.Save(fd, | 67 | self.manifest.Save(fd, |
63 | peg_rev = opt.peg_rev) | 68 | peg_rev = opt.peg_rev, |
69 | peg_rev_upstream = opt.peg_rev_upstream) | ||
64 | fd.close() | 70 | fd.close() |
65 | if opt.output_file != '-': | 71 | if opt.output_file != '-': |
66 | print >>sys.stderr, 'Saved manifest to %s' % opt.output_file | 72 | print >>sys.stderr, 'Saved manifest to %s' % opt.output_file |