mirror of
git://projects.qi-hardware.com/eda-tools.git
synced 2024-11-29 20:53:55 +02:00
eeshow/: detect if repo is dirty and add history entry with commit = NULL
This commit is contained in:
parent
7dc1211cfd
commit
ba95c01249
@ -142,7 +142,7 @@ bool vcs_git_try(const char *path)
|
||||
|
||||
struct hist *vcs_git_hist(const char *path)
|
||||
{
|
||||
struct hist *head;
|
||||
struct hist *head, *dirty;
|
||||
git_repository *repo;
|
||||
git_oid oid;
|
||||
const git_error *e;
|
||||
@ -173,7 +173,17 @@ struct hist *vcs_git_hist(const char *path)
|
||||
}
|
||||
|
||||
recurse(head, 1, &head);
|
||||
return head;
|
||||
|
||||
if (!git_repo_is_dirty(repo))
|
||||
return head;
|
||||
|
||||
dirty = new_commit(0);
|
||||
dirty->older = alloc_type(struct hist *);
|
||||
dirty->older[0] = head;
|
||||
dirty->n_older = 1;
|
||||
uplink(head, dirty);
|
||||
|
||||
return dirty;
|
||||
}
|
||||
|
||||
|
||||
@ -182,6 +192,8 @@ const char *vcs_git_summary(struct hist *h)
|
||||
const char *summary;
|
||||
const git_error *e;
|
||||
|
||||
if (!h->commit)
|
||||
return "Uncommitted changes";
|
||||
summary = git_commit_summary(h->commit);
|
||||
if (summary)
|
||||
return summary;
|
||||
@ -210,13 +222,19 @@ void dump_hist(struct hist *h)
|
||||
const git_error *e;
|
||||
unsigned i;
|
||||
|
||||
if (git_object_short_id(&buf, (git_object *) h->commit)) {
|
||||
e = giterr_last();
|
||||
fprintf(stderr, "git_object_short_id: %s\n", e->message);
|
||||
exit(1);
|
||||
if (h->commit) {
|
||||
if (git_object_short_id(&buf, (git_object *) h->commit)) {
|
||||
e = giterr_last();
|
||||
fprintf(stderr, "git_object_short_id: %s\n",
|
||||
e->message);
|
||||
exit(1);
|
||||
}
|
||||
printf("%*s%s %s\n",
|
||||
2 * h->branch, "", buf.ptr, vcs_git_summary(h));
|
||||
git_buf_free(&buf);
|
||||
} else {
|
||||
printf("dirty\n");
|
||||
}
|
||||
printf("%*s%s %s\n", 2 * h->branch, "", buf.ptr, vcs_git_summary(h));
|
||||
git_buf_free(&buf);
|
||||
|
||||
for (i = 0; i != h->n_older; i++)
|
||||
if (h->older[i]->newer[h->older[i]->n_newer - 1] == h)
|
||||
|
@ -19,7 +19,7 @@
|
||||
|
||||
|
||||
struct hist {
|
||||
struct git_commit *commit;
|
||||
struct git_commit *commit; /* NULL if uncommitted changes */
|
||||
|
||||
unsigned branch; /* branch index */
|
||||
|
||||
|
@ -11,12 +11,60 @@
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include <git2.h>
|
||||
|
||||
#include "git-util.h"
|
||||
|
||||
|
||||
/*
|
||||
* This seems to be an efficient way for finding out if a repo is dirty.
|
||||
*
|
||||
* http://ben.straub.cc/2013/04/02/libgit2-checkout/
|
||||
*
|
||||
* References:
|
||||
* https://libgit2.github.com/libgit2/#HEAD/group/checkout/git_checkout_index
|
||||
* https://libgit2.github.com/libgit2/#HEAD/type/git_checkout_options
|
||||
* https://github.com/libgit2/libgit2/blob/HEAD/include/git2/checkout.h#L251-295
|
||||
*/
|
||||
|
||||
|
||||
static int checkout_notify_cb(git_checkout_notify_t why,
|
||||
const char *path, const git_diff_file *baseline,
|
||||
const git_diff_file *target, const git_diff_file *workdir,
|
||||
void *payload)
|
||||
{
|
||||
bool *res = payload;
|
||||
|
||||
assert(why == GIT_CHECKOUT_NOTIFY_DIRTY);
|
||||
|
||||
*res = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
bool git_repo_is_dirty(git_repository *repo)
|
||||
{
|
||||
git_checkout_options opts;
|
||||
bool res = 0;
|
||||
|
||||
/*
|
||||
* Initialization with GIT_CHECKOUT_OPTIONS_INIT complains about not
|
||||
* setting checkout_strategy. git_checkout_init_options is fine.
|
||||
*/
|
||||
git_checkout_init_options(&opts, GIT_CHECKOUT_OPTIONS_VERSION);
|
||||
opts.checkout_strategy = GIT_CHECKOUT_NONE;
|
||||
/* let's be explicit about this */
|
||||
opts.notify_flags = GIT_CHECKOUT_NOTIFY_DIRTY;
|
||||
opts.notify_cb = checkout_notify_cb;
|
||||
opts.notify_payload = &res;
|
||||
git_checkout_index(repo, NULL, &opts);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Git documentation says that git_libgit2_init can be called more then once
|
||||
* but doesn't quite what happens then, e.g., whether references obtained
|
||||
|
@ -13,6 +13,12 @@
|
||||
#ifndef GIT_UTIL_H
|
||||
#define GIT_UTIL_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <git2.h>
|
||||
|
||||
|
||||
bool git_repo_is_dirty(git_repository *repo);
|
||||
void git_init_once(void);
|
||||
|
||||
#endif /* !GIT_UTIL_H */
|
||||
|
Loading…
Reference in New Issue
Block a user