refactor: use clearer names for params

This commit is contained in:
Aleksey Kulikov 2021-06-18 17:19:01 +03:00
parent 2d1c026e73
commit 4bc2da5800
2 changed files with 34 additions and 34 deletions

View file

@ -140,11 +140,11 @@ String getValue(Pointer<git_config> cfg, String variable) {
/// highest level (usually the local one). /// highest level (usually the local one).
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void setBool(Pointer<git_config> cfg, String name, bool value) { void setBool(Pointer<git_config> cfg, String variable, bool value) {
final nameC = name.toNativeUtf8().cast<Int8>(); final name = variable.toNativeUtf8().cast<Int8>();
final valueC = value ? 1 : 0; final valueC = value ? 1 : 0;
final error = libgit2.git_config_set_bool(cfg, nameC, valueC); final error = libgit2.git_config_set_bool(cfg, name, valueC);
calloc.free(nameC); calloc.free(name);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -155,10 +155,10 @@ void setBool(Pointer<git_config> cfg, String name, bool value) {
/// highest level (usually the local one). /// highest level (usually the local one).
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void setInt(Pointer<git_config> cfg, String name, int value) { void setInt(Pointer<git_config> cfg, String variable, int value) {
final nameC = name.toNativeUtf8().cast<Int8>(); final name = variable.toNativeUtf8().cast<Int8>();
final error = libgit2.git_config_set_int64(cfg, nameC, value); final error = libgit2.git_config_set_int64(cfg, name, value);
calloc.free(nameC); calloc.free(name);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -169,11 +169,11 @@ void setInt(Pointer<git_config> cfg, String name, int value) {
/// highest level (usually the local one). /// highest level (usually the local one).
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void setString(Pointer<git_config> cfg, String name, String value) { void setString(Pointer<git_config> cfg, String variable, String value) {
final nameC = name.toNativeUtf8().cast<Int8>(); final name = variable.toNativeUtf8().cast<Int8>();
final valueC = value.toNativeUtf8().cast<Int8>(); final valueC = value.toNativeUtf8().cast<Int8>();
final error = libgit2.git_config_set_string(cfg, nameC, valueC); final error = libgit2.git_config_set_string(cfg, name, valueC);
calloc.free(nameC); calloc.free(name);
calloc.free(valueC); calloc.free(valueC);
if (error < 0) { if (error < 0) {
@ -204,10 +204,10 @@ Map<String, String> getEntries(Pointer<git_config> cfg) {
/// (usually the local one). /// (usually the local one).
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void deleteVariable(Pointer<git_config> cfg, String name) { void deleteVariable(Pointer<git_config> cfg, String variable) {
final nameC = name.toNativeUtf8().cast<Int8>(); final name = variable.toNativeUtf8().cast<Int8>();
final error = libgit2.git_config_delete_entry(cfg, nameC); final error = libgit2.git_config_delete_entry(cfg, name);
calloc.free(nameC); calloc.free(name);
if (error < 0) { if (error < 0) {
throw LibGit2Error(libgit2.git_error_last()); throw LibGit2Error(libgit2.git_error_last());
@ -220,14 +220,14 @@ void deleteVariable(Pointer<git_config> cfg, String name) {
/// values which match the pattern. /// values which match the pattern.
List<String> getMultivar( List<String> getMultivar(
Pointer<git_config> cfg, Pointer<git_config> cfg,
String name, String variable,
String? regexp, String? regexp,
) { ) {
final nameC = name.toNativeUtf8().cast<Int8>(); final name = variable.toNativeUtf8().cast<Int8>();
final regexpC = regexp?.toNativeUtf8().cast<Int8>() ?? nullptr; final regexpC = regexp?.toNativeUtf8().cast<Int8>() ?? nullptr;
final iterator = calloc<Pointer<git_config_iterator>>(); final iterator = calloc<Pointer<git_config_iterator>>();
final entry = calloc<Pointer<git_config_entry>>(); final entry = calloc<Pointer<git_config_entry>>();
libgit2.git_config_multivar_iterator_new(iterator, cfg, nameC, regexpC); libgit2.git_config_multivar_iterator_new(iterator, cfg, name, regexpC);
var error = 0; var error = 0;
final entries = <String>[]; final entries = <String>[];
@ -240,7 +240,7 @@ List<String> getMultivar(
} }
} }
calloc.free(nameC); calloc.free(name);
calloc.free(regexpC); calloc.free(regexpC);
calloc.free(iterator); calloc.free(iterator);
calloc.free(entry); calloc.free(entry);
@ -254,16 +254,16 @@ List<String> getMultivar(
/// The regular expression is applied case-sensitively on the value. /// The regular expression is applied case-sensitively on the value.
void setMultivar( void setMultivar(
Pointer<git_config> cfg, Pointer<git_config> cfg,
String name, String variable,
String regexp, String regexp,
String value, String value,
) { ) {
final nameC = name.toNativeUtf8().cast<Int8>(); final name = variable.toNativeUtf8().cast<Int8>();
final regexpC = regexp.toNativeUtf8().cast<Int8>(); final regexpC = regexp.toNativeUtf8().cast<Int8>();
final valueC = value.toNativeUtf8().cast<Int8>(); final valueC = value.toNativeUtf8().cast<Int8>();
libgit2.git_config_set_multivar(cfg, nameC, regexpC, valueC); libgit2.git_config_set_multivar(cfg, name, regexpC, valueC);
calloc.free(nameC); calloc.free(name);
calloc.free(regexpC); calloc.free(regexpC);
calloc.free(valueC); calloc.free(valueC);
} }

View file

@ -134,33 +134,33 @@ class Config {
} }
} }
/// Deletes variable from the config file with the highest level /// Deletes [variable] from the config file with the highest level
/// (usually the local one). /// (usually the local one).
/// ///
/// Throws a [LibGit2Error] if error occured. /// Throws a [LibGit2Error] if error occured.
void deleteVariable(String key) { void deleteVariable(String variable) {
try { try {
config.deleteVariable(configPointer.value, key); config.deleteVariable(configPointer.value, variable);
} catch (e) { } catch (e) {
rethrow; rethrow;
} }
} }
/// Returns list of values for multivar [key] /// Returns list of values for multivar [variable]
/// ///
/// If [regexp] is present, then the iterator will only iterate over all /// If [regexp] is present, then the iterator will only iterate over all
/// values which match the pattern. /// values which match the pattern.
List<String> getMultivar(String key, {String? regexp}) { List<String> getMultivar(String variable, {String? regexp}) {
return config.getMultivar(configPointer.value, key, regexp); return config.getMultivar(configPointer.value, variable, regexp);
} }
/// Sets the [value] of a multivar [key] in the config file with the /// Sets the [value] of a multivar [variable] in the config file with the
/// highest level (usually the local one). /// highest level (usually the local one).
/// ///
/// The [regexp] is applied case-sensitively on the value. /// The [regexp] is applied case-sensitively on the value.
/// Empty [regexp] sets [value] for all values of a multivar [key] /// Empty [regexp] sets [value] for all values of a multivar [variable]
void setMultivar(String key, String regexp, String value) { void setMultivar(String variable, String regexp, String value) {
config.setMultivar(configPointer.value, key, regexp, value); config.setMultivar(configPointer.value, variable, regexp, value);
} }
/// Releases memory allocated for config object. /// Releases memory allocated for config object.