Files
git/mru.c
Olga Telezhnaya 8865859dfc mru: use double-linked list from list.h
Simplify mru.[ch] and related code by reusing the double-linked list
implementation from list.h instead of a custom one.
This commit is an intermediate step. Our final goal is to get rid of
mru.[ch] at all and inline all logic.

Mentored-by: Christian Couder <christian.couder@gmail.com>
Mentored by: Jeff King <peff@peff.net>
Signed-off-by: Olga Telezhnaia <olyatelezhnaya@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-10-01 17:30:26 +09:00

28 lines
570 B
C

#include "cache.h"
#include "mru.h"
void mru_append(struct mru *head, void *item)
{
struct mru *cur = xmalloc(sizeof(*cur));
cur->item = item;
list_add_tail(&cur->list, &head->list);
}
void mru_mark(struct mru *head, struct mru *entry)
{
/* To mark means to put at the front of the list. */
list_del(&entry->list);
list_add(&entry->list, &head->list);
}
void mru_clear(struct mru *head)
{
struct list_head *pos;
struct list_head *tmp;
list_for_each_safe(pos, tmp, &head->list) {
free(list_entry(pos, struct mru, list));
}
INIT_LIST_HEAD(&head->list);
}