Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
libgit2/src/transport_local.c at development · kiryl/libgit2 · GitHub
Skip to content
Navigation Menu
Sign in
Products
Platform
GitHub
Repository hosting, code review, and collaboration
Copilot
AI coding agent for tasks, projects and automated work
Build & Ship
Actions
CI/CD and automation
Code Quality
Quality analysis, fixes, and enforcement
Codespaces
Cloud development environments
Secure
Code Security
Vulnerability detection and remediation
Secret Protection
Secret scanning and leak prevention
All Features
Developers
Learn
Documentation
Training
Certifications
Build
Build with Copilot
Customize Copilot
Integrations
Explore
Trending repos
GitHub Sponsors
Events
Changelog
Changelog
Your source for the latest features, improvements, and fixes across GitHub products, all in one place.
Businesses
By Stage
Enterprises
Team
Startups
Nonprofits
By Industry
Healthcare
Financial services
Manufacturing
Government
See all industries
Evaluate GitHub
Why GitHub
Customer Stories
Business insights
Trust Center
Add-ons
GitHub Advanced Security
Enterprise-grade code security
Copilot for business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Resources
Learn & Connect
Documentation
Resource center
Blog
Events & webinars
Community Forum
Customer Stories
Integrations
Support
Customer support
Training
GitHub Status
Company
About
Partners
Changelog
GitHub Universe
GitHub Universe
The event for developers, by developers — talks, workshops, and what’s next for GitHub.
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
kiryl
libgit2
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
development
Breadcrumbs
libgit2
/
src
/
transport_local.c
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
234 lines (187 loc) · 5.13 KB
development
Breadcrumbs
libgit2
/
src
/
transport_local.c
Copy path
Top
File metadata and controls
Code
Blame
234 lines (187 loc) · 5.13 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
#include
"common.h"
#include
"git2/types.h"
#include
"git2/transport.h"
#include
"git2/net.h"
#include
"git2/repository.h"
#include
"git2/object.h"
#include
"git2/tag.h"
#include
"refs.h"
#include
"transport.h"
#include
"posix.h"
typedef
struct
{
git_transport
parent
;
git_repository
*
repo
;
git_vector
*
refs
;
git_headarray
wants_list
;
}
transport_local
;
/*
* Try to open the url as a git directory. The direction doesn't
* matter in this case because we're calulating the heads ourselves.
*/
static
int
local_connect
(
git_transport
*
transport
,
int
GIT_UNUSED
(
direction
))
{
git_repository
*
repo
;
int
error
;
transport_local
*
t
=
(
transport_local
*
)
transport
;
const
char
*
path
;
const
char
file_prefix
[]
=
"file://"
;
GIT_UNUSED_ARG
(
direction
);
/* The repo layer doesn't want the prefix */
if
(!
git__prefixcmp
(
transport
->
url
,
file_prefix
))
path
=
transport
->
url
+
STRLEN
(
file_prefix
);
else
path
=
transport
->
url
;
error
=
git_repository_open
(
&
repo
,
path
);
if
(
error
<
GIT_SUCCESS
)
return
git__rethrow
(
error
,
"Failed to open remote"
);
t
->
repo
=
repo
;
t
->
parent
.
connected
=
1
;
return
GIT_SUCCESS
;
}
static
int
add_ref
(
const
char
*
name
,
git_repository
*
repo
,
git_vector
*
vec
)
{
const
char
peeled
[]
=
"^{}"
;
git_remote_head
*
head
;
git_reference
*
ref
;
git_object
*
obj
=
NULL
;
int
error
=
GIT_SUCCESS
,
peel_len
,
ret
;
head
=
git__malloc
(
sizeof
(
git_remote_head
));
if
(
head
==
NULL
)
return
GIT_ENOMEM
;
head
->
name
=
git__strdup
(
name
);
if
(
head
->
name
==
NULL
) {
error
=
GIT_ENOMEM
;
goto
out
;
}
error
=
git_reference_lookup
(
&
ref
,
repo
,
name
);
if
(
error
<
GIT_SUCCESS
)
goto
out
;
error
=
git_reference_resolve
(
&
ref
,
ref
);
if
(
error
<
GIT_SUCCESS
)
goto
out
;
git_oid_cpy
(
&
head
->
oid
,
git_reference_oid
(
ref
));
error
=
git_vector_insert
(
vec
,
head
);
if
(
error
<
GIT_SUCCESS
)
goto
out
;
/* If it's not a tag, we don't need to try to peel it */
if
(
git__prefixcmp
(
name
,
GIT_REFS_TAGS_DIR
))
goto
out
;
error
=
git_object_lookup
(
&
obj
,
repo
,
&
head
->
oid
,
GIT_OBJ_ANY
);
if
(
error
<
GIT_SUCCESS
) {
git__rethrow
(
error
,
"Failed to lookup object"
);
}
/* If it's not an annotated tag, just get out */
if
(
git_object_type
(
obj
)
!=
GIT_OBJ_TAG
)
goto
out
;
/* And if it's a tag, peel it, and add it to the list */
head
=
git__malloc
(
sizeof
(
git_remote_head
));
peel_len
=
strlen
(
name
)
+
STRLEN
(
peeled
);
head
->
name
=
git__malloc
(
peel_len
+
1
);
ret
=
p_snprintf
(
head
->
name
,
peel_len
+
1
,
"%s%s"
,
name
,
peeled
);
if
(
ret
>=
peel_len
+
1
) {
error
=
git__throw
(
GIT_ERROR
,
"The string is magically to long"
);
}
git_oid_cpy
(
&
head
->
oid
,
git_tag_target_oid
((
git_tag
*
)
obj
));
error
=
git_vector_insert
(
vec
,
head
);
if
(
error
<
GIT_SUCCESS
)
goto
out
;
out
:
git_object_close
(
obj
);
if
(
error
<
GIT_SUCCESS
) {
free
(
head
->
name
);
free
(
head
);
}
return
error
;
}
static
int
local_ls
(
git_transport
*
transport
,
git_headarray
*
array
)
{
int
error
;
unsigned
int
i
;
git_repository
*
repo
;
git_vector
*
vec
;
git_strarray
refs
;
transport_local
*
t
=
(
transport_local
*
)
transport
;
assert
(
transport
&&
transport
->
connected
);
repo
=
t
->
repo
;
error
=
git_reference_listall
(
&
refs
,
repo
,
GIT_REF_LISTALL
);
if
(
error
<
GIT_SUCCESS
)
return
git__rethrow
(
error
,
"Failed to list remote heads"
);
vec
=
git__malloc
(
sizeof
(
git_vector
));
if
(
vec
==
NULL
) {
error
=
GIT_ENOMEM
;
goto
out
;
}
error
=
git_vector_init
(
vec
,
refs
.
count
,
NULL
);
if
(
error
<
GIT_SUCCESS
)
return
error
;
/* Sort the references first */
git__tsort
((
void
*
*
)
refs
.
strings
,
refs
.
count
,
&
git__strcmp_cb
);
/* Add HEAD */
error
=
add_ref
(
GIT_HEAD_FILE
,
repo
,
vec
);
if
(
error
<
GIT_SUCCESS
)
goto
out
;
for
(
i
=
0
;
i
<
refs
.
count
;
++
i
) {
error
=
add_ref
(
refs
.
strings
[
i
],
repo
,
vec
);
if
(
error
<
GIT_SUCCESS
)
goto
out
;
}
array
->
len
=
vec
->
length
;
array
->
heads
=
(
git_remote_head
*
*
)
vec
->
contents
;
t
->
refs
=
vec
;
out
:
git_strarray_free
(
&
refs
);
return
error
;
}
static
int
local_send_wants
(
git_transport
*
transport
,
git_headarray
*
array
)
{
transport_local
*
t
=
(
transport_local
*
)
transport
;
git_headarray
*
wants
=
&
t
->
wants_list
;
/*
* We need to store the list of wanted references so we can figure
* out what to transmit later.
*/
wants
->
len
=
array
->
len
;
wants
->
heads
=
array
->
heads
;
/* We're local anyway, so we don't need this */
return
GIT_SUCCESS
;
}
static
int
local_close
(
git_transport
*
GIT_UNUSED
(
transport
))
{
/* Nothing to do */
GIT_UNUSED_ARG
(
transport
);
return
GIT_SUCCESS
;
}
static
void
local_free
(
git_transport
*
transport
)
{
unsigned
int
i
;
transport_local
*
t
=
(
transport_local
*
)
transport
;
git_vector
*
vec
=
t
->
refs
;
assert
(
transport
);
for
(
i
=
0
;
i
<
vec
->
length
;
++
i
) {
git_remote_head
*
h
=
git_vector_get
(
vec
,
i
);
free
(
h
->
name
);
free
(
h
);
}
git_vector_free
(
vec
);
free
(
vec
);
git_repository_free
(
t
->
repo
);
free
(
t
->
parent
.
url
);
free
(
t
);
}
/**************
* Public API *
**************/
int
git_transport_local
(
git_transport
*
*
out
)
{
transport_local
*
t
;
t
=
git__malloc
(
sizeof
(
transport_local
));
if
(
t
==
NULL
)
return
GIT_ENOMEM
;
t
->
parent
.
connect
=
local_connect
;
t
->
parent
.
ls
=
local_ls
;
t
->
parent
.
send_wants
=
local_send_wants
;
t
->
parent
.
close
=
local_close
;
t
->
parent
.
free
=
local_free
;
*
out
=
(
git_transport
*
)
t
;
return
GIT_SUCCESS
;
}
You can’t perform that action at this time.