summaryrefslogtreecommitdiffstats
path: root/project.py
diff options
context:
space:
mode:
authorShawn O. Pearce <sop@google.com>2009-04-18 15:04:41 -0700
committerShawn O. Pearce <sop@google.com>2009-04-18 15:04:41 -0700
commit89e717d9481c0c69292a39f85599f5df8277b004 (patch)
tree1fc613edd34eb349b673505b872be21a416ab52f /project.py
parent0f0dfa3930bc16078ef0b1a00ff6849333038fc7 (diff)
downloadgit-repo-89e717d9481c0c69292a39f85599f5df8277b004.tar.gz
Improve checkout performance for the common unmodified case
Most projects will have their branch heads matching in all branches, so switching between them should be just a matter of updating the work tree's HEAD symref. This can be done in pure Python, saving quite a bit of time over forking 'git checkout'. Signed-off-by: Shawn O. Pearce <sop@google.com>
Diffstat (limited to 'project.py')
-rw-r--r--project.py43
1 files changed, 32 insertions, 11 deletions
diff --git a/project.py b/project.py
index 10a9b257..029a80f4 100644
--- a/project.py
+++ b/project.py
@@ -779,9 +779,8 @@ class Project(object):
779 779
780 all = self.bare_ref.all 780 all = self.bare_ref.all
781 if (R_HEADS + name) in all: 781 if (R_HEADS + name) in all:
782 cmd = ['checkout', name, '--']
783 return GitCommand(self, 782 return GitCommand(self,
784 cmd, 783 ['checkout', name, '--'],
785 capture_stdout = True, 784 capture_stdout = True,
786 capture_stderr = True).Wait() == 0 785 capture_stderr = True).Wait() == 0
787 786
@@ -815,9 +814,8 @@ class Project(object):
815 branch.Save() 814 branch.Save()
816 return True 815 return True
817 816
818 cmd = ['checkout', '-b', branch.name, rev]
819 if GitCommand(self, 817 if GitCommand(self,
820 cmd, 818 ['checkout', '-b', branch.name, rev],
821 capture_stdout = True, 819 capture_stdout = True,
822 capture_stderr = True).Wait() == 0: 820 capture_stderr = True).Wait() == 0:
823 branch.Save() 821 branch.Save()
@@ -827,16 +825,39 @@ class Project(object):
827 def CheckoutBranch(self, name): 825 def CheckoutBranch(self, name):
828 """Checkout a local topic branch. 826 """Checkout a local topic branch.
829 """ 827 """
828 rev = R_HEADS + name
829 head = self.work_git.GetHead()
830 if head == rev:
831 # Already on the branch
832 #
833 return True
830 834
831 # Be sure the branch exists 835 all = self.bare_ref.all
832 try: 836 try:
833 tip_rev = self.bare_git.rev_parse(R_HEADS + name) 837 revid = all[rev]
834 except GitError: 838 except KeyError:
835 return False; 839 # Branch does not exist in this project
840 #
841 return False
842
843 if head.startswith(R_HEADS):
844 try:
845 head = all[head]
846 except KeyError:
847 head = None
848
849 if head == revid:
850 # Same revision; just update HEAD to point to the new
851 # target branch, but otherwise take no other action.
852 #
853 _lwrite(os.path.join(self.worktree, '.git', HEAD),
854 'ref: %s%s\n' % (R_HEADS, name))
855 return True
836 856
837 # Do the checkout 857 return GitCommand(self,
838 cmd = ['checkout', name, '--'] 858 ['checkout', name, '--'],
839 return GitCommand(self, cmd).Wait() == 0 859 capture_stdout = True,
860 capture_stderr = True).Wait() == 0
840 861
841 def AbandonBranch(self, name): 862 def AbandonBranch(self, name):
842 """Destroy a local topic branch. 863 """Destroy a local topic branch.