* Introduction of GpluginLoader Plugin for Git
@ 2025-01-18 7:07 Tianxiaoxiao1021
0 siblings, 0 replies; only message in thread
From: Tianxiaoxiao1021 @ 2025-01-18 7:07 UTC (permalink / raw)
To: git
[-- Attachment #1.1: Type: text/plain, Size: 661 bytes --]
Dear Git Community,
To address the different needs for workflows between community members and developers, I have developed GpluginLoader, a plugin loader for loading plugins based on c/c++ source code, and it is platform independent.
Additionally, I have included several source files to provide APIs for plugins, including functions for retrieving the current repository's README file, profile, and holder, among others. These APIs are encapsulated in the git-plugin-api.c and git-plugin-api.h files.
You can find the GpluginLoader repository here: https://github.com/Tianxiaoxiao1021/GpluginLoader.
Best regards,
Tianxiaoxiao developer team: Tianxiaoxiao1021
[-- Attachment #1.2: Type: text/html, Size: 836 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: git-plugin-api.c --]
[-- Type: text/x-c; name=git-plugin-api.c, Size: 2444 bytes --]
/*
* GpluginLoader:git-plugin-api.c
*
* 插件可调用的API实现
*/
#include "git-plugin-api.h"
#include "builtin.h"
#include "repository.h"
#include "strbuf.h"
#include "config.h"
static const char* git_get_repo_name(void) {
const char *gitdir = repo_git_path(the_repository, "");
if (!gitdir)
return NULL;
const char *last_slash = strrchr(gitdir, '/');
if (last_slash && strcmp(last_slash + 1, ".git") == 0) {
const char *parent_dir = last_slash - 1;
while (parent_dir > gitdir && *parent_dir != '/')
parent_dir--;
return parent_dir + 1;
}
return NULL;
}
static const char* git_get_repo_owner(void) {
const char *owner = NULL;
if (!git_config_get_string("user.name", &owner))
return owner;
return NULL;
}
static const char* git_get_repo_description(void) {
static struct strbuf buf = STRBUF_INIT;
strbuf_reset(&buf);
if (strbuf_read_file(&buf, repo_git_path(the_repository, "description"), 0) > 0)
return buf.buf;
return NULL;
}
static char* git_get_repo_readme(void) {
static const char *readme_names[] = {
"README.md",
"README",
"README.txt",
NULL
};
static struct strbuf buf = STRBUF_INIT;
const char **name;
strbuf_reset(&buf);
for (name = readme_names; *name; name++) {
if (strbuf_read_file(&buf, *name, 0) > 0)
return strbuf_detach(&buf, NULL);
}
return NULL;
}
static int git_add_command(const char *name, int (*fn)(int, const char **, const char *)) {
return register_builtin(name, fn);
}
static int git_modify_command(const char *name, int (*fn)(int, const char **, const char *)) {
if (unregister_builtin(name) != 0) {
return -1;
}
return register_builtin(name, fn);
}
static struct git_plugin_api plugin_api = {
.register_command = register_builtin,
.unregister_command = unregister_builtin,
.get_repository = the_repository,
.get_repo_name = git_get_repo_name,
.get_repo_owner = git_get_repo_owner,
.get_repo_description = git_get_repo_description,
.get_repo_readme = git_get_repo_readme,
.add_command = git_add_command,
.modify_command = git_modify_command
};
struct git_plugin_api* get_git_plugin_api(void) {
return &plugin_api;
}
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: git-plugin-api.h --]
[-- Type: text/x-c; name=git-plugin-api.h, Size: 840 bytes --]
#ifndef GIT_PLUGIN_API_H
#define GIT_PLUGIN_API_H
#include "repository.h"
struct git_plugin_api {
// 命令注册相关API
int (*register_command)(const char *name, int (*fn)(int, const char **, const char *));
int (*unregister_command)(const char *name);
struct repository* (*get_repository)(void);
// 仓库信息API
const char* (*get_repo_name)(void);
const char* (*get_repo_owner)(void);
const char* (*get_repo_description)(void);
char* (*get_repo_readme)(void);
// 新增API:添加和修改命令
int (*add_command)(const char *name, int (*fn)(int, const char **, const char *));
int (*modify_command)(const char *name, int (*fn)(int, const char **, const char *));
};
// 获取插件API实例
struct git_plugin_api* get_git_plugin_api(void);
#endif
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2025-01-18 7:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-18 7:07 Introduction of GpluginLoader Plugin for Git Tianxiaoxiao1021
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).