aboutsummaryrefslogtreecommitdiff
path: root/difftool
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-21 12:41:31 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2019-08-21 12:42:40 +0200
commite27ddbbbc74e931c1e53ec5fe1d559a1ba106032 (patch)
tree8821645711feb86471a419594c61336b4cb41ade /difftool
parente14ffcf8e092758bc21d0d5c795b58ea0b1773f2 (diff)
Cleanup difftool dir entry comparion
- Replace a/b nomenclature with old/new - Remove special case handling that isn't needed Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'difftool')
-rw-r--r--difftool/compare_dir.c92
1 files changed, 32 insertions, 60 deletions
diff --git a/difftool/compare_dir.c b/difftool/compare_dir.c
index 8d4a186..cc3f8bc 100644
--- a/difftool/compare_dir.c
+++ b/difftool/compare_dir.c
@@ -6,90 +6,62 @@
*/
#include "difftool.h"
-int compare_dir_entries(tree_node_t *a, tree_node_t *b)
+int compare_dir_entries(tree_node_t *old, tree_node_t *new)
{
- tree_node_t *ait = a->data.dir->children, *aprev = NULL;
- tree_node_t *bit = b->data.dir->children, *bprev = NULL;
+ tree_node_t *old_it = old->data.dir->children, *old_prev = NULL;
+ tree_node_t *new_it = new->data.dir->children, *new_prev = NULL;
int ret, result = 0;
- char *path, arrow;
+ char *path;
- while (ait != NULL && bit != NULL) {
- ret = strcmp(ait->name, bit->name);
+ while (old_it != NULL || new_it != NULL) {
+ if (old_it != NULL && new_it != NULL) {
+ ret = strcmp(old_it->name, new_it->name);
+ } else if (old_it == NULL) {
+ ret = 1;
+ } else {
+ ret = -1;
+ }
if (ret < 0) {
result = 1;
- path = node_path(ait);
+ path = node_path(old_it);
if (path == NULL)
return -1;
fprintf(stdout, "< %s\n", path);
free(path);
- if (aprev == NULL) {
- a->data.dir->children = ait->next;
- free(ait);
- ait = a->data.dir->children;
+ if (old_prev == NULL) {
+ old->data.dir->children = old_it->next;
+ free(old_it);
+ old_it = old->data.dir->children;
} else {
- aprev->next = ait->next;
- free(ait);
- ait = aprev->next;
+ old_prev->next = old_it->next;
+ free(old_it);
+ old_it = old_prev->next;
}
} else if (ret > 0) {
result = 1;
- path = node_path(bit);
+ path = node_path(new_it);
if (path == NULL)
return -1;
fprintf(stdout, "> %s\n", path);
free(path);
- if (bprev == NULL) {
- b->data.dir->children = bit->next;
- free(bit);
- bit = b->data.dir->children;
+ if (new_prev == NULL) {
+ new->data.dir->children = new_it->next;
+ free(new_it);
+ new_it = new->data.dir->children;
} else {
- bprev->next = bit->next;
- free(bit);
- bit = bprev->next;
+ new_prev->next = new_it->next;
+ free(new_it);
+ new_it = new_prev->next;
}
} else {
- aprev = ait;
- ait = ait->next;
-
- bprev = bit;
- bit = bit->next;
- }
- }
-
- if (ait != NULL || bit != NULL) {
- result = 1;
+ old_prev = old_it;
+ old_it = old_it->next;
- if (ait != NULL) {
- if (aprev == NULL) {
- a->data.dir->children = NULL;
- } else {
- aprev->next = NULL;
- }
- arrow = '<';
- } else {
- if (bprev == NULL) {
- b->data.dir->children = NULL;
- } else {
- bprev->next = NULL;
- }
- arrow = '>';
- ait = bit;
- }
-
- while (ait != NULL) {
- path = node_path(ait);
- if (path == NULL) {
- result = -1;
- } else {
- fprintf(stdout, "%c %s\n", arrow, path);
- free(path);
- }
- aprev = ait;
- ait = ait->next;
- free(aprev);
+ new_prev = new_it;
+ new_it = new_it->next;
}
}