<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/e97116aeaec0d859dc2aeee14377ce4d639ceef5">https://github.com/macports/macports-base/commit/e97116aeaec0d859dc2aeee14377ce4d639ceef5</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit e97116aeaec0d859dc2aeee14377ce4d639ceef5
</span>Author: Umesh Singla <umeshksingla@macports.org>
AuthorDate: Fri Aug 18 07:55:00 2017 +0530
<span style='display:block; white-space:pre;color:#404040;'> Add propget and ports_get method for a snapshot
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> 1. propset are currently not supported for a snapshot
</span><span style='display:block; white-space:pre;color:#404040;'> 2. A method to convert a list of snapshot_ports to a
</span><span style='display:block; white-space:pre;color:#404040;'> list Tcl obj is currently underway
</span>---
src/cregistry/snapshot.c | 81 +++++++++++++++++++++++++++++++++++++++++++
src/cregistry/snapshot.h | 5 +++
src/registry2.0/snapshotobj.c | 36 +++++++++++++++----
3 files changed, 116 insertions(+), 6 deletions(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/cregistry/snapshot.c b/src/cregistry/snapshot.c
</span><span style='display:block; white-space:pre;color:#808080;'>index c3934e3..c6a0348 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/cregistry/snapshot.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/cregistry/snapshot.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -475,3 +475,84 @@ int reg_snapshot_port_variants_get(reg_registry* reg, sqlite_int64 snapshot_port
</span> return -1;
}
}
<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;'>+ * Gets a named property of a snapshot. The property named must be one
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * that exists in the table and must not be one with internal meaning
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * such as `id` or `state`.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * @param [in] snapshot snapshot to get property from
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * @param [in] key property to get
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * @param [out] value the value of the property
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * @param [out] errPtr on error, a description of the error that occurred
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * @return true if success; false if failure
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int reg_snapshot_propget(reg_snapshot* snapshot, char* key, char** value,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_error* errPtr) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_registry* reg = snapshot->reg;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int result = 0;
</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;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ const char *text;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ query = sqlite3_mprintf("SELECT %q FROM registry.snapshots WHERE id=%lld", key,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ snapshot->id);
</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;'>+ 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_ROW:
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ text = (const char*)sqlite3_column_text(stmt, 0);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (text) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *value = strdup(text);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ result = 1;
</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;'>+ }
</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;'>+ errPtr->code = REG_INVALID;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ errPtr->description = "an invalid snapshot was passed";
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ errPtr->free = NULL;
</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_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;'>+ }
</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;'>+ sqlite3_free(query);
</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;'>+/**
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * Gets all the 'ports' of a snapshot. The property named must be one
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * that exists in the table and must not be one with internal meaning
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * such as `id` or `state`.
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * A 'port' here is a row in registry.snapshot_ports table and its
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * corresponding variants in registry.snapshot_port_variants table
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ *
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * @param [in] snapshot snapshot to get property from
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * @param [in] key property to get
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * @param [out] value the value of the property
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * @param [out] errPtr on error, a description of the error that occurred
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ * @return true if success; false if failure
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int reg_snapshot_ports_get(reg_snapshot* snapshot, port** ports,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_error* errPtr) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_registry* reg = snapshot->reg;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int result = 0;
</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;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ const char *text;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // TODO: get ports and their variants using snapshot->id as Fk
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return result;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</span>\ No newline at end of file
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/cregistry/snapshot.h b/src/cregistry/snapshot.h
</span><span style='display:block; white-space:pre;color:#808080;'>index 6ea9325..a578162 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/cregistry/snapshot.h
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/cregistry/snapshot.h
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -73,4 +73,9 @@ int snapshot_store_ports(reg_registry* reg, reg_snapshot* snapshot,
</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:#e0ffe0;'>+int reg_snapshot_propget(reg_snapshot* snapshot, char* key, char** value,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_error* errPtr);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+int reg_snapshot_ports_get(reg_snapshot* snapshot, port** ports,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_error* errPtr);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> #endif /* _CSNAPSHOT_H */
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/registry2.0/snapshotobj.c b/src/registry2.0/snapshotobj.c
</span><span style='display:block; white-space:pre;color:#808080;'>index 1280dcd..b2ecc23 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/registry2.0/snapshotobj.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/registry2.0/snapshotobj.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -45,7 +45,7 @@ const char* snapshot_props[] = {
</span> NULL
};
<span style='display:block; white-space:pre;background:#ffe0e0;'>-/* ${snapshot} prop ?value? */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+/* ${snapshot} prop */
</span> static int snapshot_obj_prop(Tcl_Interp* interp, reg_snapshot* snapshot, int objc,
Tcl_Obj* CONST objv[]) {
int index;
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -73,18 +73,42 @@ static int snapshot_obj_prop(Tcl_Interp* interp, reg_snapshot* snapshot, int obj
</span> return registry_failed(interp, &error);
}
return TCL_ERROR;
<span style='display:block; white-space:pre;background:#ffe0e0;'>- } else {
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- /* ${snapshot} prop name value; set a new value */
</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;'>+/* ${snapshot} ports */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+static int snapshot_obj_ports(Tcl_Interp* interp, reg_snapshot* snapshot, int objc,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_Obj* CONST objv[]) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int index;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (objc > 3) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_WrongNumArgs(interp, 2, objv, "?value?");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_ERROR;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ }
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (objc == 2) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ /* ${snapshot} prop; return the current value */
</span> reg_registry* reg = registry_for(interp, reg_attached);
if (reg == NULL) {
return TCL_ERROR;
}
if (Tcl_GetIndexFromObj(interp, objv[1], snapshot_props, "prop", 0, &index)
== TCL_OK) {
<span style='display:block; white-space:pre;background:#ffe0e0;'>- char* key = Tcl_GetString(objv[1]);
</span><span style='display:block; white-space:pre;background:#ffe0e0;'>- char* value = Tcl_GetString(objv[2]);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ port** ports;
</span> reg_error error;
<span style='display:block; white-space:pre;background:#ffe0e0;'>- if (reg_snapshot_propset(snapshot, key, value, &error)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (reg_snapshot_ports_get(snapshot, &ports, &error)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // TODO: correct the below for 'ports', added as a prototype for now
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // Tcl_Obj** objs;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // int retval = TCL_ERROR;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // if (list_entry_to_obj(interp, &objs, entries, entry_count, &error)){
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // Tcl_Obj* result = Tcl_NewListObj(entry_count, objs);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // Tcl_SetObjResult(interp, result);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // free(objs);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // retval = TCL_OK;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ // retval = registry_failed(interp, &error);
</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;'>+ free(ports);
</span> return TCL_OK;
}
return registry_failed(interp, &error);
</pre><pre style='margin:0'>
</pre>