Permalink
Browse files

Oh jesus it's messy. So very messy. Oh god.

  • Loading branch information...
1 parent 423a767 commit e3eb5c2cb836eec540f6a5a8f58e1bfd477548ca @samcday samcday committed Mar 31, 2011
Showing with 397 additions and 233 deletions.
  1. +7 −7 src/commit.cc
  2. +4 −4 src/commit.h
  3. +22 −46 src/gitobjectwrap.h
  4. +6 −8 src/gitteh.cc
  5. +190 −0 src/object_cache.h
  6. +0 −2 src/object_factory.h
  7. +1 −92 src/object_store.h
  8. +141 −67 src/repository.cc
  9. +7 −6 src/repository.h
  10. +17 −0 test.js
  11. +2 −1 wscript
View
@@ -24,8 +24,7 @@
#include "commit.h"
#include "repository.h"
-#include "object_factory.h"
-#include "tree.h"
+//#include "tree.h"
#include <time.h>
#include <stdlib.h>
#include "signature.h"
@@ -91,10 +90,9 @@ Handle<Value> Commit::New(const Arguments& args) {
HandleScope scope;
REQ_ARGS(1);
- REQ_EXT_ARG(0, theCommit);
+ REQ_EXT_ARG(0, commitArg);
- Commit *commit = new Commit();
- commit->commit_ = (git_commit*)theCommit->Value();
+ Commit *commit = static_cast<Commit*>(commitArg->Value());
commit->Wrap(args.This());
return args.This();
@@ -330,11 +328,12 @@ int Commit::EIO_AfterSave(eio_req *req) {
return 0;
}
-void* Commit::loadInitData() {
+void* Commit::loadInitData(int *result) {
commit_data *data = new commit_data;
repository_->lockRepository();
const git_oid *commitId = git_commit_id(commit_);
git_oid_fmt(data->id, commitId);
+
data->message = new std::string(git_commit_message(commit_));
data->author = git_signature_dup(git_commit_author(commit_));
data->committer = git_signature_dup(git_commit_committer(commit_));
@@ -402,7 +401,8 @@ void Commit::setOwner(void *owner) {
repository_ = static_cast<Repository*>(owner);
}
-Commit::Commit() : GitObjectWrap() {
+Commit::Commit(git_commit *commit) : GitObjectWrap<Commit>() {
+ commit_ = commit;
}
Commit::~Commit() {
View
@@ -8,11 +8,11 @@ namespace gitteh {
class Repository;
-class Commit : public GitObjectWrap {
+class Commit : public GitObjectWrap<Commit> {
public:
static Persistent<FunctionTemplate> constructor_template;
static void Init(Handle<Object>);
- Commit();
+ Commit(git_commit*);
~Commit();
static Handle<Value> SaveObject(Handle<Object>, Repository*, Handle<Value>, bool);
@@ -30,8 +30,8 @@ class Commit : public GitObjectWrap {
static Handle<Value> GetParent(const Arguments&);
static Handle<Value> Save(const Arguments&);
- void processInitData(void *data);
- void* loadInitData();
+ void processInitData(void*);
+ void* loadInitData(int*);
int parentCount_;
View
@@ -6,23 +6,15 @@
namespace gitteh {
+template<class T>
class GitObjectWrap : public ObjectWrap {
public:
GitObjectWrap() : ObjectWrap() {
CREATE_MUTEX(gatekeeperLock_);
initialized_ = 0;
- initInterest_ = 0;
data_ = NULL;
}
- // Shortcut, if this is a newly allocated object for a newly created Git
- // object, then there's not going to be any threads fighting for access,
- // we just mark it as initialized straight up, no need to even use a mutex.
- void forceInitialized() {
- processInitData(NULL);
- initialized_ = true;
- }
-
bool isInitialized() {
LOCK_MUTEX(gatekeeperLock_);
bool initialized = initialized_;
@@ -31,37 +23,29 @@ class GitObjectWrap : public ObjectWrap {
return initialized;
}
- void registerInitInterest() {
- LOCK_MUTEX(gatekeeperLock_);
- Ref();
- UNLOCK_MUTEX(gatekeeperLock_);
- }
-
- void removeInitInterest() {
- LOCK_MUTEX(gatekeeperLock_);
- Unref();
- initInterest_--;
-
- if(initInterest_ == 0) {
- DESTROY_MUTEX(initLock_);
- }
- UNLOCK_MUTEX(gatekeeperLock_);
- }
-
- void waitForInitialization() {
+ int waitForInitialization() {
bool needInitialization = false;
LOCK_MUTEX(gatekeeperLock_);
- if(!initInterest_++) {
+ if(!initialized_) {
needInitialization = true;
CREATE_MUTEX(initLock_);
LOCK_MUTEX(initLock_);
}
UNLOCK_MUTEX(gatekeeperLock_);
if(needInitialization) {
- void* data = loadInitData();
- initializationDone(data);
- return;
+ int result = GIT_SUCCESS;
+ void* data = loadInitData(&result);
+
+ LOCK_MUTEX(gatekeeperLock_);
+ data_ = data;
+ UNLOCK_MUTEX(gatekeeperLock_);
+
+ UNLOCK_MUTEX(initLock_);
+
+ if(result != GIT_SUCCESS) {
+ return result;
+ }
}
//LOCK_MUTEX(initLock_);
@@ -75,21 +59,13 @@ class GitObjectWrap : public ObjectWrap {
usleep(1000);
}
UNLOCK_MUTEX(initLock_);
- }
- void syncInitialize(void *data) {
- LOCK_MUTEX(gatekeeperLock_);
- UNLOCK_MUTEX(gatekeeperLock_);
+ return GIT_SUCCESS;
}
- // Signalled by the thread that is building the commit data that the data
- // is now done and JS object can be finalized.
- void initializationDone(void *data) {
+ void syncInitialize(void *data) {
LOCK_MUTEX(gatekeeperLock_);
- data_ = data;
UNLOCK_MUTEX(gatekeeperLock_);
-
- UNLOCK_MUTEX(initLock_);
}
// This should only be called from main thread. When one or more requests
@@ -99,10 +75,11 @@ class GitObjectWrap : public ObjectWrap {
// the JS object. All the requests will call this, but only the first one
// will actually make anything meaningful happen.
void ensureInitDone() {
- // FIXME? don't think any locking is necessary here as this is ONLY
- // called from main thread.
LOCK_MUTEX(gatekeeperLock_);
- if(data_ != NULL) {
+ if(!initialized_) {
+ Handle<Value> constructorArgs[1] = { External::New(this) };
+ T::constructor_template->GetFunction()->NewInstance(1, constructorArgs);
+
processInitData(data_);
initialized_ = true;
data_ = NULL;
@@ -116,11 +93,10 @@ class GitObjectWrap : public ObjectWrap {
// This is implemented by actual object classes. Implements MUST free all
// resources allocated by the data on the heap.
virtual void processInitData(void *data) = 0;
- virtual void* loadInitData() = 0;
+ virtual void* loadInitData(int *result) = 0;
private:
bool initialized_;
- int initInterest_;
gitteh_lock gatekeeperLock_;
gitteh_lock initLock_;
void *data_;
View
@@ -25,42 +25,40 @@
#include "gitteh.h"
#include "commit.h"
-#include "tree.h"
#include "repository.h"
+/*#include "tree.h"
#include "index.h"
#include "index_entry.h"
#include "tag.h"
#include "rev_walker.h"
-#include "error.h"
#include "ref.h"
-#include "blob.h"
+#include "blob.h"*/
+#include "error.h"
#include "thread.h"
namespace gitteh {
-#if 0
static void gcNotif(GCType type, GCCallbackFlags flags) {
std::cout << "gc is happening yo.\n";
}
-#endif
extern "C" void
init(Handle<Object> target) {
HandleScope scope;
Repository::Init(target);
Commit::Init(target);
- Tree::Init(target);
+ /*Tree::Init(target);
Index::Init(target);
IndexEntry::Init(target);
Tag::Init(target);
RevWalker::Init(target);
Reference::Init(target);
- Blob::Init(target);
+ Blob::Init(target);*/
ErrorInit(target);
- //V8::AddGCPrologueCallback(gcNotif);
+ V8::AddGCPrologueCallback(gcNotif);
}
} // namespace gitteh
Oops, something went wrong.

0 comments on commit e3eb5c2

Please sign in to comment.