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

Function current_pointed_by_HEAD

log-tree.c:294–326  ·  view source on GitHub ↗

* Do we have HEAD in the output, and also the branch it points at? * If so, find that decoration entry for that current branch. */

Source from the content-addressed store, hash-verified

292 * If so, find that decoration entry for that current branch.
293 */
294static const struct name_decoration *current_pointed_by_HEAD(const struct name_decoration *decoration)
295{
296 const struct name_decoration *list, *head = NULL;
297 const char *branch_name = NULL;
298 int rru_flags;
299
300 /* First find HEAD */
301 for (list = decoration; list; list = list->next)
302 if (list->type == DECORATION_REF_HEAD) {
303 head = list;
304 break;
305 }
306 if (!head)
307 return NULL;
308
309 /* Now resolve and find the matching current branch */
310 branch_name = refs_resolve_ref_unsafe(get_main_ref_store(the_repository),
311 "HEAD", 0, NULL, &rru_flags);
312 if (!branch_name || !(rru_flags & REF_ISSYMREF))
313 return NULL;
314
315 if (!starts_with(branch_name, "refs/"))
316 return NULL;
317
318 /* OK, do we have that ref in the list? */
319 for (list = decoration; list; list = list->next)
320 if ((list->type == DECORATION_REF_LOCAL) &&
321 !strcmp(branch_name, list->name)) {
322 return list;
323 }
324
325 return NULL;
326}
327
328static void show_name(struct strbuf *sb, const struct name_decoration *decoration)
329{

Callers 1

format_decorationsFunction · 0.85

Calls 3

refs_resolve_ref_unsafeFunction · 0.85
get_main_ref_storeFunction · 0.85
starts_withFunction · 0.85

Tested by

no test coverage detected