add some unimplemented stubs for tree diffing
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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163
diff --git a/include/got_diff.h b/include/got_diff.h
index 8ba8533..78322cd 100644
--- a/include/got_diff.h
+++ b/include/got_diff.h
@@ -16,3 +16,5 @@
const struct got_error *got_diff_blob(struct got_blob_object *,
struct got_blob_object *, const char *, const char *, FILE *);
+const struct got_error *got_diff_tree(struct got_tree_object *,
+ struct got_tree_object *, struct got_repository *);
diff --git a/lib/diff.c b/lib/diff.c
index 0032f42..5588ba0 100644
--- a/lib/diff.c
+++ b/lib/diff.c
@@ -53,7 +53,7 @@ open_tempfile(FILE **sfp, char **sfn)
const struct got_error *
got_diff_blob(struct got_blob_object *blob1, struct got_blob_object *blob2,
- const char *label1, const char *label2 ,FILE *outfile)
+ const char *label1, const char *label2, FILE *outfile)
{
struct got_diff_state ds;
struct got_diff_args args;
@@ -119,3 +119,139 @@ done:
free(n2);
return err;
}
+
+static const struct got_error *
+match_entry_by_name(struct got_tree_entry **te, struct got_tree_entry *te1,
+ struct got_tree_object *tree2)
+{
+ *te = NULL;
+ return NULL;
+}
+
+static int
+same_id(struct got_object_id *id1, struct got_object_id *id2)
+{
+ return (memcmp(id1->sha1, id2->sha1, SHA1_DIGEST_LENGTH) == 0);
+}
+
+static const struct got_error *
+diff_added_blob(struct got_object_id *id)
+{
+ return NULL;
+}
+
+static const struct got_error *
+diff_modified_blob(struct got_object_id *id1, struct got_object_id *id2)
+{
+ return NULL;
+}
+
+static const struct got_error *
+diff_deleted_blob(struct got_object_id *id)
+{
+ return NULL;
+}
+
+static const struct got_error *
+diff_added_tree(struct got_object_id *id)
+{
+ return NULL;
+}
+
+static const struct got_error *
+diff_modified_tree(struct got_object_id *id1, struct got_object_id *id2)
+{
+ return NULL;
+}
+
+static const struct got_error *
+diff_deleted_tree(struct got_object_id *id)
+{
+ return NULL;
+}
+
+static const struct got_error *
+diff_kind_mismatch(struct got_object_id *id1, struct got_object_id *id2)
+{
+ return NULL;
+}
+
+static const struct got_error *
+diff_entry_old_new(struct got_tree_entry *te1, struct got_tree_object *tree2)
+{
+ const struct got_error *err;
+ struct got_tree_entry *te2;
+
+ err = match_entry_by_name(&te2, te1, tree2);
+ if (err)
+ return err;
+ if (te2 == NULL) {
+ if (S_ISDIR(te1->mode))
+ return diff_deleted_tree(&te1->id);
+ return diff_deleted_blob(&te1->id);
+ }
+
+ if (S_ISDIR(te1->mode) == S_ISDIR(te2->mode)) {
+ if (!same_id(&te1->id, &te2->id))
+ 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);
+ } else
+ return diff_kind_mismatch(&te1->id, &te2->id);
+
+ return NULL;
+}
+
+static const struct got_error *
+diff_entry_new_old(struct got_tree_entry *te2, struct got_tree_object *tree1)
+{
+ const struct got_error *err;
+ struct got_tree_entry *te1;
+
+ err = match_entry_by_name(&te1, te2, tree1);
+ if (err)
+ return err;
+ if (te1 != NULL) /* handled by diff_entry_old_new() */
+ return NULL;
+
+ if (S_ISDIR(te2->mode))
+ return diff_added_tree(&te2->id);
+ return diff_added_blob(&te2->id);
+}
+
+const struct got_error *
+got_diff_tree(struct got_tree_object *tree1, struct got_tree_object *tree2,
+ struct got_repository *repo)
+{
+ const struct got_error *err = NULL;
+ struct got_tree_entry *te1;
+ struct got_tree_entry *te2;
+
+ if (tree1->nentries == 0 && tree2->nentries == 0)
+ return NULL;
+
+ te1 = SIMPLEQ_FIRST(&tree1->entries);
+ te2 = SIMPLEQ_FIRST(&tree2->entries);
+
+ do {
+ if (te1) {
+ err = diff_entry_old_new(te1, tree2);
+ if (err)
+ break;
+ }
+
+ if (te2) {
+ err = diff_entry_new_old(te2, tree1);
+ if (err)
+ break;
+ }
+
+ if (te1)
+ te1 = SIMPLEQ_NEXT(te1, entry);
+ if (te2)
+ te2 = SIMPLEQ_NEXT(te2, entry);
+ } while (te1 || te2);
+
+ return err;
+}