<pre style='margin:0'>
Umesh Singla (umeshksingla) pushed a commit to branch gsoc17-migrate
in repository macports-base.

</pre>
<p><a href="https://github.com/macports/macports-base/commit/585ed35fb7fade782fc19f9a4ed615df3848c93a">https://github.com/macports/macports-base/commit/585ed35fb7fade782fc19f9a4ed615df3848c93a</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit 585ed35fb7fade782fc19f9a4ed615df3848c93a
</span>Author: Umesh Singla <umeshksingla@macports.org>
AuthorDate: Tue Jul 11 05:15:45 2017 +0530

<span style='display:block; white-space:pre;color:#404040;'>    Store variants with sign in registrydb as part of snapshot
</span>---
 src/cregistry/entry.c | 41 +++++++++++++++++++++++++++++------------
 src/cregistry/entry.h |  2 +-
 2 files changed, 30 insertions(+), 13 deletions(-)

<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/cregistry/entry.c b/src/cregistry/entry.c
</span><span style='display:block; white-space:pre;color:#808080;'>index 2b49a0a..049cf89 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/cregistry/entry.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/cregistry/entry.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1393,6 +1393,7 @@ int snapshot_store_ports(reg_registry* reg, reg_entry* snap_entry, reg_error* er
</span>                                             break;
                                         case 0:
                                             reg_sqlite_error(reg->db, errPtr, query);
<span style='display:block; white-space:pre;background:#e0ffe0;'>+                                            result = 0;
</span>                                             break;
                                     }
                                 }
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1414,6 +1415,7 @@ int snapshot_store_ports(reg_registry* reg, reg_entry* snap_entry, reg_error* er
</span>                     sqlite3_finalize(stmt);
                 }
             }
<span style='display:block; white-space:pre;background:#e0ffe0;'>+            free(entry);
</span>         }
     }
     return result;
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1423,7 +1425,7 @@ int snapshot_store_port_variants(reg_registry* reg, reg_entry* port_entry,
</span>     int snapshot_ports_id, reg_error* errPtr) {
 
     reg_error error;
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    int i, result = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    int i, result = 1;
</span> 
     char* key1 = "variants";
     char* key2 = "negated_variants";
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1438,17 +1440,27 @@ int snapshot_store_port_variants(reg_registry* reg, reg_entry* port_entry,
</span>         
         //return 1;
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        variant* all_variants;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-        
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-        all_variants = (variant*) malloc(sizeof(variant));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        int variant_space = 10;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        variant* all_variants = (variant*) malloc(variant_space * sizeof(variant));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        if (all_variants == NULL) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            return 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        }
</span> 
         char* pos_delim = "+";
         char* neg_delim = "-";
 
         int variant_count = 0;
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        get_parsed_variants(positive_variants_str, all_variants, pos_delim, &variant_count);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-        get_parsed_variants(negative_variants_str, all_variants, neg_delim, &variant_count);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        int p = get_parsed_variants(positive_variants_str, all_variants, pos_delim, &variant_count);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        if (p < 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            return 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        int n = get_parsed_variants(negative_variants_str, all_variants, neg_delim, &variant_count);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        if (n < 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            return 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        }
</span> 
         printf("total var count: %d, ", variant_count);
 
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1457,7 +1469,7 @@ int snapshot_store_port_variants(reg_registry* reg, reg_entry* port_entry,
</span>             char* query = "INSERT INTO registry.snapshot_port_variants "
                 "(snapshot_ports_id, variant_name, variant_sign) "
                 "VALUES (?, ?, ?)";
<span style='display:block; white-space:pre;background:#ffe0e0;'>-            variant v = all_variants[i];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            variant v = *(all_variants + i);
</span>             if((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
                     && (sqlite3_bind_int64(stmt, 1, snapshot_ports_id) == SQLITE_OK)
                     && (sqlite3_bind_text(stmt, 2, v.variant_name, -1, SQLITE_STATIC) == SQLITE_OK)
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1469,7 +1481,6 @@ int snapshot_store_port_variants(reg_registry* reg, reg_entry* port_entry,
</span>                         case SQLITE_DONE:
                             printf("\nvariant stored: %s with sign: %s",
                                 v.variant_name, v.variant_sign);
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                            result = 1;
</span>                             break;
                         case SQLITE_BUSY:
                             break;
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1489,7 +1500,7 @@ int snapshot_store_port_variants(reg_registry* reg, reg_entry* port_entry,
</span>     return result;
 }
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-void get_parsed_variants(char* variants_str, variant* all_variants, char* delim, int* variant_count) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int get_parsed_variants(char* variants_str, variant* all_variants, char* delim, int* variant_count) {
</span>     
     printf("var count yet %d, ", *variant_count);
     
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1503,12 +1514,18 @@ void get_parsed_variants(char* variants_str, variant* all_variants, char* delim,
</span>         variant v;
         v.variant_name = token;
         v.variant_sign = delim;
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-        all_variants[*variant_count] = v;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        *(all_variants + *variant_count) = v;
</span>         *variant_count = *variant_count + 1;
<span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        // all_variants = (variant*) realloc(all_variants, sizeof(variant));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        // if(!all_variants) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        //     return -1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        // }
</span>     }
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    return ;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    return 0;
</span> }
 
 /**
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/cregistry/entry.h b/src/cregistry/entry.h
</span><span style='display:block; white-space:pre;color:#808080;'>index 9361f1a..7de38e5 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/cregistry/entry.h
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/cregistry/entry.h
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -106,7 +106,7 @@ int snapshot_store_ports(reg_registry* reg, reg_entry* entry,
</span> int snapshot_store_port_variants(reg_registry* reg, reg_entry* port_entry,
         int snapshot_ports_id, reg_error* errPtr);
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-void get_parsed_variants(char* variants_str, variant* all_variants,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int get_parsed_variants(char* variants_str, variant* all_variants,
</span>     char* delim, int* variant_count);
 
 int reg_all_open_entries(reg_registry* reg, reg_entry*** entries);
</pre><pre style='margin:0'>

</pre>