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 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
14 * implied. See the License for the specific language governing
15 * permissions and limitations under the License.
16 *
17 * SPDX-License-Identifier: Apache-2.0
18 */
19
28#ifndef __N_GIT_H__
29#define __N_GIT_H__
30
31#ifdef __cplusplus
32extern "C" {
33#endif
34
35#ifdef HAVE_LIBGIT2
36
42#include "nilorea/n_str.h"
43#include "nilorea/n_list.h"
44#include <git2.h>
45
47#define N_GIT_STATUS_NEW 1
49#define N_GIT_STATUS_MODIFIED 2
51#define N_GIT_STATUS_DELETED 4
53#define N_GIT_STATUS_STAGED 8
54
56#define N_GIT_AUTH_NONE 0
58#define N_GIT_AUTH_TOKEN 1
60#define N_GIT_AUTH_BASIC 2
62#define N_GIT_AUTH_SSH 3
63
79
81typedef struct N_GIT_REPO {
83 git_repository* repo;
85 char* path;
89 char last_status[512];
91
93typedef struct N_GIT_STATUS_ENTRY {
95 char path[512];
97 int flags;
99
101typedef struct N_GIT_COMMIT_INFO {
103 char hash[42];
105 char short_hash[10];
107 char message[512];
109 char author[256];
111 int64_t timestamp;
113
118N_GIT_REPO* n_git_open(const char* path);
119
124N_GIT_REPO* n_git_init(const char* path);
125
131N_GIT_REPO* n_git_init_ex(const char* path, const char* initial_branch);
132
136void n_git_close(N_GIT_REPO** repo);
137
143
157int n_git_stage(N_GIT_REPO* repo, const char* filepath);
158
163int n_git_stage_all(N_GIT_REPO* repo);
164
170int n_git_unstage(N_GIT_REPO* repo, const char* filepath);
171
179int n_git_commit(N_GIT_REPO* repo, const char* message, const char* author_name, const char* author_email);
180
186LIST* n_git_log(N_GIT_REPO* repo, size_t max_entries);
187
193
200N_STR* n_git_diff_commits(N_GIT_REPO* repo, const char* hash_a, const char* hash_b);
201
207int n_git_checkout_path(N_GIT_REPO* repo, const char* filepath);
208
214int n_git_checkout_commit(N_GIT_REPO* repo, const char* hash);
215
221
229int n_git_create_branch(N_GIT_REPO* repo, const char* branch_name);
230
236int n_git_switch_branch(N_GIT_REPO* repo, const char* branch_name);
237
244int n_git_current_branch(N_GIT_REPO* repo, char* out, size_t out_size);
245
251int n_git_delete_branch(N_GIT_REPO* repo, const char* branch_name);
252
260
267int n_git_remote_set_url(N_GIT_REPO* repo, const char* url);
268
274int n_git_push(N_GIT_REPO* repo);
275
282int n_git_pull(N_GIT_REPO* repo);
283
289int n_git_fetch(N_GIT_REPO* repo);
290
298int n_git_ahead_behind(N_GIT_REPO* repo, size_t* ahead, size_t* behind);
299
304#endif /* HAVE_LIBGIT2 */
305
306#ifdef __cplusplus
307}
308#endif
309
310#endif /* __N_GIT_H__ */
char short_hash[10]
short (abbreviated) hex hash
Definition n_git.h:105
char author[256]
author name and email
Definition n_git.h:109
int64_t timestamp
unix timestamp of the commit
Definition n_git.h:111
char message[512]
first line of commit message
Definition n_git.h:107
char * password
password or personal access token, or NULL
Definition n_git.h:71
char * ssh_privkey_path
path to SSH private key file, or NULL
Definition n_git.h:75
char hash[42]
full hex hash
Definition n_git.h:103
char * ssh_pubkey_path
path to SSH public key file, or NULL (derived from private key + ".pub")
Definition n_git.h:73
int flags
combination of N_GIT_STATUS_* flags
Definition n_git.h:97
char * path
filesystem path to the repository
Definition n_git.h:85
git_repository * repo
libgit2 repository handle
Definition n_git.h:83
char * ssh_passphrase
passphrase for SSH key, or NULL
Definition n_git.h:77
char last_status[512]
human-readable status message from the last operation
Definition n_git.h:89
int type
auth type: N_GIT_AUTH_NONE/TOKEN/BASIC/SSH
Definition n_git.h:67
char * username
username for basic auth or SSH, or NULL
Definition n_git.h:69
char path[512]
relative path of the file
Definition n_git.h:95
N_GIT_REMOTE_AUTH * remote_auth
credentials for remote operations, or NULL
Definition n_git.h:87
void n_git_close(N_GIT_REPO **repo)
Close a Git repository and free resources.
Definition n_git.c:241
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:714
int n_git_fetch(N_GIT_REPO *repo)
Fetch from the "origin" remote without merging.
Definition n_git.c:1438
int n_git_push(N_GIT_REPO *repo)
Push the current branch to the "origin" remote.
Definition n_git.c:1225
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:1187
int n_git_switch_branch(N_GIT_REPO *repo, const char *branch_name)
Switch to an existing local branch.
Definition n_git.c:980
int n_git_pull(N_GIT_REPO *repo)
Fetch from "origin" and fast-forward merge the current branch.
Definition n_git.c:1295
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:796
LIST * n_git_list_branches(N_GIT_REPO *repo)
List all local branch names.
Definition n_git.c:868
LIST * n_git_status(N_GIT_REPO *repo)
Get the status of all files in the working directory.
Definition n_git.c:266
int n_git_unstage(N_GIT_REPO *repo, const char *filepath)
Unstage a single file (reset from HEAD).
Definition n_git.c:458
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:1154
LIST * n_git_log(N_GIT_REPO *repo, size_t max_entries)
Retrieve commit log entries starting from HEAD.
Definition n_git.c:596
N_GIT_REPO * n_git_init_ex(const char *path, const char *initial_branch)
Initialize a new Git repository with a custom initial branch name.
Definition n_git.c:205
int n_git_stage_all(N_GIT_REPO *repo)
Stage all modified and untracked files.
Definition n_git.c:416
int n_git_stage(N_GIT_REPO *repo, const char *filepath)
Stage a file or directory by path.
Definition n_git.c:354
int n_git_ahead_behind(N_GIT_REPO *repo, size_t *ahead, size_t *behind)
Count commits ahead and behind relative to the remote tracking branch.
Definition n_git.c:1477
int n_git_create_branch(N_GIT_REPO *repo, const char *branch_name)
Create a new branch from HEAD.
Definition n_git.c:911
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:1030
int n_git_checkout_commit(N_GIT_REPO *repo, const char *hash)
Checkout a specific commit (detached HEAD).
Definition n_git.c:827
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:507
N_GIT_REPO * n_git_open(const char *path)
Open an existing Git repository.
Definition n_git.c:163
N_STR * n_git_diff_workdir(N_GIT_REPO *repo)
Get a diff of the working directory against the index.
Definition n_git.c:684
N_GIT_REPO * n_git_init(const char *path)
Initialize a new Git repository.
Definition n_git.c:195
int n_git_delete_branch(N_GIT_REPO *repo, const char *branch_name)
Delete a local branch.
Definition n_git.c:1079
Commit metadata.
Definition n_git.h:101
Credentials for remote operations.
Definition n_git.h:65
Wrapper around a git_repository handle.
Definition n_git.h:81
Single file status entry.
Definition n_git.h:93
Structure of a generic LIST container.
Definition n_list.h:59
A box including a string and his lenght.
Definition n_str.h:61
List structures and definitions.
N_STR and string function declaration.