public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Tianxiaoxiao1021 <bf_bug_feedback@126•com>
To: git@vger•kernel.org
Subject: Introduction of GpluginLoader Plugin for Git
Date: Sat, 18 Jan 2025 15:07:28 +0800 (CST)	[thread overview]
Message-ID: <cd89db5.1b48.194783cf396.Coremail.bf_bug_feedback@126.com> (raw)


[-- 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 

                 reply	other threads:[~2025-01-18  7:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cd89db5.1b48.194783cf396.Coremail.bf_bug_feedback@126.com \
    --to=bf_bug_feedback@126$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox