Skip to content

Commit 878ef6e

Browse files
committed
General housekeeping to the project.
- Fixed broken, and removed unnecessary, entries from the .gitignore. - Cleaned up the README, including code examples. - Deleted the distracting TODO file. - Migrated code generation into the build directory. - Renamed the npm run gen command to codegen.
1 parent 217d32a commit 878ef6e

8 files changed

Lines changed: 158 additions & 109 deletions

File tree

.gitignore

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
# Files
2-
.DS_Store
3-
/sftp-config.json
4-
5-
# Directories
6-
/build
7-
/example/stress/test
8-
/doc
9-
!doc/Theme.css
1+
/build/*
2+
!/build/codegen/
3+
/doc/*
4+
!/doc/Theme.css
105
/node_modules
11-
/testing.js
12-
/out
13-
/test.git
146
/test/.reposCache
15-
.idea

README.md

Lines changed: 122 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,169 @@
1-
nodegit
2-
=======
1+
NodeGit
2+
-------
33

4-
> Node.js libgit2 bindings
4+
> Node bindings to the [libgit2](http://libgit2.github.com/) project.
55
6-
**v0.1.1** [![Build
7-
Status](https://travis-ci.org/nodegit/nodegit.png)](https://travis-ci.org/nodegit/nodegit)
6+
**Stable: 0.1.1**
7+
8+
[![Build
9+
Status](https://travis-ci.org/tbranyen/nodegit.png)](https://travis-ci.org/nodegit/nodegit)
810

911
Maintained by Tim Branyen [@tbranyen](http://twitter.com/tbranyen), Michael
10-
Robinson [@codeofinterest](http://twitter.com/codeofinterest), and Nick Kallen [@nk](http://twitter.com/nk), with help from
11-
[awesome
12+
Robinson [@codeofinterest](http://twitter.com/codeofinterest), and Nick Kallen
13+
[@nk](http://twitter.com/nk), with help from [awesome
1214
contributors](https://github.com/tbranyen/nodegit/contributors)!
1315

14-
API Documentation
15-
------------------------
16+
## API Documentation. ##
1617

17-
Documentation may be found here: [`nodegit` documentation](http://www.nodegit.org/nodegit/).
18+
http://www.nodegit.org/nodegit/
1819

19-
Building and installing
20-
-----------------------
20+
## Building and Installing. ##
2121

22-
### Dependencies ###
22+
Dependencies:
2323

24-
To install `nodegit` you need `Node.js`, `python` and `cmake` (>=2.8).
24+
* [Python 2](https://www.python.org/)
25+
* [CMake >= 2.8](http://www.cmake.org/)
2526

26-
### Easy install (Recommended) ###
27-
This will install and configure everything you need to use `nodegit`.
27+
``` bash
28+
npm install nodegit
29+
```
2830

29-
```` bash
30-
$ npm run-script gen && npm install && npm test
31-
````
31+
### Building manually: ###
3232

33-
### Mac OS X/Linux/Unix ###
33+
If you wish to help contribute to nodegit it is useful to build locally.
3434

35-
#### Install `nodegit` by cloning source from GitHub and running `node install`: ####
35+
``` bash
36+
# Fetch this project.
37+
git clone git://github.com/tbranyen/nodegit.git
3638

37-
```` bash
38-
# Install system dependencies
39-
$ brew install cmake libzip
40-
$ npm install -g node-gyp
41-
````
39+
# Enter the repository.
40+
cd nodegit
4241

43-
```` bash
44-
$ git clone git://github.com/tbranyen/nodegit.git
45-
$ cd nodegit
46-
$ npm install ejs && npm run-script gen && npm install
47-
````
48-
### Ubuntu ###
42+
# Install the template engine, run the code generation script, and install.
43+
npm install ejs && npm run codegen && npm install
44+
```
4945

50-
```` bash
51-
# Install system dependencies as root
52-
$ sudo apt-get install libzip-dev
53-
````
46+
If you encounter errors, you most likely have not configured the dependencies
47+
correctly.
5448

55-
### Windows via Cygwin ###
49+
### Installing dependencies: ###
5650

57-
#### `nodegit` has been compiled and tested to work with the setup required to build and run `Node.js` itself. ####
51+
Using Brew on OS X:
52+
53+
``` bash
54+
brew install cmake libzip
55+
```
5856

59-
Instructions on compiling `Node.js` on a Windows platform can be found here:
60-
[https://github.com/ry/node/wiki/Building-node.js-on-Cygwin-(Windows)](https://github.com/ry/node/wiki/Building-node.js-on-Cygwin-%28Windows%29)
57+
Using APT on Ubuntu:
6158

62-
API Example Usage
63-
-----------------
59+
``` bash
60+
sudo apt-get install cmake libzip-dev build-essential
61+
```
6462

65-
Below are two examples. [There are several more](https://github.com/nodegit/nodegit/tree/master/example).
63+
## API examples. ##
6664

67-
### Git Log Emulation ###
65+
### Emulating git log: ###
6866

69-
```JavaScript
70-
var git = require('../'),
71-
path = require('path');
67+
``` javascript
68+
var open = require("/home/tim/git/nodegit/nodegit").Repo.open;
7269

73-
git.Repo.open(path.resolve(__dirname, '/tmp/repo/.git'), function(error, repo) {
74-
if (error) throw error;
70+
// Open the repository directory.
71+
open("tmp", function(err, repo) {
72+
if (err) {
73+
throw err;
74+
}
7575

76-
repo.getMaster(function(error, branch) {
77-
if (error) throw error;
76+
// Open the master branch.
77+
repo.getMaster(function(err, branch) {
78+
if (err) {
79+
throw err;
80+
}
7881

79-
// History returns an event.
82+
// Create a new history event emitter.
8083
var history = branch.history();
8184

82-
// History emits 'commit' event for each commit in the branch's history
83-
history.on('commit', function(commit) {
84-
console.log('commit ' + commit.sha());
85-
console.log('Author:', commit.author().name() + ' <' + commit.author().email() + '>');
86-
console.log('Date:', commit.date());
87-
console.log('\n ' + commit.message());
85+
// Create a counter to only show up to 9 entries.
86+
var count = 0;
87+
88+
// Listen for commit events from the history.
89+
history.on("commit", function(commit) {
90+
// Disregard commits past 9.
91+
if (++count >= 9) {
92+
return;
93+
}
94+
95+
// Show the commit sha.
96+
console.log("commit " + commit.sha());
97+
98+
// Store the author object.
99+
var author = commit.author();
100+
101+
// Display author information.
102+
console.log("Author:\t" + author.name() + " <", author.email() + ">");
103+
104+
// Show the commit date.
105+
console.log("Date:\t" + commit.date());
106+
107+
// Give some space and show the message.
108+
console.log("\n " + commit.message());
88109
});
89110

90-
// Don't forget to call `start()`!
111+
// Start emitting events.
91112
history.start();
92113
});
93114
});
94-
95115
```
96116

97-
### Clone a repo and read a file ###
117+
### Cloning a repository and reading a file: ###
118+
119+
``` javascript
120+
var clone = require("/home/tim/git/nodegit/nodegit").Repo.clone;
121+
122+
// Clone a given repository into a specific folder.
123+
clone("https://github.com/nodegit/nodegit", "tmp", null, function(err, repo) {
124+
if (err) {
125+
throw err;
126+
}
98127

99-
```JavaScript
100-
git.Repo.clone("https://github.com/nodegit/nodegit.git", path, null, function(error, repo) {
101-
if (error) throw error;
128+
// Use a known commit sha from this repository.
129+
var sha = "59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5";
102130

103-
repo.getCommit('59b20b8d5c6ff8d09518454d4dd8b7b30f095ab5', function(error, commit) {
104-
if (error) throw error;
131+
// Look up this known commit.
132+
repo.getCommit(sha, function(err, commit) {
133+
if (err) {
134+
throw error;
135+
}
105136

106-
commit.getEntry('README.md', function(error, entry) {
107-
if (error) throw error;
137+
// Look up a specific file within that commit.
138+
commit.getEntry("README.md", function(err, entry) {
139+
if (err) {
140+
throw error;
141+
}
108142

109-
entry.getBlob(function(error, blob) {
110-
if (error) throw error;
143+
// Get the blob contents from the file.
144+
entry.getBlob(function(err, blob) {
145+
if (err) {
146+
throw err;
147+
}
111148

112-
console.log(entry.name(), entry.sha(), blob.size() + 'b');
113-
console.log('========================================================\n\n');
114-
var firstTenLines = blob.toString().split('\n').slice(0, 10).join('\n');
115-
console.log(firstTenLines);
116-
console.log('...');
149+
// Show the name, sha, and filesize in byes.
150+
console.log(entry.name() + entry.sha() + blob.size() + "b");
151+
152+
// Show a spacer.
153+
console.log(Array(72).join("=") + "\n\n");
154+
155+
// Show the entire file.
156+
console.log(String(blob));
117157
});
118158
});
119159
});
120160
});
121161
```
122162

123-
[![githalytics.com alpha](https://cruel-carlota.pagodabox.com/a81b20d9f61dbcdc7c68002c6a564b5b "githalytics.com")](http://githalytics.com/tbranyen/nodegit)
163+
## Unit tests. ##
164+
165+
You will need to build locally before running the tests. See above.
166+
167+
``` bash
168+
npm test
169+
```

TODO

Lines changed: 0 additions & 1 deletion
This file was deleted.

build/codegen/generate.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const fs = require("fs");
2+
const ejs = require("ejs");
3+
const path = require("path");
4+
5+
var idefs = require("./v0.20.0.json");
6+
7+
var classTemplate = ejs.compile(
8+
fs.readFileSync(String(path.resolve("./templates/class.cc.ejs")), {
9+
filename: "class.cc"
10+
});
11+
12+
var headerTemplate = ejs.compile(
13+
fs.readFileSync(String(path.resolve("./templates/header.h.ejs")), {
14+
filename: "header.h"
15+
});
16+
17+
Object.keys(idefs).forEach(function(keyName) {
18+
var idef = idefs[keyName];
19+
20+
if (idef.ignore) {
21+
return;
22+
}
23+
24+
fs.writeFileSync(
25+
path.resolve("./include/" + idef.filename), headerTemplate(idef));
26+
27+
fs.writeFileSync(
28+
path.resolve("./src/" + path.basename(idef.filename, ".h") + ".cc"),
29+
classTemplate(idef));
30+
});
File renamed without changes.

gen.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@
4646
"scripts": {
4747
"install": "node install.js",
4848
"test": "cd test && nodeunit nodegit.js",
49-
"gen": "node gen.js"
49+
"codegen": "node build/codegen/generate.js"
5050
}
5151
}

vendor/libgit2

Submodule libgit2 updated 136 files

0 commit comments

Comments
 (0)