MCPcopy Create free account
hub / github.com/git/git / ls_refs

Function ls_refs

ls-refs.c:161–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161int ls_refs(struct repository *r, struct packet_reader *request)
162{
163 struct refs_for_each_ref_options opts = { 0 };
164 struct ls_refs_data data;
165
166 memset(&data, 0, sizeof(data));
167 strvec_init(&data.prefixes);
168 strbuf_init(&data.buf, 0);
169 strvec_init(&data.hidden_refs);
170
171 repo_config(the_repository, ls_refs_config, &data);
172
173 while (packet_reader_read(request) == PACKET_READ_NORMAL) {
174 const char *arg = request->line;
175 const char *out;
176
177 if (!strcmp("peel", arg))
178 data.peel = 1;
179 else if (!strcmp("symrefs", arg))
180 data.symrefs = 1;
181 else if (skip_prefix(arg, "ref-prefix ", &out)) {
182 if (data.prefixes.nr < TOO_MANY_PREFIXES)
183 strvec_push(&data.prefixes, out);
184 }
185 else if (!strcmp("unborn", arg))
186 data.unborn = !!unborn_config(r);
187 else
188 die(_("unexpected line: '%s'"), arg);
189 }
190
191 if (request->status != PACKET_READ_FLUSH)
192 die(_("expected flush after ls-refs arguments"));
193
194 /*
195 * If we saw too many prefixes, we must avoid using them at all; as
196 * soon as we have any prefix, they are meant to form a comprehensive
197 * list.
198 */
199 if (data.prefixes.nr >= TOO_MANY_PREFIXES)
200 strvec_clear(&data.prefixes);
201
202 send_possibly_unborn_head(&data);
203 if (!data.prefixes.nr)
204 strvec_push(&data.prefixes, "");
205
206 opts.exclude_patterns = hidden_refs_to_excludes(&data.hidden_refs);
207 opts.namespace = get_git_namespace();
208
209 refs_for_each_ref_in_prefixes(get_main_ref_store(r), data.prefixes.v,
210 &opts, send_ref, &data);
211 packet_fflush(stdout);
212 strvec_clear(&data.prefixes);
213 strbuf_release(&data.buf);
214 strvec_clear(&data.hidden_refs);
215 return 0;
216}
217
218int ls_refs_advertise(struct repository *r, struct strbuf *value)

Callers

nothing calls this directly

Calls 15

strvec_initFunction · 0.85
strbuf_initFunction · 0.85
packet_reader_readFunction · 0.85
strvec_pushFunction · 0.85
unborn_configFunction · 0.85
strvec_clearFunction · 0.85
hidden_refs_to_excludesFunction · 0.85
get_git_namespaceFunction · 0.85
get_main_ref_storeFunction · 0.85
packet_fflushFunction · 0.85

Tested by

no test coverage detected