FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
git2cpp/src/utils/progress.cpp at main · 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
/
utils
/
progress.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
145 lines (127 loc) · 4.03 KB
Breadcrumbs
git2cpp
/
src
/
utils
/
progress.cpp
Copy path
File metadata and controls
145 lines (127 loc) · 4.03 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
#
include
"
../utils/progress.hpp
"
#
include
<
iomanip
>
#
include
<
iostream
>
#
include
<
string_view
>
#
include
"
../utils/common.hpp
"
int
sideband_progress
(
const
char
* str,
int
len,
void
*)
{
printf
(
"
remote: %.*s
"
, len, str);
fflush
(stdout);
return
0
;
}
int
fetch_progress
(
const
git_indexer_progress* stats,
void
* payload)
{
static
bool
done =
false
;
//
We need to copy stats into payload even if the fetch is done,
//
because the checkout_progress callback will be called with the
//
same payload and needs the data to be up do date.
auto
* pr =
reinterpret_cast
<git_indexer_progress*>(payload);
*pr = *stats;
if
(done)
{
return
0
;
}
int
network_percent = pr->
total_objects
>
0
? (
100
* pr->
received_objects
/ pr->
total_objects
) :
0
;
size_t
kbytes = pr->
received_bytes
/
1024
;
size_t
mbytes = kbytes /
1024
;
std::cout <<
"
Receiving objects:
"
<<
std::setw
(
4
) << network_percent <<
"
% (
"
<< pr->
received_objects
<<
"
/
"
<< pr->
total_objects
<<
"
),
"
;
if
(mbytes !=
0
)
{
std::cout << mbytes <<
"
MiB
"
;
}
else
if
(kbytes !=
0
)
{
std::cout << kbytes <<
"
KiB
"
;
}
else
{
std::cout << pr->
received_bytes
<<
"
bytes
"
;
}
//
TODO: compute speed
if
(pr->
received_objects
== pr->
total_objects
)
{
std::cout <<
"
, done.
"
<< std::endl;
done =
true
;
}
else
{
std::cout <<
'
\r
'
;
}
return
0
;
}
void
checkout_progress
(
const
char
* path,
size_t
cur,
size_t
tot,
void
* payload)
{
static
bool
done =
false
;
if
(done)
{
return
;
}
auto
* pr =
reinterpret_cast
<git_indexer_progress*>(payload);
int
deltas_percent = pr->
total_deltas
>
0
? (
100
* pr->
indexed_deltas
/ pr->
total_deltas
) :
0
;
std::cout <<
"
Resolving deltas:
"
<<
std::setw
(
4
) << deltas_percent <<
"
% (
"
<< pr->
indexed_deltas
<<
"
/
"
<< pr->
total_deltas
<<
"
)
"
;
if
(pr->
indexed_deltas
== pr->
total_deltas
)
{
std::cout <<
"
, done.
"
<< std::endl;
done =
true
;
}
else
{
std::cout <<
'
\r
'
;
}
}
int
update_refs
(
const
char
* refname,
const
git_oid* a,
const
git_oid* b, git_refspec*,
void
*)
{
std::string b_str =
oid_to_hex
(*b);
if
(
git_oid_is_zero
(a))
{
std::string n, name, ref;
const
size_t
last_slash_idx =
std::string_view
(refname).
find_last_of
(
'
/
'
);
name =
std::string_view
(refname).
substr
(last_slash_idx +
1
, -
1
);
if
(
std::string_view
(refname).
find
(
"
remote
"
) != std::string::npos)
//
maybe will string_view need the
//
size of the string
{
n =
"
* [new branch]
"
;
auto
new_refname =
std::string_view
(refname).
substr
(
0
, last_slash_idx -
1
);
const
size_t
second_to_last_slash_idx =
std::string_view
(new_refname).
find_last_of
(
'
/
'
);
ref =
std::string_view
(refname).
substr
(second_to_last_slash_idx +
1
, -
1
);
}
else
if
(
std::string_view
(refname).
find
(
"
tags
"
) != std::string::npos)
{
n =
"
* [new tag]
"
;
ref = name;
}
else
{
//
could it be something else ?
}
std::cout << n << name <<
"
\t
->
"
<< ref << std::endl;
}
else
{
std::string a_str =
oid_to_hex
(*a);
std::cout <<
"
[updated]
"
<<
std::string
(a_str,
10
) <<
"
..
"
<<
std::string
(b_str,
10
) <<
"
"
<< refname << std::endl;
}
return
0
;
}
int
push_transfer_progress
(
unsigned
int
current,
unsigned
int
total,
size_t
bytes,
void
*)
{
if
(total >
0
)
{
int
percent = (
100
* current) / total;
std::cout <<
"
Writing objects:
"
<< percent <<
"
% (
"
<< current <<
"
/
"
<< total <<
"
),
"
<< bytes
<<
"
bytes
\r
"
;
}
return
0
;
}
int
push_update_reference
(
const
char
* refname,
const
char
* status,
void
*)
{
if
(status)
{
std::cout <<
"
! [remote rejected]
"
<< refname <<
"
(
"
<< status <<
"
)
"
<< std::endl;
return
-
1
;
}
return
0
;
}
Back
|
FazBrowse Home
|
New Git URL