[augeas-devel] [PATCH] Fix lens selection in union

David Lutterkort dlutter at redhat.com
Fri Apr 25 04:00:31 UTC 2008


# HG changeset patch
# User David Lutterkort <dlutter at redhat.com>
# Date 1209096019 25200
# Node ID 0f201c77bec5a6faaa229f0eed59f3ed39877ca5
# Parent  ffcd7c0fe252e10eb7bc500ee879ad2bcc1beb7c
Fix lens selection in union

The logic in put to select the appropriate branch in unions got it wrong if
the first branch matched the empty word, because applies only checked that
the atype for the sublens matched some of the tree. It has to check for a
complete match of its tree.

This change fixes that and adds a test to demonstrate the problem.

diff -r ffcd7c0fe252 -r 0f201c77bec5 src/put.c
--- a/src/put.c	Thu Apr 24 20:55:47 2008 -0700
+++ b/src/put.c	Thu Apr 24 21:00:19 2008 -0700
@@ -245,7 +245,7 @@ static int applies(struct lens *lens, st
         FIXME("Match failed - produce better error");
         abort();
     }
-    return (count > -1);
+    return (count == split->end - split->start);
 }
 
 static struct dict_entry *dict_lookup(const char *key, struct dict *dict) {
diff -r ffcd7c0fe252 -r 0f201c77bec5 tests/modules/pass_union_select_star.aug
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/modules/pass_union_select_star.aug	Thu Apr 24 21:00:19 2008 -0700
@@ -0,0 +1,16 @@
+module Pass_union_select_star =
+
+  (* Check that in unions the right branch is selected, even if the *)
+  (* first branch matches nothing.                                  *)
+  let a = [ key /a/ ]
+  let b = [ key /b/ ]
+
+  let lns = (a* | b+)
+
+  (* The 'rm "x"' is a noop; the grammar won't let us do a put test *)
+  (* without any commands                                           *)
+  test lns put "b" after rm "x" = "b"
+
+(* Local Variables: *)
+(* mode: caml       *)
+(* End:             *)




More information about the augeas-devel mailing list