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/fetch.c at development · fabgithub/libgit2 · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
See all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
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 }}
fabgithub
libgit2
Repository navigation
Code
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
More
items
Files
Expand file tree
development
Breadcrumbs
libgit2
/
src
/
fetch.c
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
133 lines (110 loc) · 3.15 KB
development
Breadcrumbs
libgit2
/
src
/
fetch.c
Copy path
Top
File metadata and controls
Code
Blame
133 lines (110 loc) · 3.15 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
/*
* Copyright (C) the libgit2 contributors. All rights reserved.
*
* This file is part of libgit2, distributed under the GNU GPL v2 with
* a Linking Exception. For full terms see the included COPYING file.
*/
#include
"git2/oid.h"
#include
"git2/refs.h"
#include
"git2/revwalk.h"
#include
"git2/transport.h"
#include
"common.h"
#include
"remote.h"
#include
"refspec.h"
#include
"pack.h"
#include
"fetch.h"
#include
"netops.h"
#include
"repository.h"
#include
"refs.h"
struct
filter_payload
{
git_remote
*
remote
;
const
git_refspec
*
spec
,
*
tagspec
;
git_odb
*
odb
;
int
found_head
;
};
static
int
filter_ref__cb
(
git_remote_head
*
head
,
void
*
payload
)
{
struct
filter_payload
*
p
=
payload
;
int
match
=
0
;
if
(!
git_reference_is_valid_name
(
head
->
name
))
return
0
;
if
(!
p
->
found_head
&&
strcmp
(
head
->
name
,
GIT_HEAD_FILE
)
==
0
)
p
->
found_head
=
1
;
else
if
(
p
->
remote
->
download_tags
==
GIT_REMOTE_DOWNLOAD_TAGS_ALL
) {
/*
* If tagopt is --tags, then we only use the default
* tags refspec and ignore the remote's
*/
if
(
git_refspec_src_matches
(
p
->
tagspec
,
head
->
name
))
match
=
1
;
else
return
0
;
}
else
if
(
git_remote__matching_refspec
(
p
->
remote
,
head
->
name
))
match
=
1
;
if
(!
match
)
return
0
;
/* If we have the object, mark it so we don't ask for it */
if
(
git_odb_exists
(
p
->
odb
,
&
head
->
oid
))
head
->
local
=
1
;
else
p
->
remote
->
need_pack
=
1
;
return
git_vector_insert
(
&
p
->
remote
->
refs
,
head
);
}
static
int
filter_wants
(
git_remote
*
remote
)
{
struct
filter_payload
p
;
git_refspec
tagspec
;
int
error
=
-1
;
git_vector_clear
(
&
remote
->
refs
);
if
(
git_refspec__parse
(
&
tagspec
,
GIT_REFSPEC_TAGS
, true)
<
0
)
return
error
;
/*
* The fetch refspec can be NULL, and what this means is that the
* user didn't specify one. This is fine, as it means that we're
* not interested in any particular branch but just the remote's
* HEAD, which will be stored in FETCH_HEAD after the fetch.
*/
p
.
tagspec
=
&
tagspec
;
p
.
found_head
=
0
;
p
.
remote
=
remote
;
if
(
git_repository_odb__weakptr
(
&
p
.
odb
,
remote
->
repo
)
<
0
)
goto
cleanup
;
error
=
git_remote_ls
(
remote
,
filter_ref__cb
,
&
p
);
cleanup
:
git_refspec__free
(
&
tagspec
);
return
error
;
}
/*
* In this first version, we push all our refs in and start sending
* them out. When we get an ACK we hide that commit and continue
* traversing until we're done
*/
int
git_fetch_negotiate
(
git_remote
*
remote
)
{
git_transport
*
t
=
remote
->
transport
;
if
(
filter_wants
(
remote
)
<
0
) {
giterr_set
(
GITERR_NET
,
"Failed to filter the reference list for wants"
);
return
-1
;
}
/* Don't try to negotiate when we don't want anything */
if
(
remote
->
refs
.
length
==
0
||
!
remote
->
need_pack
)
return
0
;
/*
* Now we have everything set up so we can start tell the
* server what we want and what we have.
*/
return
t
->
negotiate_fetch
(
t
,
remote
->
repo
,
(
const
git_remote_head
*
const
*
)
remote
->
refs
.
contents
,
remote
->
refs
.
length
);
}
int
git_fetch_download_pack
(
git_remote
*
remote
,
git_transfer_progress_callback
progress_cb
,
void
*
progress_payload
)
{
git_transport
*
t
=
remote
->
transport
;
if
(!
remote
->
need_pack
)
return
0
;
return
t
->
download_pack
(
t
,
remote
->
repo
,
&
remote
->
stats
,
progress_cb
,
progress_payload
);
}
You can’t perform that action at this time.