git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Introduction of GpluginLoader Plugin for Git

From
TTianxiaoxiao1021 <bf_bug_feedback@126.com>
Date
Jan 18, 2025, 07:07 UTC
Message-ID
<cd89db5.1b48.194783cf396.Coremail.bf_bug_feedback@126.com>

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

/*
* 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;
}

#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 
Message 1 of 1 in “Introduction of GpluginLoader Plugin for Git”
  1. Tianxiaoxiao1021Jan 18, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.