summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--project.py55
-rw-r--r--subcmds/sync.py12
2 files changed, 46 insertions, 21 deletions
diff --git a/project.py b/project.py
index b61bcacb..a69407da 100644
--- a/project.py
+++ b/project.py
@@ -36,7 +36,7 @@ except ImportError:
36 36
37from color import Coloring 37from color import Coloring
38from git_command import GitCommand 38from git_command import GitCommand
39from git_config import GitConfig, IsId, GetSchemeFromUrl 39from git_config import GitConfig, IsId, GetSchemeFromUrl, ID_RE
40from error import DownloadError 40from error import DownloadError
41from error import GitError, HookError, ImportError, UploadError 41from error import GitError, HookError, ImportError, UploadError
42from error import ManifestInvalidRevisionError 42from error import ManifestInvalidRevisionError
@@ -900,7 +900,7 @@ class Project(object):
900 900
901## Sync ## 901## Sync ##
902 902
903 def Sync_NetworkHalf(self, quiet=False, is_new=None): 903 def Sync_NetworkHalf(self, quiet=False, is_new=None, current_branch_only=False):
904 """Perform only the network IO portion of the sync process. 904 """Perform only the network IO portion of the sync process.
905 Local working directory/branch state is not affected. 905 Local working directory/branch state is not affected.
906 """ 906 """
@@ -926,21 +926,10 @@ class Project(object):
926 if alt_dir is None and self._ApplyCloneBundle(initial=is_new, quiet=quiet): 926 if alt_dir is None and self._ApplyCloneBundle(initial=is_new, quiet=quiet):
927 is_new = False 927 is_new = False
928 928
929 if not self._RemoteFetch(initial=is_new, quiet=quiet, alt_dir=alt_dir): 929 if not self._RemoteFetch(initial=is_new, quiet=quiet, alt_dir=alt_dir,
930 current_branch_only=current_branch_only):
930 return False 931 return False
931 932
932 #Check that the requested ref was found after fetch
933 #
934 try:
935 self.GetRevisionId()
936 except ManifestInvalidRevisionError:
937 # if the ref is a tag. We can try fetching
938 # the tag manually as a last resort
939 #
940 rev = self.revisionExpr
941 if rev.startswith(R_TAGS):
942 self._RemoteFetch(None, rev[len(R_TAGS):], quiet=quiet)
943
944 if self.worktree: 933 if self.worktree:
945 self._InitMRef() 934 self._InitMRef()
946 else: 935 else:
@@ -1335,10 +1324,30 @@ class Project(object):
1335 1324
1336## Direct Git Commands ## 1325## Direct Git Commands ##
1337 1326
1338 def _RemoteFetch(self, name=None, tag=None, 1327 def _RemoteFetch(self, name=None,
1328 current_branch_only=False,
1339 initial=False, 1329 initial=False,
1340 quiet=False, 1330 quiet=False,
1341 alt_dir=None): 1331 alt_dir=None):
1332
1333 is_sha1 = False
1334 tag_name = None
1335
1336 if current_branch_only:
1337 if ID_RE.match(self.revisionExpr) is not None:
1338 is_sha1 = True
1339 elif self.revisionExpr.startswith(R_TAGS):
1340 # this is a tag and its sha1 value should never change
1341 tag_name = self.revisionExpr[len(R_TAGS):]
1342
1343 if is_sha1 or tag_name is not None:
1344 try:
1345 self.GetRevisionId()
1346 return True
1347 except ManifestInvalidRevisionError:
1348 # There is no such persistent revision. We have to fetch it.
1349 pass
1350
1342 if not name: 1351 if not name:
1343 name = self.remote.name 1352 name = self.remote.name
1344 1353
@@ -1401,9 +1410,19 @@ class Project(object):
1401 if not self.worktree: 1410 if not self.worktree:
1402 cmd.append('--update-head-ok') 1411 cmd.append('--update-head-ok')
1403 cmd.append(name) 1412 cmd.append(name)
1404 if tag is not None: 1413
1414 if not current_branch_only or is_sha1:
1415 # Fetch whole repo
1416 cmd.append('--tags')
1417 cmd.append((u'+refs/heads/*:') + remote.ToLocal('refs/heads/*'))
1418 elif tag_name is not None:
1405 cmd.append('tag') 1419 cmd.append('tag')
1406 cmd.append(tag) 1420 cmd.append(tag_name)
1421 else:
1422 branch = self.revisionExpr
1423 if branch.startswith(R_HEADS):
1424 branch = branch[len(R_HEADS):]
1425 cmd.append((u'+refs/heads/%s:' % branch) + remote.ToLocal('refs/heads/%s' % branch))
1407 1426
1408 ok = False 1427 ok = False
1409 for i in range(2): 1428 for i in range(2):
diff --git a/subcmds/sync.py b/subcmds/sync.py
index a3d06922..c5955a38 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -131,6 +131,9 @@ later is required to fix a server side protocol bug.
131 p.add_option('-d','--detach', 131 p.add_option('-d','--detach',
132 dest='detach_head', action='store_true', 132 dest='detach_head', action='store_true',
133 help='detach projects back to manifest revision') 133 help='detach projects back to manifest revision')
134 p.add_option('-c','--current-branch',
135 dest='current_branch_only', action='store_true',
136 help='fetch only current branch from server')
134 p.add_option('-q','--quiet', 137 p.add_option('-q','--quiet',
135 dest='quiet', action='store_true', 138 dest='quiet', action='store_true',
136 help='be more quiet') 139 help='be more quiet')
@@ -179,7 +182,8 @@ later is required to fix a server side protocol bug.
179 # - We always make sure we unlock the lock if we locked it. 182 # - We always make sure we unlock the lock if we locked it.
180 try: 183 try:
181 try: 184 try:
182 success = project.Sync_NetworkHalf(quiet=opt.quiet) 185 success = project.Sync_NetworkHalf(quiet=opt.quiet,
186 current_branch_only=opt.current_branch_only)
183 187
184 # Lock around all the rest of the code, since printing, updating a set 188 # Lock around all the rest of the code, since printing, updating a set
185 # and Progress.update() are not thread safe. 189 # and Progress.update() are not thread safe.
@@ -212,7 +216,8 @@ later is required to fix a server side protocol bug.
212 if self.jobs == 1: 216 if self.jobs == 1:
213 for project in projects: 217 for project in projects:
214 pm.update() 218 pm.update()
215 if project.Sync_NetworkHalf(quiet=opt.quiet): 219 if project.Sync_NetworkHalf(quiet=opt.quiet,
220 current_branch_only=opt.current_branch_only):
216 fetched.add(project.gitdir) 221 fetched.add(project.gitdir)
217 else: 222 else:
218 print >>sys.stderr, 'error: Cannot fetch %s' % project.name 223 print >>sys.stderr, 'error: Cannot fetch %s' % project.name
@@ -388,7 +393,8 @@ uncommitted changes are present' % project.relpath
388 _PostRepoUpgrade(self.manifest) 393 _PostRepoUpgrade(self.manifest)
389 394
390 if not opt.local_only: 395 if not opt.local_only:
391 mp.Sync_NetworkHalf(quiet=opt.quiet) 396 mp.Sync_NetworkHalf(quiet=opt.quiet,
397 current_branch_only=opt.current_branch_only)
392 398
393 if mp.HasChanges: 399 if mp.HasChanges:
394 syncbuf = SyncBuffer(mp.config) 400 syncbuf = SyncBuffer(mp.config)