summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/commit2.c55
-rw-r--r--src/common/defs.h10
2 files changed, 49 insertions, 16 deletions
diff --git a/src/commit2.c b/src/commit2.c
index 1679d76..6a6a211 100644
--- a/src/commit2.c
+++ b/src/commit2.c
@@ -415,6 +415,7 @@ process_func(GNode *node, gpointer data)
gpointer gp = ((GNode*)node)->data;
struct Config *c = &((struct VyattaNode*)gp)->_config;
struct Data *d = &((struct VyattaNode*)gp)->_data;
+ struct Aux *a = &((struct VyattaNode*)gp)->_aux;
NODE_OPERATION op = d->_operation;
int status = 0;
@@ -523,27 +524,14 @@ process_func(GNode *node, gpointer data)
//set location env
setenv(ENV_DATA_PATH,d->_path,1);
- //do first/last/only sibling check, restrict to nodes with operations defined
- GNode *n_last_op = NULL;
- GNode *n_first_op = NULL;
- GNode *sib = g_node_first_sibling(node);
- while (sib != NULL) {
- if (!IS_NOOP(((struct VyattaNode*)(sib->data))->_data._operation)) {
- if (n_first_op == NULL) {
- n_first_op = sib;
- }
- n_last_op = sib;
- }
- sib = sib->next;
- }
- if (n_last_op != NULL && n_first_op != NULL && node == n_first_op && node == n_last_op) {
+ if (a->_first && a->_last) {
setenv(ENV_SIBLING_POSITION,"FIRSTLAST",1);
}
- else if (n_first_op != NULL && node == n_first_op) {
+ else if (a->_first) {
setenv(ENV_SIBLING_POSITION,"FIRST",1);
}
- else if (n_last_op != NULL && node == n_last_op) {
+ else if (a->_last) {
setenv(ENV_SIBLING_POSITION,"LAST",1);
}
@@ -1251,8 +1239,43 @@ validate_func(GNode *node, gpointer data)
gpointer gp = ((GNode*)node)->data;
struct Config *c = &((struct VyattaNode*)gp)->_config;
struct Data *d = &((struct VyattaNode*)gp)->_data;
+ struct Aux *a = &((struct VyattaNode*)gp)->_aux;
struct Result *result = (struct Result*)data;
+
+
+
+ //let's mark first last nodes here for use later
+ //do first/last/only sibling check, restrict to nodes with operations defined
+ GNode *n_last_op = NULL;
+ GNode *n_first_op = NULL;
+
+ GNode *sib = g_node_first_sibling(node);
+ while (sib != NULL) {
+ if (IS_DELETE(((struct VyattaNode*)(sib->data))->_data._operation)) {
+ if (n_first_op == NULL) {
+ n_first_op = sib;
+ }
+ n_last_op = sib;
+ }
+ sib = sib->next;
+ }
+
+ sib = g_node_first_sibling(node);
+ while (sib != NULL) {
+ if (IS_SET_OR_CREATE(((struct VyattaNode*)(sib->data))->_data._operation)) {
+ if (n_first_op == NULL) {
+ n_first_op = sib;
+ }
+ n_last_op = sib;
+ }
+ sib = sib->next;
+ }
+
+ a->_first = (node == n_first_op);
+ a->_last = (node == n_last_op);
+
+
//since this visits all working nodes, let's maintain a set of nodes to commit
GSList *coll = (GSList*)result->_data;
if (d->_path != NULL) {
diff --git a/src/common/defs.h b/src/common/defs.h
index dcced15..b931bd9 100644
--- a/src/common/defs.h
+++ b/src/common/defs.h
@@ -85,10 +85,20 @@ struct Data
NODE_ACTIVATE _disable_op; //is this node currently deactivated?
};
+/*
+ * additional data to be defined and used by client
+ */
+struct Aux
+{
+ boolean _first;
+ boolean _last;
+};
+
struct VyattaNode
{
struct Data _data;
struct Config _config;
+ struct Aux _aux;
};
#endif //__DEFS_H__