<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/ce89b899af792395e9eb5fe1e0526cdbece03cc7">https://github.com/macports/macports-base/commit/ce89b899af792395e9eb5fe1e0526cdbece03cc7</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit ce89b899af792395e9eb5fe1e0526cdbece03cc7
</span>Author: Umesh Singla <umeshksingla@macports.org>
AuthorDate: Mon Jun 26 03:12:38 2017 +0530

<span style='display:block; white-space:pre;color:#404040;'>    WIP: Add function to store port variants (with sign) as part of a
</span><span style='display:block; white-space:pre;color:#404040;'>    snapshot
</span>---
 src/cregistry/entry.c | 94 +++++++++++++++++++++++++++++++++++++++++++++------
 src/cregistry/entry.h |  8 +++++
 2 files changed, 91 insertions(+), 11 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 e43ca49..cbb3247 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;'>@@ -1297,8 +1297,6 @@ reg_entry* reg_snapshot_create(reg_registry* reg, char* note, reg_error* errPtr)
</span>             && (sqlite3_bind_text(stmt, 1, note, -1, SQLITE_STATIC)
                 == SQLITE_OK)) {
         int r;
<span style='display:block; white-space:pre;background:#ffe0e0;'>-        Tcl_HashEntry* hash;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-        int is_new;
</span>         do {
             r = sqlite3_step(stmt);
             switch (r) {
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1308,11 +1306,8 @@ reg_entry* reg_snapshot_create(reg_registry* reg, char* note, reg_error* errPtr)
</span>                         entry->id = sqlite3_last_insert_rowid(reg->db);
                         entry->reg = reg;
                         entry->proc = NULL;
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                        hash = Tcl_CreateHashEntry(&reg->open_entries,
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                                (const char*)&entry->id, &is_new);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-                        Tcl_SetHashValue(hash, entry);
</span> 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                        printf("%lld\n", entry->id);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        printf("snapshot id: %lld\n", entry->id);
</span> 
                         // TODO: move this functions to a different file
                         int ports_saved = snapshot_store_ports(reg, entry, errPtr);
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1345,7 +1340,7 @@ reg_entry* reg_snapshot_create(reg_registry* reg, char* note, reg_error* errPtr)
</span>     return entry;
 }
 
<span style='display:block; white-space:pre;background:#ffe0e0;'>-int snapshot_store_ports(reg_registry* reg, reg_entry* entry, reg_error* errPtr){
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int snapshot_store_ports(reg_registry* reg, reg_entry* snap_entry, reg_error* errPtr){
</span>     reg_entry** entries;
     reg_error error;
     int i, entry_count;
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1353,20 +1348,22 @@ int snapshot_store_ports(reg_registry* reg, reg_entry* entry, reg_error* errPtr)
</span>     entry_count = reg_entry_imaged(reg, NULL, NULL, NULL, NULL,
             &entries, &error);
     printf("entry count: %d\n", entry_count);
<span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    char* key1 = "name";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    char* key2 = "requested";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span>     if (entry_count >= 0) {
         for ( i = 0; i < entry_count; i++){
<span style='display:block; white-space:pre;background:#ffe0e0;'>-            char* key1 = "name";
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-            char* key2 = "requested";
</span>             char* port_name;
             char* requested;
             sqlite3_stmt* stmt = NULL;
<span style='display:block; white-space:pre;background:#e0ffe0;'>+            reg_entry* port_entry = NULL;
</span>             if(reg_entry_propget(entries[i], key1, &port_name, &error)
                 && reg_entry_propget(entries[i], key2, &requested, &error)){
                 char* query = "INSERT INTO registry.snapshot_ports (snapshots_id, port_name, requested) "
                     "VALUES (?, ?, ?)";
<span style='display:block; white-space:pre;background:#ffe0e0;'>-                // entry->id is snapshot's id
</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, entry->id) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        && (sqlite3_bind_int64(stmt, 1, snap_entry->id) == SQLITE_OK)
</span>                         && (sqlite3_bind_text(stmt, 2, port_name, -1, SQLITE_STATIC) == SQLITE_OK)
                         && (sqlite3_bind_int64(stmt, 3, atoi(requested)) == SQLITE_OK)) {
                     int r;
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1375,6 +1372,26 @@ int snapshot_store_ports(reg_registry* reg, reg_entry* entry, reg_error* errPtr)
</span>                         switch (r) {
                             case SQLITE_DONE:
                                 // store variants for entries[i]
<span style='display:block; white-space:pre;background:#e0ffe0;'>+                                port_entry = malloc(sizeof(reg_entry));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                if (port_entry) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                    port_entry->id = sqlite3_last_insert_rowid(reg->db);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                    port_entry->reg = reg;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                    port_entry->proc = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                    printf("port id: %lld\n", port_entry->id);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                    // TODO: move this functions to a different file
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                    int port_variants_saved = snapshot_store_port_variants(reg, port_entry, errPtr);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                    switch (port_variants_saved) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                        case 1:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                            // TODO: pass the custom SUCCESS messages
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                            break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                        case 0:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                            reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                            break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                    }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                                }
</span>                                 printf("done with %s port\n", port_name);
                                 break;
                             case SQLITE_BUSY:
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -1399,6 +1416,61 @@ int snapshot_store_ports(reg_registry* reg, reg_entry* entry, reg_error* errPtr)
</span>     return result;
 }
 
<span style='display:block; white-space:pre;background:#e0ffe0;'>+int snapshot_store_port_variants(reg_registry* reg, reg_entry* port_entry, reg_error* errPtr){
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    reg_entry* entry;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    reg_error error;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    int i, result = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    char* key = "variants";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    char* variants;
</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, key, &variants, &error)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        printf("%s\n", variants);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        variant** installed_variants;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        int variant_count = get_parsed_variants(variants, &installed_variants);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+        for ( i = 0; i < variant_count; i++){
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            sqlite3_stmt* stmt = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            char* query = "INSERT INTO registry.snapshot_port_variants "
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                "(snapshot_ports_id, variant_name, variant_sign) "
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                "VALUES (?, ?, ?)";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            variant* v = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            v = installed_variants[i];
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            if((sqlite3_prepare_v2(reg->db, query, -1, &stmt, NULL) == SQLITE_OK)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    && (sqlite3_bind_int64(stmt, 1, port_entry->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><span style='display:block; white-space:pre;background:#e0ffe0;'>+                int r;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                do {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    r = sqlite3_step(stmt);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    switch (r) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        case SQLITE_DONE:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                            printf("variant stored: %s with sign: %s\n",
</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;'>+                            break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        case SQLITE_BUSY:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                            break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                        default:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                            reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                            result = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                            break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                    }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                } while (r == SQLITE_BUSY);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+            } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                reg_sqlite_error(reg->db, errPtr, query);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+                result = 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;'>+    }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    return result;
</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 get_parsed_variants(char* variants, variant*** installed_variants){
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    int length = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    return length;
</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 91f929d..10802ab 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;'>@@ -42,6 +42,11 @@ typedef struct {
</span>     char* proc; /* name of Tcl proc, if using Tcl */
 } reg_entry;
 
<span style='display:block; white-space:pre;background:#e0ffe0;'>+typedef struct {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    char* variant_name;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+    char* variant_sign;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+} variant;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> reg_entry* reg_entry_create(reg_registry* reg, char* name, char* version,
         char* revision, char* variants, char* epoch, reg_error* errPtr);
 
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -98,6 +103,9 @@ reg_entry* reg_snapshot_create(reg_registry* reg, char* note,
</span>         reg_error* errPtr);
 int snapshot_store_ports(reg_registry* reg, reg_entry* entry,
         reg_error* errPtr);
<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;'>+        reg_error* errPtr);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int get_parsed_variants(char* variants, variant*** installed_variants);
</span> 
 int reg_all_open_entries(reg_registry* reg, reg_entry*** entries);
 
</pre><pre style='margin:0'>

</pre>