diff options
Diffstat (limited to 'project.py')
-rw-r--r-- | project.py | 38 |
1 files changed, 4 insertions, 34 deletions
@@ -459,9 +459,6 @@ class Project(object): | |||
459 | # These objects can be shared between several working trees. | 459 | # These objects can be shared between several working trees. |
460 | shareable_files = ['description', 'info'] | 460 | shareable_files = ['description', 'info'] |
461 | shareable_dirs = ['hooks', 'objects', 'rr-cache', 'svn'] | 461 | shareable_dirs = ['hooks', 'objects', 'rr-cache', 'svn'] |
462 | # These objects can only be used by a single working tree. | ||
463 | working_tree_files = ['config', 'packed-refs', 'shallow'] | ||
464 | working_tree_dirs = ['logs', 'refs'] | ||
465 | 462 | ||
466 | def __init__(self, | 463 | def __init__(self, |
467 | manifest, | 464 | manifest, |
@@ -2483,10 +2480,9 @@ class Project(object): | |||
2483 | os.makedirs(self.gitdir) | 2480 | os.makedirs(self.gitdir) |
2484 | 2481 | ||
2485 | if init_obj_dir or init_git_dir: | 2482 | if init_obj_dir or init_git_dir: |
2486 | self._ReferenceGitDir(self.objdir, self.gitdir, share_refs=False, | 2483 | self._ReferenceGitDir(self.objdir, self.gitdir, copy_all=True) |
2487 | copy_all=True) | ||
2488 | try: | 2484 | try: |
2489 | self._CheckDirReference(self.objdir, self.gitdir, share_refs=False) | 2485 | self._CheckDirReference(self.objdir, self.gitdir) |
2490 | except GitError as e: | 2486 | except GitError as e: |
2491 | if force_sync: | 2487 | if force_sync: |
2492 | print("Retrying clone after deleting %s" % | 2488 | print("Retrying clone after deleting %s" % |
@@ -2650,40 +2646,19 @@ class Project(object): | |||
2650 | else: | 2646 | else: |
2651 | active_git.symbolic_ref('-m', msg, ref, dst) | 2647 | active_git.symbolic_ref('-m', msg, ref, dst) |
2652 | 2648 | ||
2653 | def _CheckDirReference(self, srcdir, destdir, share_refs): | 2649 | def _CheckDirReference(self, srcdir, destdir): |
2654 | # Git worktrees don't use symlinks to share at all. | 2650 | # Git worktrees don't use symlinks to share at all. |
2655 | if self.use_git_worktrees: | 2651 | if self.use_git_worktrees: |
2656 | return | 2652 | return |
2657 | 2653 | ||
2658 | symlink_files = self.shareable_files[:] | 2654 | symlink_files = self.shareable_files[:] |
2659 | symlink_dirs = self.shareable_dirs[:] | 2655 | symlink_dirs = self.shareable_dirs[:] |
2660 | if share_refs: | ||
2661 | symlink_files += self.working_tree_files | ||
2662 | symlink_dirs += self.working_tree_dirs | ||
2663 | to_symlink = symlink_files + symlink_dirs | 2656 | to_symlink = symlink_files + symlink_dirs |
2664 | for name in set(to_symlink): | 2657 | for name in set(to_symlink): |
2665 | # Try to self-heal a bit in simple cases. | 2658 | # Try to self-heal a bit in simple cases. |
2666 | dst_path = os.path.join(destdir, name) | 2659 | dst_path = os.path.join(destdir, name) |
2667 | src_path = os.path.join(srcdir, name) | 2660 | src_path = os.path.join(srcdir, name) |
2668 | 2661 | ||
2669 | if name in self.working_tree_dirs: | ||
2670 | # If the dir is missing under .repo/projects/, create it. | ||
2671 | if not os.path.exists(src_path): | ||
2672 | os.makedirs(src_path) | ||
2673 | |||
2674 | elif name in self.working_tree_files: | ||
2675 | # If it's a file under the checkout .git/ and the .repo/projects/ has | ||
2676 | # nothing, move the file under the .repo/projects/ tree. | ||
2677 | if not os.path.exists(src_path) and os.path.isfile(dst_path): | ||
2678 | platform_utils.rename(dst_path, src_path) | ||
2679 | |||
2680 | # If the path exists under the .repo/projects/ and there's no symlink | ||
2681 | # under the checkout .git/, recreate the symlink. | ||
2682 | if name in self.working_tree_dirs or name in self.working_tree_files: | ||
2683 | if os.path.exists(src_path) and not os.path.exists(dst_path): | ||
2684 | platform_utils.symlink( | ||
2685 | os.path.relpath(src_path, os.path.dirname(dst_path)), dst_path) | ||
2686 | |||
2687 | dst = platform_utils.realpath(dst_path) | 2662 | dst = platform_utils.realpath(dst_path) |
2688 | if os.path.lexists(dst): | 2663 | if os.path.lexists(dst): |
2689 | src = platform_utils.realpath(src_path) | 2664 | src = platform_utils.realpath(src_path) |
@@ -2696,22 +2671,17 @@ class Project(object): | |||
2696 | ' use `repo sync --force-sync {0}` to ' | 2671 | ' use `repo sync --force-sync {0}` to ' |
2697 | 'proceed.'.format(self.relpath)) | 2672 | 'proceed.'.format(self.relpath)) |
2698 | 2673 | ||
2699 | def _ReferenceGitDir(self, gitdir, dotgit, share_refs, copy_all): | 2674 | def _ReferenceGitDir(self, gitdir, dotgit, copy_all): |
2700 | """Update |dotgit| to reference |gitdir|, using symlinks where possible. | 2675 | """Update |dotgit| to reference |gitdir|, using symlinks where possible. |
2701 | 2676 | ||
2702 | Args: | 2677 | Args: |
2703 | gitdir: The bare git repository. Must already be initialized. | 2678 | gitdir: The bare git repository. Must already be initialized. |
2704 | dotgit: The repository you would like to initialize. | 2679 | dotgit: The repository you would like to initialize. |
2705 | share_refs: If true, |dotgit| will store its refs under |gitdir|. | ||
2706 | Only one work tree can store refs under a given |gitdir|. | ||
2707 | copy_all: If true, copy all remaining files from |gitdir| -> |dotgit|. | 2680 | copy_all: If true, copy all remaining files from |gitdir| -> |dotgit|. |
2708 | This saves you the effort of initializing |dotgit| yourself. | 2681 | This saves you the effort of initializing |dotgit| yourself. |
2709 | """ | 2682 | """ |
2710 | symlink_files = self.shareable_files[:] | 2683 | symlink_files = self.shareable_files[:] |
2711 | symlink_dirs = self.shareable_dirs[:] | 2684 | symlink_dirs = self.shareable_dirs[:] |
2712 | if share_refs: | ||
2713 | symlink_files += self.working_tree_files | ||
2714 | symlink_dirs += self.working_tree_dirs | ||
2715 | to_symlink = symlink_files + symlink_dirs | 2685 | to_symlink = symlink_files + symlink_dirs |
2716 | 2686 | ||
2717 | to_copy = [] | 2687 | to_copy = [] |