1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220 | diff --git a/usd/clone.py b/usd/clone.py
index 50f62b5..a95fd63 100644
--- a/usd/clone.py
+++ b/usd/clone.py
@@ -152,30 +152,21 @@ Example:
if self.lp_user == LP_USER_NONE:
usd_proto = self.proto
- self.local_repo.add_remote(self.package, 'usd-import-team',
- 'lpusip', self.lp_user)
- self.local_repo.fetch_remote('lpusip', must_exist=True)
+ self.local_repo.add_base_remotes(pkgname=self.package,
+ repo_owner='usd-import-team',
+ lp_user=self.lp_user)
+ self.local_repo.fetch_base_remotes(must_exist=True)
if self.lp_user != LP_USER_NONE:
self.local_repo.add_remote(
- self.package,
- self.lp_user,
- 'lpmep',
- self.lp_user
+ pkgname=self.package,
+ repo_owner=self.lp_user,
+ remote_name=self.lp_user,
+ lp_user=self.lp_user
)
- self.local_repo.fetch_remote('lpmep', must_exist=False)
+ self.local_repo.fetch_remote(self.lp_user, must_exist=False)
logging.debug("added remote 'lpmep' -> %s",
- self.local_repo.remotes['lpmep'].url
- )
-
- try:
- self.local_repo.create_tracking_branch('ubuntu/devel',
- 'lpusip/ubuntu/devel'
- )
- self.local_repo.checkout_commitish('ubuntu/devel')
- except:
- logging.error('Unable to checkout ubuntu/devel, does '
- 'lpusip/ubuntu/devel exist?'
+ self.local_repo.remotes[self.lp_user].url
)
if os.path.isfile(os.path.join(self.directory,
diff --git a/usd/git_repository.py b/usd/git_repository.py
index 0e400f8..221727b 100644
--- a/usd/git_repository.py
+++ b/usd/git_repository.py
@@ -199,7 +199,7 @@ class USDGitRepository:
)
sys.exit(1)
- def fetch_remote(self, remote_name, must_exist=False):
+ def _fetch_remote(self, remote_name, must_exist):
try:
# Does not seem to be working with https
# self.local_repo.remotes[remote_name].fetch()
@@ -210,20 +210,21 @@ class USDGitRepository:
if must_exist:
raise
- def add_remote(self, pkgname, repo_owner, remote_name, lp_user):
+ def fetch_base_remotes(self, must_exist=False):
+ self._fetch_remote('debian', must_exist)
+ self._fetch_remote('ubuntu', must_exist)
+
+ def fetch_remote(self, remote_name, must_exist=False):
+ self._fetch_remote(remote_name, must_exist)
+
+ def _add_remote(self, remote_name, remote_url, remote_namespace,
+ lp_user, add_base_tags=False):
if not self.fetch_proto:
raise Exception('Cannot fetch using an object without a protocol')
- remote_url = ('git.launchpad.net/~%s/ubuntu/+source/%s' %
- (repo_owner, pkgname)
- )
fetch_url = '%s://%s' % (self.fetch_proto, remote_url)
- push_url = 'ssh://%s@%s' % (lp_user, remote_url)
+
logging.debug('Adding %s as remote %s', fetch_url, remote_name)
- # Namespace change:
- # '' (remote)
- # remote_namespace/ (local)
- # fetch will mirror origin to remote_namespace, grabbing tags as needed
# This should be a function in pygit2?
# https://github.com/libgit2/pygit2/issues/671
remote_exists = False
@@ -232,34 +233,46 @@ class USDGitRepository:
remote_exists = True
break
if not remote_exists:
+ if remote_namespace:
+ head_refspec = 'refs/heads/%s/*:refs/remotes/%s/*' % (
+ remote_namespace, remote_name)
+ tag_refspec = 'refs/tags/%s/*:refs/tags/%s/*' % (
+ remote_namespace, remote_name)
+ else:
+ head_refspec = 'refs/heads/*:refs/remotes/%s/*' % remote_name
+ tag_refspec = 'refs/tags/*:refs/tags/%s/*' % remote_name
self.local_repo.remotes.create(remote_name,
fetch_url,
- '+refs/heads/*:refs/heads/%s/*' % remote_name
- )
+ head_refspec)
# grab unreachable tags (orphans)
- self.local_repo.remotes.add_fetch(remote_name,
- '+refs/tags/*:refs/tags/%s/*' % remote_name
- )
+ self.local_repo.remotes.add_fetch(remote_name, tag_refspec)
+ if add_base_tags:
+ self.local_repo.remotes.add_fetch(remote_name,
+ 'refs/tags/import/*:refs/tags/import/*')
+ self.local_repo.remotes.add_fetch(remote_name,
+ 'refs/tags/orphan/*:refs/tags/orphan/*')
self.git_run(['config',
'remote.%s.tagOpt' % remote_name,
'--no-tags'
]
)
- self.local_repo.remotes.set_push_url(remote_name,
- push_url
- )
- # Namespace changes back:
- # remote_name/ (local)
- # '' (Launchpad)
- self.local_repo.remotes.add_push(remote_name,
- 'refs/heads/%s/*:refs/heads/*' % remote_name
- )
- self.local_repo.remotes.add_push(remote_name,
- 'refs/tags/%s/*:refs/tags/*' % remote_name
- )
+ def add_base_remotes(self, pkgname, repo_owner, lp_user):
+ if not self.fetch_proto:
+ raise Exception('Cannot fetch using an object without a protocol')
+ remote_url = ('git.launchpad.net/~%s/ubuntu/+source/%s' %
+ (repo_owner, pkgname))
+
+ self._add_remote('debian', remote_url, 'debian', lp_user)
+ self._add_remote('ubuntu', remote_url, 'ubuntu', lp_user, True)
+
+ def add_remote(self, pkgname, repo_owner, remote_name, lp_user):
+ if not self.fetch_proto:
+ raise Exception('Cannot fetch using an object without a protocol')
+ remote_url = ('git.launchpad.net/~%s/ubuntu/+source/%s' %
+ (repo_owner, pkgname))
- self.remote_name = remote_name
+ self._add_remote(remote_name, remote_url, None, lp_user)
@property
def env(self):
@@ -325,20 +338,6 @@ class USDGitRepository:
def garbage_collect(self):
self.git_run(['gc'])
- def push(self, remote_name):
- logging.debug('Pushing branches and tags')
- # libgit2 currently does not support pushing by wildcard
- # https://github.com/libgit2/libgit2/issues/1125
- #self._local_repo.remotes[remote_namespace].push(
- # self._local_repo.remotes[remote_namespace].push_refspecs,
- # pygit2.RemoteCallbacks(credentials=pygit2.credentials.KeypairFromAgent(user)
- # )
- # )
- self.git_run(['push', remote_name])
-
- def push_lpusip(self):
- self.push('lpusip')
-
def extract_file_from_treeish(self, treeish, filename, outfile=None):
"""extract a file from @treeish to a local file
diff --git a/usd/importer.py b/usd/importer.py
index 28648c1..5f10250 100755
--- a/usd/importer.py
+++ b/usd/importer.py
@@ -1104,10 +1104,17 @@ class USDImport:
atexit.register(self.cleanup, no_clean, self.local_repo.local_dir)
-
- self.local_repo.add_remote(pkgname, owner, self.namespace, user)
+ self.local_repo.add_base_remotes(pkgname=pkgname, repo_owner=owner,
+ lp_user=user)
if not args.no_fetch:
- self.local_repo.fetch_remote(self.namespace, must_exist=False)
+ self.local_repo.fetch_base_remotes(must_exist=False)
+
+ # XXX: copy +refs/remotes/{debian,ubuntu}/*:refs/heads/import/{debian,ubuntu]/* and delete anything not present in remotes/*
+ # fetch +refs/tags/*:refs/tags/import/* # and delete anything not present in remotes/*
+ # should we just delete all local branches first and then
+ # update-ref for each remote branch? (or create tracking
+ # branches?)
+ # same for tags
debian_source_information = USDSourceInformation(
'debian',
@@ -1231,10 +1238,15 @@ class USDImport:
if no_push:
logging.info('Not pushing to remote as specified')
else:
- if owner != 'usd-import-team':
- self.local_repo.push(owner)
- else:
- self.local_repo.push_lpusip()
+ push_url = ('ssh://%s@git.launchpad.net/~%s/ubuntu/+source/%s' %
+ (user, owner, pkgname))
+
+ self.local_repo.git_run(['push', push_url,
+ 'refs/heads/import/debian/*:refs/heads/debian/*'])
+ self.git_run(['push', push_url,
+ 'refs/heads/import/ubuntu/*:refs/heads/ubuntu/*'])
+ self.git_run(['push', push_url,
+ 'refs/tags/import/*:refs/tags/*'])
lp = launchpad_login_auth()
lp_git_repo = lp.git_repositories.getByPath(
path='~%s/ubuntu/+source/%s/+git/%s' %
|