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
12 changes: 12 additions & 0 deletions src/config_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@
*/
extern int git_config_backend_from_file(git_config_backend **out, const char *path);

/**
* Create a readonly configuration file backend from another backend
*
* This copies the complete contents of the source backend to the
* new backend. The new backend will be completely read-only and
* cannot be modified.
*
* @param out the new snapshotted backend
* @param source the backend to copy
*/
extern int git_config_backend_snapshot(git_config_backend **out, git_config_backend *source);

/**
* Create an in-memory configuration file backend
*
Expand Down
47 changes: 32 additions & 15 deletions src/config_entries.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,36 @@ int git_config_entries_new(git_config_entries **out)
return error;
}

int git_config_entries_dup_entry(git_config_entries *entries, const git_config_entry *entry)
Comment thread
tiennou marked this conversation as resolved.
{
git_config_entry *duplicated;
int error;

duplicated = git__calloc(1, sizeof(git_config_entry));
GIT_ERROR_CHECK_ALLOC(duplicated);

duplicated->name = git__strdup(entry->name);
GIT_ERROR_CHECK_ALLOC(duplicated->name);

if (entry->value) {
duplicated->value = git__strdup(entry->value);
GIT_ERROR_CHECK_ALLOC(duplicated->value);
}
duplicated->level = entry->level;
duplicated->include_depth = entry->include_depth;

if ((error = git_config_entries_append(entries, duplicated)) < 0)
goto out;

out:
if (error && duplicated) {
git__free((char *) duplicated->name);
git__free((char *) duplicated->value);
git__free(duplicated);
}
return error;
}

int git_config_entries_dup(git_config_entries **out, git_config_entries *entries)
{
git_config_entries *result = NULL;
Expand All @@ -76,22 +106,9 @@ int git_config_entries_dup(git_config_entries **out, git_config_entries *entries
if ((error = git_config_entries_new(&result)) < 0)
goto out;

for (head = entries->list; head; head = head->next) {
git_config_entry *dup;

dup = git__calloc(1, sizeof(git_config_entry));
dup->name = git__strdup(head->entry->name);
GIT_ERROR_CHECK_ALLOC(dup->name);
if (head->entry->value) {
dup->value = git__strdup(head->entry->value);
GIT_ERROR_CHECK_ALLOC(dup->value);
}
dup->level = head->entry->level;
dup->include_depth = head->entry->include_depth;

if ((error = git_config_entries_append(result, dup)) < 0)
for (head = entries->list; head; head = head->next)
if ((git_config_entries_dup_entry(result, head->entry)) < 0)
goto out;
}

*out = result;
result = NULL;
Expand Down
1 change: 1 addition & 0 deletions src/config_entries.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ typedef struct git_config_entries git_config_entries;

int git_config_entries_new(git_config_entries **out);
int git_config_entries_dup(git_config_entries **out, git_config_entries *entries);
int git_config_entries_dup_entry(git_config_entries *entries, const git_config_entry *entry);
void git_config_entries_incref(git_config_entries *entries);
void git_config_entries_free(git_config_entries *entries);
/* Add or append the new config option */
Expand Down
Loading