mirror of
https://github.com/SkinnyMind/libgit2dart.git
synced 2025-05-05 04:39:07 -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);
|
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.
|
/// Return the diff delta for an entry in the diff list.
|
||||||
///
|
///
|
||||||
/// Throws [RangeError] if index out of range.
|
/// 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.
|
/// Releases memory allocated for diff object.
|
||||||
void free() => bindings.free(_diffPointer);
|
void free() => bindings.free(_diffPointer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,6 +188,7 @@ index e69de29..c217c63 100644
|
||||||
expect(diff.length, 1);
|
expect(diff.length, 1);
|
||||||
expect(stats.filesChanged, 1);
|
expect(stats.filesChanged, 1);
|
||||||
expect(stats.insertions, 1);
|
expect(stats.insertions, 1);
|
||||||
|
expect(diff.patchId.sha, '699556913185bc38632ae20a49d5c18b9233335e');
|
||||||
|
|
||||||
stats.free();
|
stats.free();
|
||||||
diff.free();
|
diff.free();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue