Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf495e94

Browse files
committed
src,#519: collect all is_<platform>() calls
1 parent29eb301 commitf495e94

14 files changed

+66
-47
lines changed

‎git/cmd.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
# just to satisfy flake8 on py3
4141
unicode,
4242
safe_decode,
43+
is_posix,
44+
is_win,
4345
)
4446

4547
execute_kwargs= ('istream','with_keep_cwd','with_extended_output',
@@ -50,9 +52,9 @@
5052
log=logging.getLogger('git.cmd')
5153
log.addHandler(logging.NullHandler())
5254

53-
__all__= ('Git',)
55+
__all__= ('Git',)
5456

55-
ifsys.platform!='win32':
57+
ifis_win():
5658
WindowsError=OSError
5759

5860
ifPY3:
@@ -236,7 +238,7 @@ def dict_to_slots_and__excluded_are_none(self, d, excluded=()):
236238
## CREATE_NEW_PROCESS_GROUP is needed to allow killing it afterwards,
237239
# seehttps://docs.python.org/3/library/subprocess.html#subprocess.Popen.send_signal
238240
PROC_CREATIONFLAGS= (CREATE_NO_WINDOW|subprocess.CREATE_NEW_PROCESS_GROUP
239-
ifsys.platform=='win32'
241+
ifis_win()
240242
else0)
241243

242244

@@ -628,7 +630,7 @@ def execute(self, command,
628630
env["LC_ALL"]="C"
629631
env.update(self._environment)
630632

631-
ifsys.platform=='win32':
633+
ifis_win():
632634
cmd_not_found_exception=WindowsError
633635
ifkill_after_timeout:
634636
raiseGitCommandError('"kill_after_timeout" feature is not supported on Windows.')
@@ -648,7 +650,7 @@ def execute(self, command,
648650
stderr=PIPE,
649651
stdout=PIPEifwith_stdoutelseopen(os.devnull,'wb'),
650652
shell=self.USE_SHELL,
651-
close_fds=(os.name=='posix'),# unsupported on windows
653+
close_fds=(is_posix()),# unsupported on windows
652654
universal_newlines=universal_newlines,
653655
creationflags=PROC_CREATIONFLAGS,
654656
**subprocess_kwargs
@@ -688,7 +690,7 @@ def _kill_process(pid):
688690

689691
ifkill_after_timeout:
690692
kill_check=threading.Event()
691-
watchdog=threading.Timer(kill_after_timeout,_kill_process,args=(proc.pid,))
693+
watchdog=threading.Timer(kill_after_timeout,_kill_process,args=(proc.pid,))
692694

693695
# Wait for the process to return
694696
status=0
@@ -932,7 +934,7 @@ def make_call():
932934
returncall
933935
# END utility to recreate call after changes
934936

935-
ifsys.platform=='win32':
937+
ifis_win():
936938
try:
937939
try:
938940
returnself.execute(make_call(),**_kwargs)

‎git/compat.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"""utilities to help provide compatibility with python 3"""
88
# flake8: noqa
99

10+
importos
1011
importsys
1112

1213
fromgitdb.utils.compatimport (
@@ -79,3 +80,16 @@ def __new__(cls, name, nbases, d):
7980
# end metaclass
8081
returnmetaclass(meta.__name__+'Helper',None, {})
8182
# end handle py2
83+
84+
85+
defis_win():
86+
returnos.name=='nt'
87+
88+
89+
defis_posix():
90+
returnos.name=='posix'
91+
92+
93+
defis_darwin():
94+
returnos.name=='darwin'
95+

‎git/index/base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@
4646
string_types,
4747
force_bytes,
4848
defenc,
49-
mviter
49+
mviter,
50+
is_win
5051
)
5152

5253
fromgit.utilimport (
@@ -136,7 +137,7 @@ def _set_cache_(self, attr):
136137
# which happens during read-tree.
137138
# In this case, we will just read the memory in directly.
138139
# Its insanely bad ... I am disappointed !
139-
allow_mmap= (os.name!='nt'orsys.version_info[1]>5)
140+
allow_mmap= (is_win()orsys.version_info[1]>5)
140141
stream=file_contents_ro(fd,stream=True,allow_mmap=allow_mmap)
141142

142143
try:
@@ -1059,7 +1060,7 @@ def handle_stderr(proc, iter_checked_out_files):
10591060
# END for each possible ending
10601061
# END for each line
10611062
ifunknown_lines:
1062-
raiseGitCommandError(("git-checkout-index",),128,stderr)
1063+
raiseGitCommandError(("git-checkout-index",),128,stderr)
10631064
iffailed_files:
10641065
valid_files=list(set(iter_checked_out_files)-set(failed_files))
10651066
raiseCheckoutError(

‎git/index/fun.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
fromgit.compatimport (
4444
defenc,
4545
force_text,
46-
force_bytes
46+
force_bytes,
47+
is_posix,
4748
)
4849

4950
S_IFGITLINK=S_IFLNK|S_IFDIR# a submodule
@@ -75,7 +76,7 @@ def run_commit_hook(name, index):
7576
stdout=subprocess.PIPE,
7677
stderr=subprocess.PIPE,
7778
cwd=index.repo.working_dir,
78-
close_fds=(os.name=='posix'),
79+
close_fds=(is_posix()),
7980
universal_newlines=True,
8081
creationflags=PROC_CREATIONFLAGS,)
8182
stdout,stderr=cmd.communicate()

‎git/index/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
importstruct
33
importtempfile
44
importos
5+
fromgit.compatimportis_win
56

67
__all__= ('TemporaryFileSwap','post_clear_cache','default_index','git_working_dir')
78

@@ -29,7 +30,7 @@ def __init__(self, file_path):
2930

3031
def__del__(self):
3132
ifos.path.isfile(self.tmp_file_path):
32-
ifos.name=='nt'andos.path.exists(self.file_path):
33+
ifis_winandos.path.exists(self.file_path):
3334
os.remove(self.file_path)
3435
os.rename(self.tmp_file_path,self.file_path)
3536
# END temp file exists

‎git/remote.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
# Module implementing a remote object allowing easy access to git remotes
88
importre
9-
importos
109

1110
from .configimport (
1211
SectionConstraint,
@@ -32,7 +31,7 @@
3231
)
3332
fromgit.cmdimporthandle_process_output
3433
fromgitdb.utilimportjoin
35-
fromgit.compatimport (defenc,force_text)
34+
fromgit.compatimport (defenc,force_text,is_win)
3635
importlogging
3736

3837
log=logging.getLogger('git.remote')
@@ -113,7 +112,7 @@ def __init__(self, flags, local_ref, remote_ref_string, remote, old_commit=None,
113112
self._remote=remote
114113
self._old_commit_sha=old_commit
115114
self.summary=summary
116-
115+
117116
@property
118117
defold_commit(self):
119118
returnself._old_commit_shaandself._remote.repo.commit(self._old_commit_sha)orNone
@@ -377,7 +376,7 @@ def __init__(self, repo, name):
377376
self.repo=repo
378377
self.name=name
379378

380-
ifos.name=='nt':
379+
ifis_win():
381380
# some oddity: on windows, python 2.5, it for some reason does not realize
382381
# that it has the config_writer property, but instead calls __getattr__
383382
# which will not yield the expected results. 'pinging' the members
@@ -635,7 +634,7 @@ def _get_fetch_info_from_stderr(self, proc, progress):
635634
# end
636635
ifprogress.error_lines():
637636
stderr_text='\n'.join(progress.error_lines())
638-
637+
639638
finalize_process(proc,stderr=stderr_text)
640639

641640
# read head information
@@ -657,7 +656,7 @@ def _get_fetch_info_from_stderr(self, proc, progress):
657656
fetch_info_lines=fetch_info_lines[:l_fhi]
658657
# end truncate correct list
659658
# end sanity check + sanitization
660-
659+
661660
output.extend(FetchInfo._from_line(self.repo,err_line,fetch_line)
662661
forerr_line,fetch_lineinzip(fetch_info_lines,fetch_head_info))
663662
returnoutput
@@ -769,17 +768,17 @@ def push(self, refspec=None, progress=None, **kwargs):
769768
:param refspec: see 'fetch' method
770769
:param progress:
771770
Can take one of many value types:
772-
771+
773772
* None to discard progress information
774773
* A function (callable) that is called with the progress infomation.
775-
774+
776775
Signature: ``progress(op_code, cur_count, max_count=None, message='')``.
777-
776+
778777
`Click here <http://goo.gl/NPa7st>`_ for a description of all arguments
779778
given to the function.
780779
* An instance of a class derived from ``git.RemoteProgress`` that
781780
overrides the ``update()`` function.
782-
781+
783782
:note: No further progress information is returned after push returns.
784783
:param kwargs: Additional arguments to be passed to git-push
785784
:return:

‎git/repo/base.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
PY3,
5757
safe_decode,
5858
range,
59+
is_win,
5960
)
6061

6162
importos
@@ -71,7 +72,7 @@
7172
BlameEntry=namedtuple('BlameEntry', ['commit','linenos','orig_path','orig_linenos'])
7273

7374

74-
__all__= ('Repo',)
75+
__all__= ('Repo',)
7576

7677

7778
def_expand_path(p):
@@ -369,7 +370,7 @@ def delete_remote(self, remote):
369370
def_get_config_path(self,config_level):
370371
# we do not support an absolute path of the gitconfig on windows ,
371372
# use the global config instead
372-
ifsys.platform=="win32"andconfig_level=="system":
373+
ifis_win()andconfig_level=="system":
373374
config_level="global"
374375

375376
ifconfig_level=="system":
@@ -883,7 +884,7 @@ def _clone(cls, git, url, path, odb_default_type, progress, **kwargs):
883884
prev_cwd=None
884885
prev_path=None
885886
odbt=kwargs.pop('odbt',odb_default_type)
886-
ifos.name=='nt':
887+
ifis_win():
887888
if'~'inpath:
888889
raiseOSError("Git cannot handle the ~ character in path %r correctly"%path)
889890

‎git/test/lib/helper.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
importlogging
1414

1515
fromgitimportRepo,Remote,GitCommandError,Git
16-
fromgit.compatimportstring_types
16+
fromgit.compatimportstring_types,is_win
1717

1818
osp=os.path.dirname
1919

@@ -73,7 +73,7 @@ def _mktemp(*args):
7373
prefixing /private/ will lead to incorrect paths on OSX."""
7474
tdir=tempfile.mktemp(*args)
7575
# See :note: above to learn why this is comented out.
76-
# ifsys.platform == 'darwin':
76+
# ifis_darwin():
7777
# tdir = '/private' + tdir
7878
returntdir
7979

@@ -83,7 +83,7 @@ def _rmtree_onerror(osremove, fullpath, exec_info):
8383
Handle the case on windows that read-only files cannot be deleted by
8484
os.remove by setting it to mode 777, then retry deletion.
8585
"""
86-
ifos.name!='nt'orosremoveisnotos.remove:
86+
ifis_win()orosremoveisnotos.remove:
8787
raise
8888

8989
os.chmod(fullpath,0o777)
@@ -221,7 +221,7 @@ def remote_repo_creator(self):
221221
ifgdisnotNone:
222222
gd.proc.terminate()
223223
log.warning('git-ls-remote failed due to: %s(%s)',type(e),e)
224-
ifos.name=='nt':
224+
ifis_win():
225225
msg="git-daemon needs to run this test, but windows does not have one. "
226226
msg+='Otherwise, run: git-daemon "%s"'%temp_dir
227227
raiseAssertionError(msg)

‎git/test/test_base.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
)
2525
fromgit.objects.utilimportget_object_type_by_name
2626
fromgitdb.utilimporthex_to_bin
27+
fromgit.compatimportis_win
2728

2829

2930
classTestBase(TestBase):
@@ -117,7 +118,7 @@ def test_with_rw_remote_and_rw_repo(self, rw_repo, rw_remote_repo):
117118
assertrw_remote_repo.config_reader("repository").getboolean("core","bare")
118119
assertos.path.isdir(os.path.join(rw_repo.working_tree_dir,'lib'))
119120

120-
@skipIf(sys.version_info< (3,)andos.name=='nt',
121+
@skipIf(sys.version_info< (3,)andis_win(),
121122
"Unicode woes, see https://github.com/gitpython-developers/GitPython/pull/519")
122123
@with_rw_repo('0.1.6')
123124
deftest_add_unicode(self,rw_repo):
@@ -134,7 +135,7 @@ def test_add_unicode(self, rw_repo):
134135

135136
open(file_path,"wb").write(b'something')
136137

137-
ifos.name=='nt':
138+
ifis_win():
138139
# on windows, there is no way this works, see images on
139140
# https://github.com/gitpython-developers/GitPython/issues/147#issuecomment-68881897
140141
# Therefore, it must be added using the python implementation

‎git/test/test_git.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
)
2727
fromgitdb.test.libimportwith_rw_directory
2828

29-
fromgit.compatimportPY3
29+
fromgit.compatimportPY3,is_darwin
3030

3131
try:
3232
fromunittestimportmock
@@ -214,7 +214,7 @@ def test_environment(self, rw_dir):
214214
try:
215215
remote.fetch()
216216
exceptGitCommandErroraserr:
217-
ifsys.version_info[0]<3andsys.platform=='darwin':
217+
ifsys.version_info[0]<3andis_darwin():
218218
assert'ssh-origin'instr(err)
219219
asserterr.status==128
220220
else:

‎git/test/test_index.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
GitCommandError,
2828
CheckoutError,
2929
)
30-
fromgit.compatimportstring_types
30+
fromgit.compatimportstring_types,is_win
3131
fromgitdb.utilimporthex_to_bin
3232
importos
3333
importsys
@@ -577,7 +577,7 @@ def mixed_iterator():
577577
assertlen(entries)==1andentries[0].hexsha!=null_hex_sha
578578

579579
# add symlink
580-
ifsys.platform!="win32":
580+
ifnotis_win():
581581
fortargetin ('/etc/nonexisting','/etc/passwd','/etc'):
582582
basename="my_real_symlink"
583583

@@ -630,7 +630,7 @@ def mixed_iterator():
630630
index.checkout(fake_symlink_path)
631631

632632
# on windows we will never get symlinks
633-
ifos.name=='nt':
633+
ifis_win():
634634
# simlinks should contain the link as text ( which is what a
635635
# symlink actually is )
636636
open(fake_symlink_path,'rb').read()==link_target
@@ -711,7 +711,7 @@ def make_paths():
711711
assertfkeynotinindex.entries
712712

713713
index.add(files,write=True)
714-
ifos.name!='nt':
714+
ifis_win():
715715
hp=hook_path('pre-commit',index.repo.git_dir)
716716
hpd=os.path.dirname(hp)
717717
ifnotos.path.isdir(hpd):

‎git/test/test_submodule.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
fromgit.objects.submodule.baseimportSubmodule
1818
fromgit.objects.submodule.rootimportRootModule,RootUpdateProgress
1919
fromgit.utilimportto_native_path_linux,join_path_native
20-
fromgit.compatimportstring_types
20+
fromgit.compatimportstring_types,is_win
2121
fromgit.repo.funimport (
2222
find_git_dir,
2323
touch
@@ -26,7 +26,7 @@
2626
# Change the configuration if possible to prevent the underlying memory manager
2727
# to keep file handles open. On windows we get problems as they are not properly
2828
# closed due to mmap bugs on windows (as it appears)
29-
ifsys.platform=='win32':
29+
ifis_win():
3030
try:
3131
importsmmap.util
3232
smmap.util.MapRegion._test_read_into_memory=True

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp