[augeas-devel] [PATCH 1 of 2] Refactor tree_create
David Lutterkort
dlutter at redhat.com
Mon Jul 28 16:27:45 UTC 2008
1 file changed, 14 insertions(+), 9 deletions(-)
src/augeas.c | 23 ++++++++++++++---------
# HG changeset patch
# User David Lutterkort <dlutter at redhat.com>
# Date 1217130201 25200
# Node ID 7a5e0853f47747bfd54359bccbb8769c6928967c
# Parent 5eeceb51f4a337ee35838888cea1972f58e6c129
Refactor tree_create
diff -r 5eeceb51f4a3 -r 7a5e0853f477 src/augeas.c
--- a/src/augeas.c Sat Jul 26 20:43:19 2008 -0700
+++ b/src/augeas.c Sat Jul 26 20:43:21 2008 -0700
@@ -402,7 +402,13 @@
return path;
}
-static struct segment *aug_tree_create(struct path *path) {
+/* Expand the tree ROOT so that it contains all components of PATH. PATH
+ * must have been initialized against ROOT by a call to PATH_FIND_ONE.
+ *
+ * Return the first segment that was created by this operation, or NULL on
+ * error.
+ */
+static struct segment *tree_create(struct tree *root, struct path *path) {
struct segment *s, *seg;
for (seg = path->segments;
@@ -420,8 +426,13 @@
s->tree->children = (s+1)->tree;
}
+ struct tree *tree = seg_parent(path, seg);
+ if (tree == NULL)
+ list_append(root, seg->tree);
+ else
+ list_append(tree->children, seg->tree);
+
return seg;
-
error:
for (s = seg; s->tree != NULL && s <= last_segment(path); s++) {
free_tree(s->tree);
@@ -574,14 +585,8 @@
goto error;
if (r == 0) {
- struct segment *seg = aug_tree_create(p);
- if (seg == NULL)
+ if (tree_create(root, p) == NULL)
goto error;
- tree = seg_parent(p, seg);
- if (tree == NULL)
- list_append(root, seg->tree);
- else
- list_append(tree->children, seg->tree);
}
tree = last_segment(p)->tree;
free_path(p);
More information about the augeas-devel
mailing list