summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2008-10-23 11:58:52 -0700
committerShawn O. Pearce <sop@google.com>2008-10-23 14:43:28 -0700
commit632768bc65ae0f1dc9eb9260c9146c42d9965a18 (patch)
treef8fc564a40e5886c74062d6be751ca4c2769721c /project.py
parent0758d2f1d61288c83282749d2b36958d2c289e7f (diff)
downloadgit-repo-632768bc65ae0f1dc9eb9260c9146c42d9965a18.tar.gz
Teach repo how to download changes to the local checkoutv1.0.4
Now `repo download . 1402` would download the change numbered 1402 into the current project and check it out for the user, using a detached HEAD. `repo sync .` would back out of the change and return to the upstream version. Multiple projects can be fetched at once by listing them out on the command line as different arguments. Individual patch sets can be selected by adding a '/n' to indicate the n-th patch set should be downloaded instead of the default of patch set 1. Signed-off-by: Shawn O. Pearce <sop@google.com>
Diffstat (limited to 'project.py')
-rw-r--r--project.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/project.py b/project.py
index 2b4a4f95..e88afcca 100644
--- a/project.py
+++ b/project.py
@@ -45,6 +45,31 @@ def _info(fmt, *args):
45def not_rev(r): 45def not_rev(r):
46 return '^' + r 46 return '^' + r
47 47
48class DownloadedChange(object):
49 _commit_cache = None
50
51 def __init__(self, project, base, change_id, ps_id, commit):
52 self.project = project
53 self.base = base
54 self.change_id = change_id
55 self.ps_id = ps_id
56 self.commit = commit
57
58 @property
59 def commits(self):
60 if self._commit_cache is None:
61 self._commit_cache = self.project.bare_git.rev_list(
62 '--abbrev=8',
63 '--abbrev-commit',
64 '--pretty=oneline',
65 '--reverse',
66 '--date-order',
67 not_rev(self.base),
68 self.commit,
69 '--')
70 return self._commit_cache
71
72
48class ReviewableBranch(object): 73class ReviewableBranch(object):
49 _commit_cache = None 74 _commit_cache = None
50 75
@@ -612,6 +637,23 @@ class Project(object):
612 src = os.path.join(self.worktree, src) 637 src = os.path.join(self.worktree, src)
613 self.copyfiles.append(_CopyFile(src, dest)) 638 self.copyfiles.append(_CopyFile(src, dest))
614 639
640 def DownloadPatchSet(self, change_id, patch_id):
641 """Download a single patch set of a single change to FETCH_HEAD.
642 """
643 remote = self.GetRemote(self.remote.name)
644
645 cmd = ['fetch', remote.name]
646 cmd.append('refs/changes/%2.2d/%d/%d' \
647 % (change_id % 100, change_id, patch_id))
648 cmd.extend(map(lambda x: str(x), remote.fetch))
649 if GitCommand(self, cmd, bare=True).Wait() != 0:
650 return None
651 return DownloadedChange(self,
652 remote.ToLocal(self.revision),
653 change_id,
654 patch_id,
655 self.bare_git.rev_parse('FETCH_HEAD'))
656
615 657
616## Branch Management ## 658## Branch Management ##
617 659