mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-04 20:29:08 -04:00
refactor: remove unnecessary try-catch
This commit is contained in:
parent
9190ed2e0f
commit
4f851bc2e5
3 changed files with 22 additions and 84 deletions
|
@ -22,20 +22,12 @@ class Config {
|
|||
libgit2.git_libgit2_init();
|
||||
|
||||
if (path == null) {
|
||||
try {
|
||||
_configPointer = bindings.openDefault().value;
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
_configPointer = bindings.openDefault().value;
|
||||
} else {
|
||||
try {
|
||||
if (File(path!).existsSync()) {
|
||||
_configPointer = bindings.open(path!).value;
|
||||
} else {
|
||||
throw Exception('File not found');
|
||||
}
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
if (File(path!).existsSync()) {
|
||||
_configPointer = bindings.open(path!).value;
|
||||
} else {
|
||||
throw Exception('File not found');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,25 +96,17 @@ class Config {
|
|||
|
||||
/// Returns the value of config [variable].
|
||||
String getValue(String variable) {
|
||||
try {
|
||||
return bindings.getValue(_configPointer, variable);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
return bindings.getValue(_configPointer, variable);
|
||||
}
|
||||
|
||||
/// Sets the [value] of config [variable].
|
||||
void setValue(String variable, dynamic value) {
|
||||
try {
|
||||
if (value.runtimeType == bool) {
|
||||
bindings.setBool(_configPointer, variable, value);
|
||||
} else if (value.runtimeType == int) {
|
||||
bindings.setInt(_configPointer, variable, value);
|
||||
} else {
|
||||
bindings.setString(_configPointer, variable, value);
|
||||
}
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
if (value.runtimeType == bool) {
|
||||
bindings.setBool(_configPointer, variable, value);
|
||||
} else if (value.runtimeType == int) {
|
||||
bindings.setInt(_configPointer, variable, value);
|
||||
} else {
|
||||
bindings.setString(_configPointer, variable, value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,11 +115,7 @@ class Config {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
void deleteEntry(String variable) {
|
||||
try {
|
||||
bindings.deleteEntry(_configPointer, variable);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
bindings.deleteEntry(_configPointer, variable);
|
||||
}
|
||||
|
||||
/// Returns list of values for multivar [variable]
|
||||
|
|
|
@ -17,11 +17,7 @@ class Oid {
|
|||
Oid.fromSHA(String sha) {
|
||||
libgit2.git_libgit2_init();
|
||||
|
||||
try {
|
||||
_oidPointer = bindings.fromSHA(sha);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
_oidPointer = bindings.fromSHA(sha);
|
||||
}
|
||||
|
||||
/// Initializes a new instance of [Oid] class from provided
|
||||
|
@ -39,13 +35,7 @@ class Oid {
|
|||
Pointer<git_oid> get pointer => _oidPointer;
|
||||
|
||||
/// Returns hexadecimal SHA-1 string.
|
||||
String get sha {
|
||||
try {
|
||||
return bindings.toSHA(_oidPointer);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
String get sha => bindings.toSHA(_oidPointer);
|
||||
|
||||
@override
|
||||
bool operator ==(other) {
|
||||
|
|
|
@ -20,11 +20,7 @@ class Repository {
|
|||
Repository.open(String path) {
|
||||
libgit2.git_libgit2_init();
|
||||
|
||||
try {
|
||||
_repoPointer = bindings.open(path);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
_repoPointer = bindings.open(path);
|
||||
}
|
||||
|
||||
/// Pointer to memory address for allocated repository object.
|
||||
|
@ -58,11 +54,7 @@ class Repository {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
void setNamespace(String? namespace) {
|
||||
try {
|
||||
bindings.setNamespace(_repoPointer, namespace);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
bindings.setNamespace(_repoPointer, namespace);
|
||||
}
|
||||
|
||||
/// Checks whether this repository is a bare repository or not.
|
||||
|
@ -82,11 +74,7 @@ class Repository {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
bool get isHeadDetached {
|
||||
try {
|
||||
return bindings.isHeadDetached(_repoPointer);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
return bindings.isHeadDetached(_repoPointer);
|
||||
}
|
||||
|
||||
/// Creates a new reference.
|
||||
|
@ -186,11 +174,7 @@ class Repository {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
void setHead(String reference) {
|
||||
try {
|
||||
bindings.setHead(_repoPointer, reference);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
bindings.setHead(_repoPointer, reference);
|
||||
}
|
||||
|
||||
/// Checks if the current branch is unborn.
|
||||
|
@ -200,11 +184,7 @@ class Repository {
|
|||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
bool get isBranchUnborn {
|
||||
try {
|
||||
return bindings.isBranchUnborn(_repoPointer);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
return bindings.isBranchUnborn(_repoPointer);
|
||||
}
|
||||
|
||||
/// Sets the identity to be used for writing reflogs.
|
||||
|
@ -235,13 +215,7 @@ class Repository {
|
|||
/// Don't forget to remove the file with [removeMessage] after you create the commit.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
String get message {
|
||||
try {
|
||||
return bindings.message(_repoPointer);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
String get message => bindings.message(_repoPointer);
|
||||
|
||||
/// Removes git's prepared message.
|
||||
void removeMessage() => bindings.removeMessage(_repoPointer);
|
||||
|
@ -255,13 +229,7 @@ class Repository {
|
|||
/// merge, revert, cherry-pick, etc. For example: MERGE_HEAD, MERGE_MSG, etc.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
void stateCleanup() {
|
||||
try {
|
||||
bindings.stateCleanup(_repoPointer);
|
||||
} catch (e) {
|
||||
rethrow;
|
||||
}
|
||||
}
|
||||
void stateCleanup() => bindings.stateCleanup(_repoPointer);
|
||||
|
||||
/// Returns the path of the working directory for this repository.
|
||||
///
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue