diff options
author | Chris AtLee <chris.atlee@gmail.com> | 2014-01-16 21:32:33 -0500 |
---|---|---|
committer | David Pursehouse <david.pursehouse@sonymobile.com> | 2014-03-03 10:17:03 +0000 |
commit | 2fb6466f795eb30c1dfa598501f5b5d2981e6a5f (patch) | |
tree | 09664b3abb134e5cce4af110174e6498523540d8 /project.py | |
parent | 724aafb52d546b23658e517278e4d93ec351dbaf (diff) | |
download | git-repo-2fb6466f795eb30c1dfa598501f5b5d2981e6a5f.tar.gz |
Don't fetch from remotes if commit id exists locally
In existing workspaces where the manifest specifies a commit id in the
manifest, we can avoid doing a fetch from the remote if we have the
commit locally. This substantially improves sync times for fully
specified manifests.
Change-Id: Ide216f28a545e00e0b493ce90ed0019513c61613
Diffstat (limited to 'project.py')
-rw-r--r-- | project.py | 30 |
1 files changed, 18 insertions, 12 deletions
@@ -1078,6 +1078,13 @@ class Project(object): | |||
1078 | elif self.manifest.default.sync_c: | 1078 | elif self.manifest.default.sync_c: |
1079 | current_branch_only = True | 1079 | current_branch_only = True |
1080 | 1080 | ||
1081 | is_sha1 = False | ||
1082 | if ID_RE.match(self.revisionExpr) is not None: | ||
1083 | is_sha1 = True | ||
1084 | if is_sha1 and self._CheckForSha1(): | ||
1085 | # Don't need to fetch since we already have this revision | ||
1086 | return True | ||
1087 | |||
1081 | if not self._RemoteFetch(initial=is_new, quiet=quiet, alt_dir=alt_dir, | 1088 | if not self._RemoteFetch(initial=is_new, quiet=quiet, alt_dir=alt_dir, |
1082 | current_branch_only=current_branch_only, | 1089 | current_branch_only=current_branch_only, |
1083 | no_tags=no_tags): | 1090 | no_tags=no_tags): |
@@ -1644,6 +1651,15 @@ class Project(object): | |||
1644 | 1651 | ||
1645 | 1652 | ||
1646 | ## Direct Git Commands ## | 1653 | ## Direct Git Commands ## |
1654 | def _CheckForSha1(self): | ||
1655 | try: | ||
1656 | # if revision (sha or tag) is not present then following function | ||
1657 | # throws an error. | ||
1658 | self.bare_git.rev_parse('--verify', '%s^0' % self.revisionExpr) | ||
1659 | return True | ||
1660 | except GitError: | ||
1661 | # There is no such persistent revision. We have to fetch it. | ||
1662 | return False | ||
1647 | 1663 | ||
1648 | def _FetchArchive(self, tarpath, cwd=None): | 1664 | def _FetchArchive(self, tarpath, cwd=None): |
1649 | cmd = ['archive', '-v', '-o', tarpath] | 1665 | cmd = ['archive', '-v', '-o', tarpath] |
@@ -1668,16 +1684,6 @@ class Project(object): | |||
1668 | is_sha1 = False | 1684 | is_sha1 = False |
1669 | tag_name = None | 1685 | tag_name = None |
1670 | 1686 | ||
1671 | def CheckForSha1(): | ||
1672 | try: | ||
1673 | # if revision (sha or tag) is not present then following function | ||
1674 | # throws an error. | ||
1675 | self.bare_git.rev_parse('--verify', '%s^0' % self.revisionExpr) | ||
1676 | return True | ||
1677 | except GitError: | ||
1678 | # There is no such persistent revision. We have to fetch it. | ||
1679 | return False | ||
1680 | |||
1681 | if self.clone_depth: | 1687 | if self.clone_depth: |
1682 | depth = self.clone_depth | 1688 | depth = self.clone_depth |
1683 | else: | 1689 | else: |
@@ -1693,7 +1699,7 @@ class Project(object): | |||
1693 | tag_name = self.revisionExpr[len(R_TAGS):] | 1699 | tag_name = self.revisionExpr[len(R_TAGS):] |
1694 | 1700 | ||
1695 | if is_sha1 or tag_name is not None: | 1701 | if is_sha1 or tag_name is not None: |
1696 | if CheckForSha1(): | 1702 | if self._CheckForSha1(): |
1697 | return True | 1703 | return True |
1698 | if is_sha1 and (not self.upstream or ID_RE.match(self.upstream)): | 1704 | if is_sha1 and (not self.upstream or ID_RE.match(self.upstream)): |
1699 | current_branch_only = False | 1705 | current_branch_only = False |
@@ -1808,7 +1814,7 @@ class Project(object): | |||
1808 | # We just synced the upstream given branch; verify we | 1814 | # We just synced the upstream given branch; verify we |
1809 | # got what we wanted, else trigger a second run of all | 1815 | # got what we wanted, else trigger a second run of all |
1810 | # refs. | 1816 | # refs. |
1811 | if not CheckForSha1(): | 1817 | if not self._CheckForSha1(): |
1812 | return self._RemoteFetch(name=name, current_branch_only=False, | 1818 | return self._RemoteFetch(name=name, current_branch_only=False, |
1813 | initial=False, quiet=quiet, alt_dir=alt_dir) | 1819 | initial=False, quiet=quiet, alt_dir=alt_dir) |
1814 | 1820 | ||