FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
git2cpp/src/subcommand/fetch_subcommand.cpp at 0.0.12 · QuantStack/git2cpp · GitHub
QuantStack
git2cpp
Repository navigation
Code
Issues
6
(6)
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
git2cpp
/
src
/
subcommand
/
fetch_subcommand.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
96 lines (81 loc) · 3.1 KB
Breadcrumbs
git2cpp
/
src
/
subcommand
/
fetch_subcommand.cpp
Copy path
File metadata and controls
96 lines (81 loc) · 3.1 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#
include
"
../subcommand/fetch_subcommand.hpp
"
#
include
<
iostream
>
#
include
<
git2/remote.h
>
#
include
"
../utils/credentials.hpp
"
#
include
"
../utils/input_output.hpp
"
#
include
"
../utils/progress.hpp
"
#
include
"
../wasm/scope.hpp
"
#
include
"
../wrapper/repository_wrapper.hpp
"
fetch_subcommand::fetch_subcommand
(
const
libgit2_object&,
CLI
::App& app)
{
auto
* sub = app.
add_subcommand
(
"
fetch
"
,
"
Download objects and refs from another repository
"
);
sub->
add_option
(
"
<remote>
"
, m_remote_name,
"
The remote to fetch from
"
)->
default_val
(
"
origin
"
);
sub->
add_option
(
"
--depth
"
, m_depth,
"
deepen or shorten history of shallow clone
"
);
sub->
add_option
(
"
--deepen
"
, m_deepen,
"
deepen history of shallow clone
"
);
//
sub->add_option("--shallow-since", m_shallow_since, "<time>\ndeepen history of shallow repository based
//
on time."); sub->add_option("--shallow-exclude", m_shallow_exclude, "<ref>\ndeepen history of shallow
//
clone, excluding ref");
sub->
add_flag
(
"
--unshallow
"
, m_unshallow,
"
convert to a complete repository
"
);
//
sub->add_flag("--update-shallow", m_update_shallow, "accept refs that update .git/shallow");
sub->
callback
(
[
this
]()
{
this
->
run
();
}
);
}
void
fetch_subcommand::run
()
{
wasm_http_transport_scope transport;
//
Enables wasm http(s) transport.
auto
directory =
get_current_git_path
();
auto
repo =
repository_wrapper::open
(directory);
//
Find the remote (default to origin if not specified)
std::string remote_name = m_remote_name.
empty
() ?
"
origin
"
: m_remote_name;
auto
remote = repo.
find_remote
(remote_name);
git_indexer_progress pd = {
0
};
git_fetch_options fetch_opts =
GIT_FETCH_OPTIONS_INIT
;
if
(
want_user_credentials
())
{
fetch_opts.
callbacks
.
credentials
= user_credentials;
}
fetch_opts.
callbacks
.
sideband_progress
= sideband_progress;
fetch_opts.
callbacks
.
transfer_progress
= fetch_progress;
fetch_opts.
callbacks
.
payload
= &pd;
fetch_opts.
callbacks
.
update_refs
= update_refs;
if
(repo.
is_shallow
())
{
if
(m_unshallow)
{
fetch_opts.
depth
=
GIT_FETCH_DEPTH_UNSHALLOW
;
}
else
if
(m_deepen >
0
)
{
size_t
shallow_size = repo.
shallow_depth_from_head
();
fetch_opts.
depth
= shallow_size + m_deepen;
}
else
{
fetch_opts.
depth
= m_depth;
}
}
else
{
fetch_opts.
depth
=
0
;
}
cursor_hider ch;
//
Perform the fetch
remote.
fetch
(
nullptr
, &fetch_opts,
"
fetch
"
);
//
Show statistics
const
git_indexer_progress* stats =
git_remote_stats
(remote);
if
(stats->
local_objects
>
0
)
{
std::cout <<
"
\r
Received
"
<< stats->
indexed_objects
<<
"
/
"
<< stats->
total_objects
<<
"
objects in
"
<< stats->
received_bytes
<<
"
bytes (used
"
<< stats->
local_objects
<<
"
local objects)
"
<< std::endl;
}
else
{
std::cout <<
"
\r
Received
"
<< stats->
indexed_objects
<<
"
/
"
<< stats->
total_objects
<<
"
objects in
"
<< stats->
received_bytes
<<
"
bytes
"
<< std::endl;
}
}
Back
|
FazBrowse Home
|
New Git URL