diff options
Diffstat (limited to 'project.py')
| -rw-r--r-- | project.py | 69 |
1 files changed, 44 insertions, 25 deletions
| @@ -36,6 +36,11 @@ from trace import IsTrace, Trace | |||
| 36 | 36 | ||
| 37 | from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M | 37 | from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M |
| 38 | 38 | ||
| 39 | try: | ||
| 40 | input = raw_input | ||
| 41 | except NameError: | ||
| 42 | pass | ||
| 43 | |||
| 39 | def _lwrite(path, content): | 44 | def _lwrite(path, content): |
| 40 | lock = '%s.lock' % path | 45 | lock = '%s.lock' % path |
| 41 | 46 | ||
| @@ -78,7 +83,7 @@ def _ProjectHooks(): | |||
| 78 | if _project_hook_list is None: | 83 | if _project_hook_list is None: |
| 79 | d = os.path.abspath(os.path.dirname(__file__)) | 84 | d = os.path.abspath(os.path.dirname(__file__)) |
| 80 | d = os.path.join(d , 'hooks') | 85 | d = os.path.join(d , 'hooks') |
| 81 | _project_hook_list = map(lambda x: os.path.join(d, x), os.listdir(d)) | 86 | _project_hook_list = [os.path.join(d, x) for x in os.listdir(d)] |
| 82 | return _project_hook_list | 87 | return _project_hook_list |
| 83 | 88 | ||
| 84 | 89 | ||
| @@ -361,7 +366,7 @@ class RepoHook(object): | |||
| 361 | 'Do you want to allow this script to run ' | 366 | 'Do you want to allow this script to run ' |
| 362 | '(yes/yes-never-ask-again/NO)? ') % ( | 367 | '(yes/yes-never-ask-again/NO)? ') % ( |
| 363 | self._GetMustVerb(), self._script_fullpath) | 368 | self._GetMustVerb(), self._script_fullpath) |
| 364 | response = raw_input(prompt).lower() | 369 | response = input(prompt).lower() |
| 365 | print() | 370 | print() |
| 366 | 371 | ||
| 367 | # User is doing a one-time approval. | 372 | # User is doing a one-time approval. |
| @@ -488,6 +493,7 @@ class Project(object): | |||
| 488 | groups = None, | 493 | groups = None, |
| 489 | sync_c = False, | 494 | sync_c = False, |
| 490 | sync_s = False, | 495 | sync_s = False, |
| 496 | clone_depth = None, | ||
| 491 | upstream = None, | 497 | upstream = None, |
| 492 | parent = None, | 498 | parent = None, |
| 493 | is_derived = False): | 499 | is_derived = False): |
| @@ -533,6 +539,7 @@ class Project(object): | |||
| 533 | self.groups = groups | 539 | self.groups = groups |
| 534 | self.sync_c = sync_c | 540 | self.sync_c = sync_c |
| 535 | self.sync_s = sync_s | 541 | self.sync_s = sync_s |
| 542 | self.clone_depth = clone_depth | ||
| 536 | self.upstream = upstream | 543 | self.upstream = upstream |
| 537 | self.parent = parent | 544 | self.parent = parent |
| 538 | self.is_derived = is_derived | 545 | self.is_derived = is_derived |
| @@ -644,7 +651,7 @@ class Project(object): | |||
| 644 | all_refs = self._allrefs | 651 | all_refs = self._allrefs |
| 645 | heads = {} | 652 | heads = {} |
| 646 | 653 | ||
| 647 | for name, ref_id in all_refs.iteritems(): | 654 | for name, ref_id in all_refs.items(): |
| 648 | if name.startswith(R_HEADS): | 655 | if name.startswith(R_HEADS): |
| 649 | name = name[len(R_HEADS):] | 656 | name = name[len(R_HEADS):] |
| 650 | b = self.GetBranch(name) | 657 | b = self.GetBranch(name) |
| @@ -653,7 +660,7 @@ class Project(object): | |||
| 653 | b.revision = ref_id | 660 | b.revision = ref_id |
| 654 | heads[name] = b | 661 | heads[name] = b |
| 655 | 662 | ||
| 656 | for name, ref_id in all_refs.iteritems(): | 663 | for name, ref_id in all_refs.items(): |
| 657 | if name.startswith(R_PUB): | 664 | if name.startswith(R_PUB): |
| 658 | name = name[len(R_PUB):] | 665 | name = name[len(R_PUB):] |
| 659 | b = heads.get(name) | 666 | b = heads.get(name) |
| @@ -672,9 +679,14 @@ class Project(object): | |||
| 672 | project_groups: "all,group1,group2" | 679 | project_groups: "all,group1,group2" |
| 673 | manifest_groups: "-group1,group2" | 680 | manifest_groups: "-group1,group2" |
| 674 | the project will be matched. | 681 | the project will be matched. |
| 682 | |||
| 683 | The special manifest group "default" will match any project that | ||
| 684 | does not have the special project group "notdefault" | ||
| 675 | """ | 685 | """ |
| 676 | expanded_manifest_groups = manifest_groups or ['all', '-notdefault'] | 686 | expanded_manifest_groups = manifest_groups or ['default'] |
| 677 | expanded_project_groups = ['all'] + (self.groups or []) | 687 | expanded_project_groups = ['all'] + (self.groups or []) |
| 688 | if not 'notdefault' in expanded_project_groups: | ||
| 689 | expanded_project_groups += ['default'] | ||
| 678 | 690 | ||
| 679 | matched = False | 691 | matched = False |
| 680 | for group in expanded_manifest_groups: | 692 | for group in expanded_manifest_groups: |
| @@ -754,10 +766,7 @@ class Project(object): | |||
| 754 | paths.extend(df.keys()) | 766 | paths.extend(df.keys()) |
| 755 | paths.extend(do) | 767 | paths.extend(do) |
| 756 | 768 | ||
| 757 | paths = list(set(paths)) | 769 | for p in sorted(set(paths)): |
| 758 | paths.sort() | ||
| 759 | |||
| 760 | for p in paths: | ||
| 761 | try: | 770 | try: |
| 762 | i = di[p] | 771 | i = di[p] |
| 763 | except KeyError: | 772 | except KeyError: |
| @@ -849,13 +858,13 @@ class Project(object): | |||
| 849 | all_refs = self._allrefs | 858 | all_refs = self._allrefs |
| 850 | heads = set() | 859 | heads = set() |
| 851 | canrm = {} | 860 | canrm = {} |
| 852 | for name, ref_id in all_refs.iteritems(): | 861 | for name, ref_id in all_refs.items(): |
| 853 | if name.startswith(R_HEADS): | 862 | if name.startswith(R_HEADS): |
| 854 | heads.add(name) | 863 | heads.add(name) |
| 855 | elif name.startswith(R_PUB): | 864 | elif name.startswith(R_PUB): |
| 856 | canrm[name] = ref_id | 865 | canrm[name] = ref_id |
| 857 | 866 | ||
| 858 | for name, ref_id in canrm.iteritems(): | 867 | for name, ref_id in canrm.items(): |
| 859 | n = name[len(R_PUB):] | 868 | n = name[len(R_PUB):] |
| 860 | if R_HEADS + n not in heads: | 869 | if R_HEADS + n not in heads: |
| 861 | self.bare_git.DeleteRef(name, ref_id) | 870 | self.bare_git.DeleteRef(name, ref_id) |
| @@ -866,14 +875,14 @@ class Project(object): | |||
| 866 | heads = {} | 875 | heads = {} |
| 867 | pubed = {} | 876 | pubed = {} |
| 868 | 877 | ||
| 869 | for name, ref_id in self._allrefs.iteritems(): | 878 | for name, ref_id in self._allrefs.items(): |
| 870 | if name.startswith(R_HEADS): | 879 | if name.startswith(R_HEADS): |
| 871 | heads[name[len(R_HEADS):]] = ref_id | 880 | heads[name[len(R_HEADS):]] = ref_id |
| 872 | elif name.startswith(R_PUB): | 881 | elif name.startswith(R_PUB): |
| 873 | pubed[name[len(R_PUB):]] = ref_id | 882 | pubed[name[len(R_PUB):]] = ref_id |
| 874 | 883 | ||
| 875 | ready = [] | 884 | ready = [] |
| 876 | for branch, ref_id in heads.iteritems(): | 885 | for branch, ref_id in heads.items(): |
| 877 | if branch in pubed and pubed[branch] == ref_id: | 886 | if branch in pubed and pubed[branch] == ref_id: |
| 878 | continue | 887 | continue |
| 879 | if selected_branch and branch != selected_branch: | 888 | if selected_branch and branch != selected_branch: |
| @@ -1218,7 +1227,7 @@ class Project(object): | |||
| 1218 | cmd = ['fetch', remote.name] | 1227 | cmd = ['fetch', remote.name] |
| 1219 | cmd.append('refs/changes/%2.2d/%d/%d' \ | 1228 | cmd.append('refs/changes/%2.2d/%d/%d' \ |
| 1220 | % (change_id % 100, change_id, patch_id)) | 1229 | % (change_id % 100, change_id, patch_id)) |
| 1221 | cmd.extend(map(str, remote.fetch)) | 1230 | cmd.extend(list(map(str, remote.fetch))) |
| 1222 | if GitCommand(self, cmd, bare=True).Wait() != 0: | 1231 | if GitCommand(self, cmd, bare=True).Wait() != 0: |
| 1223 | return None | 1232 | return None |
| 1224 | return DownloadedChange(self, | 1233 | return DownloadedChange(self, |
| @@ -1607,7 +1616,7 @@ class Project(object): | |||
| 1607 | ids = set(all_refs.values()) | 1616 | ids = set(all_refs.values()) |
| 1608 | tmp = set() | 1617 | tmp = set() |
| 1609 | 1618 | ||
| 1610 | for r, ref_id in GitRefs(ref_dir).all.iteritems(): | 1619 | for r, ref_id in GitRefs(ref_dir).all.items(): |
| 1611 | if r not in all_refs: | 1620 | if r not in all_refs: |
| 1612 | if r.startswith(R_TAGS) or remote.WritesTo(r): | 1621 | if r.startswith(R_TAGS) or remote.WritesTo(r): |
| 1613 | all_refs[r] = ref_id | 1622 | all_refs[r] = ref_id |
| @@ -1622,13 +1631,10 @@ class Project(object): | |||
| 1622 | ids.add(ref_id) | 1631 | ids.add(ref_id) |
| 1623 | tmp.add(r) | 1632 | tmp.add(r) |
| 1624 | 1633 | ||
| 1625 | ref_names = list(all_refs.keys()) | ||
| 1626 | ref_names.sort() | ||
| 1627 | |||
| 1628 | tmp_packed = '' | 1634 | tmp_packed = '' |
| 1629 | old_packed = '' | 1635 | old_packed = '' |
| 1630 | 1636 | ||
| 1631 | for r in ref_names: | 1637 | for r in sorted(all_refs): |
| 1632 | line = '%s %s\n' % (all_refs[r], r) | 1638 | line = '%s %s\n' % (all_refs[r], r) |
| 1633 | tmp_packed += line | 1639 | tmp_packed += line |
| 1634 | if r not in tmp: | 1640 | if r not in tmp: |
| @@ -1642,7 +1648,10 @@ class Project(object): | |||
| 1642 | 1648 | ||
| 1643 | # The --depth option only affects the initial fetch; after that we'll do | 1649 | # The --depth option only affects the initial fetch; after that we'll do |
| 1644 | # full fetches of changes. | 1650 | # full fetches of changes. |
| 1645 | depth = self.manifest.manifestProject.config.GetString('repo.depth') | 1651 | if self.clone_depth: |
| 1652 | depth = self.clone_depth | ||
| 1653 | else: | ||
| 1654 | depth = self.manifest.manifestProject.config.GetString('repo.depth') | ||
| 1646 | if depth and initial: | 1655 | if depth and initial: |
| 1647 | cmd.append('--depth=%s' % depth) | 1656 | cmd.append('--depth=%s' % depth) |
| 1648 | 1657 | ||
| @@ -1654,11 +1663,13 @@ class Project(object): | |||
| 1654 | 1663 | ||
| 1655 | if not current_branch_only: | 1664 | if not current_branch_only: |
| 1656 | # Fetch whole repo | 1665 | # Fetch whole repo |
| 1657 | if no_tags: | 1666 | # If using depth then we should not get all the tags since they may |
| 1667 | # be outside of the depth. | ||
| 1668 | if no_tags or depth: | ||
| 1658 | cmd.append('--no-tags') | 1669 | cmd.append('--no-tags') |
| 1659 | else: | 1670 | else: |
| 1660 | cmd.append('--tags') | 1671 | cmd.append('--tags') |
| 1661 | cmd.append((u'+refs/heads/*:') + remote.ToLocal('refs/heads/*')) | 1672 | cmd.append(str((u'+refs/heads/*:') + remote.ToLocal('refs/heads/*'))) |
| 1662 | elif tag_name is not None: | 1673 | elif tag_name is not None: |
| 1663 | cmd.append('tag') | 1674 | cmd.append('tag') |
| 1664 | cmd.append(tag_name) | 1675 | cmd.append(tag_name) |
| @@ -1668,7 +1679,7 @@ class Project(object): | |||
| 1668 | branch = self.upstream | 1679 | branch = self.upstream |
| 1669 | if branch.startswith(R_HEADS): | 1680 | if branch.startswith(R_HEADS): |
| 1670 | branch = branch[len(R_HEADS):] | 1681 | branch = branch[len(R_HEADS):] |
| 1671 | cmd.append((u'+refs/heads/%s:' % branch) + remote.ToLocal('refs/heads/%s' % branch)) | 1682 | cmd.append(str((u'+refs/heads/%s:' % branch) + remote.ToLocal('refs/heads/%s' % branch))) |
| 1672 | 1683 | ||
| 1673 | ok = False | 1684 | ok = False |
| 1674 | for _i in range(2): | 1685 | for _i in range(2): |
| @@ -1702,7 +1713,7 @@ class Project(object): | |||
| 1702 | return ok | 1713 | return ok |
| 1703 | 1714 | ||
| 1704 | def _ApplyCloneBundle(self, initial=False, quiet=False): | 1715 | def _ApplyCloneBundle(self, initial=False, quiet=False): |
| 1705 | if initial and self.manifest.manifestProject.config.GetString('repo.depth'): | 1716 | if initial and (self.manifest.manifestProject.config.GetString('repo.depth') or self.clone_depth): |
| 1706 | return False | 1717 | return False |
| 1707 | 1718 | ||
| 1708 | remote = self.GetRemote(self.remote.name) | 1719 | remote = self.GetRemote(self.remote.name) |
| @@ -2099,6 +2110,10 @@ class Project(object): | |||
| 2099 | line = fd.read() | 2110 | line = fd.read() |
| 2100 | finally: | 2111 | finally: |
| 2101 | fd.close() | 2112 | fd.close() |
| 2113 | try: | ||
| 2114 | line = line.decode() | ||
| 2115 | except AttributeError: | ||
| 2116 | pass | ||
| 2102 | if line.startswith('ref: '): | 2117 | if line.startswith('ref: '): |
| 2103 | return line[5:-1] | 2118 | return line[5:-1] |
| 2104 | return line[:-1] | 2119 | return line[:-1] |
| @@ -2192,7 +2207,7 @@ class Project(object): | |||
| 2192 | if not git_require((1, 7, 2)): | 2207 | if not git_require((1, 7, 2)): |
| 2193 | raise ValueError('cannot set config on command line for %s()' | 2208 | raise ValueError('cannot set config on command line for %s()' |
| 2194 | % name) | 2209 | % name) |
| 2195 | for k, v in config.iteritems(): | 2210 | for k, v in config.items(): |
| 2196 | cmdv.append('-c') | 2211 | cmdv.append('-c') |
| 2197 | cmdv.append('%s=%s' % (k, v)) | 2212 | cmdv.append('%s=%s' % (k, v)) |
| 2198 | cmdv.append(name) | 2213 | cmdv.append(name) |
| @@ -2208,6 +2223,10 @@ class Project(object): | |||
| 2208 | name, | 2223 | name, |
| 2209 | p.stderr)) | 2224 | p.stderr)) |
| 2210 | r = p.stdout | 2225 | r = p.stdout |
| 2226 | try: | ||
| 2227 | r = r.decode() | ||
| 2228 | except AttributeError: | ||
| 2229 | pass | ||
| 2211 | if r.endswith('\n') and r.index('\n') == len(r) - 1: | 2230 | if r.endswith('\n') and r.index('\n') == len(r) - 1: |
| 2212 | return r[:-1] | 2231 | return r[:-1] |
| 2213 | return r | 2232 | return r |
