Nilorea Library
C utilities for networking, threading, graphics
Loading...
Searching...
No Matches
n_git.h
Go to the documentation of this file.
1/*
2 * Nilorea Library
3 * Copyright (C) 2005-2026 Castagnier Mickael
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
27#ifndef __N_GIT_H__
28#define __N_GIT_H__
29
30#ifdef __cplusplus
31extern "C" {
32#endif
33
34#ifdef HAVE_LIBGIT2
35
41#include "nilorea/n_str.h"
42#include "nilorea/n_list.h"
43#include <git2.h>
44
46#define N_GIT_STATUS_NEW 1
48#define N_GIT_STATUS_MODIFIED 2
50#define N_GIT_STATUS_DELETED 4
52#define N_GIT_STATUS_STAGED 8
53
55#define N_GIT_AUTH_NONE 0
57#define N_GIT_AUTH_TOKEN 1
59#define N_GIT_AUTH_BASIC 2
61#define N_GIT_AUTH_SSH 3
62
78
80typedef struct N_GIT_REPO {
82 git_repository* repo;
84 char* path;
88
90typedef struct N_GIT_STATUS_ENTRY {
92 char path[512];
94 int flags;
96
98typedef struct N_GIT_COMMIT_INFO {
100 char hash[42];
102 char short_hash[10];
104 char message[512];
106 char author[256];
108 int64_t timestamp;
110
115N_GIT_REPO* n_git_open(const char* path);
116
121N_GIT_REPO* n_git_init(const char* path);
122
126void n_git_close(N_GIT_REPO** repo);
127
133
139int n_git_stage(N_GIT_REPO* repo, const char* filepath);
140
145int n_git_stage_all(N_GIT_REPO* repo);
146
152int n_git_unstage(N_GIT_REPO* repo, const char* filepath);
153
161int n_git_commit(N_GIT_REPO* repo, const char* message, const char* author_name, const char* author_email);
162
168LIST* n_git_log(N_GIT_REPO* repo, size_t max_entries);
169
175
182N_STR* n_git_diff_commits(N_GIT_REPO* repo, const char* hash_a, const char* hash_b);
183
189int n_git_checkout_path(N_GIT_REPO* repo, const char* filepath);
190
196int n_git_checkout_commit(N_GIT_REPO* repo, const char* hash);
197
203
209int n_git_create_branch(N_GIT_REPO* repo, const char* branch_name);
210
216int n_git_switch_branch(N_GIT_REPO* repo, const char* branch_name);
217
224int n_git_current_branch(N_GIT_REPO* repo, char* out, size_t out_size);
225
231int n_git_delete_branch(N_GIT_REPO* repo, const char* branch_name);
232
240
247int n_git_remote_set_url(N_GIT_REPO* repo, const char* url);
248
254int n_git_push(N_GIT_REPO* repo);
255
262int n_git_pull(N_GIT_REPO* repo);
263
268#endif /* HAVE_LIBGIT2 */
269
270#ifdef __cplusplus
271}
272#endif
273
274#endif /* __N_GIT_H__ */
char short_hash[10]
short (abbreviated) hex hash
Definition n_git.h:102
char author[256]
author name and email
Definition n_git.h:106
int64_t timestamp
unix timestamp of the commit
Definition n_git.h:108
char message[512]
first line of commit message
Definition n_git.h:104
char * password
password or personal access token, or NULL
Definition n_git.h:70
char * ssh_privkey_path
path to SSH private key file, or NULL
Definition n_git.h:74
char hash[42]
full hex hash
Definition n_git.h:100
char * ssh_pubkey_path
path to SSH public key file, or NULL (derived from private key + ".pub")
Definition n_git.h:72
int flags
combination of N_GIT_STATUS_* flags
Definition n_git.h:94
char * path
filesystem path to the repository
Definition n_git.h:84
git_repository * repo
libgit2 repository handle
Definition n_git.h:82
char * ssh_passphrase
passphrase for SSH key, or NULL
Definition n_git.h:76
int type
auth type: N_GIT_AUTH_NONE/TOKEN/BASIC/SSH
Definition n_git.h:66
char * username
username for basic auth or SSH, or NULL
Definition n_git.h:68
char path[512]
relative path of the file
Definition n_git.h:92
N_GIT_REMOTE_AUTH * remote_auth
credentials for remote operations, or NULL
Definition n_git.h:86
void n_git_close(N_GIT_REPO **repo)
Close a Git repository and free resources.
Definition n_git.c:185
N_STR * n_git_diff_commits(N_GIT_REPO *repo, const char *hash_a, const char *hash_b)
Get a diff between two commits identified by hash.
Definition n_git.c:597
int n_git_push(N_GIT_REPO *repo)
Push the current branch to the "origin" remote.
Definition n_git.c:1057
int n_git_remote_set_url(N_GIT_REPO *repo, const char *url)
Ensure a remote named "origin" exists with the given URL.
Definition n_git.c:1019
int n_git_switch_branch(N_GIT_REPO *repo, const char *branch_name)
Switch to an existing local branch.
Definition n_git.c:833
int n_git_pull(N_GIT_REPO *repo)
Fetch from "origin" and fast-forward merge the current branch.
Definition n_git.c:1107
int n_git_checkout_path(N_GIT_REPO *repo, const char *filepath)
Restore a single file from HEAD (discard working directory changes).
Definition n_git.c:679
LIST * n_git_list_branches(N_GIT_REPO *repo)
List all local branch names.
Definition n_git.c:749
LIST * n_git_status(N_GIT_REPO *repo)
Get the status of all files in the working directory.
Definition n_git.c:210
int n_git_unstage(N_GIT_REPO *repo, const char *filepath)
Unstage a single file (reset from HEAD).
Definition n_git.c:366
int n_git_set_remote_auth(N_GIT_REPO *repo, const N_GIT_REMOTE_AUTH *auth)
Set remote authentication credentials on a repo handle.
Definition n_git.c:986
LIST * n_git_log(N_GIT_REPO *repo, size_t max_entries)
Retrieve commit log entries starting from HEAD.
Definition n_git.c:491
int n_git_stage_all(N_GIT_REPO *repo)
Stage all modified and untracked files.
Definition n_git.c:328
int n_git_stage(N_GIT_REPO *repo, const char *filepath)
Stage a single file by path.
Definition n_git.c:290
int n_git_create_branch(N_GIT_REPO *repo, const char *branch_name)
Create a new branch from HEAD.
Definition n_git.c:790
int n_git_current_branch(N_GIT_REPO *repo, char *out, size_t out_size)
Get the name of the current branch.
Definition n_git.c:879
int n_git_checkout_commit(N_GIT_REPO *repo, const char *hash)
Checkout a specific commit (detached HEAD).
Definition n_git.c:708
int n_git_commit(N_GIT_REPO *repo, const char *message, const char *author_name, const char *author_email)
Create a commit from the current index.
Definition n_git.c:412
N_GIT_REPO * n_git_open(const char *path)
Open an existing Git repository.
Definition n_git.c:123
N_STR * n_git_diff_workdir(N_GIT_REPO *repo)
Get a diff of the working directory against the index.
Definition n_git.c:567
N_GIT_REPO * n_git_init(const char *path)
Initialize a new Git repository.
Definition n_git.c:155
int n_git_delete_branch(N_GIT_REPO *repo, const char *branch_name)
Delete a local branch.
Definition n_git.c:909
Commit metadata.
Definition n_git.h:98
Credentials for remote operations.
Definition n_git.h:64
Wrapper around a git_repository handle.
Definition n_git.h:80
Single file status entry.
Definition n_git.h:90
Structure of a generic LIST container.
Definition n_list.h:58
A box including a string and his lenght.
Definition n_str.h:60
List structures and definitions.
N_STR and string function declaration.