implement diff_modified_blob
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
diff --git a/lib/diff.c b/lib/diff.c
index 08c283d..3766bf1 100644
--- a/lib/diff.c
+++ b/lib/diff.c
@@ -161,9 +161,53 @@ diff_added_blob(struct got_object_id *id, struct got_repository *repo)
}
static const struct got_error *
-diff_modified_blob(struct got_object_id *id1, struct got_object_id *id2)
+diff_modified_blob(struct got_object_id *id1, struct got_object_id *id2,
+ struct got_repository *repo)
{
- return NULL;
+ const struct got_error *err;
+ struct got_object *obj1 = NULL;
+ struct got_object *obj2 = NULL;
+ struct got_blob_object *blob1 = NULL;
+ struct got_blob_object *blob2 = NULL;
+
+ err = got_object_open(&obj1, repo, id1);
+ if (err)
+ return got_error(GOT_ERR_BAD_OBJ_HDR);
+ if (obj1->type != GOT_OBJ_TYPE_BLOB) {
+ err = got_error(GOT_ERR_OBJ_TYPE);
+ goto done;
+ }
+
+ err = got_object_open(&obj2, repo, id2);
+ if (err) {
+ err= got_error(GOT_ERR_BAD_OBJ_HDR);
+ goto done;
+ }
+ if (obj2->type != GOT_OBJ_TYPE_BLOB) {
+ err = got_error(GOT_ERR_BAD_OBJ_DATA);
+ goto done;
+ }
+
+ err = got_object_blob_open(&blob1, repo, obj1, 512);
+ if (err != NULL) {
+ err = got_error(GOT_ERR_FILE_OPEN);
+ goto done;
+ }
+
+ err = got_object_blob_open(&blob2, repo, obj2, 512);
+ if (err != NULL) {
+ err = got_error(GOT_ERR_FILE_OPEN);
+ goto done;
+ }
+
+ err = got_diff_blob(blob1, blob2, NULL, NULL, stdout);
+
+done:
+ got_object_close(obj1);
+ got_object_close(obj2);
+ got_object_blob_close(blob1);
+ got_object_blob_close(blob2);
+ return err;
}
static const struct got_error *
@@ -197,7 +241,8 @@ diff_kind_mismatch(struct got_object_id *id1, struct got_object_id *id2)
}
static const struct got_error *
-diff_entry_old_new(struct got_tree_entry *te1, struct got_tree_object *tree2)
+diff_entry_old_new(struct got_tree_entry *te1, struct got_tree_object *tree2,
+ struct got_repository *repo)
{
const struct got_error *err;
struct got_tree_entry *te2;
@@ -216,7 +261,7 @@ diff_entry_old_new(struct got_tree_entry *te1, struct got_tree_object *tree2)
return diff_modified_tree(&te1->id, &te2->id);
} else if (S_ISREG(te1->mode) && S_ISREG(te2->mode)) {
if (!same_id(&te1->id, &te2->id))
- return diff_modified_blob(&te1->id, &te2->id);
+ return diff_modified_blob(&te1->id, &te2->id, repo);
}
return diff_kind_mismatch(&te1->id, &te2->id);
@@ -256,7 +301,7 @@ got_diff_tree(struct got_tree_object *tree1, struct got_tree_object *tree2,
do {
if (te1) {
- err = diff_entry_old_new(te1, tree2);
+ err = diff_entry_old_new(te1, tree2, repo);
if (err)
break;
}