Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
Poulpe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
octobus
Poulpe
Commits
c6e49a0f
Commit
c6e49a0f
authored
3 years ago
by
Simon Sapin
Browse files
Options
Downloads
Patches
Plain Diff
Extract subprocess handling into a new function
parent
0a2c98d9
No related branches found
Branches containing commit
No related tags found
1 merge request
!1
Initial implementation
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.rs
+21
-10
21 additions, 10 deletions
src/main.rs
with
21 additions
and
10 deletions
src/main.rs
+
21
−
10
View file @
c6e49a0f
...
...
@@ -53,12 +53,12 @@
.to_str
()
.ok_or
(
"Non-Unicode base name"
)
?
;
let
today
=
time
::
OffsetDateTime
::
now_utc
()
.date
();
let
hg_id_outp
ut
=
process
::
Command
::
new
(
"hg"
)
.arg
(
"id
"
)
.arg
(
"
--
id"
)
.arg
(
"-
R
"
)
.arg
(
&
self
.directory
)
.output
()
?
;
let
id
=
if
hg_id_output
.status
.success
(
)
{
format!
(
"_{}"
,
st
r
::
from_utf8
(
&
hg_id_output
.stdout
)
?
.trim
()
)
let
id
=
if
let
Some
(
stdo
ut
)
=
sub
process
_output
(
process
::
Command
::
new
(
"hg
"
)
.arg
(
"id"
)
.arg
(
"-
-id
"
)
.arg
(
"-R"
)
.arg
(
&
self
.directory
),
)
?
{
format!
(
"_{}"
,
st
dout
)
}
else
{
...
...
@@ -64,6 +64,4 @@
}
else
{
let
hg_stderr
=
str
::
from_utf8
(
&
hg_id_output
.stderr
)
?
;
eprintln!
(
"{}"
,
style
(
hg_stderr
.trim
())
.red
());
println!
(
"Not a Mercurial repository?"
);
format!
(
""
)
};
...
...
@@ -167,6 +165,19 @@
}
}
/// If the proccess has a successful exit code, return its trimmed stdout
/// If the process has an error exit code, print its stderr in red and return None
/// Return an error if the spawning the process or UTF-8 decoding fails
fn
subprocess_output
(
command
:
&
mut
process
::
Command
)
->
Result
<
Option
<
String
>>
{
let
out
=
command
.output
()
?
;
if
out
.status
.success
()
{
Ok
(
Some
(
str
::
from_utf8
(
&
out
.stdout
)
?
.trim
()
.to_owned
()))
}
else
{
eprintln!
(
"{}"
,
style
(
str
::
from_utf8
(
&
out
.stderr
)
?
.trim
())
.red
());
Ok
(
None
)
}
}
struct
Tee
<
A
,
B
>
(
A
,
B
);
impl
<
A
:
io
::
Write
,
B
:
io
::
Write
>
io
::
Write
for
Tee
<
A
,
B
>
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment