summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
Diffstat (limited to 'project.py')
-rw-r--r--project.py68
1 files changed, 50 insertions, 18 deletions
diff --git a/project.py b/project.py
index 874a40bd..f963576b 100644
--- a/project.py
+++ b/project.py
@@ -46,6 +46,32 @@ def _info(fmt, *args):
46def not_rev(r): 46def not_rev(r):
47 return '^' + r 47 return '^' + r
48 48
49
50hook_list = None
51def repo_hooks():
52 global hook_list
53 if hook_list is None:
54 d = os.path.abspath(os.path.dirname(__file__))
55 d = os.path.join(d , 'hooks')
56 hook_list = map(lambda x: os.path.join(d, x), os.listdir(d))
57 return hook_list
58
59def relpath(dst, src):
60 src = os.path.dirname(src)
61 top = os.path.commonprefix([dst, src])
62 if top.endswith('/'):
63 top = top[:-1]
64 else:
65 top = os.path.dirname(top)
66
67 tmp = src
68 rel = ''
69 while top != tmp:
70 rel += '../'
71 tmp = os.path.dirname(tmp)
72 return rel + dst[len(top) + 1:]
73
74
49class DownloadedChange(object): 75class DownloadedChange(object):
50 _commit_cache = None 76 _commit_cache = None
51 77
@@ -472,7 +498,10 @@ class Project(object):
472 self._RepairAndroidImportErrors() 498 self._RepairAndroidImportErrors()
473 self._InitMRef() 499 self._InitMRef()
474 return True 500 return True
475 501
502 def PostRepoUpgrade(self):
503 self._InitHooks()
504
476 def _CopyFiles(self): 505 def _CopyFiles(self):
477 for file in self.copyfiles: 506 for file in self.copyfiles:
478 file._Copy() 507 file._Copy()
@@ -795,14 +824,29 @@ class Project(object):
795 to_rm = [] 824 to_rm = []
796 for old_hook in to_rm: 825 for old_hook in to_rm:
797 os.remove(os.path.join(hooks, old_hook)) 826 os.remove(os.path.join(hooks, old_hook))
798 827 self._InitHooks()
799 # TODO(sop) install custom repo hooks
800 828
801 m = self.manifest.manifestProject.config 829 m = self.manifest.manifestProject.config
802 for key in ['user.name', 'user.email']: 830 for key in ['user.name', 'user.email']:
803 if m.Has(key, include_defaults = False): 831 if m.Has(key, include_defaults = False):
804 self.config.SetString(key, m.GetString(key)) 832 self.config.SetString(key, m.GetString(key))
805 833
834 def _InitHooks(self):
835 hooks = self._gitdir_path('hooks')
836 if not os.path.exists(hooks):
837 os.makedirs(hooks)
838 for stock_hook in repo_hooks():
839 dst = os.path.join(hooks, os.path.basename(stock_hook))
840 try:
841 os.symlink(relpath(stock_hook, dst), dst)
842 except OSError, e:
843 if e.errno == errno.EEXIST:
844 pass
845 elif e.errno == errno.EPERM:
846 raise GitError('filesystem must support symlinks')
847 else:
848 raise
849
806 def _InitRemote(self): 850 def _InitRemote(self):
807 if self.remote.fetchUrl: 851 if self.remote.fetchUrl:
808 remote = self.GetRemote(self.remote.name) 852 remote = self.GetRemote(self.remote.name)
@@ -842,19 +886,6 @@ class Project(object):
842 if not os.path.exists(dotgit): 886 if not os.path.exists(dotgit):
843 os.makedirs(dotgit) 887 os.makedirs(dotgit)
844 888
845 topdir = os.path.commonprefix([self.gitdir, dotgit])
846 if topdir.endswith('/'):
847 topdir = topdir[:-1]
848 else:
849 topdir = os.path.dirname(topdir)
850
851 tmpdir = dotgit
852 relgit = ''
853 while topdir != tmpdir:
854 relgit += '../'
855 tmpdir = os.path.dirname(tmpdir)
856 relgit += self.gitdir[len(topdir) + 1:]
857
858 for name in ['config', 889 for name in ['config',
859 'description', 890 'description',
860 'hooks', 891 'hooks',
@@ -866,8 +897,9 @@ class Project(object):
866 'rr-cache', 897 'rr-cache',
867 'svn']: 898 'svn']:
868 try: 899 try:
869 os.symlink(os.path.join(relgit, name), 900 src = os.path.join(self.gitdir, name)
870 os.path.join(dotgit, name)) 901 dst = os.path.join(dotgit, name)
902 os.symlink(relpath(src, dst), dst)
871 except OSError, e: 903 except OSError, e:
872 if e.errno == errno.EPERM: 904 if e.errno == errno.EPERM:
873 raise GitError('filesystem must support symlinks') 905 raise GitError('filesystem must support symlinks')