Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
repo
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YongjieWang
repo
Commits
8368c65f
Commit
8368c65f
authored
Sep 11, 2015
by
Matthias Putz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Portable: pager and coloring, using subprocess and redirect sysin, sysout and syserr on Windows
parent
1790cd09
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
3 deletions
+71
-3
main.py
main.py
+8
-2
portable.py
portable.py
+61
-0
repo
repo
+2
-1
No files found.
main.py
View file @
8368c65f
...
...
@@ -20,6 +20,7 @@ import imp
import
netrc
import
optparse
import
os
import
portable
import
sys
import
time
...
...
@@ -168,7 +169,10 @@ class _Repo(object):
if
use_pager
is
None
:
use_pager
=
cmd
.
WantPager
(
copts
)
if
use_pager
:
RunPager
(
config
)
# RunPager(cmd)
portable
.
RunPager
(
cmd
)
else
:
portable
.
NoPager
(
cmd
)
start
=
time
.
time
()
try
:
...
...
@@ -514,12 +518,14 @@ def _Main(argv):
argv
=
list
(
sys
.
argv
)
argv
.
extend
(
rce
.
extra_args
)
try
:
os
.
execv
(
__file__
,
argv
)
# os.execv(__file__, argv)
subprocess
.
call
([
__file__
,
argv
])
except
OSError
as
e
:
print
(
'fatal: cannot restart repo after upgrade'
,
file
=
sys
.
stderr
)
print
(
'fatal:
%
s'
%
e
,
file
=
sys
.
stderr
)
result
=
128
portable
.
WaitForProcess
()
sys
.
exit
(
result
)
if
__name__
==
'__main__'
:
...
...
portable.py
View file @
8368c65f
import
os
import
pager
import
platform
import
socket
import
sys
import
subprocess
import
threading
from
trace
import
Trace
...
...
@@ -78,3 +81,61 @@ class socket_reader():
def
fileno
(
self
):
return
self
.
server_socket
.
fileno
()
child_process
=
None
def
RunPager
(
cmd
):
if
isUnix
():
pager
.
RunPager
(
cmd
.
manifest
.
globalConfig
)
else
:
RunWindowsPager
(
cmd
)
def
RunWindowsPager
(
cmd
):
executable
=
pager
.
_SelectPager
(
cmd
.
manifest
.
globalConfig
)
redirect_all
(
executable
)
pager
.
active
=
True
def
NoPager
(
cmd
):
if
not
isUnix
():
RunWindowsShell
(
cmd
)
def
RunWindowsShell
(
cmd
):
executable
=
_SelectCatenate
(
cmd
.
manifest
.
globalConfig
)
redirect_all
(
executable
)
def
redirect_all
(
executable
):
old_sysin
=
sys
.
stdin
old_sysout
=
sys
.
stdout
old_syserr
=
sys
.
stderr
Trace
(
"redirecting to
%
s"
%
executable
)
p
=
subprocess
.
Popen
([
executable
],
stdin
=
subprocess
.
PIPE
,
stdout
=
old_sysout
,
stderr
=
old_syserr
)
sys
.
stdout
=
p
.
stdin
sys
.
stderr
=
p
.
stdin
old_sysout
.
close
()
global
child_process
child_process
=
p
def
_SelectCatenate
(
globalConfig
):
try
:
return
os
.
environ
[
'GIT_CATENATE'
]
except
KeyError
:
pass
pager
=
globalConfig
.
GetString
(
'core.catenate'
)
if
pager
:
return
pager
try
:
return
os
.
environ
[
'CATENATE'
]
except
KeyError
:
pass
return
'cat'
def
WaitForProcess
():
if
not
isUnix
():
global
child_process
if
child_process
:
child_process
.
stdin
.
close
()
child_process
.
wait
()
repo
View file @
8368c65f
...
...
@@ -775,7 +775,8 @@ def main(orig_args):
me
.
extend
(
orig_args
)
me
.
extend
(
extra_args
)
try
:
os
.
execv
(
sys
.
executable
,
me
)
# os.execv(sys.executable, me)
subprocess
.
call
(
me
)
except
OSError
as
e
:
_print
(
"fatal: unable to start
%
s"
%
repo_main
,
file
=
sys
.
stderr
)
_print
(
"fatal:
%
s"
%
e
,
file
=
sys
.
stderr
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment