Introduction of GpluginLoader Plugin for Git

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux