Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fuzzers/config_file_fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
goto out;
}

if ((err = git_config_backend_from_string(&backend, (const char*)data, size)) != 0) {
if ((err = git_config_backend_from_string(&backend, (const char*)data, size, NULL)) != 0) {
goto out;
}
if ((err = git_config_add_backend(cfg, backend, 0, NULL, 0)) != 0) {
Expand Down
32 changes: 26 additions & 6 deletions include/git2/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,32 @@ typedef enum {
* An entry in a configuration file
*/
typedef struct git_config_entry {
const char *name; /**< Name of the entry (normalised) */
const char *value; /**< String value of the entry */
unsigned int include_depth; /**< Depth of includes where this variable was found */
git_config_level_t level; /**< Which config file this was found in */
void GIT_CALLBACK(free)(struct git_config_entry *entry); /**< Free function for this entry */
void *payload; /**< Opaque value for the free function. Do not read or write */
/** Name of the configuration entry (normalized) */
const char *name;

/** Literal (string) value of the entry */
const char *value;

/** The type of backend that this entry exists in (eg, "file") */
const char *backend_type;

/**
* The path to the origin of this entry. For config files, this is
* the path to the file.
*/
const char *origin_path;

/** Depth of includes where this variable was found */
unsigned int include_depth;

/** Configuration level for the file this was found in */
git_config_level_t level;

/**
* Free function for this entry; for internal purposes. Callers
* should call `git_config_entry_free` to free data.
*/
void GIT_CALLBACK(free)(struct git_config_entry *entry);
} git_config_entry;

/**
Expand Down
51 changes: 51 additions & 0 deletions include/git2/sys/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,57 @@ GIT_EXTERN(int) git_config_add_backend(
const git_repository *repo,
int force);

/** Options for in-memory configuration backends. */
typedef struct {
unsigned int version;

/**
* The type of this backend (eg, "command line"). If this is
* NULL, then this will be "in-memory".
*/
const char *backend_type;

/**
* The path to the origin; if this is NULL then it will be
* left unset in the resulting configuration entries.
*/
const char *origin_path;
} git_config_backend_memory_options;

#define GIT_CONFIG_BACKEND_MEMORY_OPTIONS_VERSION 1
#define GIT_CONFIG_BACKEND_MEMORY_OPTIONS_INIT { GIT_CONFIG_BACKEND_MEMORY_OPTIONS_VERSION }


/**
* Create an in-memory configuration backend from a string in standard
* git configuration file format.
*
* @param out the new backend
* @param cfg the configuration that is to be parsed
* @param len the length of the string pointed to by `cfg`
* @param opts the options to initialize this backend with, or NULL
*/
extern int git_config_backend_from_string(
git_config_backend **out,
const char *cfg,
size_t len,
git_config_backend_memory_options *opts);

/**
* Create an in-memory configuration backend from a list of name/value
* pairs.
*
* @param out the new backend
* @param values the configuration values to set (in "key=value" format)
* @param len the length of the values array
* @param opts the options to initialize this backend with, or NULL
*/
extern int git_config_backend_from_values(
git_config_backend **out,
const char **values,
size_t len,
git_config_backend_memory_options *opts);

/** @} */
GIT_END_DECL
#endif
2 changes: 1 addition & 1 deletion src/cli/cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* a Linking Exception. For full terms see the included COPYING file.
*/

#include "cli.h"
#include "common.h"
#include "cmd.h"

const cli_cmd_spec *cli_cmd_spec_byname(const char *name)
Expand Down
1 change: 1 addition & 0 deletions src/cli/cmd.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ extern const cli_cmd_spec *cli_cmd_spec_byname(const char *name);
/* Commands */
extern int cmd_cat_file(int argc, char **argv);
extern int cmd_clone(int argc, char **argv);
extern int cmd_config(int argc, char **argv);
extern int cmd_hash_object(int argc, char **argv);
extern int cmd_help(int argc, char **argv);

Expand Down
9 changes: 4 additions & 5 deletions src/cli/cmd_cat_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

#include <git2.h>
#include "cli.h"
#include "common.h"
#include "cmd.h"

#define COMMAND_NAME "cat-file"
Expand All @@ -24,9 +24,7 @@ static int display = DISPLAY_CONTENT;
static char *type_name, *object_spec;

static const cli_opt_spec opts[] = {
{ CLI_OPT_TYPE_SWITCH, "help", 0, &show_help, 1,
CLI_OPT_USAGE_HIDDEN | CLI_OPT_USAGE_STOP_PARSING, NULL,
"display help about the " COMMAND_NAME " command" },
CLI_COMMON_OPT,

{ CLI_OPT_TYPE_SWITCH, NULL, 't', &display, DISPLAY_TYPE,
CLI_OPT_USAGE_REQUIRED, NULL, "display the type of the object" },
Expand Down Expand Up @@ -139,6 +137,7 @@ static int print_pretty(git_object *object)

int cmd_cat_file(int argc, char **argv)
{
cli_repository_open_options open_opts = { argv + 1, argc - 1};
git_repository *repo = NULL;
git_object *object = NULL;
git_object_t type;
Expand All @@ -153,7 +152,7 @@ int cmd_cat_file(int argc, char **argv)
return 0;
}

if (git_repository_open_ext(&repo, ".", GIT_REPOSITORY_OPEN_FROM_ENV, NULL) < 0)
if (cli_repository_open(&repo, &open_opts) < 0)
return cli_error_git();

if ((giterr = git_revparse_single(&object, repo, object_spec)) < 0) {
Expand Down
6 changes: 2 additions & 4 deletions src/cli/cmd_clone.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <stdio.h>
#include <git2.h>
#include "cli.h"
#include "common.h"
#include "cmd.h"
#include "error.h"
#include "sighandler.h"
Expand All @@ -24,9 +24,7 @@ static bool local_path_exists;
static cli_progress progress = CLI_PROGRESS_INIT;

static const cli_opt_spec opts[] = {
{ CLI_OPT_TYPE_SWITCH, "help", 0, &show_help, 1,
CLI_OPT_USAGE_HIDDEN | CLI_OPT_USAGE_STOP_PARSING, NULL,
"display help about the " COMMAND_NAME " command" },
CLI_COMMON_OPT,

{ CLI_OPT_TYPE_SWITCH, "quiet", 'q', &quiet, 1,
CLI_OPT_USAGE_DEFAULT, NULL, "display the type of the object" },
Expand Down
Loading