<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/c342d9b73f286592f03d04331b38c0697249cf2b">https://github.com/macports/macports-base/commit/c342d9b73f286592f03d04331b38c0697249cf2b</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit c342d9b73f286592f03d04331b38c0697249cf2b
</span>Author: Umesh Singla <umeshksingla@macports.org>
AuthorDate: Wed Aug 9 04:31:19 2017 +0530
<span style='display:block; white-space:pre;color:#404040;'> WIP: Add C functions to get snapshot
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> Add C functions to get ports and their variants from snapshots
</span><span style='display:block; white-space:pre;color:#404040;'> database, provided a snapshot_id.
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> This commit overrides the approach used in the previous commit.
</span><span style='display:block; white-space:pre;color:#404040;'> Functions to get ports and variants for each port can be modified
</span><span style='display:block; white-space:pre;color:#404040;'> if we plan to write snapshot starting from a higher level.
</span>---
src/cregistry/entry.c | 195 ++++++++++++++++++++++++++++++++++++++----------
src/registry2.0/entry.c | 9 ++-
2 files changed, 159 insertions(+), 45 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 7908468..08258e9 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;'>@@ -1566,57 +1566,170 @@ char* reg_snapshot_get_id(reg_registry* reg, reg_error* errPtr) {
</span>
}
<span style='display:block; white-space:pre;background:#ffe0e0;'>-static int reg_stmt_to_snapshot(void* userdata, void** entry, void* stmt,
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- void* calldata UNUSED, reg_error* errPtr UNUSED) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int is_new;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_registry* reg = (reg_registry*)userdata;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- Tcl_HashEntry* hash = Tcl_CreateHashEntry(®->open_entries,
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- (const char*)&id, &is_new);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (is_new) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_snapshot* e = malloc(sizeof(reg_snapshot));
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (!e) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int reg_snapshot_port_variants_get(reg_registry* reg, sqlite_int64 snapshot_port_id, variant** variants, reg_error* errPtr) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("inside getting variants\n");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_stmt* stmt = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* query = "SELECT * FROM registry.snapshot_port_variants WHERE snapshot_ports_id=?";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</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, snapshot_port_id) == SQLITE_OK )) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ variant* result = malloc(10 * sizeof(variant));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (!result) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return -1;
</span> }
<span style='display:block; white-space:pre;background:#ffe0e0;'>- e->reg = reg;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- e->id = id;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- e->proc = NULL;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- *entry = e;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- Tcl_SetHashValue(hash, e);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int result_count = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int result_space = 10;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int r;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</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_ROW:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* variant_name = (const char*)sqlite3_column_text(stmt, 2);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* variant_sign = (const char*)sqlite3_column_text(stmt, 3);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ variant element = malloc(10 * sizeof(variant));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (!element) {
</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;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ element->variant_name = variant_name;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ element->variant_sign = variant_sign;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (!reg_listcat((void***)&result, &result_count, &result_space, element)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ r = SQLITE_ERROR;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case SQLITE_DONE:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case SQLITE_BUSY:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ continue;
</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;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } while (r == SQLITE_ROW || r == SQLITE_BUSY);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_finalize(stmt);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (r == SQLITE_DONE) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *variants = result;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return result_count;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int i;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ for (i = 0; i < result_count; i++) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ free(result[i]);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ free(result);
</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;'>+
</span> } else {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- *entry = Tcl_GetHashValue(hash);
</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;'>+ if (stmt) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_finalize(stmt);
</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:#ffe0e0;'>- return 1;
</span> }
<span style='display:block; white-space:pre;background:#ffe0e0;'>-static int reg_all_snapshots(reg_registry* reg, char* query, int query_len,
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_snapshot*** objects, reg_error* errPtr) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- int lower_bound = 0;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- return reg_all_objects(reg, query, query_len, (void***)objects,
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_stmt_to_snapshot, &lower_bound, NULL, errPtr);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-}
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-reg_snapshot* reg_snapshot_get(reg_registry* reg, char* id, reg_error* errPtr) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int reg_snapshot_get(reg_registry* reg, char* id, reg_snapshot* snapshot, reg_error* errPtr) {
</span>
printf("inside cregistry get snapshot..\n");
sqlite3_stmt* stmt = NULL;
<span style='display:block; white-space:pre;background:#ffe0e0;'>- reg_snapshot** snapshots;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* query = "SELECT port_name, requested, variant_name, variant_sign "
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- "FROM registry.snapshots "
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- "INNER JOIN "
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- "registry.snapshot_ports ON "
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- "snapshots.id=snapshot_ports.snapshots_id "
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- "LEFT JOIN "
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- "registry.snapshot_port_variants ON "
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- "snapshot_ports.id=snapshot_port_variants.snapshot_ports_id"
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- "WHERE snapshots.id=?";
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>-
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- query = sqlite3_mprintf(query, id);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- result = reg_all_snapshots(reg, query, -1, snapshots, errPtr);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- sqlite3_free(query);
</span>
<span style='display:block; white-space:pre;background:#ffe0e0;'>- return result;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* query = "SELECT * FROM registry.snapshot_ports WHERE snapshots_id=?";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ const char* port_name;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ const char* state;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</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, (sqlite_int64)id) == SQLITE_OK )) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ port** result = malloc(10 * sizeof(port*));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (!result) {
</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;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int result_count = 0;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int result_space = 10;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int r;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</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_ROW:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite_int64 snapshot_port_id = sqlite3_column_int64(stmt, 0);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ port_name = (const char*) sqlite3_column_text(stmt, 2);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int requested = (int) sqlite3_column_int64(stmt, 3);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ state = (const char*) sqlite3_column_text(stmt, 4);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ port* current_port;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ current_port = (port*) malloc(sizeof(port*));
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (!current_port) {
</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;'>+ current_port->name = port_name;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ current_port->requested = requested;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ current_port->state = state;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ current_port->variants = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // get variants for the current port using its id
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ variant* variants;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int variant_count = reg_snapshot_port_variants_get(reg, snapshot_port_id, &variants, errPtr);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (!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:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (variant_count > 0) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ current_port->variants = variants;
</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;'>+ if (!reg_listcat((void***)&result, &result_count, &result_space, current_port)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ r = SQLITE_ERROR;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ case SQLITE_DONE:
</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;'>+ continue;
</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;'>+ break;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } while (r == SQLITE_ROW || r == SQLITE_BUSY);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_finalize(stmt);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (r == SQLITE_DONE) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ (*snapshot)->id = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ (*snapshot)->note = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ (*snapshot)->ports = result;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return result_count;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int i;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ for (i=0; i<result_count; i++) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ free(result[i]);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ free(result);
</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;'>+ } 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;'>+ if (stmt) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_finalize(stmt);
</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;color:#808080;'>diff --git a/src/registry2.0/entry.c b/src/registry2.0/entry.c
</span><span style='display:block; white-space:pre;color:#808080;'>index 422fbeb..864695b 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/registry2.0/entry.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/registry2.0/entry.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -557,11 +557,12 @@ static int get_snapshot(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]) {
</span> } else {
char* id = Tcl_GetString(objv[2]);
reg_error error;
<span style='display:block; white-space:pre;background:#ffe0e0;'>- snapshot* snapshot = reg_snapshot_get(reg, id, &error);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_snapshot* snapshot;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int port_count = reg_snapshot_get(reg, id, &snapshot, &error);
</span> if (snapshot != NULL) {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- Tcl_Obj* result;
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- if (entry_to_obj(interp, &result, snapshot, NULL, &error)) {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- Tcl_SetObjResult(interp, result);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_Obj* resultObj;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (entry_to_obj(interp, &resultObj, snapshot, NULL, &error)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_SetObjResult(interp, resultObj);
</span> return TCL_OK;
}
}
</pre><pre style='margin:0'>
</pre>