diff options
| -rw-r--r-- | git_config.py | 12 | ||||
| -rw-r--r-- | hooks.py | 4 | ||||
| -rw-r--r-- | manifest_xml.py | 9 | ||||
| -rw-r--r-- | project.py | 196 | ||||
| -rw-r--r-- | subcmds/info.py | 9 | ||||
| -rw-r--r-- | subcmds/sync.py | 12 | ||||
| -rw-r--r-- | subcmds/upload.py | 10 | ||||
| -rw-r--r-- | subcmds/version.py | 8 | ||||
| -rw-r--r-- | tests/test_project.py | 13 |
9 files changed, 144 insertions, 129 deletions
diff --git a/git_config.py b/git_config.py index 0ad01f5ff..f3f1e5b8c 100644 --- a/git_config.py +++ b/git_config.py | |||
| @@ -28,9 +28,7 @@ import urllib.request | |||
| 28 | 28 | ||
| 29 | import error | 29 | import error |
| 30 | import git_command | 30 | import git_command |
| 31 | from git_refs import R_CHANGES | 31 | import git_refs |
| 32 | from git_refs import R_HEADS | ||
| 33 | from git_refs import R_TAGS | ||
| 34 | import platform_utils | 32 | import platform_utils |
| 35 | import repo_trace | 33 | import repo_trace |
| 36 | 34 | ||
| @@ -45,7 +43,7 @@ REVIEW_CACHE = {} | |||
| 45 | 43 | ||
| 46 | 44 | ||
| 47 | def IsChange(rev): | 45 | def IsChange(rev): |
| 48 | return rev.startswith(R_CHANGES) | 46 | return rev.startswith(git_refs.R_CHANGES) |
| 49 | 47 | ||
| 50 | 48 | ||
| 51 | def IsId(rev: str) -> bool: | 49 | def IsId(rev: str) -> bool: |
| @@ -53,7 +51,7 @@ def IsId(rev: str) -> bool: | |||
| 53 | 51 | ||
| 54 | 52 | ||
| 55 | def IsTag(rev): | 53 | def IsTag(rev): |
| 56 | return rev.startswith(R_TAGS) | 54 | return rev.startswith(git_refs.R_TAGS) |
| 57 | 55 | ||
| 58 | 56 | ||
| 59 | def IsImmutable(rev): | 57 | def IsImmutable(rev): |
| @@ -741,13 +739,13 @@ class Remote: | |||
| 741 | return rev | 739 | return rev |
| 742 | 740 | ||
| 743 | if not rev.startswith("refs/"): | 741 | if not rev.startswith("refs/"): |
| 744 | rev = R_HEADS + rev | 742 | rev = git_refs.R_HEADS + rev |
| 745 | 743 | ||
| 746 | for spec in self.fetch: | 744 | for spec in self.fetch: |
| 747 | if spec.SourceMatches(rev): | 745 | if spec.SourceMatches(rev): |
| 748 | return spec.MapSource(rev) | 746 | return spec.MapSource(rev) |
| 749 | 747 | ||
| 750 | if not rev.startswith(R_HEADS): | 748 | if not rev.startswith(git_refs.R_HEADS): |
| 751 | return rev | 749 | return rev |
| 752 | 750 | ||
| 753 | raise error.GitError( | 751 | raise error.GitError( |
| @@ -20,7 +20,7 @@ import traceback | |||
| 20 | import urllib.parse | 20 | import urllib.parse |
| 21 | 21 | ||
| 22 | import error | 22 | import error |
| 23 | from git_refs import HEAD | 23 | import git_refs |
| 24 | 24 | ||
| 25 | 25 | ||
| 26 | # The API we've documented to hook authors. Keep in sync with repo-hooks.md. | 26 | # The API we've documented to hook authors. Keep in sync with repo-hooks.md. |
| @@ -142,7 +142,7 @@ class RepoHook: | |||
| 142 | # NOTE: Local (non-committed) changes will not be factored into this | 142 | # NOTE: Local (non-committed) changes will not be factored into this |
| 143 | # hash. I think this is OK, since we're really only worried about | 143 | # hash. I think this is OK, since we're really only worried about |
| 144 | # warning the user about upstream changes. | 144 | # warning the user about upstream changes. |
| 145 | return self._hooks_project.work_git.rev_parse(HEAD) | 145 | return self._hooks_project.work_git.rev_parse(git_refs.HEAD) |
| 146 | 146 | ||
| 147 | def _GetMustVerb(self): | 147 | def _GetMustVerb(self): |
| 148 | """Return 'must' if the hook is required; 'should' if not.""" | 148 | """Return 'must' if the hook is required; 'should' if not.""" |
diff --git a/manifest_xml.py b/manifest_xml.py index 590e6b6d1..58da71f1c 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
| @@ -23,8 +23,7 @@ import xml.dom.minidom | |||
| 23 | 23 | ||
| 24 | import error | 24 | import error |
| 25 | from git_config import GitConfig | 25 | from git_config import GitConfig |
| 26 | from git_refs import HEAD | 26 | import git_refs |
| 27 | from git_refs import R_HEADS | ||
| 28 | from git_superproject import Superproject | 27 | from git_superproject import Superproject |
| 29 | import platform_utils | 28 | import platform_utils |
| 30 | from project import Annotation | 29 | from project import Annotation |
| @@ -711,7 +710,7 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
| 711 | if self.IsMirror: | 710 | if self.IsMirror: |
| 712 | value = p.bare_git.ResolveCommit(p.revisionExpr) | 711 | value = p.bare_git.ResolveCommit(p.revisionExpr) |
| 713 | else: | 712 | else: |
| 714 | value = p.work_git.ResolveCommit(HEAD) | 713 | value = p.work_git.ResolveCommit(git_refs.HEAD) |
| 715 | e.setAttribute("revision", value) | 714 | e.setAttribute("revision", value) |
| 716 | if peg_rev_upstream: | 715 | if peg_rev_upstream: |
| 717 | if p.upstream: | 716 | if p.upstream: |
| @@ -1208,8 +1207,8 @@ https://gerrit.googlesource.com/git-repo/+/HEAD/docs/manifest-format.md | |||
| 1208 | try: | 1207 | try: |
| 1209 | m = self.manifestProject | 1208 | m = self.manifestProject |
| 1210 | b = m.GetBranch(m.CurrentBranch).merge | 1209 | b = m.GetBranch(m.CurrentBranch).merge |
| 1211 | if b is not None and b.startswith(R_HEADS): | 1210 | if b is not None and b.startswith(git_refs.R_HEADS): |
| 1212 | b = b[len(R_HEADS) :] | 1211 | b = b[len(git_refs.R_HEADS) :] |
| 1213 | self.branch = b | 1212 | self.branch = b |
| 1214 | 1213 | ||
| 1215 | parent_groups = self.parent_groups.copy() | 1214 | parent_groups = self.parent_groups.copy() |
diff --git a/project.py b/project.py index 2bde23f3f..13361d1e3 100644 --- a/project.py +++ b/project.py | |||
| @@ -40,13 +40,7 @@ from git_config import GetSchemeFromUrl | |||
| 40 | from git_config import GetUrlCookieFile | 40 | from git_config import GetUrlCookieFile |
| 41 | from git_config import GitConfig | 41 | from git_config import GitConfig |
| 42 | from git_config import IsId | 42 | from git_config import IsId |
| 43 | from git_refs import GitRefs | 43 | import git_refs |
| 44 | from git_refs import HEAD | ||
| 45 | from git_refs import R_HEADS | ||
| 46 | from git_refs import R_M | ||
| 47 | from git_refs import R_PUB | ||
| 48 | from git_refs import R_TAGS | ||
| 49 | from git_refs import R_WORKTREE_M | ||
| 50 | import git_status | 44 | import git_status |
| 51 | import git_superproject | 45 | import git_superproject |
| 52 | from git_trace2_event_log import EventLog | 46 | from git_trace2_event_log import EventLog |
| @@ -209,7 +203,7 @@ class ReviewableBranch: | |||
| 209 | "--reverse", | 203 | "--reverse", |
| 210 | "--date-order", | 204 | "--date-order", |
| 211 | not_rev(self.base), | 205 | not_rev(self.base), |
| 212 | R_HEADS + self.name, | 206 | git_refs.R_HEADS + self.name, |
| 213 | "--", | 207 | "--", |
| 214 | ) | 208 | ) |
| 215 | try: | 209 | try: |
| @@ -232,7 +226,7 @@ class ReviewableBranch: | |||
| 232 | def unabbrev_commits(self): | 226 | def unabbrev_commits(self): |
| 233 | r = {} | 227 | r = {} |
| 234 | for commit in self.project.bare_git.rev_list( | 228 | for commit in self.project.bare_git.rev_list( |
| 235 | not_rev(self.base), R_HEADS + self.name, "--" | 229 | not_rev(self.base), git_refs.R_HEADS + self.name, "--" |
| 236 | ): | 230 | ): |
| 237 | r[commit[0:8]] = commit | 231 | r[commit[0:8]] = commit |
| 238 | return r | 232 | return r |
| @@ -240,13 +234,17 @@ class ReviewableBranch: | |||
| 240 | @property | 234 | @property |
| 241 | def date(self): | 235 | def date(self): |
| 242 | return self.project.bare_git.log( | 236 | return self.project.bare_git.log( |
| 243 | "--pretty=format:%cd", "-n", "1", R_HEADS + self.name, "--" | 237 | "--pretty=format:%cd", |
| 238 | "-n", | ||
| 239 | "1", | ||
| 240 | git_refs.R_HEADS + self.name, | ||
| 241 | "--", | ||
| 244 | ) | 242 | ) |
| 245 | 243 | ||
| 246 | @property | 244 | @property |
| 247 | def modified_files(self) -> List[str]: | 245 | def modified_files(self) -> List[str]: |
| 248 | return self.project.bare_git.diff( | 246 | return self.project.bare_git.diff( |
| 249 | "--name-only", f"{self.base}...{R_HEADS}{self.name}" | 247 | "--name-only", f"{self.base}...{git_refs.R_HEADS}{self.name}" |
| 250 | ).splitlines() | 248 | ).splitlines() |
| 251 | 249 | ||
| 252 | @property | 250 | @property |
| @@ -747,7 +745,7 @@ class Project: | |||
| 747 | else: | 745 | else: |
| 748 | self.work_git = None | 746 | self.work_git = None |
| 749 | self.bare_git = self._GitGetByExec(self, bare=True, gitdir=self.gitdir) | 747 | self.bare_git = self._GitGetByExec(self, bare=True, gitdir=self.gitdir) |
| 750 | self.bare_ref = GitRefs(self.gitdir) | 748 | self.bare_ref = git_refs.GitRefs(self.gitdir) |
| 751 | self.bare_objdir = self._GitGetByExec( | 749 | self.bare_objdir = self._GitGetByExec( |
| 752 | self, bare=True, gitdir=self.objdir | 750 | self, bare=True, gitdir=self.objdir |
| 753 | ) | 751 | ) |
| @@ -784,8 +782,8 @@ class Project: | |||
| 784 | # If the local checkout is in a bad state, don't barf. Let the | 782 | # If the local checkout is in a bad state, don't barf. Let the |
| 785 | # callers process this like the head is unreadable. | 783 | # callers process this like the head is unreadable. |
| 786 | return None | 784 | return None |
| 787 | if b and b.startswith(R_HEADS): | 785 | if b and b.startswith(git_refs.R_HEADS): |
| 788 | return b[len(R_HEADS) :] | 786 | return b[len(git_refs.R_HEADS) :] |
| 789 | return None | 787 | return None |
| 790 | 788 | ||
| 791 | def _GetHead(self) -> Optional[str]: | 789 | def _GetHead(self) -> Optional[str]: |
| @@ -916,7 +914,7 @@ class Project: | |||
| 916 | def _IsDirtyLegacy(self, consider_untracked: bool = True) -> bool: | 914 | def _IsDirtyLegacy(self, consider_untracked: bool = True) -> bool: |
| 917 | """Check dirty state with plumbing supported by older Git.""" | 915 | """Check dirty state with plumbing supported by older Git.""" |
| 918 | self._RefreshIndexStatCache() | 916 | self._RefreshIndexStatCache() |
| 919 | if self.work_git.DiffZ("diff-index", "-M", "--cached", HEAD): | 917 | if self.work_git.DiffZ("diff-index", "-M", "--cached", git_refs.HEAD): |
| 920 | return True | 918 | return True |
| 921 | if self.work_git.DiffZ("diff-files"): | 919 | if self.work_git.DiffZ("diff-files"): |
| 922 | return True | 920 | return True |
| @@ -965,7 +963,7 @@ class Project: | |||
| 965 | # The snapshot already failed; don't run git status again. | 963 | # The snapshot already failed; don't run git status again. |
| 966 | is_dirty = self._IsDirtyLegacy(consider_untracked=True) | 964 | is_dirty = self._IsDirtyLegacy(consider_untracked=True) |
| 967 | try: | 965 | try: |
| 968 | head = self.work_git.rev_parse(HEAD) | 966 | head = self.work_git.rev_parse(git_refs.HEAD) |
| 969 | except error.GitError: | 967 | except error.GitError: |
| 970 | head = None | 968 | head = None |
| 971 | return is_dirty, head | 969 | return is_dirty, head |
| @@ -1019,8 +1017,8 @@ class Project: | |||
| 1019 | heads = {} | 1017 | heads = {} |
| 1020 | 1018 | ||
| 1021 | for name, ref_id in all_refs.items(): | 1019 | for name, ref_id in all_refs.items(): |
| 1022 | if name.startswith(R_HEADS): | 1020 | if name.startswith(git_refs.R_HEADS): |
| 1023 | name = name[len(R_HEADS) :] | 1021 | name = name[len(git_refs.R_HEADS) :] |
| 1024 | b = self.GetBranch(name) | 1022 | b = self.GetBranch(name) |
| 1025 | b.current = name == current | 1023 | b.current = name == current |
| 1026 | b.published = None | 1024 | b.published = None |
| @@ -1028,8 +1026,8 @@ class Project: | |||
| 1028 | heads[name] = b | 1026 | heads[name] = b |
| 1029 | 1027 | ||
| 1030 | for name, ref_id in all_refs.items(): | 1028 | for name, ref_id in all_refs.items(): |
| 1031 | if name.startswith(R_PUB): | 1029 | if name.startswith(git_refs.R_PUB): |
| 1032 | name = name[len(R_PUB) :] | 1030 | name = name[len(git_refs.R_PUB) :] |
| 1033 | b = heads.get(name) | 1031 | b = heads.get(name) |
| 1034 | if b: | 1032 | if b: |
| 1035 | b.published = ref_id | 1033 | b.published = ref_id |
| @@ -1120,7 +1118,9 @@ class Project: | |||
| 1120 | if not get_all: | 1118 | if not get_all: |
| 1121 | return details | 1119 | return details |
| 1122 | 1120 | ||
| 1123 | changes = self.work_git.DiffZ("diff-index", "--cached", HEAD).keys() | 1121 | changes = self.work_git.DiffZ( |
| 1122 | "diff-index", "--cached", git_refs.HEAD | ||
| 1123 | ).keys() | ||
| 1124 | if changes: | 1124 | if changes: |
| 1125 | details.extend(changes) | 1125 | details.extend(changes) |
| 1126 | if not get_all: | 1126 | if not get_all: |
| @@ -1209,7 +1209,7 @@ class Project: | |||
| 1209 | """Render status using plumbing supported by older Git.""" | 1209 | """Render status using plumbing supported by older Git.""" |
| 1210 | self._RefreshIndexStatCache() | 1210 | self._RefreshIndexStatCache() |
| 1211 | rb = self.IsRebaseInProgress() | 1211 | rb = self.IsRebaseInProgress() |
| 1212 | di = self.work_git.DiffZ("diff-index", "-M", "--cached", HEAD) | 1212 | di = self.work_git.DiffZ("diff-index", "-M", "--cached", git_refs.HEAD) |
| 1213 | df = self.work_git.DiffZ("diff-files") | 1213 | df = self.work_git.DiffZ("diff-files") |
| 1214 | do = self.work_git.LsOthers() | 1214 | do = self.work_git.LsOthers() |
| 1215 | if quiet and (rb or di or df or do): | 1215 | if quiet and (rb or di or df or do): |
| @@ -1243,7 +1243,7 @@ class Project: | |||
| 1243 | left_right = self.work_git.rev_list( | 1243 | left_right = self.work_git.rev_list( |
| 1244 | "--left-right", | 1244 | "--left-right", |
| 1245 | "--count", | 1245 | "--count", |
| 1246 | f"{local_merge}...{R_HEADS}{branch_name}", | 1246 | f"{local_merge}...{git_refs.R_HEADS}{branch_name}", |
| 1247 | ) | 1247 | ) |
| 1248 | left, right = left_right[0].split() | 1248 | left, right = left_right[0].split() |
| 1249 | behind = int(left) | 1249 | behind = int(left) |
| @@ -1366,7 +1366,7 @@ class Project: | |||
| 1366 | cmd = ["diff"] | 1366 | cmd = ["diff"] |
| 1367 | if out.is_on: | 1367 | if out.is_on: |
| 1368 | cmd.append("--color") | 1368 | cmd.append("--color") |
| 1369 | cmd.append(HEAD) | 1369 | cmd.append(git_refs.HEAD) |
| 1370 | if absolute_paths: | 1370 | if absolute_paths: |
| 1371 | cmd.append("--src-prefix=a/%s/" % self.RelPath(local)) | 1371 | cmd.append("--src-prefix=a/%s/" % self.RelPath(local)) |
| 1372 | cmd.append("--dst-prefix=b/%s/" % self.RelPath(local)) | 1372 | cmd.append("--dst-prefix=b/%s/" % self.RelPath(local)) |
| @@ -1395,7 +1395,7 @@ class Project: | |||
| 1395 | If so, returns the SHA-1 hash of the last published | 1395 | If so, returns the SHA-1 hash of the last published |
| 1396 | state for the branch. | 1396 | state for the branch. |
| 1397 | """ | 1397 | """ |
| 1398 | key = R_PUB + branch | 1398 | key = git_refs.R_PUB + branch |
| 1399 | if all_refs is None: | 1399 | if all_refs is None: |
| 1400 | try: | 1400 | try: |
| 1401 | return self.bare_git.rev_parse(key) | 1401 | return self.bare_git.rev_parse(key) |
| @@ -1414,14 +1414,14 @@ class Project: | |||
| 1414 | heads = set() | 1414 | heads = set() |
| 1415 | canrm = {} | 1415 | canrm = {} |
| 1416 | for name, ref_id in all_refs.items(): | 1416 | for name, ref_id in all_refs.items(): |
| 1417 | if name.startswith(R_HEADS): | 1417 | if name.startswith(git_refs.R_HEADS): |
| 1418 | heads.add(name) | 1418 | heads.add(name) |
| 1419 | elif name.startswith(R_PUB): | 1419 | elif name.startswith(git_refs.R_PUB): |
| 1420 | canrm[name] = ref_id | 1420 | canrm[name] = ref_id |
| 1421 | 1421 | ||
| 1422 | for name, ref_id in canrm.items(): | 1422 | for name, ref_id in canrm.items(): |
| 1423 | n = name[len(R_PUB) :] | 1423 | n = name[len(git_refs.R_PUB) :] |
| 1424 | if R_HEADS + n not in heads: | 1424 | if git_refs.R_HEADS + n not in heads: |
| 1425 | self.bare_git.DeleteRef(name, ref_id) | 1425 | self.bare_git.DeleteRef(name, ref_id) |
| 1426 | 1426 | ||
| 1427 | def GetUploadableBranches(self, selected_branch=None): | 1427 | def GetUploadableBranches(self, selected_branch=None): |
| @@ -1430,10 +1430,10 @@ class Project: | |||
| 1430 | branch = self.GetBranch(selected_branch) | 1430 | branch = self.GetBranch(selected_branch) |
| 1431 | if not branch.LocalMerge: | 1431 | if not branch.LocalMerge: |
| 1432 | return [] | 1432 | return [] |
| 1433 | head_id = self.bare_ref.get(R_HEADS + selected_branch) | 1433 | head_id = self.bare_ref.get(git_refs.R_HEADS + selected_branch) |
| 1434 | if not head_id: | 1434 | if not head_id: |
| 1435 | return [] | 1435 | return [] |
| 1436 | pub_id = self.bare_ref.get(R_PUB + selected_branch) | 1436 | pub_id = self.bare_ref.get(git_refs.R_PUB + selected_branch) |
| 1437 | if pub_id and pub_id == head_id: | 1437 | if pub_id and pub_id == head_id: |
| 1438 | return [] | 1438 | return [] |
| 1439 | rb = self.GetUploadableBranch(selected_branch) | 1439 | rb = self.GetUploadableBranch(selected_branch) |
| @@ -1520,8 +1520,8 @@ class Project: | |||
| 1520 | dest_branch = self.dest_branch | 1520 | dest_branch = self.dest_branch |
| 1521 | if dest_branch is None: | 1521 | if dest_branch is None: |
| 1522 | dest_branch = branch.merge | 1522 | dest_branch = branch.merge |
| 1523 | if not dest_branch.startswith(R_HEADS): | 1523 | if not dest_branch.startswith(git_refs.R_HEADS): |
| 1524 | dest_branch = R_HEADS + dest_branch | 1524 | dest_branch = git_refs.R_HEADS + dest_branch |
| 1525 | 1525 | ||
| 1526 | if not branch.remote.projectname: | 1526 | if not branch.remote.projectname: |
| 1527 | branch.remote.projectname = self.name | 1527 | branch.remote.projectname = self.name |
| @@ -1550,10 +1550,10 @@ class Project: | |||
| 1550 | 1550 | ||
| 1551 | cmd.append(url) | 1551 | cmd.append(url) |
| 1552 | 1552 | ||
| 1553 | if dest_branch.startswith(R_HEADS): | 1553 | if dest_branch.startswith(git_refs.R_HEADS): |
| 1554 | dest_branch = dest_branch[len(R_HEADS) :] | 1554 | dest_branch = dest_branch[len(git_refs.R_HEADS) :] |
| 1555 | 1555 | ||
| 1556 | ref_spec = f"{R_HEADS + branch.name}:refs/for/{dest_branch}" | 1556 | ref_spec = f"{git_refs.R_HEADS + branch.name}:refs/for/{dest_branch}" |
| 1557 | opts = [] | 1557 | opts = [] |
| 1558 | if topic is not None: | 1558 | if topic is not None: |
| 1559 | opts += [f"topic={topic}"] | 1559 | opts += [f"topic={topic}"] |
| @@ -1607,7 +1607,9 @@ class Project: | |||
| 1607 | if not dryrun: | 1607 | if not dryrun: |
| 1608 | msg = f"posted to {branch.remote.review} for {dest_branch}" | 1608 | msg = f"posted to {branch.remote.review} for {dest_branch}" |
| 1609 | self.bare_git.UpdateRef( | 1609 | self.bare_git.UpdateRef( |
| 1610 | R_PUB + branch.name, R_HEADS + branch.name, message=msg | 1610 | git_refs.R_PUB + branch.name, |
| 1611 | git_refs.R_HEADS + branch.name, | ||
| 1612 | message=msg, | ||
| 1611 | ) | 1613 | ) |
| 1612 | 1614 | ||
| 1613 | @staticmethod | 1615 | @staticmethod |
| @@ -2020,7 +2022,9 @@ class Project: | |||
| 2020 | """Get revisionId of a commit.""" | 2022 | """Get revisionId of a commit.""" |
| 2021 | if self.revisionId: | 2023 | if self.revisionId: |
| 2022 | return self.revisionId | 2024 | return self.revisionId |
| 2023 | if all_refs is None and not self.revisionExpr.startswith(R_TAGS): | 2025 | if all_refs is None and not self.revisionExpr.startswith( |
| 2026 | git_refs.R_TAGS | ||
| 2027 | ): | ||
| 2024 | all_refs = self._allrefs | 2028 | all_refs = self._allrefs |
| 2025 | return self.GetRevisionId(all_refs) | 2029 | return self.GetRevisionId(all_refs) |
| 2026 | 2030 | ||
| @@ -2031,7 +2035,7 @@ class Project: | |||
| 2031 | """ | 2035 | """ |
| 2032 | if self.work_git: | 2036 | if self.work_git: |
| 2033 | if not self.use_git_worktrees and self.bare_ref.is_loaded: | 2037 | if not self.use_git_worktrees and self.bare_ref.is_loaded: |
| 2034 | head = self.bare_ref.get(HEAD) | 2038 | head = self.bare_ref.get(git_refs.HEAD) |
| 2035 | if head: | 2039 | if head: |
| 2036 | return head | 2040 | return head |
| 2037 | try: | 2041 | try: |
| @@ -2052,7 +2056,7 @@ class Project: | |||
| 2052 | # so GetRevisionId always returns a commit SHA. | 2056 | # so GetRevisionId always returns a commit SHA. |
| 2053 | if ( | 2057 | if ( |
| 2054 | all_refs is not None | 2058 | all_refs is not None |
| 2055 | and not rev.startswith(R_TAGS) | 2059 | and not rev.startswith(git_refs.R_TAGS) |
| 2056 | and rev in all_refs | 2060 | and rev in all_refs |
| 2057 | ): | 2061 | ): |
| 2058 | return all_refs[rev] | 2062 | return all_refs[rev] |
| @@ -2163,8 +2167,8 @@ class Project: | |||
| 2163 | return | 2167 | return |
| 2164 | 2168 | ||
| 2165 | head = self._GetHead() | 2169 | head = self._GetHead() |
| 2166 | if head and head.startswith(R_HEADS): | 2170 | if head and head.startswith(git_refs.R_HEADS): |
| 2167 | branch = head[len(R_HEADS) :] | 2171 | branch = head[len(git_refs.R_HEADS) :] |
| 2168 | try: | 2172 | try: |
| 2169 | head = all_refs[head] | 2173 | head = all_refs[head] |
| 2170 | except KeyError: | 2174 | except KeyError: |
| @@ -2235,7 +2239,9 @@ class Project: | |||
| 2235 | return | 2239 | return |
| 2236 | else: | 2240 | else: |
| 2237 | if verbose: | 2241 | if verbose: |
| 2238 | lost_output = self._revlist("--count", not_rev(revid), HEAD) | 2242 | lost_output = self._revlist( |
| 2243 | "--count", not_rev(revid), git_refs.HEAD | ||
| 2244 | ) | ||
| 2239 | lost = int(lost_output[0]) if lost_output else 0 | 2245 | lost = int(lost_output[0]) if lost_output else 0 |
| 2240 | if lost: | 2246 | if lost: |
| 2241 | syncbuf.info(self, "discarding %d commits", lost) | 2247 | syncbuf.info(self, "discarding %d commits", lost) |
| @@ -2277,14 +2283,14 @@ class Project: | |||
| 2277 | self._CopyAndLinkFiles() | 2283 | self._CopyAndLinkFiles() |
| 2278 | return | 2284 | return |
| 2279 | 2285 | ||
| 2280 | gain_output = self._revlist("--count", not_rev(HEAD), revid) | 2286 | gain_output = self._revlist("--count", not_rev(git_refs.HEAD), revid) |
| 2281 | upstream_gain = int(gain_output[0]) if gain_output else 0 | 2287 | upstream_gain = int(gain_output[0]) if gain_output else 0 |
| 2282 | 2288 | ||
| 2283 | # See if we can perform a fast forward merge. This can happen if our | 2289 | # See if we can perform a fast forward merge. This can happen if our |
| 2284 | # branch isn't in the exact same state as we last published. | 2290 | # branch isn't in the exact same state as we last published. |
| 2285 | try: | 2291 | try: |
| 2286 | self.work_git.merge_base( | 2292 | self.work_git.merge_base( |
| 2287 | "--is-ancestor", HEAD, revid, log_as_error=False | 2293 | "--is-ancestor", git_refs.HEAD, revid, log_as_error=False |
| 2288 | ) | 2294 | ) |
| 2289 | # Skip the published logic. | 2295 | # Skip the published logic. |
| 2290 | pub = False | 2296 | pub = False |
| @@ -2330,7 +2336,9 @@ class Project: | |||
| 2330 | 2336 | ||
| 2331 | # Examine the local commits not in the remote. Find the | 2337 | # Examine the local commits not in the remote. Find the |
| 2332 | # last one attributed to this user, if any. | 2338 | # last one attributed to this user, if any. |
| 2333 | local_changes = self._revlist(not_rev(revid), HEAD, format="%H %ce") | 2339 | local_changes = self._revlist( |
| 2340 | not_rev(revid), git_refs.HEAD, format="%H %ce" | ||
| 2341 | ) | ||
| 2334 | last_mine = None | 2342 | last_mine = None |
| 2335 | cnt_mine = 0 | 2343 | cnt_mine = 0 |
| 2336 | for commit in local_changes: | 2344 | for commit in local_changes: |
| @@ -2375,7 +2383,7 @@ class Project: | |||
| 2375 | # In case of manifest sync the revisionExpr might be a SHA1. | 2383 | # In case of manifest sync the revisionExpr might be a SHA1. |
| 2376 | branch.merge = self.revisionExpr | 2384 | branch.merge = self.revisionExpr |
| 2377 | if not branch.merge.startswith("refs/"): | 2385 | if not branch.merge.startswith("refs/"): |
| 2378 | branch.merge = R_HEADS + branch.merge | 2386 | branch.merge = git_refs.R_HEADS + branch.merge |
| 2379 | branch.Save() | 2387 | branch.Save() |
| 2380 | 2388 | ||
| 2381 | if cnt_mine > 0 and self.rebase: | 2389 | if cnt_mine > 0 and self.rebase: |
| @@ -2654,11 +2662,11 @@ class Project: | |||
| 2654 | if not branch_merge: | 2662 | if not branch_merge: |
| 2655 | branch_merge = self.revisionExpr | 2663 | branch_merge = self.revisionExpr |
| 2656 | head = self.work_git.GetHead() | 2664 | head = self.work_git.GetHead() |
| 2657 | if head == (R_HEADS + name): | 2665 | if head == (git_refs.R_HEADS + name): |
| 2658 | return True | 2666 | return True |
| 2659 | 2667 | ||
| 2660 | all_refs = self.bare_ref.all | 2668 | all_refs = self.bare_ref.all |
| 2661 | if R_HEADS + name in all_refs: | 2669 | if git_refs.R_HEADS + name in all_refs: |
| 2662 | git_command.GitCommand( | 2670 | git_command.GitCommand( |
| 2663 | self, ["checkout", "-q", name, "--"], verify_command=True | 2671 | self, ["checkout", "-q", name, "--"], verify_command=True |
| 2664 | ).Wait() | 2672 | ).Wait() |
| @@ -2668,22 +2676,22 @@ class Project: | |||
| 2668 | branch.remote = self.GetRemote() | 2676 | branch.remote = self.GetRemote() |
| 2669 | branch.merge = branch_merge | 2677 | branch.merge = branch_merge |
| 2670 | if not branch.merge.startswith("refs/") and not IsId(branch_merge): | 2678 | if not branch.merge.startswith("refs/") and not IsId(branch_merge): |
| 2671 | branch.merge = R_HEADS + branch_merge | 2679 | branch.merge = git_refs.R_HEADS + branch_merge |
| 2672 | 2680 | ||
| 2673 | if revision is None: | 2681 | if revision is None: |
| 2674 | revid = self.GetRevisionId(all_refs) | 2682 | revid = self.GetRevisionId(all_refs) |
| 2675 | else: | 2683 | else: |
| 2676 | revid = self.work_git.rev_parse(revision) | 2684 | revid = self.work_git.rev_parse(revision) |
| 2677 | 2685 | ||
| 2678 | if head.startswith(R_HEADS): | 2686 | if head.startswith(git_refs.R_HEADS): |
| 2679 | try: | 2687 | try: |
| 2680 | head = all_refs[head] | 2688 | head = all_refs[head] |
| 2681 | except KeyError: | 2689 | except KeyError: |
| 2682 | head = None | 2690 | head = None |
| 2683 | if revid and head and revid == head: | 2691 | if revid and head and revid == head: |
| 2684 | ref = R_HEADS + name | 2692 | ref = git_refs.R_HEADS + name |
| 2685 | self.work_git.update_ref(ref, revid) | 2693 | self.work_git.update_ref(ref, revid) |
| 2686 | self.work_git.symbolic_ref(HEAD, ref) | 2694 | self.work_git.symbolic_ref(git_refs.HEAD, ref) |
| 2687 | branch.Save() | 2695 | branch.Save() |
| 2688 | return True | 2696 | return True |
| 2689 | 2697 | ||
| @@ -2705,7 +2713,7 @@ class Project: | |||
| 2705 | True if the checkout succeeded; False if the | 2713 | True if the checkout succeeded; False if the |
| 2706 | branch doesn't exist. | 2714 | branch doesn't exist. |
| 2707 | """ | 2715 | """ |
| 2708 | rev = R_HEADS + name | 2716 | rev = git_refs.R_HEADS + name |
| 2709 | head = self.work_git.GetHead() | 2717 | head = self.work_git.GetHead() |
| 2710 | if head == rev: | 2718 | if head == rev: |
| 2711 | # Already on the branch. | 2719 | # Already on the branch. |
| @@ -2718,7 +2726,7 @@ class Project: | |||
| 2718 | # Branch does not exist in this project. | 2726 | # Branch does not exist in this project. |
| 2719 | return False | 2727 | return False |
| 2720 | 2728 | ||
| 2721 | if head.startswith(R_HEADS): | 2729 | if head.startswith(git_refs.R_HEADS): |
| 2722 | try: | 2730 | try: |
| 2723 | head = all_refs[head] | 2731 | head = all_refs[head] |
| 2724 | except KeyError: | 2732 | except KeyError: |
| @@ -2727,7 +2735,7 @@ class Project: | |||
| 2727 | if head == revid: | 2735 | if head == revid: |
| 2728 | # Same revision; just update HEAD to point to the new | 2736 | # Same revision; just update HEAD to point to the new |
| 2729 | # target branch, but otherwise take no other action. | 2737 | # target branch, but otherwise take no other action. |
| 2730 | self.work_git.SetHead(R_HEADS + name) | 2738 | self.work_git.SetHead(git_refs.R_HEADS + name) |
| 2731 | return True | 2739 | return True |
| 2732 | 2740 | ||
| 2733 | git_command.GitCommand( | 2741 | git_command.GitCommand( |
| @@ -2749,7 +2757,7 @@ class Project: | |||
| 2749 | True if the abandon succeeded; Raises GitCommandError if it didn't; | 2757 | True if the abandon succeeded; Raises GitCommandError if it didn't; |
| 2750 | None if the branch didn't exist. | 2758 | None if the branch didn't exist. |
| 2751 | """ | 2759 | """ |
| 2752 | rev = R_HEADS + name | 2760 | rev = git_refs.R_HEADS + name |
| 2753 | all_refs = self.bare_ref.all | 2761 | all_refs = self.bare_ref.all |
| 2754 | if rev not in all_refs: | 2762 | if rev not in all_refs: |
| 2755 | # Doesn't exist | 2763 | # Doesn't exist |
| @@ -2781,8 +2789,8 @@ class Project: | |||
| 2781 | left = self._allrefs | 2789 | left = self._allrefs |
| 2782 | cb = self.CurrentBranch | 2790 | cb = self.CurrentBranch |
| 2783 | for name in left.keys(): | 2791 | for name in left.keys(): |
| 2784 | if name.startswith(R_HEADS): | 2792 | if name.startswith(git_refs.R_HEADS): |
| 2785 | name = name[len(R_HEADS) :] | 2793 | name = name[len(git_refs.R_HEADS) :] |
| 2786 | if cb is None or name != cb: | 2794 | if cb is None or name != cb: |
| 2787 | kill.append(name) | 2795 | kill.append(name) |
| 2788 | 2796 | ||
| @@ -2792,13 +2800,13 @@ class Project: | |||
| 2792 | return [] | 2800 | return [] |
| 2793 | 2801 | ||
| 2794 | rev = self.GetCommitRevisionId(left) | 2802 | rev = self.GetCommitRevisionId(left) |
| 2795 | head = left.get(R_HEADS + cb) if cb is not None else None | 2803 | head = left.get(git_refs.R_HEADS + cb) if cb is not None else None |
| 2796 | if ( | 2804 | if ( |
| 2797 | cb is not None | 2805 | cb is not None |
| 2798 | and head == rev | 2806 | and head == rev |
| 2799 | and not self.IsDirty(consider_untracked=False) | 2807 | and not self.IsDirty(consider_untracked=False) |
| 2800 | ): | 2808 | ): |
| 2801 | self.work_git.DetachHead(HEAD) | 2809 | self.work_git.DetachHead(git_refs.HEAD) |
| 2802 | kill.append(cb) | 2810 | kill.append(cb) |
| 2803 | 2811 | ||
| 2804 | if kill: | 2812 | if kill: |
| @@ -2825,14 +2833,16 @@ class Project: | |||
| 2825 | self.bare_git.DetachHead(old) | 2833 | self.bare_git.DetachHead(old) |
| 2826 | else: | 2834 | else: |
| 2827 | branch = ( | 2835 | branch = ( |
| 2828 | old[len(R_HEADS) :] if old.startswith(R_HEADS) else old | 2836 | old[len(git_refs.R_HEADS) :] |
| 2837 | if old.startswith(git_refs.R_HEADS) | ||
| 2838 | else old | ||
| 2829 | ) | 2839 | ) |
| 2830 | if branch not in kill: | 2840 | if branch not in kill: |
| 2831 | self.bare_git.SetHead(old) | 2841 | self.bare_git.SetHead(old) |
| 2832 | left = self._allrefs | 2842 | left = self._allrefs |
| 2833 | 2843 | ||
| 2834 | for branch in kill: | 2844 | for branch in kill: |
| 2835 | if (R_HEADS + branch) not in left: | 2845 | if (git_refs.R_HEADS + branch) not in left: |
| 2836 | self.CleanPublishedCache() | 2846 | self.CleanPublishedCache() |
| 2837 | break | 2847 | break |
| 2838 | 2848 | ||
| @@ -2842,7 +2852,7 @@ class Project: | |||
| 2842 | 2852 | ||
| 2843 | kept = [] | 2853 | kept = [] |
| 2844 | for branch in kill: | 2854 | for branch in kill: |
| 2845 | if R_HEADS + branch in left: | 2855 | if git_refs.R_HEADS + branch in left: |
| 2846 | branch = self.GetBranch(branch) | 2856 | branch = self.GetBranch(branch) |
| 2847 | branch.current = branch.name == cb | 2857 | branch.current = branch.name == cb |
| 2848 | base = branch.LocalMerge | 2858 | base = branch.LocalMerge |
| @@ -3335,7 +3345,7 @@ class Project: | |||
| 3335 | if not default: | 3345 | if not default: |
| 3336 | return None | 3346 | return None |
| 3337 | for cand in (default.upstreamExpr, default.revisionExpr): | 3347 | for cand in (default.upstreamExpr, default.revisionExpr): |
| 3338 | if cand and not IsId(cand) and not cand.startswith(R_TAGS): | 3348 | if cand and not IsId(cand) and not cand.startswith(git_refs.R_TAGS): |
| 3339 | return cand | 3349 | return cand |
| 3340 | return None | 3350 | return None |
| 3341 | 3351 | ||
| @@ -3390,12 +3400,12 @@ class Project: | |||
| 3390 | else: | 3400 | else: |
| 3391 | current_branch_only = False | 3401 | current_branch_only = False |
| 3392 | 3402 | ||
| 3393 | if self.revisionExpr.startswith(R_TAGS): | 3403 | if self.revisionExpr.startswith(git_refs.R_TAGS): |
| 3394 | # This is a tag and its commit id should never change. | 3404 | # This is a tag and its commit id should never change. |
| 3395 | tag_name = self.revisionExpr[len(R_TAGS) :] | 3405 | tag_name = self.revisionExpr[len(git_refs.R_TAGS) :] |
| 3396 | elif upstream and upstream.startswith(R_TAGS): | 3406 | elif upstream and upstream.startswith(git_refs.R_TAGS): |
| 3397 | # This is a tag and its commit id should never change. | 3407 | # This is a tag and its commit id should never change. |
| 3398 | tag_name = upstream[len(R_TAGS) :] | 3408 | tag_name = upstream[len(git_refs.R_TAGS) :] |
| 3399 | 3409 | ||
| 3400 | if is_sha1 or tag_name is not None: | 3410 | if is_sha1 or tag_name is not None: |
| 3401 | has_shallow = self._HasShallow() | 3411 | has_shallow = self._HasShallow() |
| @@ -3427,9 +3437,9 @@ class Project: | |||
| 3427 | 3437 | ||
| 3428 | update_ref_cmds = [] | 3438 | update_ref_cmds = [] |
| 3429 | 3439 | ||
| 3430 | for r, ref_id in GitRefs(ref_dir).all.items(): | 3440 | for r, ref_id in git_refs.GitRefs(ref_dir).all.items(): |
| 3431 | if r not in all_refs: | 3441 | if r not in all_refs: |
| 3432 | if r.startswith(R_TAGS) or remote.WritesTo(r): | 3442 | if r.startswith(git_refs.R_TAGS) or remote.WritesTo(r): |
| 3433 | update_ref_cmds.append(f"create {r} {ref_id}\n") | 3443 | update_ref_cmds.append(f"create {r} {ref_id}\n") |
| 3434 | all_refs[r] = ref_id | 3444 | all_refs[r] = ref_id |
| 3435 | ids.add(ref_id) | 3445 | ids.add(ref_id) |
| @@ -3527,7 +3537,7 @@ class Project: | |||
| 3527 | branch = upstream | 3537 | branch = upstream |
| 3528 | if branch is not None and branch.strip(): | 3538 | if branch is not None and branch.strip(): |
| 3529 | if not branch.startswith("refs/"): | 3539 | if not branch.startswith("refs/"): |
| 3530 | branch = R_HEADS + branch | 3540 | branch = git_refs.R_HEADS + branch |
| 3531 | spec.append(str(("+%s:" % branch) + remote.ToLocal(branch))) | 3541 | spec.append(str(("+%s:" % branch) + remote.ToLocal(branch))) |
| 3532 | 3542 | ||
| 3533 | # If mirroring repo and we cannot deduce the tag or branch to fetch, | 3543 | # If mirroring repo and we cannot deduce the tag or branch to fetch, |
| @@ -4014,8 +4024,8 @@ class Project: | |||
| 4014 | |revid|, since there is then nothing to materialize. | 4024 | |revid|, since there is then nothing to materialize. |
| 4015 | """ | 4025 | """ |
| 4016 | old = self._GetHead() | 4026 | old = self._GetHead() |
| 4017 | if old and old.startswith(R_HEADS): | 4027 | if old and old.startswith(git_refs.R_HEADS): |
| 4018 | old = old[len(R_HEADS) :] | 4028 | old = old[len(git_refs.R_HEADS) :] |
| 4019 | if head != revid: | 4029 | if head != revid: |
| 4020 | self._Reproject(revid, verbose=verbose) | 4030 | self._Reproject(revid, verbose=verbose) |
| 4021 | self.work_git.DetachHead( | 4031 | self.work_git.DetachHead( |
| @@ -4035,7 +4045,7 @@ class Project: | |||
| 4035 | commit the branch is at; the ref write fails if it moved meanwhile. | 4045 | commit the branch is at; the ref write fails if it moved meanwhile. |
| 4036 | """ | 4046 | """ |
| 4037 | self._Reproject(revid, verbose=verbose) | 4047 | self._Reproject(revid, verbose=verbose) |
| 4038 | self.work_git.UpdateRef(HEAD, revid, old=head, message=message) | 4048 | self.work_git.UpdateRef(git_refs.HEAD, revid, old=head, message=message) |
| 4039 | 4049 | ||
| 4040 | def _Reproject(self, revid: str, verbose: bool = False) -> None: | 4050 | def _Reproject(self, revid: str, verbose: bool = False) -> None: |
| 4041 | """Make the index and worktree match |revid| with repo.reprojectcmd. | 4051 | """Make the index and worktree match |revid| with repo.reprojectcmd. |
| @@ -4431,13 +4441,13 @@ class Project: | |||
| 4431 | # Set up the m/ space to point to the worktree-specific ref | 4441 | # Set up the m/ space to point to the worktree-specific ref |
| 4432 | # space. We'll update the worktree-specific ref space on each | 4442 | # space. We'll update the worktree-specific ref space on each |
| 4433 | # checkout. | 4443 | # checkout. |
| 4434 | ref = R_M + self.manifest.branch | 4444 | ref = git_refs.R_M + self.manifest.branch |
| 4435 | if not self.bare_ref.symref(ref): | 4445 | if not self.bare_ref.symref(ref): |
| 4436 | self.bare_git.symbolic_ref( | 4446 | self.bare_git.symbolic_ref( |
| 4437 | "-m", | 4447 | "-m", |
| 4438 | "redirecting to worktree scope", | 4448 | "redirecting to worktree scope", |
| 4439 | ref, | 4449 | ref, |
| 4440 | R_WORKTREE_M + self.manifest.branch, | 4450 | git_refs.R_WORKTREE_M + self.manifest.branch, |
| 4441 | ) | 4451 | ) |
| 4442 | 4452 | ||
| 4443 | # We can't update this ref with git worktrees until it exists. | 4453 | # We can't update this ref with git worktrees until it exists. |
| @@ -4445,18 +4455,18 @@ class Project: | |||
| 4445 | if not os.path.exists(self.worktree): | 4455 | if not os.path.exists(self.worktree): |
| 4446 | return | 4456 | return |
| 4447 | 4457 | ||
| 4448 | base = R_WORKTREE_M | 4458 | base = git_refs.R_WORKTREE_M |
| 4449 | active_git = self.work_git | 4459 | active_git = self.work_git |
| 4450 | 4460 | ||
| 4451 | self._InitAnyMRef(HEAD, self.bare_git, detach=True) | 4461 | self._InitAnyMRef(git_refs.HEAD, self.bare_git, detach=True) |
| 4452 | else: | 4462 | else: |
| 4453 | base = R_M | 4463 | base = git_refs.R_M |
| 4454 | active_git = self.bare_git | 4464 | active_git = self.bare_git |
| 4455 | 4465 | ||
| 4456 | self._InitAnyMRef(base + self.manifest.branch, active_git) | 4466 | self._InitAnyMRef(base + self.manifest.branch, active_git) |
| 4457 | 4467 | ||
| 4458 | def _InitMirrorHead(self): | 4468 | def _InitMirrorHead(self): |
| 4459 | self._InitAnyMRef(HEAD, self.bare_git) | 4469 | self._InitAnyMRef(git_refs.HEAD, self.bare_git) |
| 4460 | 4470 | ||
| 4461 | def _InitAnyMRef(self, ref, active_git, detach=False): | 4471 | def _InitAnyMRef(self, ref, active_git, detach=False): |
| 4462 | """Initialize |ref| in |active_git| to the value in the manifest. | 4472 | """Initialize |ref| in |active_git| to the value in the manifest. |
| @@ -4659,10 +4669,12 @@ class Project: | |||
| 4659 | self._createDotGit(dotgit) | 4669 | self._createDotGit(dotgit) |
| 4660 | 4670 | ||
| 4661 | if init_dotgit: | 4671 | if init_dotgit: |
| 4662 | self.work_git.UpdateRef(HEAD, self.GetRevisionId(), detach=True) | 4672 | self.work_git.UpdateRef( |
| 4673 | git_refs.HEAD, self.GetRevisionId(), detach=True | ||
| 4674 | ) | ||
| 4663 | 4675 | ||
| 4664 | # Finish checking out the worktree. | 4676 | # Finish checking out the worktree. |
| 4665 | cmd = ["read-tree", "--reset", "-u", "-v", HEAD] | 4677 | cmd = ["read-tree", "--reset", "-u", "-v", git_refs.HEAD] |
| 4666 | try: | 4678 | try: |
| 4667 | if git_command.GitCommand(self, cmd).Wait() != 0: | 4679 | if git_command.GitCommand(self, cmd).Wait() != 0: |
| 4668 | raise error.GitError( | 4680 | raise error.GitError( |
| @@ -5051,7 +5063,7 @@ class Project: | |||
| 5051 | # "refs/heads/.invalid" placeholder used for unborn branches, | 5063 | # "refs/heads/.invalid" placeholder used for unborn branches, |
| 5052 | # empty repositories, or when the reftables backend is used | 5064 | # empty repositories, or when the reftables backend is used |
| 5053 | # (which will be the default in Git 3.0). | 5065 | # (which will be the default in Git 3.0). |
| 5054 | if not ref or ref == R_HEADS + ".invalid": | 5066 | if not ref or ref == git_refs.R_HEADS + ".invalid": |
| 5055 | return None | 5067 | return None |
| 5056 | return ref | 5068 | return ref |
| 5057 | else: | 5069 | else: |
| @@ -5068,7 +5080,7 @@ class Project: | |||
| 5068 | try: | 5080 | try: |
| 5069 | # Catch AssertionError raised by GetDotgitPath when worktree | 5081 | # Catch AssertionError raised by GetDotgitPath when worktree |
| 5070 | # .git pointer file is malformed (e.g. missing 'gitdir:'). | 5082 | # .git pointer file is malformed (e.g. missing 'gitdir:'). |
| 5071 | path = self.GetDotgitPath(subpath=HEAD) | 5083 | path = self.GetDotgitPath(subpath=git_refs.HEAD) |
| 5072 | if not platform_utils.islink(path): | 5084 | if not platform_utils.islink(path): |
| 5073 | with open( | 5085 | with open( |
| 5074 | path, "r", encoding="utf-8", errors="replace" | 5086 | path, "r", encoding="utf-8", errors="replace" |
| @@ -5080,13 +5092,15 @@ class Project: | |||
| 5080 | pass | 5092 | pass |
| 5081 | 5093 | ||
| 5082 | try: | 5094 | try: |
| 5083 | return self.symbolic_ref("-q", HEAD, log_as_error=False) | 5095 | return self.symbolic_ref( |
| 5096 | "-q", git_refs.HEAD, log_as_error=False | ||
| 5097 | ) | ||
| 5084 | except error.GitError: | 5098 | except error.GitError: |
| 5085 | pass | 5099 | pass |
| 5086 | 5100 | ||
| 5087 | try: | 5101 | try: |
| 5088 | # If symbolic-ref fails, try to treat as detached HEAD. | 5102 | # If symbolic-ref fails, try to treat as detached HEAD. |
| 5089 | return self.rev_parse(HEAD) | 5103 | return self.rev_parse(git_refs.HEAD) |
| 5090 | except error.GitError as e: | 5104 | except error.GitError as e: |
| 5091 | logger.warning( | 5105 | logger.warning( |
| 5092 | "project %s: unparseable HEAD; trying to recover.\n" | 5106 | "project %s: unparseable HEAD; trying to recover.\n" |
| @@ -5134,7 +5148,7 @@ class Project: | |||
| 5134 | cmdv = [] | 5148 | cmdv = [] |
| 5135 | if message is not None: | 5149 | if message is not None: |
| 5136 | cmdv.extend(["-m", message]) | 5150 | cmdv.extend(["-m", message]) |
| 5137 | cmdv.append(HEAD) | 5151 | cmdv.append(git_refs.HEAD) |
| 5138 | cmdv.append(ref) | 5152 | cmdv.append(ref) |
| 5139 | self.symbolic_ref(*cmdv) | 5153 | self.symbolic_ref(*cmdv) |
| 5140 | 5154 | ||
| @@ -5142,7 +5156,7 @@ class Project: | |||
| 5142 | cmdv = ["--no-deref"] | 5156 | cmdv = ["--no-deref"] |
| 5143 | if message is not None: | 5157 | if message is not None: |
| 5144 | cmdv.extend(["-m", message]) | 5158 | cmdv.extend(["-m", message]) |
| 5145 | cmdv.append(HEAD) | 5159 | cmdv.append(git_refs.HEAD) |
| 5146 | cmdv.append(new) | 5160 | cmdv.append(new) |
| 5147 | self.update_ref(*cmdv) | 5161 | self.update_ref(*cmdv) |
| 5148 | 5162 | ||
| @@ -5479,7 +5493,7 @@ class MetaProject(Project): | |||
| 5479 | all_refs = self.bare_ref.all | 5493 | all_refs = self.bare_ref.all |
| 5480 | revid = self.GetRevisionId(all_refs) | 5494 | revid = self.GetRevisionId(all_refs) |
| 5481 | head = self._GetHead() | 5495 | head = self._GetHead() |
| 5482 | if head and head.startswith(R_HEADS): | 5496 | if head and head.startswith(git_refs.R_HEADS): |
| 5483 | try: | 5497 | try: |
| 5484 | head = all_refs[head] | 5498 | head = all_refs[head] |
| 5485 | except KeyError: | 5499 | except KeyError: |
| @@ -5487,7 +5501,7 @@ class MetaProject(Project): | |||
| 5487 | 5501 | ||
| 5488 | if revid == head: | 5502 | if revid == head: |
| 5489 | return False | 5503 | return False |
| 5490 | elif self._revlist("-1", not_rev(HEAD), revid): | 5504 | elif self._revlist("-1", not_rev(git_refs.HEAD), revid): |
| 5491 | return True | 5505 | return True |
| 5492 | return False | 5506 | return False |
| 5493 | 5507 | ||
diff --git a/subcmds/info.py b/subcmds/info.py index e120cae33..aed7d4029 100644 --- a/subcmds/info.py +++ b/subcmds/info.py | |||
| @@ -23,8 +23,7 @@ from typing import Any, Dict, List, NamedTuple, Optional, Tuple | |||
| 23 | from color import Coloring | 23 | from color import Coloring |
| 24 | from command import DEFAULT_LOCAL_JOBS | 24 | from command import DEFAULT_LOCAL_JOBS |
| 25 | from command import PagedCommand | 25 | from command import PagedCommand |
| 26 | from git_refs import R_HEADS | 26 | import git_refs |
| 27 | from git_refs import R_M | ||
| 28 | 27 | ||
| 29 | 28 | ||
| 30 | class BranchInfo(NamedTuple): | 29 | class BranchInfo(NamedTuple): |
| @@ -333,9 +332,9 @@ class Info(PagedCommand): | |||
| 333 | branch = project.manifest.manifestProject.config.GetBranch( | 332 | branch = project.manifest.manifestProject.config.GetBranch( |
| 334 | "default" | 333 | "default" |
| 335 | ).merge | 334 | ).merge |
| 336 | if branch.startswith(R_HEADS): | 335 | if branch.startswith(git_refs.R_HEADS): |
| 337 | branch = branch[len(R_HEADS) :] | 336 | branch = branch[len(git_refs.R_HEADS) :] |
| 338 | logTarget = R_M + branch | 337 | logTarget = git_refs.R_M + branch |
| 339 | 338 | ||
| 340 | localCommits, originCommits = cls._GetDiffCommits( | 339 | localCommits, originCommits = cls._GetDiffCommits( |
| 341 | project, logTarget | 340 | project, logTarget |
diff --git a/subcmds/sync.py b/subcmds/sync.py index 24cd74d2b..117f158d6 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
| @@ -62,8 +62,7 @@ import event_log | |||
| 62 | import git_command | 62 | import git_command |
| 63 | from git_config import GetUrlCookieFile | 63 | from git_config import GetUrlCookieFile |
| 64 | from git_config import RepoConfig | 64 | from git_config import RepoConfig |
| 65 | from git_refs import HEAD | 65 | import git_refs |
| 66 | from git_refs import R_HEADS | ||
| 67 | import git_superproject | 66 | import git_superproject |
| 68 | from hooks import RepoHook | 67 | from hooks import RepoHook |
| 69 | from manifest_xml import XmlManifest | 68 | from manifest_xml import XmlManifest |
| @@ -866,8 +865,8 @@ later is required to fix a server side protocol bug. | |||
| 866 | """ | 865 | """ |
| 867 | b = manifest_project.GetBranch(manifest_project.CurrentBranch) | 866 | b = manifest_project.GetBranch(manifest_project.CurrentBranch) |
| 868 | branch = b.merge | 867 | branch = b.merge |
| 869 | if branch.startswith(R_HEADS): | 868 | if branch.startswith(git_refs.R_HEADS): |
| 870 | branch = branch[len(R_HEADS) :] | 869 | branch = branch[len(git_refs.R_HEADS) :] |
| 871 | return branch | 870 | return branch |
| 872 | 871 | ||
| 873 | @classmethod | 872 | @classmethod |
| @@ -3501,7 +3500,10 @@ def _PostRepoFetch(rp, repo_verify=True, verbose=False): | |||
| 3501 | logger.warning("warning: Skipped upgrade to unverified version") | 3500 | logger.warning("warning: Skipped upgrade to unverified version") |
| 3502 | else: | 3501 | else: |
| 3503 | if verbose: | 3502 | if verbose: |
| 3504 | print("repo version %s is current" % rp.work_git.describe(HEAD)) | 3503 | print( |
| 3504 | "repo version %s is current" | ||
| 3505 | % rp.work_git.describe(git_refs.HEAD) | ||
| 3506 | ) | ||
| 3505 | 3507 | ||
| 3506 | 3508 | ||
| 3507 | class _FetchTimes: | 3509 | class _FetchTimes: |
diff --git a/subcmds/upload.py b/subcmds/upload.py index 67eea2e66..bb4390d22 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py | |||
| @@ -23,7 +23,7 @@ from command import DEFAULT_LOCAL_JOBS | |||
| 23 | from command import InteractiveCommand | 23 | from command import InteractiveCommand |
| 24 | from editor import Editor | 24 | from editor import Editor |
| 25 | import error | 25 | import error |
| 26 | from git_refs import R_HEADS | 26 | import git_refs |
| 27 | import git_superproject | 27 | import git_superproject |
| 28 | from hooks import RepoHook | 28 | from hooks import RepoHook |
| 29 | from project import ReviewableBranch | 29 | from project import ReviewableBranch |
| @@ -607,11 +607,11 @@ Gerrit Code Review: https://www.gerritcodereview.com/ | |||
| 607 | ) | 607 | ) |
| 608 | 608 | ||
| 609 | full_dest = destination | 609 | full_dest = destination |
| 610 | if not full_dest.startswith(R_HEADS): | 610 | if not full_dest.startswith(git_refs.R_HEADS): |
| 611 | full_dest = R_HEADS + full_dest | 611 | full_dest = git_refs.R_HEADS + full_dest |
| 612 | full_revision = branch.project.revisionExpr | 612 | full_revision = branch.project.revisionExpr |
| 613 | if not full_revision.startswith(R_HEADS): | 613 | if not full_revision.startswith(git_refs.R_HEADS): |
| 614 | full_revision = R_HEADS + full_revision | 614 | full_revision = git_refs.R_HEADS + full_revision |
| 615 | 615 | ||
| 616 | # If the merge branch of the local branch is different from | 616 | # If the merge branch of the local branch is different from |
| 617 | # the project's revision AND destination, this might not be | 617 | # the project's revision AND destination, this might not be |
diff --git a/subcmds/version.py b/subcmds/version.py index 557bdddca..ab1a2a862 100644 --- a/subcmds/version.py +++ b/subcmds/version.py | |||
| @@ -19,7 +19,7 @@ from typing import Any, Tuple | |||
| 19 | from command import Command | 19 | from command import Command |
| 20 | from command import MirrorSafeCommand | 20 | from command import MirrorSafeCommand |
| 21 | import git_command | 21 | import git_command |
| 22 | from git_refs import HEAD | 22 | import git_refs |
| 23 | from wrapper import Wrapper | 23 | from wrapper import Wrapper |
| 24 | 24 | ||
| 25 | 25 | ||
| @@ -38,15 +38,15 @@ class Version(Command, MirrorSafeCommand): | |||
| 38 | """Return repo's describe string and commit date.""" | 38 | """Return repo's describe string and commit date.""" |
| 39 | if git_command.git_require((2, 32, 0)): | 39 | if git_command.git_require((2, 32, 0)): |
| 40 | output = project.bare_git.log( | 40 | output = project.bare_git.log( |
| 41 | "-1", "--format=%(describe)%n%cD", HEAD | 41 | "-1", "--format=%(describe)%n%cD", git_refs.HEAD |
| 42 | ) | 42 | ) |
| 43 | description, commit_date = output.rstrip("\n").split("\n", 1) | 43 | description, commit_date = output.rstrip("\n").split("\n", 1) |
| 44 | if description: | 44 | if description: |
| 45 | return description, commit_date | 45 | return description, commit_date |
| 46 | 46 | ||
| 47 | return ( | 47 | return ( |
| 48 | project.bare_git.describe(HEAD), | 48 | project.bare_git.describe(git_refs.HEAD), |
| 49 | project.bare_git.log("-1", "--format=%cD", HEAD), | 49 | project.bare_git.log("-1", "--format=%cD", git_refs.HEAD), |
| 50 | ) | 50 | ) |
| 51 | 51 | ||
| 52 | def Execute(self, opt, args): | 52 | def Execute(self, opt, args): |
diff --git a/tests/test_project.py b/tests/test_project.py index 9b4bae660..f65e83f95 100644 --- a/tests/test_project.py +++ b/tests/test_project.py | |||
| @@ -31,6 +31,7 @@ import utils_for_test | |||
| 31 | import error | 31 | import error |
| 32 | import git_command | 32 | import git_command |
| 33 | import git_config | 33 | import git_config |
| 34 | import git_refs | ||
| 34 | import git_status | 35 | import git_status |
| 35 | import git_trace2_event_log | 36 | import git_trace2_event_log |
| 36 | import manifest_xml | 37 | import manifest_xml |
| @@ -3792,8 +3793,10 @@ class ReprojectCmdTests(unittest.TestCase): | |||
| 3792 | 3793 | ||
| 3793 | proj.bare_ref = mock.MagicMock() | 3794 | proj.bare_ref = mock.MagicMock() |
| 3794 | if branch: | 3795 | if branch: |
| 3795 | proj.bare_ref.head = project.R_HEADS + branch | 3796 | proj.bare_ref.head = git_refs.R_HEADS + branch |
| 3796 | proj.bare_ref.all = {project.R_HEADS + branch: head} if head else {} | 3797 | proj.bare_ref.all = ( |
| 3798 | {git_refs.R_HEADS + branch: head} if head else {} | ||
| 3799 | ) | ||
| 3797 | # A branch that does not track upstream; tests that need one | 3800 | # A branch that does not track upstream; tests that need one |
| 3798 | # tracking upstream replace this with _tracking_branch(). | 3801 | # tracking upstream replace this with _tracking_branch(). |
| 3799 | proj.GetBranch = mock.MagicMock( | 3802 | proj.GetBranch = mock.MagicMock( |
| @@ -3806,7 +3809,7 @@ class ReprojectCmdTests(unittest.TestCase): | |||
| 3806 | def _revlist(*args: Any, **kwargs: Any) -> List[str]: | 3809 | def _revlist(*args: Any, **kwargs: Any) -> List[str]: |
| 3807 | if kwargs.get("format"): | 3810 | if kwargs.get("format"): |
| 3808 | return list(local_changes) | 3811 | return list(local_changes) |
| 3809 | if project.not_rev(project.HEAD) in args: | 3812 | if project.not_rev(git_refs.HEAD) in args: |
| 3810 | if "--count" in args: | 3813 | if "--count" in args: |
| 3811 | return [str(len(upstream_gain))] | 3814 | return [str(len(upstream_gain))] |
| 3812 | return list(upstream_gain) | 3815 | return list(upstream_gain) |
| @@ -3909,7 +3912,7 @@ class ReprojectCmdTests(unittest.TestCase): | |||
| 3909 | self.assertTrue(syncbuf.Finish()) | 3912 | self.assertTrue(syncbuf.Finish()) |
| 3910 | proj._Reproject.assert_called_once_with(self.REVID, verbose=False) | 3913 | proj._Reproject.assert_called_once_with(self.REVID, verbose=False) |
| 3911 | proj.work_git.UpdateRef.assert_called_once_with( | 3914 | proj.work_git.UpdateRef.assert_called_once_with( |
| 3912 | project.HEAD, | 3915 | git_refs.HEAD, |
| 3913 | self.REVID, | 3916 | self.REVID, |
| 3914 | old=self.HEAD_ID, | 3917 | old=self.HEAD_ID, |
| 3915 | message=f"merge {self.REVID}: Fast-forward", | 3918 | message=f"merge {self.REVID}: Fast-forward", |
| @@ -3956,7 +3959,7 @@ class ReprojectCmdTests(unittest.TestCase): | |||
| 3956 | self.assertTrue(syncbuf.Finish()) | 3959 | self.assertTrue(syncbuf.Finish()) |
| 3957 | proj._Reproject.assert_called_once_with(self.REVID, verbose=False) | 3960 | proj._Reproject.assert_called_once_with(self.REVID, verbose=False) |
| 3958 | proj.work_git.UpdateRef.assert_called_once_with( | 3961 | proj.work_git.UpdateRef.assert_called_once_with( |
| 3959 | project.HEAD, | 3962 | git_refs.HEAD, |
| 3960 | self.REVID, | 3963 | self.REVID, |
| 3961 | old=self.HEAD_ID, | 3964 | old=self.HEAD_ID, |
| 3962 | message=f"reset: moving to {self.REVID}", | 3965 | message=f"reset: moving to {self.REVID}", |
