summaryrefslogtreecommitdiff
path: root/src/diff.h
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-07-24 17:48:37 -0700
committerRussell Belfer <rb@github.com>2013-07-24 17:48:37 -0700
commiteffdbeb3239b777e2b19fc4944643fc7f2a768c3 (patch)
tree997fc8b3a975010d7a9df07226bda8d5c0e92dea /src/diff.h
parenta5140f4dda66263a34080b11cfc34a49c9743100 (diff)
downloadlibgit2-effdbeb3239b777e2b19fc4944643fc7f2a768c3.tar.gz
Make rename detection file size fix better
The previous fix for checking file sizes with rename detection always loads the blob. In this version, if the odb backend can get the object header without loading the whole thing into memory, then we'll just use that, so that we can eliminate possible rename sources & targets without loading them.
Diffstat (limited to 'src/diff.h')
-rw-r--r--src/diff.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/diff.h b/src/diff.h
index d09a130bc..d1bec00c6 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -16,6 +16,7 @@
#include "iterator.h"
#include "repository.h"
#include "pool.h"
+#include "odb.h"
#define DIFF_OLD_PREFIX_DEFAULT "a/"
#define DIFF_NEW_PREFIX_DEFAULT "b/"
@@ -108,5 +109,33 @@ extern void git_diff_find_similar__hashsig_free(void *sig, void *payload);
extern int git_diff_find_similar__calc_similarity(
int *score, void *siga, void *sigb, void *payload);
+/*
+ * Sometimes a git_diff_file will have a zero size; this attempts to
+ * fill in the size without loading the blob if possible. If that is
+ * not possible, then it will return the git_odb_object that had to be
+ * loaded and the caller can use it or dispose of it as needed.
+ */
+GIT_INLINE(int) git_diff_file__resolve_zero_size(
+ git_diff_file *file, git_odb_object **odb_obj, git_repository *repo)
+{
+ int error;
+ git_odb *odb;
+ size_t len;
+ git_otype type;
+
+ if ((error = git_repository_odb(&odb, repo)) < 0)
+ return error;
+
+ error = git_odb__read_header_or_object(
+ odb_obj, &len, &type, odb, &file->oid);
+
+ git_odb_free(odb);
+
+ if (!error)
+ file->size = (git_off_t)len;
+
+ return error;
+}
+
#endif