summaryrefslogtreecommitdiff
path: root/file/git-hist.h
blob: da865a9b02048a7c881d4168b6924c9edaf46706 (plain)
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
/*
 * file/git-hist.h - Retrieve revision history from GIT repo
 *
 * Written 2016 by Werner Almesberger
 * Copyright 2016 by Werner Almesberger
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 */

#ifndef FILE_GIT_HIST_H
#define	FILE_GIT_HIST_H

#include <stdbool.h>

#include <git2.h>


enum thread {
	thread_none	=	0,
	thread_self	=	1 << 0,		/* -o- */
	thread_newer	=	1 << 1,		/* -'- or -+- */
	thread_older	=	1 << 2,		/* -.- or -+- */
	thread_other	=	1 << 3,		/* -|- or -+- */
};

struct vcs_hist {
	struct git_commit *commit; /* NULL if uncommitted changes */

	unsigned branch;	/* branch index */

	const char **branches;	/* NULL if none */
	unsigned n_branches;

	struct vcs_hist **newer;
	unsigned n_newer;

	struct vcs_hist **older;
	unsigned n_older;

	struct vcs_hist *next;	/* no specific order */
	unsigned seen;		/* for traversal */

	unsigned pos;		/* position in thread vector */
	const struct vcs_hist **threads; /* previous thread members, or NULL */
	unsigned n_threads;
};

struct vcs_history;


bool vcs_git_try(const char *path);
struct vcs_history *vcs_git_history(const char *path, unsigned depth);

char *vcs_git_get_rev(struct vcs_hist *h);
bool vcs_is_empty(const struct vcs_history *history);
const char *vcs_git_summary(const struct vcs_hist *hist);
char *vcs_git_summary_for_pango(const struct vcs_hist *hist,
    char *(*formatter)(const char *fmt, ...));
char *vcs_git_long_for_pango(const struct vcs_hist *hist,
    char *(*formatter)(const char *fmt, ...), bool full);

unsigned threads_number(const struct vcs_history *history);
enum thread *threads_classify(const struct vcs_history *history,
    const struct vcs_hist *h, const struct vcs_hist *next);

void hist_iterate(struct vcs_history *history,
    void (*fn)(void *user, struct vcs_hist *h, const struct vcs_hist *next),
    void *user);
void dump_hist(struct vcs_history *history);

#endif /* !FILE_GIT_HIST_H */