OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 # Monkeypatch IMapIterator so that Ctrl-C can kill everything properly. | 5 # Monkeypatch IMapIterator so that Ctrl-C can kill everything properly. |
6 # Derived from https://gist.github.com/aljungberg/626518 | 6 # Derived from https://gist.github.com/aljungberg/626518 |
7 import multiprocessing.pool | 7 import multiprocessing.pool |
8 from multiprocessing.pool import IMapIterator | 8 from multiprocessing.pool import IMapIterator |
9 def wrapper(func): | 9 def wrapper(func): |
10 def wrap(self, timeout=None): | 10 def wrap(self, timeout=None): |
11 return func(self, timeout=timeout or 1e100) | 11 return func(self, timeout=timeout or 1e100) |
12 return wrap | 12 return wrap |
13 IMapIterator.next = wrapper(IMapIterator.next) | 13 IMapIterator.next = wrapper(IMapIterator.next) |
14 IMapIterator.__next__ = IMapIterator.next | 14 IMapIterator.__next__ = IMapIterator.next |
15 # TODO(iannucci): Monkeypatch all other 'wait' methods too. | 15 # TODO(iannucci): Monkeypatch all other 'wait' methods too. |
16 | 16 |
17 | 17 |
18 import binascii | 18 import binascii |
19 import collections | 19 import collections |
20 import contextlib | 20 import contextlib |
21 import functools | 21 import functools |
22 import logging | 22 import logging |
23 import os | 23 import os |
24 import re | 24 import re |
| 25 import shutil |
25 import signal | 26 import signal |
26 import sys | 27 import sys |
27 import tempfile | 28 import tempfile |
28 import textwrap | 29 import textwrap |
29 import threading | 30 import threading |
30 | 31 |
31 import subprocess2 | 32 import subprocess2 |
32 | 33 |
33 ROOT = os.path.abspath(os.path.dirname(__file__)) | 34 ROOT = os.path.abspath(os.path.dirname(__file__)) |
34 | 35 |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
810 hash=branch_hash, upstream=upstream_branch, ahead=ahead, behind=behind) | 811 hash=branch_hash, upstream=upstream_branch, ahead=ahead, behind=behind) |
811 | 812 |
812 # Set None for upstreams which are not branches (e.g empty upstream, remotes | 813 # Set None for upstreams which are not branches (e.g empty upstream, remotes |
813 # and deleted upstream branches). | 814 # and deleted upstream branches). |
814 missing_upstreams = {} | 815 missing_upstreams = {} |
815 for info in info_map.values(): | 816 for info in info_map.values(): |
816 if info.upstream not in info_map and info.upstream not in missing_upstreams: | 817 if info.upstream not in info_map and info.upstream not in missing_upstreams: |
817 missing_upstreams[info.upstream] = None | 818 missing_upstreams[info.upstream] = None |
818 | 819 |
819 return dict(info_map.items() + missing_upstreams.items()) | 820 return dict(info_map.items() + missing_upstreams.items()) |
| 821 |
| 822 |
| 823 def make_workdir_common(repository, new_workdir, files_to_symlink, |
| 824 files_to_copy): |
| 825 os.makedirs(new_workdir) |
| 826 for entry in files_to_symlink: |
| 827 clone_file(repository, new_workdir, entry, os.symlink) |
| 828 for entry in files_to_copy: |
| 829 clone_file(repository, new_workdir, entry, shutil.copy) |
| 830 |
| 831 |
| 832 def make_workdir(repository, new_workdir): |
| 833 GIT_DIRECTORY_WHITELIST = [ |
| 834 'config', |
| 835 'info', |
| 836 'hooks', |
| 837 'logs/refs', |
| 838 'objects', |
| 839 'packed-refs', |
| 840 'refs', |
| 841 'remotes', |
| 842 'rr-cache', |
| 843 'svn' |
| 844 ] |
| 845 make_workdir_common(repository, new_workdir, GIT_DIRECTORY_WHITELIST, |
| 846 ['HEAD']) |
| 847 |
| 848 |
| 849 def clone_file(repository, new_workdir, link, operation): |
| 850 if not os.path.exists(os.path.join(repository, link)): |
| 851 return |
| 852 link_dir = os.path.dirname(os.path.join(new_workdir, link)) |
| 853 if not os.path.exists(link_dir): |
| 854 os.makedirs(link_dir) |
| 855 operation(os.path.join(repository, link), os.path.join(new_workdir, link)) |
OLD | NEW |