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
|
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>ls-remote.c</title>
<link rel="stylesheet" href="../../css.css">
<style type="text/css">
a.fnlink {text-decoration: none}
a.fnlink:hover {text-decoration: underline}
</style>
</head>
<body>
<div id='container'>
<div id="background"></div>
<div id="jump_to">
Jump To …
<div id="jump_wrapper">
<div id="jump_page">
<a class="source" href="../../#v0.22.2">API Docs</a>
<a class="source" href="../add.html">add.c</a>
<a class="source" href="../blame.html">blame.c</a>
<a class="source" href="../cat-file.html">cat-file.c</a>
<a class="source" href="../common.html">common.c</a>
<a class="source" href="../describe.html">describe.c</a>
<a class="source" href="../diff.html">diff.c</a>
<a class="source" href="../for-each-ref.html">for-each-ref.c</a>
<a class="source" href="../general.html">general.c</a>
<a class="source" href="../init.html">init.c</a>
<a class="source" href="../log.html">log.c</a>
<a class="source" href="clone.html">clone.c</a>
<a class="source" href="common.html">common.c</a>
<a class="source" href="fetch.html">fetch.c</a>
<a class="source" href="git2.html">git2.c</a>
<a class="source" href="index-pack.html">index-pack.c</a>
<a class="source" href="ls-remote.html">ls-remote.c</a>
<a class="source" href="../rev-list.html">rev-list.c</a>
<a class="source" href="../rev-parse.html">rev-parse.c</a>
<a class="source" href="../showindex.html">showindex.c</a>
<a class="source" href="../status.html">status.c</a>
<a class="source" href="../tag.html">tag.c</a>
</div>
</div>
</div>
<table cellspacing=0 cellpadding=0>
<thead>
<tr>
<th class=docs><h1>ls-remote.c</h1></th>
<th class=code></th>
</tr>
</thead>
<tbody>
<tr id='section-1'>
<td class=docs>
<div class="pilwrap">
<a class="pilcrow" href="#section-1">¶</a>
</div>
</td>
<td class=code>
<div class='highlight'><pre><span class="cp">#include <git2.h></span>
<span class="cp">#include <stdlib.h></span>
<span class="cp">#include <stdio.h></span>
<span class="cp">#include <string.h></span>
<span class="cp">#include "common.h"</span>
<span class="k">static</span> <span class="kt">int</span> <span class="nf">use_remote</span><span class="p">(</span><span class="n">git_repository</span> <span class="o">*</span><span class="n">repo</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span><span class="n">name</span><span class="p">)</span>
<span class="p">{</span>
<span class="n">git_remote</span> <span class="o">*</span><span class="n">remote</span> <span class="o">=</span> <span class="nb">NULL</span><span class="p">;</span>
<span class="kt">int</span> <span class="n">error</span><span class="p">;</span>
<span class="k">const</span> <span class="n">git_remote_head</span> <span class="o">**</span><span class="n">refs</span><span class="p">;</span>
<span class="kt">size_t</span> <span class="n">refs_len</span><span class="p">,</span> <span class="n">i</span><span class="p">;</span>
<span class="n">git_remote_callbacks</span> <span class="n">callbacks</span> <span class="o">=</span> <span class="n">GIT_REMOTE_CALLBACKS_INIT</span><span class="p">;</span></pre></div>
</td>
</tr>
<tr id='section-2'>
<td class=docs>
<div class="pilwrap">
<a class="pilcrow" href="#section-2">¶</a>
</div>
<p>Find the remote by name</p>
</td>
<td class=code>
<div class='highlight'><pre> <span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_remote_lookup-3" class="fnlink" href="../../#v0.22.2/group/remote/git_remote_lookup">git_remote_lookup</a></span><span class="p">(</span><span class="o">&</span><span class="n">remote</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">name</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">error</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
<span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_remote_create_anonymous-2" class="fnlink" href="../../#v0.22.2/group/remote/git_remote_create_anonymous">git_remote_create_anonymous</a></span><span class="p">(</span><span class="o">&</span><span class="n">remote</span><span class="p">,</span> <span class="n">repo</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">error</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span>
<span class="k">goto</span> <span class="n">cleanup</span><span class="p">;</span>
<span class="p">}</span></pre></div>
</td>
</tr>
<tr id='section-3'>
<td class=docs>
<div class="pilwrap">
<a class="pilcrow" href="#section-3">¶</a>
</div>
<p>Connect to the remote and call the printing function for
each of the remote references.</p>
</td>
<td class=code>
<div class='highlight'><pre> <span class="n">callbacks</span><span class="p">.</span><span class="n">credentials</span> <span class="o">=</span> <span class="n">cred_acquire_cb</span><span class="p">;</span>
<span class="n"><a name="git_remote_set_callbacks-7" class="fnlink" href="../../#v0.22.2/group/remote/git_remote_set_callbacks">git_remote_set_callbacks</a></span><span class="p">(</span><span class="n">remote</span><span class="p">,</span> <span class="o">&</span><span class="n">callbacks</span><span class="p">);</span>
<span class="n">error</span> <span class="o">=</span> <span class="n"><a name="git_remote_connect-4" class="fnlink" href="../../#v0.22.2/group/remote/git_remote_connect">git_remote_connect</a></span><span class="p">(</span><span class="n">remote</span><span class="p">,</span> <span class="n">GIT_DIRECTION_FETCH</span><span class="p">);</span>
<span class="k">if</span> <span class="p">(</span><span class="n">error</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span>
<span class="k">goto</span> <span class="n">cleanup</span><span class="p">;</span></pre></div>
</td>
</tr>
<tr id='section-4'>
<td class=docs>
<div class="pilwrap">
<a class="pilcrow" href="#section-4">¶</a>
</div>
<p>Get the list of references on the remote and print out
their name next to what they point to.</p>
</td>
<td class=code>
<div class='highlight'><pre> <span class="k">if</span> <span class="p">(</span><span class="n"><a name="git_remote_ls-5" class="fnlink" href="../../#v0.22.2/group/remote/git_remote_ls">git_remote_ls</a></span><span class="p">(</span><span class="o">&</span><span class="n">refs</span><span class="p">,</span> <span class="o">&</span><span class="n">refs_len</span><span class="p">,</span> <span class="n">remote</span><span class="p">)</span> <span class="o"><</span> <span class="mi">0</span><span class="p">)</span>
<span class="k">goto</span> <span class="n">cleanup</span><span class="p">;</span>
<span class="k">for</span> <span class="p">(</span><span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="n">i</span> <span class="o"><</span> <span class="n">refs_len</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
<span class="kt">char</span> <span class="n">oid</span><span class="p">[</span><span class="n">GIT_OID_HEXSZ</span> <span class="o">+</span> <span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="p">{</span><span class="mi">0</span><span class="p">};</span>
<span class="n"><a name="git_oid_fmt-1" class="fnlink" href="../../#v0.22.2/group/oid/git_oid_fmt">git_oid_fmt</a></span><span class="p">(</span><span class="n">oid</span><span class="p">,</span> <span class="o">&</span><span class="n">refs</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-></span><span class="n">oid</span><span class="p">);</span>
<span class="n">printf</span><span class="p">(</span><span class="s">"%s</span><span class="se">\t</span><span class="s">%s</span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">oid</span><span class="p">,</span> <span class="n">refs</span><span class="p">[</span><span class="n">i</span><span class="p">]</span><span class="o">-></span><span class="n">name</span><span class="p">);</span>
<span class="p">}</span>
<span class="nl">cleanup</span><span class="p">:</span>
<span class="n"><a name="git_remote_free-6" class="fnlink" href="../../#v0.22.2/group/remote/git_remote_free">git_remote_free</a></span><span class="p">(</span><span class="n">remote</span><span class="p">);</span>
<span class="k">return</span> <span class="n">error</span><span class="p">;</span>
<span class="p">}</span></pre></div>
</td>
</tr>
<tr id='section-5'>
<td class=docs>
<div class="pilwrap">
<a class="pilcrow" href="#section-5">¶</a>
</div>
<p>Entry point for this command</p>
</td>
<td class=code>
<div class='highlight'><pre><span class="kt">int</span> <span class="nf">ls_remote</span><span class="p">(</span><span class="n">git_repository</span> <span class="o">*</span><span class="n">repo</span><span class="p">,</span> <span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">**</span><span class="n">argv</span><span class="p">)</span>
<span class="p">{</span>
<span class="kt">int</span> <span class="n">error</span><span class="p">;</span>
<span class="k">if</span> <span class="p">(</span><span class="n">argc</span> <span class="o"><</span> <span class="mi">2</span><span class="p">)</span> <span class="p">{</span>
<span class="n">fprintf</span><span class="p">(</span><span class="n">stderr</span><span class="p">,</span> <span class="s">"usage: %s ls-remote <remote></span><span class="se">\n</span><span class="s">"</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]);</span>
<span class="k">return</span> <span class="n">EXIT_FAILURE</span><span class="p">;</span>
<span class="p">}</span>
<span class="n">error</span> <span class="o">=</span> <span class="n">use_remote</span><span class="p">(</span><span class="n">repo</span><span class="p">,</span> <span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">]);</span>
<span class="k">return</span> <span class="n">error</span><span class="p">;</span>
<span class="p">}</span></pre></div>
</td>
</tr>
</table>
</div>
</body>
|