diff options
| author | David Pursehouse <david.pursehouse@sonymobile.com> | 2012-09-24 12:15:13 +0900 |
|---|---|---|
| committer | Gustaf Lundh <gustaf.lundh@sonymobile.com> | 2012-10-09 12:45:30 +0200 |
| commit | 8a68ff96057ec58e524a3e41a2d8dca7b5d016bc (patch) | |
| tree | 22f6971e8d3c4a90d11d3704602d073a852328b4 /project.py | |
| parent | e3b1c45aebed329cbc9ad172b1d8e812cf208117 (diff) | |
| download | git-repo-8a68ff96057ec58e524a3e41a2d8dca7b5d016bc.tar.gz | |
Coding style cleanup
Fix the following issues reported by pylint:
C0321: More than one statement on a single line
W0622: Redefining built-in 'name'
W0612: Unused variable 'name'
W0613: Unused argument 'name'
W0102: Dangerous default value 'value' as argument
W0105: String statement has no effect
Also fixed a few cases of inconsistent indentation.
Change-Id: Ie0db839e7c57d576cff12d8c055fe87030d00744
Diffstat (limited to 'project.py')
| -rw-r--r-- | project.py | 119 |
1 files changed, 58 insertions, 61 deletions
| @@ -328,7 +328,6 @@ class RepoHook(object): | |||
| 328 | HookError: Raised if the user doesn't approve and abort_if_user_denies | 328 | HookError: Raised if the user doesn't approve and abort_if_user_denies |
| 329 | was passed to the consturctor. | 329 | was passed to the consturctor. |
| 330 | """ | 330 | """ |
| 331 | hooks_dir = self._hooks_project.worktree | ||
| 332 | hooks_config = self._hooks_project.config | 331 | hooks_config = self._hooks_project.config |
| 333 | git_approval_key = 'repo.hooks.%s.approvedhash' % self._hook_type | 332 | git_approval_key = 'repo.hooks.%s.approvedhash' % self._hook_type |
| 334 | 333 | ||
| @@ -608,25 +607,24 @@ class Project(object): | |||
| 608 | """Get all existing local branches. | 607 | """Get all existing local branches. |
| 609 | """ | 608 | """ |
| 610 | current = self.CurrentBranch | 609 | current = self.CurrentBranch |
| 611 | all = self._allrefs | 610 | all_refs = self._allrefs |
| 612 | heads = {} | 611 | heads = {} |
| 613 | pubd = {} | ||
| 614 | 612 | ||
| 615 | for name, id in all.iteritems(): | 613 | for name, ref_id in all_refs.iteritems(): |
| 616 | if name.startswith(R_HEADS): | 614 | if name.startswith(R_HEADS): |
| 617 | name = name[len(R_HEADS):] | 615 | name = name[len(R_HEADS):] |
| 618 | b = self.GetBranch(name) | 616 | b = self.GetBranch(name) |
| 619 | b.current = name == current | 617 | b.current = name == current |
| 620 | b.published = None | 618 | b.published = None |
| 621 | b.revision = id | 619 | b.revision = ref_id |
| 622 | heads[name] = b | 620 | heads[name] = b |
| 623 | 621 | ||
| 624 | for name, id in all.iteritems(): | 622 | for name, ref_id in all_refs.iteritems(): |
| 625 | if name.startswith(R_PUB): | 623 | if name.startswith(R_PUB): |
| 626 | name = name[len(R_PUB):] | 624 | name = name[len(R_PUB):] |
| 627 | b = heads.get(name) | 625 | b = heads.get(name) |
| 628 | if b: | 626 | if b: |
| 629 | b.published = id | 627 | b.published = ref_id |
| 630 | 628 | ||
| 631 | return heads | 629 | return heads |
| 632 | 630 | ||
| @@ -785,40 +783,40 @@ class Project(object): | |||
| 785 | 783 | ||
| 786 | ## Publish / Upload ## | 784 | ## Publish / Upload ## |
| 787 | 785 | ||
| 788 | def WasPublished(self, branch, all=None): | 786 | def WasPublished(self, branch, all_refs=None): |
| 789 | """Was the branch published (uploaded) for code review? | 787 | """Was the branch published (uploaded) for code review? |
| 790 | If so, returns the SHA-1 hash of the last published | 788 | If so, returns the SHA-1 hash of the last published |
| 791 | state for the branch. | 789 | state for the branch. |
| 792 | """ | 790 | """ |
| 793 | key = R_PUB + branch | 791 | key = R_PUB + branch |
| 794 | if all is None: | 792 | if all_refs is None: |
| 795 | try: | 793 | try: |
| 796 | return self.bare_git.rev_parse(key) | 794 | return self.bare_git.rev_parse(key) |
| 797 | except GitError: | 795 | except GitError: |
| 798 | return None | 796 | return None |
| 799 | else: | 797 | else: |
| 800 | try: | 798 | try: |
| 801 | return all[key] | 799 | return all_refs[key] |
| 802 | except KeyError: | 800 | except KeyError: |
| 803 | return None | 801 | return None |
| 804 | 802 | ||
| 805 | def CleanPublishedCache(self, all=None): | 803 | def CleanPublishedCache(self, all_refs=None): |
| 806 | """Prunes any stale published refs. | 804 | """Prunes any stale published refs. |
| 807 | """ | 805 | """ |
| 808 | if all is None: | 806 | if all_refs is None: |
| 809 | all = self._allrefs | 807 | all_refs = self._allrefs |
| 810 | heads = set() | 808 | heads = set() |
| 811 | canrm = {} | 809 | canrm = {} |
| 812 | for name, id in all.iteritems(): | 810 | for name, ref_id in all_refs.iteritems(): |
| 813 | if name.startswith(R_HEADS): | 811 | if name.startswith(R_HEADS): |
| 814 | heads.add(name) | 812 | heads.add(name) |
| 815 | elif name.startswith(R_PUB): | 813 | elif name.startswith(R_PUB): |
| 816 | canrm[name] = id | 814 | canrm[name] = ref_id |
| 817 | 815 | ||
| 818 | for name, id in canrm.iteritems(): | 816 | for name, ref_id in canrm.iteritems(): |
| 819 | n = name[len(R_PUB):] | 817 | n = name[len(R_PUB):] |
| 820 | if R_HEADS + n not in heads: | 818 | if R_HEADS + n not in heads: |
| 821 | self.bare_git.DeleteRef(name, id) | 819 | self.bare_git.DeleteRef(name, ref_id) |
| 822 | 820 | ||
| 823 | def GetUploadableBranches(self, selected_branch=None): | 821 | def GetUploadableBranches(self, selected_branch=None): |
| 824 | """List any branches which can be uploaded for review. | 822 | """List any branches which can be uploaded for review. |
| @@ -826,15 +824,15 @@ class Project(object): | |||
| 826 | heads = {} | 824 | heads = {} |
| 827 | pubed = {} | 825 | pubed = {} |
| 828 | 826 | ||
| 829 | for name, id in self._allrefs.iteritems(): | 827 | for name, ref_id in self._allrefs.iteritems(): |
| 830 | if name.startswith(R_HEADS): | 828 | if name.startswith(R_HEADS): |
| 831 | heads[name[len(R_HEADS):]] = id | 829 | heads[name[len(R_HEADS):]] = ref_id |
| 832 | elif name.startswith(R_PUB): | 830 | elif name.startswith(R_PUB): |
| 833 | pubed[name[len(R_PUB):]] = id | 831 | pubed[name[len(R_PUB):]] = ref_id |
| 834 | 832 | ||
| 835 | ready = [] | 833 | ready = [] |
| 836 | for branch, id in heads.iteritems(): | 834 | for branch, ref_id in heads.iteritems(): |
| 837 | if branch in pubed and pubed[branch] == id: | 835 | if branch in pubed and pubed[branch] == ref_id: |
| 838 | continue | 836 | continue |
| 839 | if selected_branch and branch != selected_branch: | 837 | if selected_branch and branch != selected_branch: |
| 840 | continue | 838 | continue |
| @@ -978,18 +976,18 @@ class Project(object): | |||
| 978 | self._InitHooks() | 976 | self._InitHooks() |
| 979 | 977 | ||
| 980 | def _CopyFiles(self): | 978 | def _CopyFiles(self): |
| 981 | for file in self.copyfiles: | 979 | for copyfile in self.copyfiles: |
| 982 | file._Copy() | 980 | copyfile._Copy() |
| 983 | 981 | ||
| 984 | def GetRevisionId(self, all=None): | 982 | def GetRevisionId(self, all_refs=None): |
| 985 | if self.revisionId: | 983 | if self.revisionId: |
| 986 | return self.revisionId | 984 | return self.revisionId |
| 987 | 985 | ||
| 988 | rem = self.GetRemote(self.remote.name) | 986 | rem = self.GetRemote(self.remote.name) |
| 989 | rev = rem.ToLocal(self.revisionExpr) | 987 | rev = rem.ToLocal(self.revisionExpr) |
| 990 | 988 | ||
| 991 | if all is not None and rev in all: | 989 | if all_refs is not None and rev in all_refs: |
| 992 | return all[rev] | 990 | return all_refs[rev] |
| 993 | 991 | ||
| 994 | try: | 992 | try: |
| 995 | return self.bare_git.rev_parse('--verify', '%s^0' % rev) | 993 | return self.bare_git.rev_parse('--verify', '%s^0' % rev) |
| @@ -1002,16 +1000,16 @@ class Project(object): | |||
| 1002 | """Perform only the local IO portion of the sync process. | 1000 | """Perform only the local IO portion of the sync process. |
| 1003 | Network access is not required. | 1001 | Network access is not required. |
| 1004 | """ | 1002 | """ |
| 1005 | all = self.bare_ref.all | 1003 | all_refs = self.bare_ref.all |
| 1006 | self.CleanPublishedCache(all) | 1004 | self.CleanPublishedCache(all_refs) |
| 1007 | revid = self.GetRevisionId(all) | 1005 | revid = self.GetRevisionId(all_refs) |
| 1008 | 1006 | ||
| 1009 | self._InitWorkTree() | 1007 | self._InitWorkTree() |
| 1010 | head = self.work_git.GetHead() | 1008 | head = self.work_git.GetHead() |
| 1011 | if head.startswith(R_HEADS): | 1009 | if head.startswith(R_HEADS): |
| 1012 | branch = head[len(R_HEADS):] | 1010 | branch = head[len(R_HEADS):] |
| 1013 | try: | 1011 | try: |
| 1014 | head = all[head] | 1012 | head = all_refs[head] |
| 1015 | except KeyError: | 1013 | except KeyError: |
| 1016 | head = None | 1014 | head = None |
| 1017 | else: | 1015 | else: |
| @@ -1067,7 +1065,7 @@ class Project(object): | |||
| 1067 | return | 1065 | return |
| 1068 | 1066 | ||
| 1069 | upstream_gain = self._revlist(not_rev(HEAD), revid) | 1067 | upstream_gain = self._revlist(not_rev(HEAD), revid) |
| 1070 | pub = self.WasPublished(branch.name, all) | 1068 | pub = self.WasPublished(branch.name, all_refs) |
| 1071 | if pub: | 1069 | if pub: |
| 1072 | not_merged = self._revlist(not_rev(revid), pub) | 1070 | not_merged = self._revlist(not_rev(revid), pub) |
| 1073 | if not_merged: | 1071 | if not_merged: |
| @@ -1190,8 +1188,8 @@ class Project(object): | |||
| 1190 | if head == (R_HEADS + name): | 1188 | if head == (R_HEADS + name): |
| 1191 | return True | 1189 | return True |
| 1192 | 1190 | ||
| 1193 | all = self.bare_ref.all | 1191 | all_refs = self.bare_ref.all |
| 1194 | if (R_HEADS + name) in all: | 1192 | if (R_HEADS + name) in all_refs: |
| 1195 | return GitCommand(self, | 1193 | return GitCommand(self, |
| 1196 | ['checkout', name, '--'], | 1194 | ['checkout', name, '--'], |
| 1197 | capture_stdout = True, | 1195 | capture_stdout = True, |
| @@ -1200,11 +1198,11 @@ class Project(object): | |||
| 1200 | branch = self.GetBranch(name) | 1198 | branch = self.GetBranch(name) |
| 1201 | branch.remote = self.GetRemote(self.remote.name) | 1199 | branch.remote = self.GetRemote(self.remote.name) |
| 1202 | branch.merge = self.revisionExpr | 1200 | branch.merge = self.revisionExpr |
| 1203 | revid = self.GetRevisionId(all) | 1201 | revid = self.GetRevisionId(all_refs) |
| 1204 | 1202 | ||
| 1205 | if head.startswith(R_HEADS): | 1203 | if head.startswith(R_HEADS): |
| 1206 | try: | 1204 | try: |
| 1207 | head = all[head] | 1205 | head = all_refs[head] |
| 1208 | except KeyError: | 1206 | except KeyError: |
| 1209 | head = None | 1207 | head = None |
| 1210 | 1208 | ||
| @@ -1245,9 +1243,9 @@ class Project(object): | |||
| 1245 | # | 1243 | # |
| 1246 | return True | 1244 | return True |
| 1247 | 1245 | ||
| 1248 | all = self.bare_ref.all | 1246 | all_refs = self.bare_ref.all |
| 1249 | try: | 1247 | try: |
| 1250 | revid = all[rev] | 1248 | revid = all_refs[rev] |
| 1251 | except KeyError: | 1249 | except KeyError: |
| 1252 | # Branch does not exist in this project | 1250 | # Branch does not exist in this project |
| 1253 | # | 1251 | # |
| @@ -1255,7 +1253,7 @@ class Project(object): | |||
| 1255 | 1253 | ||
| 1256 | if head.startswith(R_HEADS): | 1254 | if head.startswith(R_HEADS): |
| 1257 | try: | 1255 | try: |
| 1258 | head = all[head] | 1256 | head = all_refs[head] |
| 1259 | except KeyError: | 1257 | except KeyError: |
| 1260 | head = None | 1258 | head = None |
| 1261 | 1259 | ||
| @@ -1283,8 +1281,8 @@ class Project(object): | |||
| 1283 | didn't exist. | 1281 | didn't exist. |
| 1284 | """ | 1282 | """ |
| 1285 | rev = R_HEADS + name | 1283 | rev = R_HEADS + name |
| 1286 | all = self.bare_ref.all | 1284 | all_refs = self.bare_ref.all |
| 1287 | if rev not in all: | 1285 | if rev not in all_refs: |
| 1288 | # Doesn't exist | 1286 | # Doesn't exist |
| 1289 | return None | 1287 | return None |
| 1290 | 1288 | ||
| @@ -1293,9 +1291,9 @@ class Project(object): | |||
| 1293 | # We can't destroy the branch while we are sitting | 1291 | # We can't destroy the branch while we are sitting |
| 1294 | # on it. Switch to a detached HEAD. | 1292 | # on it. Switch to a detached HEAD. |
| 1295 | # | 1293 | # |
| 1296 | head = all[head] | 1294 | head = all_refs[head] |
| 1297 | 1295 | ||
| 1298 | revid = self.GetRevisionId(all) | 1296 | revid = self.GetRevisionId(all_refs) |
| 1299 | if head == revid: | 1297 | if head == revid: |
| 1300 | _lwrite(os.path.join(self.worktree, '.git', HEAD), | 1298 | _lwrite(os.path.join(self.worktree, '.git', HEAD), |
| 1301 | '%s\n' % revid) | 1299 | '%s\n' % revid) |
| @@ -1412,33 +1410,33 @@ class Project(object): | |||
| 1412 | packed_refs = os.path.join(self.gitdir, 'packed-refs') | 1410 | packed_refs = os.path.join(self.gitdir, 'packed-refs') |
| 1413 | remote = self.GetRemote(name) | 1411 | remote = self.GetRemote(name) |
| 1414 | 1412 | ||
| 1415 | all = self.bare_ref.all | 1413 | all_refs = self.bare_ref.all |
| 1416 | ids = set(all.values()) | 1414 | ids = set(all_refs.values()) |
| 1417 | tmp = set() | 1415 | tmp = set() |
| 1418 | 1416 | ||
| 1419 | for r, id in GitRefs(ref_dir).all.iteritems(): | 1417 | for r, ref_id in GitRefs(ref_dir).all.iteritems(): |
| 1420 | if r not in all: | 1418 | if r not in all_refs: |
| 1421 | if r.startswith(R_TAGS) or remote.WritesTo(r): | 1419 | if r.startswith(R_TAGS) or remote.WritesTo(r): |
| 1422 | all[r] = id | 1420 | all_refs[r] = ref_id |
| 1423 | ids.add(id) | 1421 | ids.add(ref_id) |
| 1424 | continue | 1422 | continue |
| 1425 | 1423 | ||
| 1426 | if id in ids: | 1424 | if ref_id in ids: |
| 1427 | continue | 1425 | continue |
| 1428 | 1426 | ||
| 1429 | r = 'refs/_alt/%s' % id | 1427 | r = 'refs/_alt/%s' % ref_id |
| 1430 | all[r] = id | 1428 | all_refs[r] = ref_id |
| 1431 | ids.add(id) | 1429 | ids.add(ref_id) |
| 1432 | tmp.add(r) | 1430 | tmp.add(r) |
| 1433 | 1431 | ||
| 1434 | ref_names = list(all.keys()) | 1432 | ref_names = list(all_refs.keys()) |
| 1435 | ref_names.sort() | 1433 | ref_names.sort() |
| 1436 | 1434 | ||
| 1437 | tmp_packed = '' | 1435 | tmp_packed = '' |
| 1438 | old_packed = '' | 1436 | old_packed = '' |
| 1439 | 1437 | ||
| 1440 | for r in ref_names: | 1438 | for r in ref_names: |
| 1441 | line = '%s %s\n' % (all[r], r) | 1439 | line = '%s %s\n' % (all_refs[r], r) |
| 1442 | tmp_packed += line | 1440 | tmp_packed += line |
| 1443 | if r not in tmp: | 1441 | if r not in tmp: |
| 1444 | old_packed += line | 1442 | old_packed += line |
| @@ -1477,7 +1475,7 @@ class Project(object): | |||
| 1477 | cmd.append((u'+refs/heads/%s:' % branch) + remote.ToLocal('refs/heads/%s' % branch)) | 1475 | cmd.append((u'+refs/heads/%s:' % branch) + remote.ToLocal('refs/heads/%s' % branch)) |
| 1478 | 1476 | ||
| 1479 | ok = False | 1477 | ok = False |
| 1480 | for i in range(2): | 1478 | for _i in range(2): |
| 1481 | ret = GitCommand(self, cmd, bare=True, ssh_proxy=ssh_proxy).Wait() | 1479 | ret = GitCommand(self, cmd, bare=True, ssh_proxy=ssh_proxy).Wait() |
| 1482 | if ret == 0: | 1480 | if ret == 0: |
| 1483 | ok = True | 1481 | ok = True |
| @@ -2034,7 +2032,7 @@ class _Later(object): | |||
| 2034 | self.action() | 2032 | self.action() |
| 2035 | out.nl() | 2033 | out.nl() |
| 2036 | return True | 2034 | return True |
| 2037 | except GitError, e: | 2035 | except GitError: |
| 2038 | out.nl() | 2036 | out.nl() |
| 2039 | return False | 2037 | return False |
| 2040 | 2038 | ||
| @@ -2104,7 +2102,6 @@ class MetaProject(Project): | |||
| 2104 | """A special project housed under .repo. | 2102 | """A special project housed under .repo. |
| 2105 | """ | 2103 | """ |
| 2106 | def __init__(self, manifest, name, gitdir, worktree): | 2104 | def __init__(self, manifest, name, gitdir, worktree): |
| 2107 | repodir = manifest.repodir | ||
| 2108 | Project.__init__(self, | 2105 | Project.__init__(self, |
| 2109 | manifest = manifest, | 2106 | manifest = manifest, |
| 2110 | name = name, | 2107 | name = name, |
| @@ -2156,12 +2153,12 @@ class MetaProject(Project): | |||
| 2156 | if not self.remote or not self.revisionExpr: | 2153 | if not self.remote or not self.revisionExpr: |
| 2157 | return False | 2154 | return False |
| 2158 | 2155 | ||
| 2159 | all = self.bare_ref.all | 2156 | all_refs = self.bare_ref.all |
| 2160 | revid = self.GetRevisionId(all) | 2157 | revid = self.GetRevisionId(all_refs) |
| 2161 | head = self.work_git.GetHead() | 2158 | head = self.work_git.GetHead() |
| 2162 | if head.startswith(R_HEADS): | 2159 | if head.startswith(R_HEADS): |
| 2163 | try: | 2160 | try: |
| 2164 | head = all[head] | 2161 | head = all_refs[head] |
| 2165 | except KeyError: | 2162 | except KeyError: |
| 2166 | head = None | 2163 | head = None |
| 2167 | 2164 | ||
