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

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

<span style='display:block; white-space:pre;color:#404040;'>    WIP: Parse variants and store in registry
</span><span style='display:block; white-space:pre;color:#404040;'>    
</span><span style='display:block; white-space:pre;color:#404040;'>    Facing malloc error but uploading before everything gets ruined
</span>---
 src/cregistry/entry.c        | 112 ++++++++++++++++++++++++++++++++-----------
 src/cregistry/entry.h        |   6 ++-
 src/macports1.0/snapshot.tcl |  29 ++++++++++-
 3 files changed, 116 insertions(+), 31 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 7590635..fc74361 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;'>@@ -1385,11 +1385,14 @@ int snapshot_store_ports(reg_registry* reg, reg_entry* snap_entry, reg_error* er
</span>             char* port_name;
             char* requested;
             sqlite3_stmt* stmt = NULL;
<span style='display:block; white-space:pre;background:#ffe0e0;'>-            reg_entry* port_entry = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            reg_entry* entry = NULL;
</span>             if(reg_entry_propget(entries[i], key1, &port_name, &error)
                 && reg_entry_propget(entries[i], key2, &requested, &error)){
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                char* query = "INSERT INTO registry.snapshot_ports (snapshots_id, port_name, requested) "
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                char* query = "INSERT INTO registry.snapshot_ports "
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    "(snapshots_id, port_name, requested) "
</span>                     "VALUES (?, ?, ?)";
<span style='display:block; white-space:pre;background:#e0ffe0;'>+                
</span>                 if ((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
                         && (sqlite3_bind_int64(stmt, 1, snap_entry->id) == SQLITE_OK)
                         && (sqlite3_bind_text(stmt, 2, port_name, -1, SQLITE_STATIC) == SQLITE_OK)
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1400,16 +1403,17 @@ int snapshot_store_ports(reg_registry* reg, reg_entry* snap_entry, reg_error* er
</span>                         switch (r) {
                             case SQLITE_DONE:
                                 // store variants for entries[i]
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                                port_entry = malloc(sizeof(reg_entry));
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                                if (port_entry) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                                    port_entry->id = sqlite3_last_insert_rowid(reg->db);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                                    port_entry->reg = reg;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                                    port_entry->proc = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                entry = malloc(sizeof(reg_entry));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                if (entry) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                    entry->id = sqlite3_last_insert_rowid(reg->db);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                    entry->reg = reg;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                    entry->proc = NULL;
</span> 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                                    printf("port id: %lld\n", port_entry->id);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                    printf("port id: %lld, ", entry->id);
</span> 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                                    // TODO: move this functions to a different file
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                                    int port_variants_saved = snapshot_store_port_variants(reg, port_entry, errPtr);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                    // TODO: move this function to a different file
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                    int port_variants_saved = snapshot_store_port_variants(
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                        reg, entries[i], entry->id, errPtr);
</span> 
                                     switch (port_variants_saved) {
                                         case 1:
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1420,7 +1424,7 @@ int snapshot_store_ports(reg_registry* reg, reg_entry* snap_entry, reg_error* er
</span>                                             break;
                                     }
                                 }
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                                printf("done with %s port\n", port_name);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                printf("done with *%s* port\n\n", port_name);
</span>                                 break;
                             case SQLITE_BUSY:
                                 break;
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1444,39 +1448,57 @@ int snapshot_store_ports(reg_registry* reg, reg_entry* snap_entry, reg_error* er
</span>     return result;
 }
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-int snapshot_store_port_variants(reg_registry* reg, reg_entry* port_entry, reg_error* errPtr){
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-    reg_entry* entry;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int snapshot_store_port_variants(reg_registry* reg, reg_entry* port_entry,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    int snapshot_ports_id, reg_error* errPtr) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span>     reg_error error;
     int i, result = 0;
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    char* key = "variants";
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-    char* variants;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    char* key1 = "variants";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    char* key2 = "negated_variants";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    char* positive_variants_str;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    char* negative_variants_str;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    if(reg_entry_propget(port_entry, key1, &positive_variants_str, &error) 
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        && reg_entry_propget(port_entry, key2, &negative_variants_str, &error)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        printf("+ve .. %s, ", positive_variants_str);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        printf("-ve .. %s ", negative_variants_str);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        
</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:#e0ffe0;'>+        variant* all_variants;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        all_variants = (variant*) malloc(sizeof(variant));
</span> 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-    if(reg_entry_propget(port_entry, key, &variants, &error)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        char* pos_delim = "+";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        char* neg_delim = "-";
</span> 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        printf("%s\n", variants);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        int variant_count = 0;
</span> 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        variant** installed_variants;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-        int variant_count = get_parsed_variants(variants, &installed_variants);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        get_parsed_variants(positive_variants_str, all_variants, pos_delim, &variant_count);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        get_parsed_variants(negative_variants_str, all_variants, neg_delim, &variant_count);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        printf("total var count: %d\n", variant_count);
</span> 
         for ( i = 0; i < variant_count; i++){
             sqlite3_stmt* stmt = NULL;
             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 = NULL;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-            v = installed_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)
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                    && (sqlite3_bind_int64(stmt, 1, port_entry->id) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                    && (sqlite3_bind_text(stmt, 2, v->variant_name, -1, SQLITE_STATIC) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                    && (sqlite3_bind_text(stmt, 3, v->variant_sign, -1, SQLITE_STATIC) == SQLITE_OK)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    && (sqlite3_bind_int64(stmt, 1, snapshot_ports_id) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    && (sqlite3_bind_text(stmt, 2, v.variant_name, -1, SQLITE_STATIC) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    && (sqlite3_bind_text(stmt, 3, v.variant_sign, -1, SQLITE_STATIC) == SQLITE_OK)) {
</span>                 int r;
                 do {
                     r = sqlite3_step(stmt);
                     switch (r) {
                         case SQLITE_DONE:
                             printf("variant stored: %s with sign: %s\n",
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                                v->variant_name, v->variant_sign);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                v.variant_name, v.variant_sign);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                            result = 1;
</span>                             break;
                         case SQLITE_BUSY:
                             break;
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1491,14 +1513,48 @@ int snapshot_store_port_variants(reg_registry* reg, reg_entry* port_entry, reg_e
</span>                 result = 0;
             }
         }
<span style='display:block; white-space:pre;background:#e0ffe0;'>+        free(all_variants);
</span>     }
     return result;
 }
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-int get_parsed_variants(char* variants, variant*** installed_variants){
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-    int length = 0;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-    return length;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+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;'>+    
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    printf("var count yet%d\n", *variant_count);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    /*char *token;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    char *rest = variants_str;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    while ((token = strtok_r(rest, delim, &rest))) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        printf("%s\n", token);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        variant v;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        v.variant_name = token;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        v.variant_sign = delim;
</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><span style='display:block; white-space:pre;background:#e0ffe0;'>+        *variant_count = *variant_count + 1;
</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;'>+    char *token = strtok(variants_str, delim);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    while (token != NULL) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        printf("%s\n", token);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        variant v;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        v.variant_name = token;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        v.variant_sign = delim;
</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><span style='display:block; white-space:pre;background:#e0ffe0;'>+        *variant_count = *variant_count + 1;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        token = strtok(NULL, delim);
</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;'>+    return;
</span> }
<span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> /**
  * Fetches a list of all open entries.
  *
<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 18ac018..ca8a5e3 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;'>@@ -104,8 +104,10 @@ reg_entry* reg_snapshot_create(reg_registry* reg, char* note,
</span> int snapshot_store_ports(reg_registry* reg, reg_entry* entry,
         reg_error* errPtr);
 int snapshot_store_port_variants(reg_registry* reg, reg_entry* port_entry,
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        reg_error* errPtr);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-int get_parsed_variants(char* variants, variant*** installed_variants);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        int snapshot_ports_id, reg_error* errPtr);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+void get_parsed_variants(char* variants_str, variant* all_variants,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    char* delim, int* variant_count);
</span> 
 int reg_all_open_entries(reg_registry* reg, reg_entry*** entries);
 
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/macports1.0/snapshot.tcl b/src/macports1.0/snapshot.tcl
</span><span style='display:block; white-space:pre;color:#808080;'>index a77fed9..1a52eca 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/macports1.0/snapshot.tcl
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/macports1.0/snapshot.tcl
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -19,15 +19,42 @@ namespace eval snapshot {
</span>         #           opts - The options passed in. Currently, there is no option available.
         # Returns:
         #           None
<span style='display:block; white-space:pre;background:#e0ffe0;'>+        #
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        # TODO: use registry::write wrapper here itself
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        #
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span>         puts "Still being developed"
         #registry::entry addsnapshot
         foreach port [registry::entry imaged] {
             puts [$port name]
         }
<span style='display:block; white-space:pre;background:#e0ffe0;'>+        puts
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        set ilist [registry::installed]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        # set vimlist [registry::installed vim]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        # foreach port $vimlist {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        #     puts $port
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        # }
</span> 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        set a [registry::entry snapshot "testsnapshot"]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        foreach port $ilist {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            puts $port
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        puts
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        set a [registry::entry snapshot "test snapshot"]
</span>         puts $a
         puts done
 
        }
<span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    proc list {opts} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        # List the snapshots
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        puts "listing"
</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;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    proc latest {opts} {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        # Get the latest snapshot
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        puts "latest"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    }
</span> }
\ No newline at end of file
</pre><pre style='margin:0'>

</pre>