[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/nodegit/nodegit/v0.0.75/include/diff_list.h [Back]  [Original]

/*
 * Copyright 2011, Tim Branyen @tbranyen 
 * @author Michael Robinson @codeofinterest 
 *
 * Dual licensed under the MIT and GPL licenses.
 */

#include 
#include 
#include 
#include 
#include 

#include "../vendor/libgit2/include/git2.h"

#include "../include/repo.h"

using namespace node;
using namespace v8;

/**
 * Class wrapper for libgit2 git_diff_list
 */
class GitDiffList : public ObjectWrap {
  public:

    /**
     * v8::FunctionTemplate used to create Node.js constructor
     */
    static Persistent constructor_template;

    static const int WALK_DELTA_THRESHHOLD = 10;

    /**
     * Used to intialize the EventEmitter from Node.js
     *
     * @param target v8::Object the Node.js module object
     */
    static void Initialize (Handle target);

    git_diff_list* GetValue();
    void SetValue(git_diff_list* diffList);
    void Close();

  protected:
    GitDiffList() {}
    ~GitDiffList() {}

    static Handle New(const Arguments& args);
    static Handle Close(const Arguments& args);

    static Handle TreeToTree(const Arguments& args);
    static void TreeToTreeWork(uv_work_t *req);
    static void TreeToTreeAfterWork(uv_work_t *req);

    /**
     * Walk the current git_diff_list
     */
    static Handle Walk(const Arguments& args);
    static void WalkWork(void *payload);
    static int WalkWorkFile(const git_diff_delta *delta, float progress,
                             void *payload);
    static int WalkWorkHunk(const git_diff_delta *delta, const git_diff_range *range,
                             const char *header, size_t header_len, void *payload);
    static int WalkWorkData(const git_diff_delta *delta, /** delta that contains this data */
                             const git_diff_range *range, /** range of lines containing this data */
                             char line_origin,            /** git_diff_list_t value from above */
                             const char *content,         /** diff data - not NUL terminated */
                             size_t content_len,          /** number of bytes of diff data */
                             void *payload);              /** user reference data */
    /**
     * Called when WalkWorkFile reaches its cache
     * thresholds. Passes data back to main thread
     *
     * @param payload The WalkBaton
     */
    static void WalkWorkSendFile(uv_async_t *handle, int status /*UNUSED*/);
    static void WalkWorkSendHunk(uv_async_t *handle, int status /*UNUSED*/);
    static void WalkWorkSendData(uv_async_t *handle, int status /*UNUSED*/);
    static void WalkWorkSendEnd(uv_async_t *handle, int status /*UNUSED*/);

  private:
    git_diff_list* diffList;
    // git_oid* oldOid;
    // git_oid* newOid;

    struct TreeToTreeBaton {
      uv_work_t request;
      const git_error* error;

      GitDiffList *diffList;
      git_repository* repo;
      git_oid oldOid;
      std::string oldSha;
      git_oid newOid;
      std::string newSha;

      git_diff_list* rawDiffList;

      Persistent callback;
    };

    struct DeltaContent {
      git_diff_range *range;
      char lineOrigin;
      size_t contentLength;
      std::string content;
    };

    struct Delta {
      git_diff_delta *raw;
      std::vector contents;
    };

    struct WalkBaton {
      uv_thread_t threadId;
      uv_mutex_t mutex;
      uv_async_t asyncFile;
      uv_async_t asyncHunk;
      uv_async_t asyncData;
      uv_async_t asyncEnd;

      const git_error* error;

      std::map fileDeltas;

      git_diff_list* rawDiffList;
      Persistent fileCallback;
      Persistent hunkCallback;
      Persistent lineCallback;
      Persistent endCallback;
    };
};

Web Proxy Viewer  |  New URL  |  Original Page