<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/1e582caccf25bc05dd0ada21de141c3dedeb2b0b">https://github.com/macports/macports-base/commit/1e582caccf25bc05dd0ada21de141c3dedeb2b0b</a></p>
<pre style="white-space: pre; background: #F8F8F8"><span style='display:block; white-space:pre;color:#808000;'>commit 1e582caccf25bc05dd0ada21de141c3dedeb2b0b
</span>Author: Umesh Singla <umeshksingla@macports.org>
AuthorDate: Mon Jun 26 00:03:32 2017 +0530
<span style='display:block; white-space:pre;color:#404040;'> WIP: Connect to registry db and add a snapshot in snapshots table
</span><span style='display:block; white-space:pre;color:#404040;'>
</span><span style='display:block; white-space:pre;color:#404040;'> Tried running `port snapshot` and check if it is able to connect to
</span><span style='display:block; white-space:pre;color:#404040;'> db (passing from Tcl to cregistry) and insert a new record there
</span>---
src/cregistry/.entry.c.swp | Bin 16384 -> 0 bytes
src/cregistry/entry.c | 64 +++++++++++++++++++++++++++++++++++++++++++
src/cregistry/entry.h | 3 ++
src/cregistry/sql.c | 2 +-
src/macports1.0/snapshot.tcl | 11 ++++++++
src/registry2.0/entry.c | 36 ++++++++++++++++++++++++
6 files changed, 115 insertions(+), 1 deletion(-)
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/cregistry/.entry.c.swp b/src/cregistry/.entry.c.swp
</span>deleted file mode 100644
<span style='display:block; white-space:pre;color:#808080;'>index baa1b7f..0000000
</span>Binary files a/src/cregistry/.entry.c.swp and /dev/null differ
<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 f82e885..e364992 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;'>@@ -1313,6 +1313,70 @@ int reg_entry_depends(reg_entry* entry, char* name, reg_error* errPtr) {
</span> return result;
}
<span style='display:block; white-space:pre;background:#e0ffe0;'>+void test_call_c() {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("inside cregsitry\n");
</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;'>+reg_entry* reg_snapshot_create(reg_registry* reg, char* note, 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 cregsitry sn cr\n");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ sqlite3_stmt* stmt = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_entry* entry = NULL;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* query = "INSERT INTO registry.snapshots (note) VALUES (?)";
</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_text(stmt, 1, note, -1, SQLITE_STATIC)
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ == SQLITE_OK)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int r;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_HashEntry* hash;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ int is_new;
</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;'>+ 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:#e0ffe0;'>+ hash = Tcl_CreateHashEntry(®->open_entries,
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ (const char*)&entry->id, &is_new);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_SetHashValue(hash, entry);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("%lld\n", 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 ports_saved = snapshot_store_ports(reg, entry, errPtr);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ switch (ports_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><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_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;'>+ 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;'>+ printf("done with the snapshot\n");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return entry;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+}
</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 67bbf5f..55e57ce 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;'>@@ -94,6 +94,9 @@ int reg_entry_dependencies(reg_entry* entry, reg_entry*** dependencies,
</span> reg_error* errPtr);
int reg_entry_depends(reg_entry* entry, char* name, reg_error* errPtr);
<span style='display:block; white-space:pre;background:#e0ffe0;'>+void test_call_c();
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+reg_entry* reg_snapshot_create(reg_registry* reg, char* note, reg_error* errPtr);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span> int reg_all_open_entries(reg_registry* reg, reg_entry*** entries);
#endif /* _CENTRY_H */
<span style='display:block; white-space:pre;color:#808080;'>diff --git a/src/cregistry/sql.c b/src/cregistry/sql.c
</span><span style='display:block; white-space:pre;color:#808080;'>index 724fb90..cf351c5 100644
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>--- a/src/cregistry/sql.c
</span><span style='display:block; white-space:pre;background:#e0e0ff;'>+++ b/src/cregistry/sql.c
</span><span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -197,7 +197,7 @@ int create_tables(sqlite3* db, reg_error* errPtr) {
</span> /* snapshots table */
"CREATE TABLE registry.snapshots ("
"id INTEGER PRIMARY KEY"
<span style='display:block; white-space:pre;background:#ffe0e0;'>- ", created_at DATETIME"
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ ", created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL"
</span> ", note TEXT"
")",
"CREATE INDEX registry.snapshot ON snapshots(id)",
<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 c8e178e..efb8cad 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;'>@@ -8,6 +8,7 @@
</span> package provide snapshot 1.0
package require macports 1.0
<span style='display:block; white-space:pre;background:#e0ffe0;'>+package require registry 1.0
</span>
namespace eval snapshot {
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -19,5 +20,15 @@ namespace eval snapshot {
</span> # Returns:
# None
puts "Still being developed"
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ #registry::entry addsnapshot
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ foreach port [registry::entry imaged] {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts [$port name]
</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;'>+ registry::entry testcall
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ set a [registry::entry snapshot "testsnapshot"]
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts $a
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ puts done
</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/registry2.0/entry.c b/src/registry2.0/entry.c
</span><span style='display:block; white-space:pre;color:#808080;'>index 0647816..71d1efe 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;'>@@ -477,6 +477,39 @@ static int entry_owner(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]) {
</span> }
}
<span style='display:block; white-space:pre;background:#e0ffe0;'>+static int test_call(){
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("inside registry2.0\n");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ test_call_c();
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("done here\n");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_OK;
</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;'>+static int snapshot_create(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ printf("inside 2.0 entry\n");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_registry* reg = registry_for(interp, reg_attached);
</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, "snapshot ?note?");
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_ERROR;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else if (reg == NULL) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_ERROR;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ } else {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ char* note = Tcl_GetString(objv[2]);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_error error;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ /* may be a new datatype for snapshot */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ reg_entry* new_snaphot = reg_snapshot_create(reg, note, &error);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (new_snaphot != NULL) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_Obj* result;
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ if (entry_to_obj(interp, &result, new_snaphot, NULL, &error)) {
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ Tcl_SetObjResult(interp, result);
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ return TCL_OK;
</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 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;'>+
</span> typedef struct {
char* name;
int (*function)(Tcl_Interp* interp, int objc, Tcl_Obj* CONST objv[]);
<span style='display:block; white-space:pre;background:#e0e0e0;'>@@ -493,6 +526,9 @@ static entry_cmd_type entry_cmds[] = {
</span> { "imaged", entry_imaged },
{ "installed", entry_installed },
{ "owner", entry_owner },
<span style='display:block; white-space:pre;background:#e0ffe0;'>+ /* test call */
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ { "testcall", test_call },
</span><span style='display:block; white-space:pre;background:#e0ffe0;'>+ { "snapshot", snapshot_create},
</span> { NULL, NULL }
};
</pre><pre style='margin:0'>
</pre>