mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 12:49:08 -04:00
feat(diff): add ability to get patchid
This commit is contained in:
parent
a7b714c2f3
commit
f7f4a395c0
3 changed files with 34 additions and 0 deletions
|
@ -199,6 +199,27 @@ void findSimilar(
|
|||
calloc.free(opts);
|
||||
}
|
||||
|
||||
/// Calculate the patch ID for the given patch.
|
||||
///
|
||||
/// Calculate a stable patch ID for the given patch by summing the hash of the file diffs,
|
||||
/// ignoring whitespace and line numbers. This can be used to derive whether two diffs are
|
||||
/// the same with a high probability.
|
||||
///
|
||||
/// Currently, this function only calculates stable patch IDs, as defined in `git-patch-id(1)`,
|
||||
/// and should in fact generate the same IDs as the upstream git project does.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
Pointer<git_oid> patchId(Pointer<git_diff> diff) {
|
||||
final out = calloc<git_oid>();
|
||||
final error = libgit2.git_diff_patchid(out, diff, nullptr);
|
||||
|
||||
if (error < 0) {
|
||||
throw LibGit2Error(libgit2.git_error_last());
|
||||
} else {
|
||||
return out;
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the diff delta for an entry in the diff list.
|
||||
///
|
||||
/// Throws [RangeError] if index out of range.
|
||||
|
|
|
@ -75,6 +75,18 @@ class Diff {
|
|||
);
|
||||
}
|
||||
|
||||
/// Calculate the patch ID for the given patch.
|
||||
///
|
||||
/// Calculate a stable patch ID for the given patch by summing the hash of the file diffs,
|
||||
/// ignoring whitespace and line numbers. This can be used to derive whether two diffs are
|
||||
/// the same with a high probability.
|
||||
///
|
||||
/// Currently, this function only calculates stable patch IDs, as defined in `git-patch-id(1)`,
|
||||
/// and should in fact generate the same IDs as the upstream git project does.
|
||||
///
|
||||
/// Throws a [LibGit2Error] if error occured.
|
||||
Oid get patchId => Oid(bindings.patchId(_diffPointer));
|
||||
|
||||
/// Releases memory allocated for diff object.
|
||||
void free() => bindings.free(_diffPointer);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue