Skip to content

Commit 70bf842

Browse files
committed
Support for fetch and clone without progress callbacks
1 parent ec74058 commit 70bf842

32 files changed

+1482
-829
lines changed

binding.gyp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
'src/odb.cc',
3535
'src/submodule.cc',
3636
'src/remote.cc',
37+
'src/clone_options.cc',
3738
'src/functions/copy.cc',
3839

3940
],

example/clone.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
var git = require('../'),
2+
rimraf = require('rimraf'),
3+
path = "/tmp/nodegit-clone-demo";
4+
5+
rimraf(path, function() {
6+
git.Repo.clone("https://github.com/nodegit/nodegit.git", path, null, function(error, repo) {
7+
if (error) throw error;
8+
9+
repo.getCommit('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5', function(error, commit) {
10+
if (error) throw error;
11+
12+
commit.getEntry('README.md', function(error, entry) {
13+
if (error) throw error;
14+
15+
entry.getBlob(function(error, blob) {
16+
if (error) throw error;
17+
18+
console.log(entry.name(), entry.sha(), blob.size() + 'b');
19+
console.log('========================================================\n\n');
20+
var firstTenLines = blob.toString().split('\n').slice(0, 10).join('\n');
21+
console.log(firstTenLines);
22+
console.log('...');
23+
});
24+
});
25+
});
26+
});
27+
});

example/fetch.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
var git = require('../'),
2+
path = require('path');
3+
4+
git.Repo.open(path.resolve(__dirname, '../.git'), function(error, repo) {
5+
if (error) throw error;
6+
7+
var remote = repo.getRemote("origin");
8+
remote.connect(0, function(error) {
9+
if (error) throw error;
10+
11+
remote.download(null, function(error) {
12+
if (error) throw error;
13+
14+
console.log("It worked!");
15+
})
16+
});
17+
});

include/clone_options.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* This code is auto-generated; unless you know what you're doing, do not modify!
3+
**/
4+
5+
#ifndef GITCLONEOPTIONS_H
6+
#define GITCLONEOPTIONS_H
7+
8+
#include <v8.h>
9+
#include <node.h>
10+
#include <string>
11+
12+
#include "git2.h"
13+
14+
using namespace node;
15+
using namespace v8;
16+
17+
class GitCloneOptions : public ObjectWrap {
18+
public:
19+
20+
static Persistent<Function> constructor_template;
21+
static void Initialize (Handle<v8::Object> target);
22+
23+
git_clone_options *GetValue();
24+
25+
static Handle<Value> New(void *raw);
26+
27+
private:
28+
GitCloneOptions(git_clone_options *raw);
29+
~GitCloneOptions();
30+
31+
static Handle<Value> New(const Arguments& args);
32+
33+
34+
git_clone_options *raw;
35+
};
36+
37+
#endif

include/remote.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ class GitRemote : public ObjectWrap {
5050
git_direction direction;
5151
Persistent<Function> callback;
5252
};
53+
static Handle<Value> Download(const Arguments& args);
54+
static void DownloadWork(uv_work_t* req);
55+
static void DownloadAfterWork(uv_work_t* req);
56+
57+
struct DownloadBaton {
58+
uv_work_t request;
59+
int error_code;
60+
const git_error* error;
61+
Persistent<Value> remoteReference;
62+
git_remote * remote;
63+
Persistent<Value> progress_cbReference;
64+
git_transfer_progress_callback progress_cb;
65+
Persistent<Value> payloadReference;
66+
void * payload;
67+
Persistent<Function> callback;
68+
};
5369
static Handle<Value> Connected(const Arguments& args);
5470
static Handle<Value> Stop(const Arguments& args);
5571
static Handle<Value> Disconnect(const Arguments& args);

include/repo.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,24 @@ class GitRepo : public ObjectWrap {
346346
git_repository * repo;
347347
Persistent<Function> callback;
348348
};
349+
static Handle<Value> Clone(const Arguments& args);
350+
static void CloneWork(uv_work_t* req);
351+
static void CloneAfterWork(uv_work_t* req);
352+
353+
struct CloneBaton {
354+
uv_work_t request;
355+
int error_code;
356+
const git_error* error;
357+
git_repository * out;
358+
Persistent<Value> urlReference;
359+
const char * url;
360+
Persistent<Value> local_pathReference;
361+
const char * local_path;
362+
Persistent<Value> optionsReference;
363+
const git_clone_options * options;
364+
Persistent<Function> callback;
365+
};
366+
static Handle<Value> GetRemote(const Arguments& args);
349367
git_repository *raw;
350368
};
351369

src/base.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "../include/submodule.h"
4141
#include "../include/tree_builder.h"
4242
#include "../include/remote.h"
43+
#include "../include/clone_options.h"
4344

4445
extern "C" void init(Handle<v8::Object> target) {
4546
HandleScope scope;
@@ -76,6 +77,9 @@ extern "C" void init(Handle<v8::Object> target) {
7677
GitDiffFile::Initialize(target);
7778
GitDelta::Initialize(target);
7879

80+
GitRemote::Initialize(target);
81+
GitCloneOptions::Initialize(target);
82+
7983
GitThreads::Initialize(target);
8084

8185
}

0 commit comments

Comments
 (0)