Commit Diff


commit - 4e22badc0de082b8d0e6cbd19be4db4f15b86718
commit + 6a213ccb7e87e3f872b132929e50d71bed1c5588
blob - 08c283d8390b089b9626c241f60656e50481144a
blob + 3766bf10f01a20a065106dd7c8e13f2832f323fb
--- lib/diff.c
+++ lib/diff.c
@@ -161,9 +161,53 @@ diff_added_blob(struct got_object_id *id, struct got_r
 }
 
 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 g
 }
 
 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 
 			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 go
 
 	do {
 		if (te1) {
-			err = diff_entry_old_new(te1, tree2);
+			err = diff_entry_old_new(te1, tree2, repo);
 			if (err)
 				break;
 		}