diff --git a/.gitignore b/.gitignore index c85f3e820..91f748bb6 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ build doc !doc/Theme.css example/stress/test +node_modules +.DS_Store diff --git a/.gitmodules b/.gitmodules index 007c6113b..c7bc5e0e7 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,12 +1,6 @@ -[submodule "vendor/nodeunit"] - path = vendor/nodeunit - url = git://github.com/caolan/nodeunit.git -[submodule "vendor/rimraf"] - path = vendor/rimraf - url = git://github.com/isaacs/rimraf.git -[submodule "vendor/libgit2"] - path = vendor/libgit2 - url = git://github.com/libgit2/libgit2.git [submodule "example/stress/jquery"] path = example/stress/jquery url = https://github.com/jquery/jquery.git +[submodule "vendor/libgit2"] + path = vendor/libgit2 + url = git://github.com/libgit2/libgit2.git diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..baa0031d5 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,3 @@ +language: node_js +node_js: + - 0.8 diff --git a/Makefile b/Makefile deleted file mode 100644 index 4207da976..000000000 --- a/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -NODE_JS = $(if $(shell test -f /usr/bin/nodejs && echo "true"),nodejs,node) -NODE_BLD = node-waf -NODE_LIB_PATH = ~/.node_modules - -BASE = . -INSTALL_PATH = $(NODE_LIB_PATH)/nodegit - -NATURAL_DOCS_PATH = $(BASE)/vendor/naturaldocs/ - -all: build - -update: clean config build uninstall install - -config: - @@$(BASE)/configure - -build: - @@$(NODE_BLD) build - -debug: - @@$(NODE_BLD) debug - -install: - @@mkdir -p $(INSTALL_PATH) - @@mkdir -p $(INSTALL_PATH)/build/Release - @@mkdir -p $(INSTALL_PATH)/lib - @@mkdir -p $(INSTALL_PATH)/vendor - - @@cp -f $(BASE)/build/Release/nodegit.node $(INSTALL_PATH)/build/Release/nodegit.node - @@cp -f $(BASE)/lib/* $(INSTALL_PATH)/lib/ - @@cp -rf $(BASE)/vendor/* $(INSTALL_PATH)/vendor/ - @@cp -f $(BASE)/package.json $(INSTALL_PATH)/ - - @@echo "Installed to $(INSTALL_PATH)" - -uninstall: - @@rm -rf $(INSTALL_PATH) - @@echo "Uninstalled from $(INSTALL_PATH)" - -clean: - @@rm -rf $(BASE)/build/ - @@rm -rf $(BASE)/vendor/libgit2/build/ - -test: - @@$(NODE_JS) $(BASE)/test/index.js test - -lint: - @@$(NODE_JS) $(BASE)/util/hint-check.js - -doc: - @@$(NATURAL_DOCS_PATH)/NaturalDocs -i $(BASE)/include -o HTML $(BASE)/doc -p $(BASE)/doc -s Theme - -.PHONY: test build doc diff --git a/README.md b/README.md index f0e0d639a..86ed14aa4 100644 --- a/README.md +++ b/README.md @@ -1,14 +1,24 @@ -Node.js libgit2 bindings +Node.js libgit2 bindings [![Build Status](https://travis-ci.org/tbranyen/nodegit.png)](https://travis-ci.org/tbranyen/nodegit) ======================= Created by Tim Branyen [@tbranyen](http://twitter.com/tbranyen) -Currently under active development (and seeking contributors), `nodegit` provides asynchronous native bindings to the `libgit2` C API. +Currently under active development (and seeking contributions), `nodegit` provides asynchronous native bindings to the [`libgit2`](http://libgit2.github.com/libgit2/) C API. + + +Contributing +------------ + +Nodegit aims to eventually provide native asynchronous bindings for as much of libgit2 as possible, but we can't do it alone! + +We welcome pull requests, but please pay attention to the following: whether your lovely code fixes a bug or adds a new feature, please include unit tests that either prove the bug is fixed, or that your new feature works as expected. See [running tests](#running-tests) + +Unit tests are what makes the Node event loop go around. Building and installing ----------------------- -### Dependancies ### +### Dependencies ### To run `nodegit` you need `Node.js` and to run unit tests you will need to have `git` installed and accessible from your `PATH` to fetch any `vendor/` addons. ### Easy install (Recommended) ### @@ -20,26 +30,19 @@ $ npm install nodegit ### Mac OS X/Linux/Unix ### -#### Install `nodegit` by cloning source from GitHub and running the `configure`, `make`, and `make install` commands: #### -\*Note: `nodegit` assumes your library path exists at `~/.node_libraries` you can change this by specifying a new lib path\* - +#### Install `nodegit` by cloning source from GitHub and running `node install`: #### + ```` bash $ git clone git://github.com/tbranyen/nodegit.git $ cd nodegit - -$ ./configure -$ make -$ make install - -$ make install NODE_LIB_PATH=/path/to/your/libraries +$ node install ```` \*Updating to a new version\* ```` bash -$ make update - -$ make update NODE_LIB_PATH=/path/to/your/libraries +$ git pull +$ node install ```` ### Windows via Cygwin ### @@ -60,22 +63,22 @@ API Example Usage var git = require("nodegit"); // Read a repository -git.repo(".git", function(err, repo) { +git.repo('.git', function(err, repo) { // Success is always 0, failure is always an error string - if (err) { throw err; } + if (error) { throw error; } // Use the master branch - repo.branch("master", function(err, branch) { - if (err) { throw err; } + repo.branch('master', function(err, branch) { + if (error) { throw error; } // Iterate over the revision history var history = branch.history(); - + // Commit event emits commit object - history.on("commit", function(commit) { + history.on('commit', function(commit) { // Print out `git log` emulation - console.log("commit " + commit.sha); - console.log(commit.author.name + "<" + commit.author.email + ">"); + console.log('commit ' + commit.sha); + console.log(commit.author.name + '<' + commit.author.email + '>'); console.log(commit.time); console.log("\n"); console.log(commit.message); @@ -88,81 +91,81 @@ git.repo(".git", function(err, repo) { #### Raw API #### ```` javascript -var git = require( 'nodegit' ).raw; +var git = require('nodegit').raw; // Create instance of Repo constructor var repo = new git.Repo(); // Read a repository -repo.open( '.git', function( err ) { +repo.open('.git', function(error) { // Err is an integer, success is 0, use strError for string representation - if( err ) { + if(error) { var error = new git.Error(); - throw error.strError( err ); + throw error.strError(error); } // Create instance of Ref constructor with this repository - var ref = new git.Ref( repo ); - + var ref = new git.Ref(repo); + // Find the master branch - repo.lookupRef( ref, '/refs/heads/master', function( err ) { - if( err ) { + repo.lookupRef(ref, '/refs/heads/master', function(err) { + if(error) { var error = new git.Error(); - throw error.strError( err ); + throw error.strError(err); } // Create instance of Commit constructor with this repository - var commit = new git.Commit( repo ), + var commit = new git.Commit(repo), // Create instance of Oid constructor oid = new git.Oid(); // Set the oid constructor internal reference to this branch reference - ref.oid( oid ); + ref.oid(oid); // Lookup the commit for this oid - commit.lookup( oid, function() { - if( err ) { + commit.lookup(oid, function(err) { + if(err) { var error = new git.Error(); throw error.strError( err ); } // Create instance of RevWalk constructor with this repository - var revwalk = new git.RevWalk( repo ); + var revwalk = new git.RevWalk(repo); // Push the commit as the start to walk - revwalk.push( commit ); + revwalk.push(commit); // Recursive walk function walk() { // Each revision walk iteration yields a commit - var revisionCommit = new git.Commit( repo ); + var revisionCommit = new git.Commit(repo); - revwalk.next( revisionCommit, function( err ) { + revwalk.next( revisionCommit, function(err) { // Finish recursion once no more revision commits are left - if( err ) { return; } + if(err) { return; } // Create instance of Oid for sha var oid = new git.Oid(); // Set oid to the revision commit - revisionCommit.id( oid ); + revisionCommit.id(oid); // Create instance of Sig for author var author = new git.Sig(); // Set the author to the revision commit author - revisionCommit.author( author ); + revisionCommit.author(author); // Convert timestamp to milliseconds and set new Date object var time = new Date( revisionCommit.time() * 1000 ); // Print out `git log` emulation - console.log( oid.toString( 40 ) ); - console.log( author.name() + '<' + author.email() + '>' ); - console.log( time ); - console.log( '\n' ); - console.log( revisionCommit.message() ); - console.log( '\n' ); + console.log(oid.toString( 40 )); + console.log(author.name() + '<' + author.email() + '>'); + console.log(time); + console.log('\n'); + console.log(revisionCommit.message()); + console.log('\n'); // Recurse! walk(); @@ -181,17 +184,15 @@ Running tests __`nodegit` library code is written adhering to a modified `JSHint`. Run these checks with `make lint` in the project root.__ -__To run unit tests ensure the submodules `nodeunit` and `rimraf` are located in the `vendor/` subdirectory.__ - -If they are not, `cd` into the `nodegit` dir and run the following `git` commands to automatically fetch them: - $ cd nodegit - $ git submodule update --init +__To run unit tests ensure to update the submodules with `git submodule update --init` and install the development dependencies nodeunit and rimraf with `npm install`.__ -Then simply run `make test` in the project root. +Then simply run `npm test` in the project root. -Generating documentation +Documentation ------------------------ +Recent documentation may be found here: [`nodegit` documentation](http://tbranyen.github.com/nodegit/) + __`nodegit` native and library code is documented to be built with `Natural Docs`.__ To create the documentation, `cd` into the `nodegit` dir and run the following: @@ -205,6 +206,15 @@ Release information __Can keep track of current method coverage at: [http://bit.ly/tb_methods](http://bit.ly/tb_methods)__ +### v0.0.7: ### + * Updated to work with Node ~0.8. + * More unit tests + * Added convenience build script + * Locked libgit2 to version 0.15.0 + +### v0.0.6: ### + * Updated to work with Node ~0.6. + ### v0.0.5: ### * Added in fast Buffer support. * Blob raw write supported added, no convenience methods yet... @@ -247,4 +257,4 @@ Getting involved If you find this project of interest, please document all issues and fork if you feel you can provide a patch. Testing is of huge importance; by simply running the unit tests on your system and reporting issues you can contribute! -__Before submitting a pull request, please ensure both unit tests and lint checks pass.__ +__Before submitting a pull request, please ensure both that you've added unit tests to cover your shiny new code, and that all unit tests and lint checks pass.__ diff --git a/binding.gyp b/binding.gyp new file mode 100644 index 000000000..7902aedd6 --- /dev/null +++ b/binding.gyp @@ -0,0 +1,49 @@ +{ + 'targets': [ + { + 'target_name': 'nodegit', + 'sources': [ + 'src/base.cc', + 'src/blob.cc', + 'src/commit.cc', + 'src/error.cc', + 'src/object.cc', + 'src/oid.cc', + 'src/reference.cc', + 'src/repo.cc', + 'src/revwalk.cc', + 'src/sig.cc', + 'src/tree.cc', + 'src/tree_entry.cc' + ], + 'todosources': [ + ], + + 'include_dirs': [ + 'vendor/libv8-convert', + 'vendor/libgit2/include' + ], + + 'libraries': [ + '-L constructor_template; + static Persistent constructor_template; /** * Used to intialize the EventEmitter from Node.js @@ -56,10 +56,11 @@ class GitCommit : public ObjectWrap { ~GitCommit() {} static Handle New(const Arguments& args); + static Handle NewInstance(); static Handle Lookup(const Arguments& args); - static void EIO_Lookup(eio_req *req); - static int EIO_AfterLookup(eio_req *req); + static void LookupWork(uv_work_t *req); + static void LookupAfterWork(uv_work_t *req); static Handle Close(const Arguments& args); static Handle Id(const Arguments& args); @@ -71,11 +72,15 @@ class GitCommit : public ObjectWrap { static Handle Author(const Arguments& args); static Handle Tree(const Arguments& args); - static int EIO_Tree(eio_req* req); - static int EIO_AfterTree(eio_req* req); + static void TreeWork(uv_work_t* req); + static void TreeAfterWork(uv_work_t* req); static Handle ParentCount(const Arguments& args); + + static Handle ParentSync(const Arguments& args); static Handle Parent(const Arguments& args); + static void ParentWork(uv_work_t* req); + static void ParentAfterWork(uv_work_t* req); private: git_commit* commit; @@ -89,10 +94,22 @@ class GitCommit : public ObjectWrap { Persistent callback; }; - //struct tree_request { - // GitCommit* commit; - // Tree* tree; - // Persistent callback; - //}; + /** + * Struct: parent_request + * Contains references to the current commit, parent commit (output) + * parent commit's index, also contains references to an error code post + * lookup, and a callback function to execute. + */ + struct ParentBaton { + uv_work_t request; + int errorCode; + const char* errorMessage; + + int index; + GitCommit *commit; + git_commit *rawParentCommit; + Persistent callback; + }; + }; #endif diff --git a/include/reference.h b/include/reference.h index cbe3caf85..8037f2dad 100755 --- a/include/reference.h +++ b/include/reference.h @@ -32,8 +32,8 @@ class GitReference : public ObjectWrap { static Handle New(const Arguments& args); static Handle Lookup(const Arguments& args); - static void EIO_Lookup(eio_req* req); - static int EIO_AfterLookup(eio_req* req); + static void EIO_Lookup(uv_work_t* req); + static void EIO_AfterLookup(uv_work_t* req); static Handle Oid(const Arguments& args); diff --git a/include/repo.h b/include/repo.h index c840036f4..322f5b3b3 100755 --- a/include/repo.h +++ b/include/repo.h @@ -42,18 +42,18 @@ class GitRepo : public ObjectWrap { static Handle New(const Arguments& args); static Handle Open(const Arguments& args); - static void EIO_Open(eio_req* req); - static int EIO_AfterOpen(eio_req* req); + static void EIO_Open(uv_work_t* req); + static void EIO_AfterOpen(uv_work_t* req); static Handle Lookup(const Arguments& args); - static int EIO_Lookup(eio_req* req); - static int EIO_AfterLookup(eio_req* req); + static void EIO_Lookup(uv_work_t* req); + static void EIO_AfterLookup(uv_work_t* req); static Handle Free(const Arguments& args); static Handle Init(const Arguments& args); - static void EIO_Init(eio_req* req); - static int EIO_AfterInit(eio_req* req); + static void EIO_Init(uv_work_t* req); + static void EIO_AfterInit(uv_work_t* req); private: git_repository* repo; diff --git a/include/revwalk.h b/include/revwalk.h index 2e1db881e..203e2cf53 100755 --- a/include/revwalk.h +++ b/include/revwalk.h @@ -41,8 +41,8 @@ class GitRevWalk : public ObjectWrap { static Handle Hide(const Arguments& args); static Handle Next(const Arguments& args); - static void EIO_Next(eio_req* req); - static int EIO_AfterNext(eio_req* req); + static void EIO_Next(uv_work_t* req); + static void EIO_AfterNext(uv_work_t* req); static Handle Sorting(const Arguments& args); static Handle Free(const Arguments& args); diff --git a/include/tree.h b/include/tree.h index 74c748aab..2b8839032 100755 --- a/include/tree.h +++ b/include/tree.h @@ -93,15 +93,15 @@ class GitTree : public ObjectWrap { static Handle New(const Arguments& args); static Handle Lookup(const Arguments& args); - static int EIO_Lookup(eio_req *req); - static int EIO_AfterLookup(eio_req *req); + static void EIO_Lookup(uv_work_t *req); + static void EIO_AfterLookup(uv_work_t *req); static Handle EntryCount(const Arguments& args); static Handle EntryByIndex(const Arguments& args); - static void EIO_EntryByIndex(eio_req *req); - static int EIO_AfterEntryByIndex(eio_req *req); + static void EIO_EntryByIndex(uv_work_t *req); + static void EIO_AfterEntryByIndex(uv_work_t *req); static Handle EntryByName(const Arguments& args); - static void EIO_EntryByName(eio_req *req); - static int EIO_AfterEntryByName(eio_req *req); + static void EIO_EntryByName(uv_work_t *req); + static void EIO_AfterEntryByName(uv_work_t *req); static Handle SortEntries(const Arguments& args); static Handle ClearEntries(const Arguments& args); diff --git a/install.js b/install.js new file mode 100644 index 000000000..1207a4a43 --- /dev/null +++ b/install.js @@ -0,0 +1,114 @@ +var async = require('async'), + child_process = require('child_process'), + spawn = child_process.spawn, + path = require('path'), + fs = require('fs'), + request = require('request'), + AdmZip = require('adm-zip'); + +function passthru() { + var args = Array.prototype.slice.call(arguments); + var cb = args.splice(-1)[0]; + var cmd = args.splice(0, 1)[0]; + var opts = {}; + if(typeof(args.slice(-1)[0]) === 'object') { + opts = args.splice(-1)[0]; + } + var child = spawn(cmd, args, opts); + + child.stdout.pipe(process.stdout); + child.stderr.pipe(process.stderr); + child.on('exit', cb); +} + +function shpassthru() { + var cmd = + passthru.apply(null, ['/bin/sh', '-c'].concat(Array.prototype.slice.call(arguments))); +} + +function envpassthru() { + passthru.apply(null, ['/usr/bin/env'].concat(Array.prototype.slice.call(arguments))); +} + +var updateSubmodules = function(mainCallback) { + console.log('[nodegit] Downloading libgit2 dependency.'); + async.series([ + function(callback) { + envpassthru('git', 'submodule', 'init', callback); + }, function(callback) { + envpassthru('git', 'submodule', 'update', callback); + } + ], function(error) { + if (error) process.exit(error); + mainCallback(); + }); +}; + +var checkoutDependencies = function(mainCallback) { + console.log('[nodegit] Downloading libgit2 dependency.'); + + var libgit2ZipUrl = 'https://github.com/libgit2/libgit2/archive/v0.15.0.zip'; + zipFile = __dirname + '/vendor/libgit2.zip', + unzippedFolderName = __dirname + '/vendor/libgit2-0.15.0', + targetFolderName = __dirname + '/vendor/libgit2'; + + async.series([ + function(callback) { + request(libgit2ZipUrl) + .pipe(fs.createWriteStream(zipFile)) + .on('close', function () { + callback(); + }); + + }, function(callback) { + var zip = new AdmZip(zipFile); + zip.extractAllTo(__dirname + '/vendor/', true); + fs.unlink(zipFile); + callback(); + }, + function renameLibgit2Folder(callback) { + fs.rename(unzippedFolderName, targetFolderName, callback); + } + ], function(error) { + if (error) process.exit(error); + mainCallback(); + }); +}; + +var buildDir = path.join(__dirname, 'vendor/libgit2/build'); +async.series([ + function(callback) { + // Check for presence of .git folder + fs.exists(__dirname + '/.git', function(exists) { + if (exists) { + updateSubmodules(callback); + } else { + checkoutDependencies(callback); + } + }); + }, + function(callback) { + console.log('[nodegit] Building libgit2 dependency.'); + envpassthru('mkdir', '-p', buildDir, callback); + }, + function(callback) { + envpassthru('cmake', '-DTHREADSAFE=1', '-DBUILD_CLAR=0', '..', { + cwd: buildDir + }, callback); + }, + function(callback) { + envpassthru('cmake', '--build', '.', { + cwd: buildDir + }, callback); + }, + function(callback) { + console.log('[nodegit] Building native module.'); + // shpassthru('node-gyp configure --debug', callback); + shpassthru('node-gyp configure', callback); + }, + function(callback) { + shpassthru('node-gyp build', callback); + } +], function(err) { + if(err) process.exit(err); +}); diff --git a/lib/commit.js b/lib/commit.js index 43afc7bae..4d7efeb32 100644 --- a/lib/commit.js +++ b/lib/commit.js @@ -4,20 +4,13 @@ var git = require( '../' ) var _Commit = function( obj ) { var self = { _cache: {} }; - //if( obj instanceof git.raw.Repo ) { - // self.commit = new git.raw.Commit( obj ); - //} - //else if( obj instanceof git.raw.Commit ) { - // self.commit = obj; - //} - if( obj instanceof git.raw.Commit ) { self.commit = obj; } else { self.commit = new git.raw.Commit(); } - + Object.defineProperty( self, 'id', { get: function() { var oid = new git.raw.Oid(); @@ -28,12 +21,12 @@ var _Commit = function( obj ) { enumerable: true }); - Object.defineProperty( self, 'sha', { + Object.defineProperty(self, 'sha', { get: function() { var oid = new git.raw.Oid(); - self.commit.id( oid ); + self.commit.id(oid); - return oid.toString( 40 ); + return oid.toString(40); }, enumerable: true }); @@ -66,10 +59,17 @@ var _Commit = function( obj ) { enumerable: true }); + Object.defineProperty(self, 'parentCount', { + get: function() { + return self.commit.parentCount(); + }, + enumerable: true + }); + Object.defineProperty( self, 'author', { get: function() { var sig = new git.raw.Sig(); - + self.commit.author( sig ); return git.sig( sig ); @@ -104,24 +104,50 @@ var _Commit = function( obj ) { return self.tree().entry( path ); }; - self.history = function( start, end ) { - var revwalk = git.revwalk( self.repo ), + self.history = function(start, end) { + var revwalk = git.revwalk(self.repo), event = new events.EventEmitter(), commits = []; - revwalk.walk( self.id, function( err, index, commit ) { - if( err ) { - event.emit( 'end', commits ); - } - else { - event.emit( 'commit', commit ); - commits.push( commit ); + revwalk.walk(self.id, function(error, index, commit) { + if(error) { + if (error === git.error.GIT_EREVWALKOVER) { + event.emit('end', null, commits); + return; + } else { + event.emit('commit', new git.error(error), commit); + return; + } } + event.emit('commit', null, commit); + commits.push(commit); }); return event; }; + /** + * Retrieve the commit's parent at the given position. + * + * @todo implement async + * + * @param {Integer} position + */ + self.parent = function(position, callback) { + var parent = + self.commit.parent(position, function(errorCode, parent) { + var error = null; + if (errorCode !== git.error.GIT_SUCCESS) { + error = git.error(errorCode); + } + callback(error, new _Commit(parent)); + }); + + }; + + self.parentSync = function(position) { + return new _Commit(self.commit.parentSync(position)); + }; return self; }; diff --git a/lib/error.js b/lib/error.js index ac4b18750..de7716670 100644 --- a/lib/error.js +++ b/lib/error.js @@ -1,22 +1,29 @@ -var git = require( '../' ); +var git = require('../'), + util = require('util'); -var _Error = function( obj ) { - var self = {}; - - if( obj instanceof git.raw.Error ) { - self.error = obj; - } - else { - if( !self.error ) { - self.error = new git.raw.Error(); - } - - if( typeof obj === 'number' ) { - return self.error.strError( obj ); - } +/** + * Initialise an Error object + * + * @param {mixed} obj A git.raw.Error object or a string describing the error. + * @return {Object} + */ +var GitError = function(object) { + var error = null; + var gitError = new git.raw.Error(); + if (typeof object === 'number') { + error = new Error(gitError.strError(object)); + error.code = object; } - - return self; + return error; }; -exports.error = _Error; +/** + * Add libgit2 error codes to git.error object. + * + * Refer to vendor/libgit2/include/git2/errors.h for error code definitions. + */ +for (var errorName in git.raw.Error.codes) { + GitError[errorName] = git.raw.Error.codes[errorName]; +} + +exports.error = GitError; diff --git a/lib/index.js b/lib/index.js index 613b17b17..3d687095f 100755 --- a/lib/index.js +++ b/lib/index.js @@ -13,7 +13,6 @@ if (~os.type().indexOf("CYGWIN") && !~path.indexOf(root)) { exports.util = require("./util.js").util; exports.blob = require("./blob.js").blob; exports.repo = require("./repo.js").repo; -exports.error = require("./error.js").error; exports.sig = require("./sig.js").sig; exports.oid = require("./oid.js").oid; exports.object = require("./object.js").object; @@ -24,6 +23,14 @@ exports.tree = require("./tree.js").tree; exports.entry = require("./tree_entry.js").entry; // Assign raw api to module -exports.raw = require("../build/Release/nodegit"); +try { + exports.raw = require('../build/Debug/nodegit'); +} catch (error) { + exports.raw = require('../build/Release/nodegit'); +} + +// Initialize error object after so it may access raw.Error +exports.error = require("./error.js").error; + // Set version -exports.version = "0.0.6"; +exports.version = "0.0.7"; diff --git a/lib/repo.js b/lib/repo.js index 89de31f60..4e05f3276 100644 --- a/lib/repo.js +++ b/lib/repo.js @@ -11,7 +11,7 @@ exports.repo = function(dir, async) { if (dir && async) { self.repo.open(dir, function() { - git.util().asyncComplete.call(this, arguments, async); + git.util().asyncComplete.call(self, arguments, async); }); } else if (dir) { diff --git a/lib/tree.js b/lib/tree.js index 57ddb2630..e51d3de41 100644 --- a/lib/tree.js +++ b/lib/tree.js @@ -18,45 +18,70 @@ var _Tree = function( obj, tree ) { self.tree = new git.raw.Tree(); } - Object.defineProperty( self, 'length', { + Object.defineProperty(self, 'length', { get: function() { return self.tree.entryCount(); }, enumerable: true }); - self.walk = function( repo ) { - var entry - , i - , len = self.length - , repo = repo || self.repo - , event = new events.EventEmitter(); + self.walk = function(repo) { + repo = repo || self.repo; - function next(i) { + var entry, + index, + length = self.length, + event = new events.EventEmitter(), + entries = []; + + function next(index) { var dir; var tree; + var prerequisites = 0; - entry = git.entry( repo ); - - self.tree.entryByIndex(entry.entry, i, function() { - if(entry.isFile()) { - event.emit( 'entry', i, entry ); + function complete(error) { + if (index < length-1) { + next(index = index+1); + } else { + event.emit('end', error, entries); } - else { + } + + entry = git.entry(repo); + + self.tree.entryByIndex(entry.entry, index, function() { + if (entry.isFile()) { + entries.push(entry); + event.emit('entry', null, index, entry); + } else { dir = entry.name; tree = entry.tree(); + prerequisites++; + if (tree.error) { + event.emit('end', tree.error); + return; + } - !tree.error && tree.walk( repo ).on( 'entry', function( i, entry ) { - entry.dir += dir + '/'; - event.emit( 'entry', i, entry ); + tree.walk(repo).on('entry', function(error, index, entry) { + if (error) { + event.emit('entry', error, index, entry); + } + entry.dir = dir + '/' + entry.dir; + event.emit('entry', null, index, entry); + }).on('end', function(error, endEntries) { + if (error) { + complete(error); + } + prerequisites--; + entries = entries.concat(endEntries); + if (prerequisites === 0) { + complete(error); + } }); } - if( i (http://twitter.com/tbranyen)", + "contributors": [ + { + "name": "Michael Robinson", + "email": "mike@pagesofinterest.net" + } + ], "main": "./lib/index.js", "repository": { "type": "git", @@ -14,10 +27,20 @@ "lib": "./lib" }, "engines": { - "node": "~0.6" + "node": "~0.8" + }, + "dependencies": { + "node-gyp": "~0.8.2" + }, + "devDependencies": { + "adm-zip": "0.2.x", + "request": "2.9.x", + "async": ">= 0.1.21", + "nodeunit": "0.7.x", + "rimraf": "1.0.x" }, "scripts": { - "preinstall": "./configure", - "install": "make" + "install": "node install.js", + "test": "cd test && nodeunit *.js" } } diff --git a/src/blob.cc b/src/blob.cc index 3ef5668a8..ff56275b5 100755 --- a/src/blob.cc +++ b/src/blob.cc @@ -21,7 +21,7 @@ void GitBlob::Initialize (Handle target) { HandleScope scope; Local t = FunctionTemplate::New(New); - + constructor_template = Persistent::New(t); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->SetClassName(String::NewSymbol("Blob")); @@ -80,9 +80,6 @@ Handle GitBlob::New(const Arguments& args) { Handle GitBlob::Lookup(const Arguments& args) { HandleScope scope; - GitBlob* blob = ObjectWrap::Unwrap(args.This()); - Local callback; - if(args.Length() == 0 || !args[0]->IsObject()) { return ThrowException(Exception::Error(String::New("Repo is required and must be an Object."))); } @@ -95,7 +92,8 @@ Handle GitBlob::Lookup(const Arguments& args) { return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); } - callback = Local::Cast(args[2]); + GitBlob* blob = ObjectWrap::Unwrap(args.This()); + Local callback = Local::Cast(args[2]); lookup_request* ar = new lookup_request(); ar->blob = blob; @@ -105,13 +103,14 @@ Handle GitBlob::Lookup(const Arguments& args) { blob->Ref(); - eio_custom(EIO_Lookup, EIO_PRI_DEFAULT, EIO_AfterLookup, ar); - ev_ref(EV_DEFAULT_UC); + uv_work_t *req = new uv_work_t; + req->data = ar; + uv_queue_work(uv_default_loop(), req, EIO_Lookup, EIO_AfterLookup); return scope.Close( Undefined() ); } -void GitBlob::EIO_Lookup(eio_req* req) { +void GitBlob::EIO_Lookup(uv_work_t* req) { lookup_request* ar = static_cast(req->data); git_oid oid = ar->oid->GetValue(); @@ -119,9 +118,9 @@ void GitBlob::EIO_Lookup(eio_req* req) { } -int GitBlob::EIO_AfterLookup(eio_req* req) { +void GitBlob::EIO_AfterLookup(uv_work_t* req) { lookup_request* ar = static_cast(req->data); - ev_unref(EV_DEFAULT_UC); + delete req; ar->blob->Unref(); Local argv[1]; @@ -131,14 +130,13 @@ int GitBlob::EIO_AfterLookup(eio_req* req) { ar->callback->Call(Context::GetCurrent()->Global(), 1, argv); - if(try_catch.HasCaught()) + if(try_catch.HasCaught()) { FatalException(try_catch); - + } + ar->callback.Dispose(); delete ar; - - return 0; } Handle GitBlob::RawContent(const Arguments& args) { @@ -151,7 +149,7 @@ Handle GitBlob::RawContent(const Arguments& args) { int bufferLength = rawSize; Buffer* buffer = Buffer::New(const_cast(contents.c_str()), bufferLength); - + Local fastBuffer; MAKE_FAST_BUFFER(buffer, fastBuffer); diff --git a/src/commit.cc b/src/commit.cc index d85a9b727..a91773de1 100755 --- a/src/commit.cc +++ b/src/commit.cc @@ -8,6 +8,7 @@ #include #include "../vendor/libgit2/include/git2.h" +#include "cvv8/v8-convert.hpp" #include "../include/reference.h" #include "../include/sig.h" @@ -22,25 +23,26 @@ using namespace node; void GitCommit::Initialize(Handle target) { HandleScope scope; - Local t = FunctionTemplate::New(New); - - constructor_template = Persistent::New(t); - constructor_template->InstanceTemplate()->SetInternalFieldCount(1); - constructor_template->SetClassName(String::NewSymbol("Commit")); - - NODE_SET_PROTOTYPE_METHOD(constructor_template, "lookup", Lookup); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "close", Close); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "id", Id); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "messageShort", MessageShort); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "message", Message); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "time", Time); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "timeOffset", TimeOffset); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "author", Author); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "tree", Tree); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "parentCount", ParentCount); - NODE_SET_PROTOTYPE_METHOD(constructor_template, "parent", Parent); - - target->Set(String::NewSymbol("Commit"), constructor_template->GetFunction()); + Local tpl = FunctionTemplate::New(New); + + tpl->InstanceTemplate()->SetInternalFieldCount(1); + tpl->SetClassName(String::NewSymbol("Commit")); + + NODE_SET_PROTOTYPE_METHOD(tpl, "lookup", Lookup); + NODE_SET_PROTOTYPE_METHOD(tpl, "close", Close); + NODE_SET_PROTOTYPE_METHOD(tpl, "id", Id); + NODE_SET_PROTOTYPE_METHOD(tpl, "messageShort", MessageShort); + NODE_SET_PROTOTYPE_METHOD(tpl, "message", Message); + NODE_SET_PROTOTYPE_METHOD(tpl, "time", Time); + NODE_SET_PROTOTYPE_METHOD(tpl, "timeOffset", TimeOffset); + NODE_SET_PROTOTYPE_METHOD(tpl, "author", Author); + NODE_SET_PROTOTYPE_METHOD(tpl, "tree", Tree); + NODE_SET_PROTOTYPE_METHOD(tpl, "parentCount", ParentCount); + NODE_SET_PROTOTYPE_METHOD(tpl, "parent", Parent); + NODE_SET_PROTOTYPE_METHOD(tpl, "parentSync", ParentSync); + + constructor_template = Persistent::New(tpl->GetFunction()); + target->Set(String::NewSymbol("Commit"), constructor_template); } git_commit* GitCommit::GetValue() { @@ -59,6 +61,7 @@ int GitCommit::Lookup(git_repository* repo, git_oid* oid) { void GitCommit::Close() { git_commit_close(this->commit); + this->commit = NULL; } const git_oid* GitCommit::Id() { @@ -112,6 +115,14 @@ Handle GitCommit::New(const Arguments& args) { return scope.Close(args.This()); } +Handle GitCommit::NewInstance() { + HandleScope scope; + + Local instance = constructor_template->NewInstance(); + + return scope.Close(instance); +} + Handle GitCommit::Lookup(const Arguments& args) { HandleScope scope; @@ -140,25 +151,26 @@ Handle GitCommit::Lookup(const Arguments& args) { commit->Ref(); - eio_custom(EIO_Lookup, EIO_PRI_DEFAULT, EIO_AfterLookup, ar); - ev_ref(EV_DEFAULT_UC); + uv_work_t *req = new uv_work_t; + req->data = ar; + uv_queue_work(uv_default_loop(), req, LookupWork, LookupAfterWork); return scope.Close( Undefined() ); } -void GitCommit::EIO_Lookup(eio_req *req) { +void GitCommit::LookupWork(uv_work_t *req) { lookup_request *ar = static_cast(req->data); git_oid oid = ar->oid->GetValue(); ar->err = ar->commit->Lookup(ar->repo->GetValue(), &oid); - } -int GitCommit::EIO_AfterLookup(eio_req *req) { +void GitCommit::LookupAfterWork(uv_work_t *req) { HandleScope scope; lookup_request *ar = static_cast(req->data); - ev_unref(EV_DEFAULT_UC); + delete req; + ar->commit->Unref(); Handle argv[1]; @@ -171,12 +183,10 @@ int GitCommit::EIO_AfterLookup(eio_req *req) { if(try_catch.HasCaught()) { FatalException(try_catch); } - + ar->callback.Dispose(); delete ar; - - return 0; } Handle GitCommit::Close(const Arguments& args) { @@ -184,8 +194,8 @@ Handle GitCommit::Close(const Arguments& args) { GitCommit *commit = ObjectWrap::Unwrap(args.This()); commit->Close(); - - return scope.Close( Undefined() ); + + return scope.Close(Undefined()); } Handle GitCommit::Id(const Arguments& args) { @@ -200,13 +210,13 @@ Handle GitCommit::Id(const Arguments& args) { GitOid *oid = ObjectWrap::Unwrap(args[0]->ToObject()); oid->SetValue(*const_cast(commit->Id())); - - return scope.Close( Undefined() ); + + return scope.Close(Undefined()); } Handle GitCommit::MessageShort(const Arguments& args) { HandleScope scope; - + GitCommit *commit = ObjectWrap::Unwrap(args.This()); return scope.Close( String::New(commit->MessageShort()) ); @@ -214,15 +224,15 @@ Handle GitCommit::MessageShort(const Arguments& args) { Handle GitCommit::Message(const Arguments& args) { HandleScope scope; - + GitCommit *commit = ObjectWrap::Unwrap(args.This()); - return scope.Close( String::New(commit->Message()) ); + return scope.Close(String::New(commit->Message())); } Handle GitCommit::Time(const Arguments& args) { HandleScope scope; - + GitCommit *commit = ObjectWrap::Unwrap(args.This()); return scope.Close( Integer::New(commit->Time()) ); @@ -232,7 +242,7 @@ Handle GitCommit::TimeOffset(const Arguments& args) { HandleScope scope; GitCommit *commit = ObjectWrap::Unwrap(args.This()); - + return scope.Close( Integer::New(commit->TimeOffset()) ); } @@ -248,7 +258,7 @@ Handle GitCommit::Committer(const Arguments& args) { GitSig *sig = ObjectWrap::Unwrap(args[0]->ToObject()); sig->SetValue(const_cast(commit->Committer())); - + return scope.Close( Undefined() ); } @@ -264,7 +274,7 @@ Handle GitCommit::Author(const Arguments& args) { GitSig *sig = ObjectWrap::Unwrap(args[0]->ToObject()); sig->SetValue(const_cast(commit->Author())); - + return scope.Close( Undefined() ); } @@ -296,27 +306,105 @@ Handle GitCommit::ParentCount(const Arguments& args) { return scope.Close( Integer::New(count) ); } -Handle GitCommit::Parent(const Arguments& args) { +Handle GitCommit::ParentSync(const Arguments& args) { HandleScope scope; + if(args.Length() == 0 || !args[0]->IsNumber()) { + return ThrowException(Exception::Error(String::New("Position must be a Number."))); + } + GitCommit *commit = ObjectWrap::Unwrap(args.This()); - if(args.Length() == 0 || !args[0]->IsObject()) { - return ThrowException(Exception::Error(String::New("Commit is required and must be an Object."))); + git_commit *parentCommitValue ; + int errorCode = git_commit_parent(&parentCommitValue, commit->commit, args[0]->ToInteger()->Value()); + + if (errorCode) { + return ThrowException(Exception::Error(String::New(git_lasterror()))); + } + + Local parent = GitCommit::constructor_template->NewInstance(); + GitCommit *parentCommit = ObjectWrap::Unwrap(parent); + parentCommit->SetValue(parentCommitValue); + + return scope.Close(parent); +} + +Handle GitCommit::Parent(const Arguments& args) { + HandleScope scope; + + if(args.Length() != 2) { + return ThrowException(Exception::Error(String::New("Position and callback are required"))); } - if(args.Length() == 1 || !args[1]->IsNumber()) { + if(!args[0]->IsNumber()) { return ThrowException(Exception::Error(String::New("Position is required and must be a Number."))); } - GitCommit* out = ObjectWrap::Unwrap(args[0]->ToObject()); - git_commit* in; - int index = args[1]->ToInteger()->Value(); + if(!args[1]->IsFunction()) { + return ThrowException(Exception::Error(String::New("Callback is required and must be a Function."))); + } + + Local callback = Local::Cast(args[1]); - int err = commit->Parent(&in, index); - out->SetValue(in); + ParentBaton* baton = new ParentBaton(); + baton->request.data = baton; + baton->commit = ObjectWrap::Unwrap(args.This()); + baton->commit->Ref(); + baton->index = args[0]->ToInteger()->Value(); + baton->callback = Persistent::New(callback); - return scope.Close( Integer::New(err) ); + uv_queue_work(uv_default_loop(), &baton->request, ParentWork, ParentAfterWork); + + return Undefined(); +} + +void GitCommit::ParentWork(uv_work_t* req) { + ParentBaton* baton = static_cast(req->data); + + baton->rawParentCommit = NULL; + baton->errorCode = git_commit_parent(&baton->rawParentCommit, baton->commit->commit, baton->index); + + if (baton->errorCode) { + baton->errorMessage = git_lasterror(); + } +} + +void GitCommit::ParentAfterWork(uv_work_t* req) { + HandleScope scope; + + ParentBaton* baton = static_cast(req->data); + delete req; + + if (baton->errorCode) { + Local argv[1] = { + Exception::Error(String::New(baton->errorMessage)) + }; + + TryCatch try_catch; + + baton->callback->Call(Context::GetCurrent()->Global(), 1, argv); + + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + } else { + + Local parent = GitCommit::constructor_template->NewInstance(); + GitCommit *parentCommit = ObjectWrap::Unwrap(parent); + parentCommit->SetValue(baton->rawParentCommit); + + Handle argv[2] = { + Local::New(Null()), + parent + }; + + TryCatch try_catch; + baton->callback->Call(Context::GetCurrent()->Global(), 2, argv); + if (try_catch.HasCaught()) { + node::FatalException(try_catch); + } + } + baton->commit->Unref(); } -Persistent GitCommit::constructor_template; +Persistent GitCommit::constructor_template; diff --git a/src/error.cc b/src/error.cc index 9f180f667..586163731 100755 --- a/src/error.cc +++ b/src/error.cc @@ -6,24 +6,70 @@ #include #include -#include "../vendor/libgit2/include/git2.h" +#include "cvv8/v8-convert.hpp" +#include "git2.h" #include "../include/error.h" using namespace v8; +using namespace cvv8; using namespace node; +namespace cvv8 { + template <> + struct NativeToJS : NativeToJS {}; +} + void GitError::Initialize (Handle target) { HandleScope scope; Local t = FunctionTemplate::New(New); - + constructor_template = Persistent::New(t); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->SetClassName(String::NewSymbol("Error")); NODE_SET_PROTOTYPE_METHOD(constructor_template, "strError", StrError); + // Add libgit2 error codes to error object + Local libgit2Errors = Object::New(); + + libgit2Errors->Set(String::NewSymbol("GIT_SUCCESS"), cvv8::CastToJS(GIT_SUCCESS), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_ERROR"), cvv8::CastToJS(GIT_ERROR), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_ENOTOID"), cvv8::CastToJS(GIT_ENOTOID), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_ENOTFOUND"), cvv8::CastToJS(GIT_ENOTFOUND), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_ENOMEM"), cvv8::CastToJS(GIT_ENOMEM), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EOSERR"), cvv8::CastToJS(GIT_EOSERR), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EOBJTYPE"), cvv8::CastToJS(GIT_EOBJTYPE), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_ENOTAREPO"), cvv8::CastToJS(GIT_ENOTAREPO), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EINVALIDTYPE"), cvv8::CastToJS(GIT_EINVALIDTYPE), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EMISSINGOBJDATA"), cvv8::CastToJS(GIT_EMISSINGOBJDATA), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EPACKCORRUPTED"), cvv8::CastToJS(GIT_EPACKCORRUPTED), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EFLOCKFAIL"), cvv8::CastToJS(GIT_EFLOCKFAIL), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EZLIB"), cvv8::CastToJS(GIT_EZLIB), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EBUSY"), cvv8::CastToJS(GIT_EBUSY), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EBAREINDEX"), cvv8::CastToJS(GIT_EBAREINDEX), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EINVALIDREFNAME"), cvv8::CastToJS(GIT_EINVALIDREFNAME), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EREFCORRUPTED"), cvv8::CastToJS(GIT_EREFCORRUPTED), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_ETOONESTEDSYMREF"), cvv8::CastToJS(GIT_ETOONESTEDSYMREF), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EPACKEDREFSCORRUPTED"), cvv8::CastToJS(GIT_EPACKEDREFSCORRUPTED), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EINVALIDPATH"), cvv8::CastToJS(GIT_EINVALIDPATH), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EREVWALKOVER"), cvv8::CastToJS(GIT_EREVWALKOVER), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EINVALIDREFSTATE"), cvv8::CastToJS(GIT_EINVALIDREFSTATE), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_ENOTIMPLEMENTED"), cvv8::CastToJS(GIT_ENOTIMPLEMENTED), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EEXISTS"), cvv8::CastToJS(GIT_EEXISTS), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EOVERFLOW"), cvv8::CastToJS(GIT_EOVERFLOW), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_ENOTNUM"), cvv8::CastToJS(GIT_ENOTNUM), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_ESTREAM"), cvv8::CastToJS(GIT_ESTREAM), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EINVALIDARGS"), cvv8::CastToJS(GIT_EINVALIDARGS), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EOBJCORRUPTED"), cvv8::CastToJS(GIT_EOBJCORRUPTED), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EAMBIGUOUSOIDPREFIX"), cvv8::CastToJS(GIT_EAMBIGUOUSOIDPREFIX), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_EPASSTHROUGH"), cvv8::CastToJS(GIT_EPASSTHROUGH), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_ENOMATCH"), cvv8::CastToJS(GIT_ENOMATCH), ReadOnly); + libgit2Errors->Set(String::NewSymbol("GIT_ESHORTBUFFER"), cvv8::CastToJS(GIT_ESHORTBUFFER), ReadOnly); + + constructor_template->Set(String::NewSymbol("codes"), libgit2Errors, ReadOnly); + target->Set(String::NewSymbol("Error"), constructor_template->GetFunction()); } diff --git a/src/oid.cc b/src/oid.cc index a7bf5481b..064457918 100755 --- a/src/oid.cc +++ b/src/oid.cc @@ -16,7 +16,7 @@ void GitOid::Initialize(Handle target) { HandleScope scope; Local t = FunctionTemplate::New(New); - + constructor_template = Persistent::New(t); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->SetClassName(String::NewSymbol("Oid")); @@ -62,7 +62,7 @@ char* GitOid::AllocFmt() { } char* GitOid::ToString(char* buffer, size_t bufferSize) { - git_oid_to_string(buffer, bufferSize, &this->oid); + return git_oid_to_string(buffer, bufferSize, &this->oid); } void GitOid::Cpy(git_oid* out) { @@ -145,7 +145,7 @@ Handle GitOid::ToString(const Arguments& args) { HandleScope scope; GitOid *oid = ObjectWrap::Unwrap(args.This()); - + if(args.Length() == 0 || !args[0]->IsNumber()) { return ThrowException(Exception::Error(String::New("Length argument is required and must be a Number."))); } @@ -160,14 +160,14 @@ Handle GitOid::Cpy(const Arguments& args) { HandleScope scope; GitOid *oid = ObjectWrap::Unwrap(args.This()); - + if(args.Length() == 0 || !args[0]->IsObject()) { return ThrowException(Exception::Error(String::New("GitOid argument is required and must be a Object."))); } GitOid *clone = ObjectWrap::Unwrap(args[0]->ToObject()); - - git_oid *out; + + git_oid *out = NULL; oid->Cpy(out); clone->SetValue(*out); @@ -177,18 +177,18 @@ Handle GitOid::Cpy(const Arguments& args) { Handle GitOid::Cmp(const Arguments& args) { HandleScope scope; - GitOid *oid = ObjectWrap::Unwrap(args.This()); - + // GitOid *oid = ObjectWrap::Unwrap(args.This()); + if(args.Length() == 0 || !args[0]->IsObject()) { return ThrowException(Exception::Error(String::New("GitOid argument is required and must be a Object."))); } - + if(args.Length() == 1 || !args[1]->IsObject()) { return ThrowException(Exception::Error(String::New("GitOid argument is required and must be a Object."))); } - GitOid* a = ObjectWrap::Unwrap(args[0]->ToObject()); - GitOid* b = ObjectWrap::Unwrap(args[1]->ToObject()); + // GitOid* a = ObjectWrap::Unwrap(args[0]->ToObject()); + // GitOid* b = ObjectWrap::Unwrap(args[1]->ToObject()); //int cmp = oid->Cmp(&a->GetValue(), &b->GetValue()); int cmp = 0; diff --git a/src/reference.cc b/src/reference.cc index 5a9f8e29b..ac824c3b4 100755 --- a/src/reference.cc +++ b/src/reference.cc @@ -19,7 +19,7 @@ void GitReference::Initialize(Handle target) { HandleScope scope; Local t = FunctionTemplate::New(New); - + constructor_template = Persistent::New(t); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->SetClassName(String::NewSymbol("Ref")); @@ -87,13 +87,14 @@ Handle GitReference::Lookup(const Arguments& args) { ref->Ref(); - eio_custom(EIO_Lookup, EIO_PRI_DEFAULT, EIO_AfterLookup, ar); - ev_ref(EV_DEFAULT_UC); + uv_work_t *req = new uv_work_t; + req->data = ar; + uv_queue_work(uv_default_loop(), req, EIO_Lookup, EIO_AfterLookup); return scope.Close( Undefined() ); } -void GitReference::EIO_Lookup(eio_req *req) { +void GitReference::EIO_Lookup(uv_work_t *req) { lookup_request *ar = static_cast(req->data); git_repository* repo = ar->repo->GetValue(); @@ -102,11 +103,11 @@ void GitReference::EIO_Lookup(eio_req *req) { } -int GitReference::EIO_AfterLookup(eio_req *req) { +void GitReference::EIO_AfterLookup(uv_work_t *req) { HandleScope scope; lookup_request *ar = static_cast(req->data); - ev_unref(EV_DEFAULT_UC); + delete req; ar->ref->Unref(); Local argv[1]; @@ -118,12 +119,10 @@ int GitReference::EIO_AfterLookup(eio_req *req) { if(try_catch.HasCaught()) FatalException(try_catch); - + ar->callback.Dispose(); delete ar; - - return 0; } Handle GitReference::Oid(const Arguments& args) { diff --git a/src/repo.cc b/src/repo.cc index f44d41236..2a9b153f1 100755 --- a/src/repo.cc +++ b/src/repo.cc @@ -19,7 +19,7 @@ void GitRepo::Initialize(Handle target) { HandleScope scope; Local t = FunctionTemplate::New(New); - + constructor_template = Persistent::New(t); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->SetClassName(String::NewSymbol("Repo")); @@ -94,24 +94,25 @@ Handle GitRepo::Open(const Arguments& args) { repo->Ref(); - eio_custom(EIO_Open, EIO_PRI_DEFAULT, EIO_AfterOpen, ar); - ev_ref(EV_DEFAULT_UC); + uv_work_t *req = new uv_work_t; + req->data = ar; + uv_queue_work(uv_default_loop(), req, EIO_Open, EIO_AfterOpen); return scope.Close( Undefined() ); } -void GitRepo::EIO_Open(eio_req *req) { +void GitRepo::EIO_Open(uv_work_t *req) { open_request *ar = static_cast(req->data); ar->err = ar->repo->Open(ar->path.c_str()); } -int GitRepo::EIO_AfterOpen(eio_req *req) { +void GitRepo::EIO_AfterOpen(uv_work_t *req) { HandleScope scope; open_request *ar = static_cast(req->data); - ev_unref(EV_DEFAULT_UC); + delete req; ar->repo->Unref(); Local argv[1]; @@ -123,12 +124,10 @@ int GitRepo::EIO_AfterOpen(eio_req *req) { if(try_catch.HasCaught()) FatalException(try_catch); - + ar->callback.Dispose(); delete ar; - - return 0; } Handle GitRepo::Lookup(const Arguments& args) { @@ -167,7 +166,7 @@ Handle GitRepo::Lookup(const Arguments& args) { return scope.Close( Undefined() ); } -int GitRepo::EIO_Lookup(eio_req *req) { +void GitRepo::EIO_Lookup(uv_work_t *req) { //lookup_request *ar = static_cast(req->data); // //String::Utf8Value name(ar->name); @@ -183,11 +182,11 @@ int GitRepo::EIO_Lookup(eio_req *req) { //return 0; } -int GitRepo::EIO_AfterLookup(eio_req *req) { +void GitRepo::EIO_AfterLookup(uv_work_t *req) { //HandleScope scope; //lookup_request *ar = static_cast(req->data); - //ev_unref(EV_DEFAULT_UC); + // delete req; //ar->repo->Unref(); //Local argv[1]; @@ -199,7 +198,7 @@ int GitRepo::EIO_AfterLookup(eio_req *req) { //if(try_catch.HasCaught()) // FatalException(try_catch); - // + // //ar->err.Dispose(); //ar->name.Dispose(); //ar->callback.Dispose(); @@ -250,24 +249,25 @@ Handle GitRepo::Init(const Arguments& args) { repo->Ref(); - eio_custom(EIO_Init, EIO_PRI_DEFAULT, EIO_AfterInit, ar); - ev_ref(EV_DEFAULT_UC); + uv_work_t *req = new uv_work_t; + req->data = ar; + uv_queue_work(uv_default_loop(), req, EIO_Init, EIO_AfterInit); return scope.Close( Undefined() ); } -void GitRepo::EIO_Init(eio_req *req) { +void GitRepo::EIO_Init(uv_work_t *req) { init_request *ar = static_cast(req->data); ar->err = ar->repo->Init(ar->path.c_str(), ar->is_bare); } -int GitRepo::EIO_AfterInit(eio_req *req) { +void GitRepo::EIO_AfterInit(uv_work_t *req) { HandleScope scope; init_request *ar = static_cast(req->data); - ev_unref(EV_DEFAULT_UC); + delete req; ar->repo->Unref(); Local argv[2]; @@ -279,11 +279,9 @@ int GitRepo::EIO_AfterInit(eio_req *req) { if(try_catch.HasCaught()) FatalException(try_catch); - + ar->callback.Dispose(); delete ar; - - return 0; } Persistent GitRepo::constructor_template; diff --git a/src/revwalk.cc b/src/revwalk.cc index 3715a601d..ec3f6163e 100755 --- a/src/revwalk.cc +++ b/src/revwalk.cc @@ -18,7 +18,7 @@ void GitRevWalk::Initialize(Handle target) { HandleScope scope; Local t = FunctionTemplate::New(New); - + constructor_template = Persistent::New(t); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->SetClassName(String::NewSymbol("RevWalk")); @@ -119,7 +119,7 @@ Handle GitRevWalk::Push(const Arguments& args) { } GitOid *oid = ObjectWrap::Unwrap(args[0]->ToObject()); - + git_oid tmp = oid->GetValue(); int err = revwalk->Push(&tmp); @@ -149,13 +149,14 @@ Handle GitRevWalk::Next(const Arguments& args) { revwalk->Ref(); - eio_custom(EIO_Next, EIO_PRI_DEFAULT, EIO_AfterNext, ar); - ev_ref(EV_DEFAULT_UC); + uv_work_t *req = new uv_work_t; + req->data = ar; + uv_queue_work(uv_default_loop(), req, EIO_Next, EIO_AfterNext); return scope.Close( Undefined() ); } -void GitRevWalk::EIO_Next(eio_req *req) { +void GitRevWalk::EIO_Next(uv_work_t *req) { next_request *ar = static_cast(req->data); git_oid oid = ar->oid->GetValue(); @@ -164,11 +165,11 @@ void GitRevWalk::EIO_Next(eio_req *req) { } -int GitRevWalk::EIO_AfterNext(eio_req *req) { +void GitRevWalk::EIO_AfterNext(uv_work_t *req) { HandleScope scope; next_request *ar = static_cast(req->data); - ev_unref(EV_DEFAULT_UC); + delete req; ar->revwalk->Unref(); Local argv[1]; @@ -180,12 +181,10 @@ int GitRevWalk::EIO_AfterNext(eio_req *req) { if(try_catch.HasCaught()) FatalException(try_catch); - + ar->callback.Dispose(); delete ar; - - return 0; } Handle GitRevWalk::Free(const Arguments& args) { diff --git a/src/tree.cc b/src/tree.cc index fe3b1bdbf..6a985b967 100755 --- a/src/tree.cc +++ b/src/tree.cc @@ -19,7 +19,7 @@ void GitTree::Initialize (Handle target) { HandleScope scope; Local t = FunctionTemplate::New(New); - + constructor_template = Persistent::New(t); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->SetClassName(String::NewSymbol("Tree")); @@ -113,7 +113,7 @@ Handle GitTree::Lookup(const Arguments& args) { // return scope.Close( Undefined() ); } -//int GitTree::EIO_Lookup(eio_req *req) { +//void GitTree::EIO_Lookup(uv_work_t *req) { // lookup_request *lr = static_cast(req->data); // // git_oid oid = lr->oid->GetValue(); @@ -122,7 +122,7 @@ Handle GitTree::Lookup(const Arguments& args) { // return 0; //} -//int GitTree::EIO_AfterLookup(eio_req *req) { +//void GitTree::EIO_AfterLookup(uv_work_t *req) { // lookup_request *lr = static_cast(req->data); // // ev_unref(EV_DEFAULT_UC); @@ -137,7 +137,7 @@ Handle GitTree::Lookup(const Arguments& args) { // // if(try_catch.HasCaught()) // FatalException(try_catch); -// +// // lr->callback.Dispose(); // // delete lr; @@ -151,7 +151,7 @@ Handle GitTree::EntryCount(const Arguments& args) { GitTree *tree = ObjectWrap::Unwrap(args.This()); int count = tree->EntryCount(); - + return scope.Close( Integer::New(count) ); } @@ -183,23 +183,24 @@ Handle GitTree::EntryByIndex(const Arguments& args) { tree->Ref(); - eio_custom(EIO_EntryByIndex, EIO_PRI_DEFAULT, EIO_AfterEntryByIndex, er); - ev_ref(EV_DEFAULT_UC); + uv_work_t *req = new uv_work_t; + req->data = er; + uv_queue_work(uv_default_loop(), req, EIO_EntryByIndex, EIO_AfterEntryByIndex); return scope.Close( Undefined() ); } -void GitTree::EIO_EntryByIndex(eio_req *req) { +void GitTree::EIO_EntryByIndex(uv_work_t *req) { entryindex_request *er = static_cast(req->data); er->entry->SetValue(er->tree->EntryByIndex(er->idx)); } -int GitTree::EIO_AfterEntryByIndex(eio_req *req) { +void GitTree::EIO_AfterEntryByIndex(uv_work_t *req) { entryindex_request *er = static_cast(req->data); - ev_unref(EV_DEFAULT_UC); + delete req; er->tree->Unref(); Handle argv[0]; @@ -210,12 +211,10 @@ int GitTree::EIO_AfterEntryByIndex(eio_req *req) { if(try_catch.HasCaught()) FatalException(try_catch); - + er->callback.Dispose(); delete er; - - return 0; } Handle GitTree::EntryByName(const Arguments& args) { @@ -248,23 +247,24 @@ Handle GitTree::EntryByName(const Arguments& args) { tree->Ref(); - eio_custom(EIO_EntryByName, EIO_PRI_DEFAULT, EIO_AfterEntryByName, er); - ev_ref(EV_DEFAULT_UC); + uv_work_t *req = new uv_work_t; + req->data = er; + uv_queue_work(uv_default_loop(), req, EIO_EntryByName, EIO_AfterEntryByName); return scope.Close( Undefined() ); } -void GitTree::EIO_EntryByName(eio_req *req) { +void GitTree::EIO_EntryByName(uv_work_t *req) { entryname_request *er = static_cast(req->data); er->entry->SetValue(er->tree->EntryByName(er->name.c_str())); } -int GitTree::EIO_AfterEntryByName(eio_req *req) { +void GitTree::EIO_AfterEntryByName(uv_work_t *req) { entryname_request *er = static_cast(req->data); - ev_unref(EV_DEFAULT_UC); + delete req; er->tree->Unref(); Handle argv[1]; @@ -276,12 +276,10 @@ int GitTree::EIO_AfterEntryByName(eio_req *req) { if(try_catch.HasCaught()) FatalException(try_catch); - + er->callback.Dispose(); delete er; - - return 0; } Handle GitTree::SortEntries(const Arguments& args) { @@ -290,7 +288,7 @@ Handle GitTree::SortEntries(const Arguments& args) { GitTree *tree = ObjectWrap::Unwrap(args.This()); int err = tree->SortEntries(); - + return scope.Close( Integer::New(err) ); } diff --git a/src/tree_entry.cc b/src/tree_entry.cc index 088ae8b82..bc35a78eb 100755 --- a/src/tree_entry.cc +++ b/src/tree_entry.cc @@ -19,7 +19,7 @@ using namespace node; void GitTreeEntry::Initialize(Handle target) { Local t = FunctionTemplate::New(New); - + constructor_template = Persistent::New(t); constructor_template->InstanceTemplate()->SetInternalFieldCount(1); constructor_template->SetClassName(String::NewSymbol("TreeEntry")); @@ -94,7 +94,7 @@ Handle GitTreeEntry::Id(const Arguments& args) { GitOid* oid = ObjectWrap::Unwrap(args[0]->ToObject()); oid->SetValue(*const_cast(entry->Id())); - + return scope.Close( Undefined() ); } @@ -118,7 +118,7 @@ Handle GitTreeEntry::ToObject(const Arguments& args) { entry->ToObject(repo->GetValue(), &out); object->SetValue(out); - + return scope.Close( Undefined() ); } Persistent GitTreeEntry::constructor_template; diff --git a/test/convenience-commit.js b/test/convenience-commit.js new file mode 100644 index 000000000..ee56240d8 --- /dev/null +++ b/test/convenience-commit.js @@ -0,0 +1,172 @@ +var git = require('../'); +var rimraf = require('rimraf'); +var fs = require( 'fs' ); + +// Helper functions +var helper = { + // Test if obj is a true function + testFunction: function(test, obj, label) { + // The object reports itself as a function + test(typeof obj, 'function', label + ' reports as a function.'); + // This ensures the repo is actually a derivative of the Function [[Class]] + test(toString.call(obj), '[object Function]', label + ' [[Class]] is of type function.'); + }, + // Test code and handle exception thrown + testException: function(test, fun, label) { + try { + fun(); + test(false, label); + } + catch (ex) { + test(true, label); + } + } +}; + +/** + * Test that the commit object is present. + * + * @param {Object} test + */ +exports.method = function(test){ + test.expect(2); + + helper.testFunction(test.equals, git.commit, 'Commmit'); + + test.done(); +}; + +/** + * Test that + * + * @param {Object} test + */ +exports.improperCommitId = function(test) { + test.expect(2); + git.repo('../.git', function(error, repository) { + repository.commit('not a proper commit sha', function(error, commit) { + test.equals(error.code, git.error.GIT_ENOTFOUND, 'Correct error should occur'); + test.equals(error.message, 'Object does not exist in the scope searched.', 'Attempting to get commit by invalid SHA should error'); + + test.done(); + }); + }); +}; + +var historyCountKnownSHA = 'fce88902e66c72b5b93e75bdb5ae717038b221f6'; + +/** + * Test that retreiving walking a given commit's history works as expected. + * + * @param {Object} test + */ +exports.history = function(test) { + test.expect(368); + git.repo('../.git', function(error, repository) { + + repository.commit(historyCountKnownSHA, function(error, commit) { + test.equals(error, 0, 'Getting latest branch commit should not error'); + + var historyCount = 0; + var expectedHistoryCount = 364; + commit.history().on('commit', function(error, commit) { + test.equals(error, null, 'There should be no errors'); + historyCount++; + }).on('end', function(error, commits) { + + test.equals(error, null, 'There should be no errors'); + test.equals(historyCount, expectedHistoryCount, 'Manual count does not match expected'); + test.equals(commits.length, expectedHistoryCount, '"end" count does not match expected'); + + test.done(); + }); + }); + }); +}; + +/** + * Test that retreiving master branch's HEAD commit works as expected. + * + * @param {Object} test + */ +exports.masterHead = function(test) { + test.expect(2); + git.repo('../.git', function(error, repository) { + repository.branch('master', function(error, branch) { + + test.equals(error, 0, 'Getting branch should not error'); + + repository.commit(branch.sha, function(error, commit) { + + test.equals(error, 0, 'Getting latest branch commit should not error'); + + test.done(); + }); + }); + }); +}; + +/** + * Test that retreiving parent works as expected. + * + * @param {Object} test + */ +exports.parentSync = function(test) { + test.expect(2); + git.repo('../.git', function(error, repository) { + repository.commit('2d71044741412280370cb0326c96d3a5a7b5dca1', function(error, commit) { + test.equals(commit.parentCount, 1, 'Commit has exactly one parent'); + var parent = commit.parentSync(0) + test.equals(parent.sha, 'e8876707938abf94d5cc02b0c4017c4fec2aa44e', 'Parent SHA should match expected value'); + test.done(); + }); + }); +}; + +/** + * Test that retreiving parent works as expected. + * + * @param {Object} test + */ +exports.parent = function(test) { + test.expect(2); + git.repo('../.git', function(error, repository) { + repository.commit('2d71044741412280370cb0326c96d3a5a7b5dca1', function(error, commit) { + test.equals(commit.parentCount, 1, 'Commit has exactly one parent'); + commit.parent(0, function(error, parent) { + if (error) throw error; + test.equals(parent.sha, 'e8876707938abf94d5cc02b0c4017c4fec2aa44e', 'Parent SHA should match expected value'); + test.done(); + }); + + }); + }); +}; + +/** + * Test that retrieving and walking a commit's tree works as expected. + * + * @param {Object} test + */ +exports.tree = function(test) { + test.expect(2); + git.repo('../.git', function(error, repository) { + + repository.commit(historyCountKnownSHA, function(error, commit) { + + test.equals(error, 0, 'Getting latest branch commit should not error'); + + var commitTreeEntryCount = 0; + var expectedCommitTreeEntryCount = 200; + + commit.tree().walk().on('entry', function(commit) { + commitTreeEntryCount++; + }).on('end', function(commits) { + + test.equals(commitTreeEntryCount, expectedCommitTreeEntryCount, 'Commit tree entry count does not match expected'); + + test.done(); + }); + }); + }); +}; diff --git a/test/convenience-error.js b/test/convenience-error.js new file mode 100644 index 000000000..c2152f1aa --- /dev/null +++ b/test/convenience-error.js @@ -0,0 +1,56 @@ +var git = require('../'); +var rimraf = require('rimraf'); +var fs = require( 'fs' ); + +// Helper functions +var helper = { + // Test if obj is a true function + testFunction: function(test, obj, label) { + // The object reports itself as a function + test(typeof obj, 'function', label + ' reports as a function.'); + // This ensures the repo is actually a derivative of the Function [[Class]] + test(toString.call(obj), '[object Function]', label + ' [[Class]] is of type function.'); + }, + // Test code and handle exception thrown + testException: function(test, fun, label) { + try { + fun(); + test(false, label); + } + catch (ex) { + test(true, label); + } + } +}; + +/** + * Test that the error object is present. + * + * @param {Object} test + */ +exports.method = function(test){ + test.expect(2); + + helper.testFunction(test.equals, git.error, 'Error'); + + test.done(); +}; + +/** + * Test that + * + * @param {Object} test + */ +exports.improperCommitId = function(test) { + test.expect(1); + git.repo('../.git', function(error, repository) { + + repository.commit('not a proper commit sha', function(error, commit) { + + test.notEqual(error.code, git.error.GIT_SUCCESS, 'Attempting to get commit by invalid SHA should error'); + + test.done(); + }); + }); +}; + diff --git a/test/convenience-repo.js b/test/convenience-repo.js index 782085adc..d9f359dce 100644 --- a/test/convenience-repo.js +++ b/test/convenience-repo.js @@ -1,17 +1,17 @@ -var git = require( "../" ); -var rimraf = require( "../vendor/rimraf"); -var fs = require( "fs" ); +var git = require( '../' ); +var rimraf = require('rimraf'); +var fs = require( 'fs' ); // Helper functions var helper = { // Test if obj is a true function testFunction: function(test, obj, label) { // The object reports itself as a function - test(typeof obj, "function", label + " reports as a function."); + test(typeof obj, 'function', label + ' reports as a function.'); // This ensures the repo is actually a derivative of the Function [[Class]] - test(toString.call(obj), "[object Function]", label + " [[Class]] is of type function."); + test(toString.call(obj), '[object Function]', label + ' [[Class]] is of type function.'); }, - // Test code and handle exception thrown + // Test code and handle exception thrown testException: function(test, fun, label) { try { fun(); @@ -29,20 +29,20 @@ var helper = { exports.method = function(test){ test.expect(5); - helper.testFunction(test.equals, git.repo, "Repo"); + helper.testFunction(test.equals, git.repo, 'Repo'); // Test callback argument existence helper.testException(test.ok, function() { - git.repo("some/path"); - }, "Throw an exception if no callback"); + git.repo('some/path'); + }, 'Throw an exception if no callback'); // Test invalid repository - git.repo("/etc/hosts", function(err, path) { - test.equals("The specified repository is invalid", err, "Invalid repository error code"); + git.repo('/etc/hosts', function(err, path) { + test.equals('The specified repository is invalid', err.message, 'Invalid repository error code'); // Test valid repository - git.repo("../.git", function(err, path) { - test.equals(0, err, "Valid repository error code"); + git.repo('../.git', function(err, path) { + test.equals(0, err, 'Valid repository error code'); test.done(); }); @@ -56,19 +56,19 @@ exports.method = function(test){ exports.init = function(test) { test.expect(4); - helper.testFunction(test.equals, git.repo().init, "Repo::Init"); + helper.testFunction(test.equals, git.repo().init, 'Repo::Init'); // Cleanup, remove test repo directory - if it exists - rimraf("./test.git", function() { + rimraf('./test.git', function() { // Create bare repo and test for creation - git.repo().init("./test.git", true, function(err, path, isBare) { - test.equals(0, err, "Successfully created bare repository"); + git.repo().init('./test.git', true, function(err, path, isBare) { + test.equals(0, err, 'Successfully created bare repository'); // Verify repo exists - git.repo("./test.git", function(err, path, repo) { - test.equals(0, err, "Valid repository created"); + git.repo('./test.git', function(err, path, repo) { + test.equals(0, err, 'Valid repository created'); // Cleanup, remove test repo directory - rimraf("./test.git", test.done); + rimraf('./test.git', test.done); }); }); }); diff --git a/test/convenience-tree.js b/test/convenience-tree.js new file mode 100644 index 000000000..d97e51b0e --- /dev/null +++ b/test/convenience-tree.js @@ -0,0 +1,28 @@ +var git = require('../'); +var rimraf = require('rimraf'); +var fs = require('fs'); + +var sha = '5716e9757886eaf38d51c86b192258c960d9cfea'; +var fileCount = 513; + +exports.walk = function(test) { + test.expect(516); + + git.repo('../.git', function(error, repo) { + if(error) { throw error; } + // @todo assert repo is correct + repo.commit(sha, function(error, commit) { + if(error) { throw error; } + var entryCount = 0; + commit.tree().walk().on('entry', function(error, index, entry) { + test.equals(error, null, 'There should be no error'); + entryCount++; + }).on('end', function(error, entries) { + test.equals(error, null, 'There should be no error'); + test.equals(entryCount, fileCount, 'The manual tree entry count and the "end" tree entry count do not match'); + test.equals(entries.length, fileCount, 'The end entries count and the manual entry count do not match'); + test.done(); + }); + }); + }); +}; diff --git a/test/index.js b/test/index.js deleted file mode 100644 index 7712e11f6..000000000 --- a/test/index.js +++ /dev/null @@ -1,59 +0,0 @@ - -try { - var reporter = require( '../vendor/nodeunit' ).reporters['default']; -} -catch( e ) { - var sys = require( 'util' ); - sys.puts( 'Cannot find nodeunit module.' ); - sys.puts( 'You can download submodules for this project by doing:' ); - sys.puts( '' ); - sys.puts( ' git submodule update --init' ); - sys.puts( '' ); - process.exit(); -} - -try { - var rimraf = require( '../vendor/rimraf' ); -} -catch(e) { - var sys = require( 'util' ); - sys.puts( 'Cannot find rimraf module.' ); - sys.puts( 'You can download submodules for this project by doing:' ); - sys.puts( '' ); - sys.puts( ' git submodule init vendor/rimraf' ); - sys.puts( ' git submodule update vendor/rimraf' ); - sys.puts( '' ); - process.exit(); -} - -process.chdir( './test' ); -reporter.run( - [ - // Raw API - 'raw-blob.js' - , 'raw-commit.js' - , 'raw-error.js' - , 'raw-object.js' - , 'raw-oid.js' - , 'raw-reference.js' - , 'raw-repo.js' - , 'raw-revwalk.js' - // Sig - // Tree - // Tree Entry - // Util - - // Convenience API - , 'convenience-repo.js' - // Blob - // Commit - // Error - // Obj - // Oid - // Ref - // RevWalk - // Sig - // Tree - // TreeEntry - ] -); diff --git a/test/raw-blob.js b/test/raw-blob.js index dd927bf9d..eab916974 100644 --- a/test/raw-blob.js +++ b/test/raw-blob.js @@ -1,6 +1,6 @@ var git = require( '../' ).raw , path = require( 'path' ) - , rimraf = require( '../vendor/rimraf' ); + , rimraf = require('rimraf'); var testRepo = new git.Repo(); diff --git a/test/raw-commit.js b/test/raw-commit.js index 60a3e1d9d..e1a3c23a6 100644 --- a/test/raw-commit.js +++ b/test/raw-commit.js @@ -1,5 +1,5 @@ var git = require( '../' ).raw, - rimraf = require( '../vendor/rimraf' ) || require( 'rimraf' ), + rimraf = require( 'rimraf' ), path = require( 'path' ); var testRepo = new git.Repo(); diff --git a/test/raw-error.js b/test/raw-error.js index ff57bec5c..075a3d805 100644 --- a/test/raw-error.js +++ b/test/raw-error.js @@ -1,5 +1,5 @@ var git = require( '../' ).raw, - rimraf = require( '../vendor/rimraf' ) || require( 'rimraf' ); + rimraf = require('rimraf'); // Helper functions var helper = { @@ -10,7 +10,7 @@ var helper = { // This ensures the repo is actually a derivative of the Function [[Class]] test( toString.call( obj ), '[object Function]', label +' [[Class]] is of type function.' ); }, - // Test code and handle exception thrown + // Test code and handle exception thrown testException: function( test, fun, label ) { try { fun(); @@ -28,7 +28,7 @@ exports.constructor = function( test ){ // Test for function helper.testFunction( test.equals, git.Error, 'Error' ); - + // Ensure we get an instance of Error test.ok( new git.Error() instanceof git.Error, 'Invocation returns an instance of Error' ); @@ -48,7 +48,7 @@ exports.str_error = function( test ) { helper.testException( test.ok, function() { testError.strError(); }, 'Throw an exception if no error code' ); - + // Test that arguments result correctly helper.testException( test.ifError, function() { testError.strError( 0 ); diff --git a/test/raw-object.js b/test/raw-object.js index 5427334c6..7a04f76f7 100644 --- a/test/raw-object.js +++ b/test/raw-object.js @@ -1,5 +1,5 @@ var git = require( '../' ).raw, - rimraf = require( '../vendor/rimraf' ); + rimraf = require('rimraf'); // Helper functions var helper = { @@ -10,7 +10,7 @@ var helper = { // This ensures the repo is actually a derivative of the Function [[Class]] test( toString.call( obj ), '[object Function]', label +' [[Class]] is of type function.' ); }, - // Test code and handle exception thrown + // Test code and handle exception thrown testException: function( test, fun, label ) { try { fun(); diff --git a/test/raw-oid.js b/test/raw-oid.js index 9e7074981..3ebf4fdaa 100644 --- a/test/raw-oid.js +++ b/test/raw-oid.js @@ -1,5 +1,5 @@ var git = require( '../' ).raw, - rimraf = require( '../vendor/rimraf' ); + rimraf = require('rimraf'); // Helper functions var helper = { @@ -10,7 +10,7 @@ var helper = { // This ensures the repo is actually a derivative of the Function [[Class]] test( toString.call( obj ), '[object Function]', label +' [[Class]] is of type function.' ); }, - // Test code and handle exception thrown + // Test code and handle exception thrown testException: function( test, fun, label ) { try { fun(); @@ -28,7 +28,7 @@ exports.constructor = function( test ){ // Test for function helper.testFunction( test.equals, git.Oid, 'Oid' ); - + // Ensure we get an instance of Oid test.ok( new git.Oid() instanceof git.Oid, 'Invocation returns an instance of Oid' ); @@ -48,7 +48,7 @@ exports.mkstr = function( test ) { helper.testException( test.ok, function() { testOid.mkstr(); }, 'Throw an exception if no hex String' ); - + // Test that both arguments result correctly helper.testException( test.ifError, function() { testOid.mkstr( "somestr" ); diff --git a/test/raw-reference.js b/test/raw-reference.js index 14a7f203c..08b003979 100644 --- a/test/raw-reference.js +++ b/test/raw-reference.js @@ -1,5 +1,5 @@ var git = require( '../' ).raw, - rimraf = require( '../vendor/rimraf' ); + rimraf = require('rimraf'); // Helper functions var helper = { diff --git a/test/raw-repo.js b/test/raw-repo.js index 9e6460f44..20fc927d3 100644 --- a/test/raw-repo.js +++ b/test/raw-repo.js @@ -1,5 +1,5 @@ var git = require( '../' ).raw, - rimraf = require( '../vendor/rimraf' ) || require( 'rimraf' ), + rimraf = require('rimraf'), path = require( 'path' ), fs = require( 'fs' ); diff --git a/test/raw-revwalk.js b/test/raw-revwalk.js index 702d7e4ba..4e7ef0f3b 100644 --- a/test/raw-revwalk.js +++ b/test/raw-revwalk.js @@ -1,5 +1,5 @@ var git = require( '../' ).raw, - rimraf = require( '../vendor/rimraf' ) || require( 'rimraf' ); + rimraf = require('rimraf'); var testRepo = new git.Repo(); diff --git a/vendor/libgit2 b/vendor/libgit2 new file mode 160000 index 000000000..3eaf34f4c --- /dev/null +++ b/vendor/libgit2 @@ -0,0 +1 @@ +Subproject commit 3eaf34f4c602b9e155e2f4c6ae26c9250ac37d50 diff --git a/vendor/libgit2/.HEADER b/vendor/libgit2/.HEADER deleted file mode 100644 index fd8430bc8..000000000 --- a/vendor/libgit2/.HEADER +++ /dev/null @@ -1,24 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ diff --git a/vendor/libgit2/.gitattributes b/vendor/libgit2/.gitattributes deleted file mode 100644 index f90540b55..000000000 --- a/vendor/libgit2/.gitattributes +++ /dev/null @@ -1,2 +0,0 @@ -*.c eol=lf -*.h eol=lf diff --git a/vendor/libgit2/CMakeLists.txt b/vendor/libgit2/CMakeLists.txt deleted file mode 100644 index e149cd27f..000000000 --- a/vendor/libgit2/CMakeLists.txt +++ /dev/null @@ -1,134 +0,0 @@ -# CMake build script for the libgit2 project -# -# Building (out of source build): -# > mkdir build && cd build -# > cmake .. [-DSETTINGS=VALUE] -# > cmake --build . -# -# Testing: -# > ctest -V -# -# Install: -# > cmake --build . --target install - -PROJECT(libgit2 C) -CMAKE_MINIMUM_REQUIRED(VERSION 2.6) - -FILE(STRINGS "include/git2.h" GIT2_HEADER REGEX "^#define LIBGIT2_VERSION \"[^\"]*\"$") - -STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"([0-9]+).*$" "\\1" LIBGIT2_VERSION_MAJOR "${GIT2_HEADER}") -STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_MINOR "${GIT2_HEADER}") -STRING(REGEX REPLACE "^.*LIBGIT2_VERSION \"[0-9]+\\.[0-9]+\\.([0-9]+).*$" "\\1" LIBGIT2_VERSION_REV "${GIT2_HEADER}") -SET(LIBGIT2_VERSION_STRING "${LIBGIT2_VERSION_MAJOR}.${LIBGIT2_VERSION_MINOR}.${LIBGIT2_VERSION_REV}") - -# Find required dependencies -INCLUDE_DIRECTORIES(src include) -IF (NOT WIN32) - FIND_PACKAGE(ZLIB) -ENDIF() - -IF (ZLIB_FOUND) - INCLUDE_DIRECTORIES(${ZLIB_INCLUDE_DIRS}) - LINK_LIBRARIES(${ZLIB_LIBRARIES}) -ELSE (ZLIB_FOUND) - INCLUDE_DIRECTORIES(deps/zlib) - ADD_DEFINITIONS(-DNO_VIZ -DSTDC -DNO_GZIP) - FILE(GLOB SRC_ZLIB deps/zlib/*.c) -ENDIF() - -# Installation paths -SET(INSTALL_BIN bin CACHE PATH "Where to install binaries to.") -SET(INSTALL_LIB lib CACHE PATH "Where to install libraries to.") -SET(INSTALL_INC include CACHE PATH "Where to install headers to.") - -# Build options -OPTION (BUILD_SHARED_LIBS "Build Shared Library (OFF for Static)" ON) -OPTION (BUILD_TESTS "Build Tests" ON) -OPTION (THREADSAFE "Build libgit2 as threadsafe" OFF) -OPTION (STDCALL "Buildl libgit2 with the __stdcall convention (Windows)" ON) - -# Platform specific compilation flags -IF (MSVC) - SET(CMAKE_C_FLAGS "/W4 /WX /nologo /Zi") - IF (STDCALL) - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /Gz") - ENDIF () - # TODO: bring back /RTC1 /RTCc - SET(CMAKE_C_FLAGS_DEBUG "/Od /DEBUG /MTd") - SET(CMAKE_C_FLAGS_RELEASE "/MT /O2") -ELSE () - SET(CMAKE_C_FLAGS "-O2 -g -Wall -Wextra") - IF (NOT MINGW) # MinGW always does PIC and complains if we tell it to - SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") - ENDIF () -ENDIF() - -# Build Debug by default -IF (NOT CMAKE_BUILD_TYPE) - SET(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel." FORCE) -ENDIF () - -IF (THREADSAFE) - IF (NOT WIN32) - find_package(Threads REQUIRED) - ENDIF() - - ADD_DEFINITIONS(-DGIT_THREADS) -ENDIF() - -ADD_DEFINITIONS(-D_FILE_OFFSET_BITS=64) - -# Collect sourcefiles -FILE(GLOB SRC_H include/git2/*.h) - -# On Windows use specific platform sources -IF (WIN32 AND NOT CYGWIN) - ADD_DEFINITIONS(-DWIN32 -D_DEBUG -D_LIB) - FILE(GLOB SRC src/*.c src/win32/*.c) -ELSE() - FILE(GLOB SRC src/*.c src/unix/*.c) -ENDIF () - -# Compile and link libgit2 -ADD_LIBRARY(git2 ${SRC} ${SRC_ZLIB}) - -IF (WIN32) - TARGET_LINK_LIBRARIES(git2 ws2_32) -ELSEIF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") - TARGET_LINK_LIBRARIES(git2 socket nsl) -ENDIF () - -TARGET_LINK_LIBRARIES(git2 ${CMAKE_THREAD_LIBS_INIT}) -SET_TARGET_PROPERTIES(git2 PROPERTIES VERSION ${LIBGIT2_VERSION_STRING}) -SET_TARGET_PROPERTIES(git2 PROPERTIES SOVERSION ${LIBGIT2_VERSION_MAJOR}) -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libgit2.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libgit2.pc @ONLY) - -# Install -INSTALL(TARGETS git2 - RUNTIME DESTINATION ${INSTALL_BIN} - LIBRARY DESTINATION ${INSTALL_LIB} - ARCHIVE DESTINATION ${INSTALL_LIB} -) -INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libgit2.pc DESTINATION ${INSTALL_LIB}/pkgconfig ) -INSTALL(DIRECTORY include/git2 DESTINATION ${INSTALL_INC} ) -INSTALL(FILES include/git2.h DESTINATION ${INSTALL_INC} ) - -# Tests -IF (BUILD_TESTS) - SET(TEST_RESOURCES "${CMAKE_CURRENT_SOURCE_DIR}/tests/resources" CACHE PATH "Path to test resources.") - ADD_DEFINITIONS(-DTEST_RESOURCES=\"${TEST_RESOURCES}\") - - INCLUDE_DIRECTORIES(tests) - FILE(GLOB SRC_TEST tests/t??-*.c) - - ADD_EXECUTABLE(libgit2_test tests/test_main.c tests/test_lib.c tests/test_helpers.c ${SRC} ${SRC_TEST} ${SRC_ZLIB}) - TARGET_LINK_LIBRARIES(libgit2_test ${CMAKE_THREAD_LIBS_INIT}) - IF (WIN32) - TARGET_LINK_LIBRARIES(libgit2_test ws2_32) - ELSEIF (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") - TARGET_LINK_LIBRARIES(libgit2_test socket nsl) - ENDIF () - - ENABLE_TESTING() - ADD_TEST(libgit2_test libgit2_test) -ENDIF () diff --git a/vendor/libgit2/CONVENTIONS b/vendor/libgit2/CONVENTIONS deleted file mode 100644 index 575cdc563..000000000 --- a/vendor/libgit2/CONVENTIONS +++ /dev/null @@ -1,107 +0,0 @@ -libgit2 conventions -=================== - -Namespace Prefixes ------------------- - -All types and functions start with 'git_'. - -All #define macros start with 'GIT_'. - - -Type Definitions ----------------- - -Most types should be opaque, e.g.: - ----- - typedef struct git_odb git_odb; ----- - -with allocation functions returning an "instance" created within -the library, and not within the application. This allows the type -to grow (or shrink) in size without rebuilding client code. - - -Public Exported Function Definitions ------------------------------------- - -All exported functions must be declared as: - ----- - GIT_EXTERN(result_type) git_modulename_functionname(arg_list); ----- - - -Semi-Private Exported Functions -------------------------------- - -Functions whose modulename is followed by two underscores, -for example 'git_odb__read_packed', are semi-private functions. -They are primarily intended for use within the library itself, -and may disappear or change their signature in a future release. - - -Calling Conventions -------------------- - -Functions should prefer to return a 'int' to indicate success or -failure and supply any output through the first argument (or first -few arguments if multiple outputs are supplied). - -int status codes are 0 for GIT_SUCCESS and < 0 for an error. -This permits common POSIX result testing: - ----- - if (git_odb_open(&odb, path)) - abort("odb open failed"); ----- - -Functions returning a pointer may return NULL instead of an int -if there is only one type of failure (ENOMEM). - -Functions returning a pointer may also return NULL if the common -case needed by the application is strictly success/failure and a -(possibly slower) function exists that the caller can use to get -more detailed information. Parsing common data structures from -on-disk formats is a good example of this pattern; in general a -"corrupt" entity can be treated as though it does not exist but -a more sophisticated "fsck" support function can report how the -entity is malformed. - - -Documentation Fomatting ------------------------ - -All comments should conform to Doxygen "javadoc" style conventions -for formatting the public API documentation. - - -Public Header Format --------------------- - -All public headers defining types, functions or macros must use -the following form, where ${filename} is the name of the file, -after replacing non-identifier characters with '_'. - ----- - #ifndef INCLUDE_git_${filename}_h__ - #define INCLUDE_git_${filename}_h__ - - #include "git/common.h" - - /** - * @file git/${filename}.h - * @brief Git some description - * @defgroup git_${filename} some description routines - * @ingroup Git - * @{ - */ - GIT_BEGIN_DECL - - ... definitions ... - - /** @} */ - GIT_END_DECL - #endif ----- diff --git a/vendor/libgit2/COPYING b/vendor/libgit2/COPYING deleted file mode 100644 index 75bc6a1fe..000000000 --- a/vendor/libgit2/COPYING +++ /dev/null @@ -1,356 +0,0 @@ - - Note that the only valid version of the GPL as far as this project - is concerned is _this_ particular version of the license (ie v2, not - v2.2 or v3.x or whatever), unless explicitly otherwise stated. - - In addition to the permissions in the GNU General Public License, - the authors give you unlimited permission to link the compiled - version of this file into combinations with other programs, - and to distribute those combinations without any restriction - coming from the use of this file. (The General Public License - restrictions do apply in other respects; for example, they cover - modification of the file, and distribution when not linked into - a combined executable.) - ----------------------------------------------------------------------- - - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. diff --git a/vendor/libgit2/Makefile.embed b/vendor/libgit2/Makefile.embed deleted file mode 100644 index fec090fa7..000000000 --- a/vendor/libgit2/Makefile.embed +++ /dev/null @@ -1,26 +0,0 @@ -rm=rm -f -CC=cc -AR=ar cq -RANLIB=ranlib -LIBNAME=libgit2.a - -INCLUDES= -I. -Isrc -Iinclude -Ideps/zlib - -DEFINES= $(INCLUDES) -DNO_VIZ -DSTDC -DNO_GZIP -D_FILE_OFFSET_BITS=64 -CFLAGS= -g $(DEFINES) -Wall -Wextra -fPIC -O2 - -SRCS = $(wildcard src/*.c) $(wildcard src/unix/*.c) $(wildcard deps/zlib/*.c) -OBJS = $(patsubst %.c,%.o,$(SRCS)) - -%.c.o: - $(CC) $(CFLAGS) -c $*.c - -all: $(LIBNAME) - -$(LIBNAME): $(OBJS) - $(rm) $@ - $(AR) $@ $(OBJS) - $(RANLIB) $@ - -clean: - $(rm) $(OBJS) $(LIBNAME) diff --git a/vendor/libgit2/README.md b/vendor/libgit2/README.md deleted file mode 100644 index b5c76a6be..000000000 --- a/vendor/libgit2/README.md +++ /dev/null @@ -1,113 +0,0 @@ -libgit2 - the Git linkable library -====================== - -libgit2 is a portable, pure C implementation of the Git core methods provided as a -re-entrant linkable library with a solid API, allowing you to write native -speed custom Git applications in any language with bindings. - -libgit2 is licensed under a **very permissive license** (GPLv2 with a special Linking Exception). -This basically means that you can link it (unmodified) with any kind of software without having to -release its source code. - -* Mailing list: -* Website: -* API documentation: -* Usage guide: - -What It Can Do -================================== - -libgit2 is already very usable. - -* SHA conversions, formatting and shortening -* abstracked ODB backend system -* commit, tag, tree and blob parsing, editing, and write-back -* tree traversal -* revision walking -* index file (staging area) manipulation -* reference management (including packed references) -* config file management -* high level repository management -* thread safety and reentrancy -* descriptive and detailed error messages -* ...and more (over 175 different API calls) - -Building libgit2 - Using CMake -============================== - -libgit2 builds cleanly on most platforms without any external dependencies. -Under Unix-like systems, like Linux, * BSD and Mac OS X, libgit2 expects `pthreads` to be available; -they should be installed by default on all systems. Under Windows, libgit2 uses the native Windows API -for threading. - -The libgit2 library is built using CMake 2.6+ () on all platforms. - -On most systems you can build the library using the following commands - - $ mkdir build && cd build - $ cmake .. - $ cmake --build . - -Alternatively you can point the CMake GUI tool to the CMakeLists.txt file and generate platform specific build project or IDE workspace. - -To install the library you can specify the install prefix by setting: - - $ cmake .. -DCMAKE_INSTALL_PREFIX=/install/prefix - $ cmake --build . --target install - -For more advanced use or questions about CMake please read . - -The following CMake variables are declared: - -- `INSTALL_BIN`: Where to install binaries to. -- `INSTALL_LIB`: Where to install libraries to. -- `INSTALL_INC`: Where to install headers to. -- `BUILD_SHARED_LIBS`: Build libgit2 as a Shared Library (defaults to ON) -- `BUILD_TESTS`: Build the libgit2 test suite (defaults to ON) -- `THREADSAFE`: Build libgit2 with threading support (defaults to OFF) - -Language Bindings -================================== - -Here are the bindings to libgit2 that are currently available: - -* Rugged (Ruby bindings) -* objective-git (Objective-C bindings) -* pygit2 (Python bindings) -* libgit2sharp (.NET bindings) -* php-git (PHP bindings) -* luagit2 (Lua bindings) -* GitForDelphi (Delphi bindings) -* node-gitteh (Node.js bindings) -* nodegit (Node.js bindings) -* go-git (Go bindings) -* libqgit2 (C++ QT bindings) -* libgit2-ocaml (ocaml bindings) -* Geef (Erlang bindings) -* libgit2net (.NET bindings, low level) -* parrot-libgit2 (Parrot Virtual Machine bindings) -* hgit2 (Haskell bindings) - -If you start another language binding to libgit2, please let us know so -we can add it to the list. - -How Can I Contribute -================================== - -Fork libgit2/libgit2 on GitHub, add your improvement, push it to a branch -in your fork named for the topic, send a pull request. - -You can also file bugs or feature requests under the libgit2 project on -GitHub, or join us on the mailing list by sending an email to: - -libgit2@librelist.com - - -License -================================== -libgit2 is under GPL2 **with linking exemption**. This means you -can link to the library with any program, commercial, open source or -other. However, you cannot modify libgit2 and distribute it without -supplying the source. - -See the COPYING file for the full license text. diff --git a/vendor/libgit2/api.docurium b/vendor/libgit2/api.docurium deleted file mode 100644 index 9e17817db..000000000 --- a/vendor/libgit2/api.docurium +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "libgit2", - "github": "libgit2/libgit2", - "input": "include/git2", - "prefix": "git_", - "output": "docs", - "branch": "gh-pages", - "examples": "examples", - "legacy": { - "input": {"src/git": ["v0.1.0"], - "src/git2": ["v0.2.0", "v0.3.0"]} - } -} diff --git a/vendor/libgit2/api.doxygen b/vendor/libgit2/api.doxygen deleted file mode 100644 index b812add85..000000000 --- a/vendor/libgit2/api.doxygen +++ /dev/null @@ -1,24 +0,0 @@ -PROJECT_NAME = libgit2 - -INPUT = include/git2 -QUIET = YES -RECURSIVE = YES -FILE_PATTERNS = *.h -OUTPUT_DIRECTORY = apidocs -GENERATE_TAGFILE = apidocs/libgit2.tag - -JAVADOC_AUTOBRIEF = YES -MACRO_EXPANSION = YES -EXPAND_ONLY_PREDEF = YES -OPTIMIZE_OUTPUT_FOR_C = YES -STRIP_CODE_COMMENTS = NO -FULL_PATH_NAMES = NO -CASE_SENSE_NAMES = NO - -PREDEFINED = \ - "GIT_EXTERN(x)=x" \ - "GIT_EXTERN_TLS(x)=x" \ - "GIT_INLINE(x)=x" \ - "GIT_BEGIN_DECL=" \ - "GIT_END_DECL=" \ - DOXYGEN= diff --git a/vendor/libgit2/deps/zlib/adler32.c b/vendor/libgit2/deps/zlib/adler32.c deleted file mode 100644 index 65ad6a5ad..000000000 --- a/vendor/libgit2/deps/zlib/adler32.c +++ /dev/null @@ -1,169 +0,0 @@ -/* adler32.c -- compute the Adler-32 checksum of a data stream - * Copyright (C) 1995-2007 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#include "zutil.h" - -#define local static - -local uLong adler32_combine_(uLong adler1, uLong adler2, z_off64_t len2); - -#define BASE 65521UL /* largest prime smaller than 65536 */ -#define NMAX 5552 -/* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */ - -#define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;} -#define DO2(buf,i) DO1(buf,i); DO1(buf,i+1); -#define DO4(buf,i) DO2(buf,i); DO2(buf,i+2); -#define DO8(buf,i) DO4(buf,i); DO4(buf,i+4); -#define DO16(buf) DO8(buf,0); DO8(buf,8); - -/* use NO_DIVIDE if your processor does not do division in hardware */ -#ifdef NO_DIVIDE -# define MOD(a) \ - do { \ - if (a >= (BASE << 16)) a -= (BASE << 16); \ - if (a >= (BASE << 15)) a -= (BASE << 15); \ - if (a >= (BASE << 14)) a -= (BASE << 14); \ - if (a >= (BASE << 13)) a -= (BASE << 13); \ - if (a >= (BASE << 12)) a -= (BASE << 12); \ - if (a >= (BASE << 11)) a -= (BASE << 11); \ - if (a >= (BASE << 10)) a -= (BASE << 10); \ - if (a >= (BASE << 9)) a -= (BASE << 9); \ - if (a >= (BASE << 8)) a -= (BASE << 8); \ - if (a >= (BASE << 7)) a -= (BASE << 7); \ - if (a >= (BASE << 6)) a -= (BASE << 6); \ - if (a >= (BASE << 5)) a -= (BASE << 5); \ - if (a >= (BASE << 4)) a -= (BASE << 4); \ - if (a >= (BASE << 3)) a -= (BASE << 3); \ - if (a >= (BASE << 2)) a -= (BASE << 2); \ - if (a >= (BASE << 1)) a -= (BASE << 1); \ - if (a >= BASE) a -= BASE; \ - } while (0) -# define MOD4(a) \ - do { \ - if (a >= (BASE << 4)) a -= (BASE << 4); \ - if (a >= (BASE << 3)) a -= (BASE << 3); \ - if (a >= (BASE << 2)) a -= (BASE << 2); \ - if (a >= (BASE << 1)) a -= (BASE << 1); \ - if (a >= BASE) a -= BASE; \ - } while (0) -#else -# define MOD(a) a %= BASE -# define MOD4(a) a %= BASE -#endif - -/* ========================================================================= */ -uLong ZEXPORT adler32(adler, buf, len) - uLong adler; - const Bytef *buf; - uInt len; -{ - unsigned long sum2; - unsigned n; - - /* split Adler-32 into component sums */ - sum2 = (adler >> 16) & 0xffff; - adler &= 0xffff; - - /* in case user likes doing a byte at a time, keep it fast */ - if (len == 1) { - adler += buf[0]; - if (adler >= BASE) - adler -= BASE; - sum2 += adler; - if (sum2 >= BASE) - sum2 -= BASE; - return adler | (sum2 << 16); - } - - /* initial Adler-32 value (deferred check for len == 1 speed) */ - if (buf == Z_NULL) - return 1L; - - /* in case short lengths are provided, keep it somewhat fast */ - if (len < 16) { - while (len--) { - adler += *buf++; - sum2 += adler; - } - if (adler >= BASE) - adler -= BASE; - MOD4(sum2); /* only added so many BASE's */ - return adler | (sum2 << 16); - } - - /* do length NMAX blocks -- requires just one modulo operation */ - while (len >= NMAX) { - len -= NMAX; - n = NMAX / 16; /* NMAX is divisible by 16 */ - do { - DO16(buf); /* 16 sums unrolled */ - buf += 16; - } while (--n); - MOD(adler); - MOD(sum2); - } - - /* do remaining bytes (less than NMAX, still just one modulo) */ - if (len) { /* avoid modulos if none remaining */ - while (len >= 16) { - len -= 16; - DO16(buf); - buf += 16; - } - while (len--) { - adler += *buf++; - sum2 += adler; - } - MOD(adler); - MOD(sum2); - } - - /* return recombined sums */ - return adler | (sum2 << 16); -} - -/* ========================================================================= */ -local uLong adler32_combine_(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off64_t len2; -{ - unsigned long sum1; - unsigned long sum2; - unsigned rem; - - /* the derivation of this formula is left as an exercise for the reader */ - rem = (unsigned)(len2 % BASE); - sum1 = adler1 & 0xffff; - sum2 = rem * sum1; - MOD(sum2); - sum1 += (adler2 & 0xffff) + BASE - 1; - sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem; - if (sum1 >= BASE) sum1 -= BASE; - if (sum1 >= BASE) sum1 -= BASE; - if (sum2 >= (BASE << 1)) sum2 -= (BASE << 1); - if (sum2 >= BASE) sum2 -= BASE; - return sum1 | (sum2 << 16); -} - -/* ========================================================================= */ -uLong ZEXPORT adler32_combine(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off_t len2; -{ - return adler32_combine_(adler1, adler2, len2); -} - -uLong ZEXPORT adler32_combine64(adler1, adler2, len2) - uLong adler1; - uLong adler2; - z_off64_t len2; -{ - return adler32_combine_(adler1, adler2, len2); -} diff --git a/vendor/libgit2/deps/zlib/crc32.c b/vendor/libgit2/deps/zlib/crc32.c deleted file mode 100644 index 91be372d2..000000000 --- a/vendor/libgit2/deps/zlib/crc32.c +++ /dev/null @@ -1,442 +0,0 @@ -/* crc32.c -- compute the CRC-32 of a data stream - * Copyright (C) 1995-2006, 2010 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - * - * Thanks to Rodney Brown for his contribution of faster - * CRC methods: exclusive-oring 32 bits of data at a time, and pre-computing - * tables for updating the shift register in one step with three exclusive-ors - * instead of four steps with four exclusive-ors. This results in about a - * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. - */ - -/* @(#) $Id$ */ - -/* - Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore - protection on the static variables used to control the first-use generation - of the crc tables. Therefore, if you #define DYNAMIC_CRC_TABLE, you should - first call get_crc_table() to initialize the tables before allowing more than - one thread to use crc32(). - */ - -#ifdef MAKECRCH -# include -# ifndef DYNAMIC_CRC_TABLE -# define DYNAMIC_CRC_TABLE -# endif /* !DYNAMIC_CRC_TABLE */ -#endif /* MAKECRCH */ - -#include "zutil.h" /* for STDC and FAR definitions */ - -#define local static - -/* Find a four-byte integer type for crc32_little() and crc32_big(). */ -#ifndef NOBYFOUR -# ifdef STDC /* need ANSI C limits.h to determine sizes */ -# include -# define BYFOUR -# if (UINT_MAX == 0xffffffffUL) - typedef unsigned int u4; -# else -# if (ULONG_MAX == 0xffffffffUL) - typedef unsigned long u4; -# else -# if (USHRT_MAX == 0xffffffffUL) - typedef unsigned short u4; -# else -# undef BYFOUR /* can't find a four-byte integer type! */ -# endif -# endif -# endif -# endif /* STDC */ -#endif /* !NOBYFOUR */ - -/* Definitions for doing the crc four data bytes at a time. */ -#ifdef BYFOUR -# define REV(w) ((((w)>>24)&0xff)+(((w)>>8)&0xff00)+ \ - (((w)&0xff00)<<8)+(((w)&0xff)<<24)) - local unsigned long crc32_little OF((unsigned long, - const unsigned char FAR *, unsigned)); - local unsigned long crc32_big OF((unsigned long, - const unsigned char FAR *, unsigned)); -# define TBLS 8 -#else -# define TBLS 1 -#endif /* BYFOUR */ - -/* Local functions for crc concatenation */ -local unsigned long gf2_matrix_times OF((unsigned long *mat, - unsigned long vec)); -local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat)); -local uLong crc32_combine_(uLong crc1, uLong crc2, z_off64_t len2); - - -#ifdef DYNAMIC_CRC_TABLE - -local volatile int crc_table_empty = 1; -local unsigned long FAR crc_table[TBLS][256]; -local void make_crc_table OF((void)); -#ifdef MAKECRCH - local void write_table OF((FILE *, const unsigned long FAR *)); -#endif /* MAKECRCH */ -/* - Generate tables for a byte-wise 32-bit CRC calculation on the polynomial: - x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1. - - Polynomials over GF(2) are represented in binary, one bit per coefficient, - with the lowest powers in the most significant bit. Then adding polynomials - is just exclusive-or, and multiplying a polynomial by x is a right shift by - one. If we call the above polynomial p, and represent a byte as the - polynomial q, also with the lowest power in the most significant bit (so the - byte 0xb1 is the polynomial x^7+x^3+x+1), then the CRC is (q*x^32) mod p, - where a mod b means the remainder after dividing a by b. - - This calculation is done using the shift-register method of multiplying and - taking the remainder. The register is initialized to zero, and for each - incoming bit, x^32 is added mod p to the register if the bit is a one (where - x^32 mod p is p+x^32 = x^26+...+1), and the register is multiplied mod p by - x (which is shifting right by one and adding x^32 mod p if the bit shifted - out is a one). We start with the highest power (least significant bit) of - q and repeat for all eight bits of q. - - The first table is simply the CRC of all possible eight bit values. This is - all the information needed to generate CRCs on data a byte at a time for all - combinations of CRC register values and incoming bytes. The remaining tables - allow for word-at-a-time CRC calculation for both big-endian and little- - endian machines, where a word is four bytes. -*/ -local void make_crc_table() -{ - unsigned long c; - int n, k; - unsigned long poly; /* polynomial exclusive-or pattern */ - /* terms of polynomial defining this crc (except x^32): */ - static volatile int first = 1; /* flag to limit concurrent making */ - static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26}; - - /* See if another task is already doing this (not thread-safe, but better - than nothing -- significantly reduces duration of vulnerability in - case the advice about DYNAMIC_CRC_TABLE is ignored) */ - if (first) { - first = 0; - - /* make exclusive-or pattern from polynomial (0xedb88320UL) */ - poly = 0UL; - for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++) - poly |= 1UL << (31 - p[n]); - - /* generate a crc for every 8-bit value */ - for (n = 0; n < 256; n++) { - c = (unsigned long)n; - for (k = 0; k < 8; k++) - c = c & 1 ? poly ^ (c >> 1) : c >> 1; - crc_table[0][n] = c; - } - -#ifdef BYFOUR - /* generate crc for each value followed by one, two, and three zeros, - and then the byte reversal of those as well as the first table */ - for (n = 0; n < 256; n++) { - c = crc_table[0][n]; - crc_table[4][n] = REV(c); - for (k = 1; k < 4; k++) { - c = crc_table[0][c & 0xff] ^ (c >> 8); - crc_table[k][n] = c; - crc_table[k + 4][n] = REV(c); - } - } -#endif /* BYFOUR */ - - crc_table_empty = 0; - } - else { /* not first */ - /* wait for the other guy to finish (not efficient, but rare) */ - while (crc_table_empty) - ; - } - -#ifdef MAKECRCH - /* write out CRC tables to crc32.h */ - { - FILE *out; - - out = fopen("crc32.h", "w"); - if (out == NULL) return; - fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n"); - fprintf(out, " * Generated automatically by crc32.c\n */\n\n"); - fprintf(out, "local const unsigned long FAR "); - fprintf(out, "crc_table[TBLS][256] =\n{\n {\n"); - write_table(out, crc_table[0]); -# ifdef BYFOUR - fprintf(out, "#ifdef BYFOUR\n"); - for (k = 1; k < 8; k++) { - fprintf(out, " },\n {\n"); - write_table(out, crc_table[k]); - } - fprintf(out, "#endif\n"); -# endif /* BYFOUR */ - fprintf(out, " }\n};\n"); - fclose(out); - } -#endif /* MAKECRCH */ -} - -#ifdef MAKECRCH -local void write_table(out, table) - FILE *out; - const unsigned long FAR *table; -{ - int n; - - for (n = 0; n < 256; n++) - fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n], - n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", ")); -} -#endif /* MAKECRCH */ - -#else /* !DYNAMIC_CRC_TABLE */ -/* ======================================================================== - * Tables of CRC-32s of all single-byte values, made by make_crc_table(). - */ -#include "crc32.h" -#endif /* DYNAMIC_CRC_TABLE */ - -/* ========================================================================= - * This function can be used by asm versions of crc32() - */ -const unsigned long FAR * ZEXPORT get_crc_table() -{ -#ifdef DYNAMIC_CRC_TABLE - if (crc_table_empty) - make_crc_table(); -#endif /* DYNAMIC_CRC_TABLE */ - return (const unsigned long FAR *)crc_table; -} - -/* ========================================================================= */ -#define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8) -#define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1 - -/* ========================================================================= */ -unsigned long ZEXPORT crc32(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - uInt len; -{ - if (buf == Z_NULL) return 0UL; - -#ifdef DYNAMIC_CRC_TABLE - if (crc_table_empty) - make_crc_table(); -#endif /* DYNAMIC_CRC_TABLE */ - -#ifdef BYFOUR - if (sizeof(void *) == sizeof(ptrdiff_t)) { - u4 endian; - - endian = 1; - if (*((unsigned char *)(&endian))) - return crc32_little(crc, buf, len); - else - return crc32_big(crc, buf, len); - } -#endif /* BYFOUR */ - crc = crc ^ 0xffffffffUL; - while (len >= 8) { - DO8; - len -= 8; - } - if (len) do { - DO1; - } while (--len); - return crc ^ 0xffffffffUL; -} - -#ifdef BYFOUR - -/* ========================================================================= */ -#define DOLIT4 c ^= *buf4++; \ - c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \ - crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24] -#define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4 - -/* ========================================================================= */ -local unsigned long crc32_little(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - unsigned len; -{ - register u4 c; - register const u4 FAR *buf4; - - c = (u4)crc; - c = ~c; - while (len && ((ptrdiff_t)buf & 3)) { - c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); - len--; - } - - buf4 = (const u4 FAR *)(const void FAR *)buf; - while (len >= 32) { - DOLIT32; - len -= 32; - } - while (len >= 4) { - DOLIT4; - len -= 4; - } - buf = (const unsigned char FAR *)buf4; - - if (len) do { - c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8); - } while (--len); - c = ~c; - return (unsigned long)c; -} - -/* ========================================================================= */ -#define DOBIG4 c ^= *++buf4; \ - c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \ - crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24] -#define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4 - -/* ========================================================================= */ -local unsigned long crc32_big(crc, buf, len) - unsigned long crc; - const unsigned char FAR *buf; - unsigned len; -{ - register u4 c; - register const u4 FAR *buf4; - - c = REV((u4)crc); - c = ~c; - while (len && ((ptrdiff_t)buf & 3)) { - c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); - len--; - } - - buf4 = (const u4 FAR *)(const void FAR *)buf; - buf4--; - while (len >= 32) { - DOBIG32; - len -= 32; - } - while (len >= 4) { - DOBIG4; - len -= 4; - } - buf4++; - buf = (const unsigned char FAR *)buf4; - - if (len) do { - c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8); - } while (--len); - c = ~c; - return (unsigned long)(REV(c)); -} - -#endif /* BYFOUR */ - -#define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */ - -/* ========================================================================= */ -local unsigned long gf2_matrix_times(mat, vec) - unsigned long *mat; - unsigned long vec; -{ - unsigned long sum; - - sum = 0; - while (vec) { - if (vec & 1) - sum ^= *mat; - vec >>= 1; - mat++; - } - return sum; -} - -/* ========================================================================= */ -local void gf2_matrix_square(square, mat) - unsigned long *square; - unsigned long *mat; -{ - int n; - - for (n = 0; n < GF2_DIM; n++) - square[n] = gf2_matrix_times(mat, mat[n]); -} - -/* ========================================================================= */ -local uLong crc32_combine_(crc1, crc2, len2) - uLong crc1; - uLong crc2; - z_off64_t len2; -{ - int n; - unsigned long row; - unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */ - unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */ - - /* degenerate case (also disallow negative lengths) */ - if (len2 <= 0) - return crc1; - - /* put operator for one zero bit in odd */ - odd[0] = 0xedb88320UL; /* CRC-32 polynomial */ - row = 1; - for (n = 1; n < GF2_DIM; n++) { - odd[n] = row; - row <<= 1; - } - - /* put operator for two zero bits in even */ - gf2_matrix_square(even, odd); - - /* put operator for four zero bits in odd */ - gf2_matrix_square(odd, even); - - /* apply len2 zeros to crc1 (first square will put the operator for one - zero byte, eight zero bits, in even) */ - do { - /* apply zeros operator for this bit of len2 */ - gf2_matrix_square(even, odd); - if (len2 & 1) - crc1 = gf2_matrix_times(even, crc1); - len2 >>= 1; - - /* if no more bits set, then done */ - if (len2 == 0) - break; - - /* another iteration of the loop with odd and even swapped */ - gf2_matrix_square(odd, even); - if (len2 & 1) - crc1 = gf2_matrix_times(odd, crc1); - len2 >>= 1; - - /* if no more bits set, then done */ - } while (len2 != 0); - - /* return combined crc */ - crc1 ^= crc2; - return crc1; -} - -/* ========================================================================= */ -uLong ZEXPORT crc32_combine(crc1, crc2, len2) - uLong crc1; - uLong crc2; - z_off_t len2; -{ - return crc32_combine_(crc1, crc2, len2); -} - -uLong ZEXPORT crc32_combine64(crc1, crc2, len2) - uLong crc1; - uLong crc2; - z_off64_t len2; -{ - return crc32_combine_(crc1, crc2, len2); -} diff --git a/vendor/libgit2/deps/zlib/crc32.h b/vendor/libgit2/deps/zlib/crc32.h deleted file mode 100644 index 8053b6117..000000000 --- a/vendor/libgit2/deps/zlib/crc32.h +++ /dev/null @@ -1,441 +0,0 @@ -/* crc32.h -- tables for rapid CRC calculation - * Generated automatically by crc32.c - */ - -local const unsigned long FAR crc_table[TBLS][256] = -{ - { - 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL, - 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL, - 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL, - 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL, - 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL, - 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL, - 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL, - 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL, - 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL, - 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL, - 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL, - 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL, - 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL, - 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL, - 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL, - 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL, - 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL, - 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL, - 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL, - 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL, - 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL, - 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL, - 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL, - 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL, - 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL, - 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL, - 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL, - 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL, - 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL, - 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL, - 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL, - 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL, - 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL, - 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL, - 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL, - 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL, - 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL, - 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL, - 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL, - 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL, - 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL, - 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL, - 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL, - 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL, - 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL, - 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL, - 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL, - 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL, - 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL, - 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL, - 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL, - 0x2d02ef8dUL -#ifdef BYFOUR - }, - { - 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL, - 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL, - 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL, - 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL, - 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL, - 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL, - 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL, - 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL, - 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL, - 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL, - 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL, - 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL, - 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL, - 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL, - 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL, - 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL, - 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL, - 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL, - 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL, - 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL, - 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL, - 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL, - 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL, - 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL, - 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL, - 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL, - 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL, - 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL, - 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL, - 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL, - 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL, - 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL, - 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL, - 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL, - 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL, - 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL, - 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL, - 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL, - 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL, - 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL, - 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL, - 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL, - 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL, - 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL, - 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL, - 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL, - 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL, - 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL, - 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL, - 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL, - 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL, - 0x9324fd72UL - }, - { - 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL, - 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL, - 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL, - 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL, - 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL, - 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL, - 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL, - 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL, - 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL, - 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL, - 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL, - 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL, - 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL, - 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL, - 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL, - 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL, - 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL, - 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL, - 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL, - 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL, - 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL, - 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL, - 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL, - 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL, - 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL, - 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL, - 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL, - 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL, - 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL, - 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL, - 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL, - 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL, - 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL, - 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL, - 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL, - 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL, - 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL, - 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL, - 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL, - 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL, - 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL, - 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL, - 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL, - 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL, - 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL, - 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL, - 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL, - 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL, - 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL, - 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL, - 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL, - 0xbe9834edUL - }, - { - 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL, - 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL, - 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL, - 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL, - 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL, - 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL, - 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL, - 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL, - 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL, - 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL, - 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL, - 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL, - 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL, - 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL, - 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL, - 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL, - 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL, - 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL, - 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL, - 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL, - 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL, - 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL, - 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL, - 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL, - 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL, - 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL, - 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL, - 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL, - 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL, - 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL, - 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL, - 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL, - 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL, - 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL, - 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL, - 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL, - 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL, - 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL, - 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL, - 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL, - 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL, - 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL, - 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL, - 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL, - 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL, - 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL, - 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL, - 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL, - 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL, - 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL, - 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL, - 0xde0506f1UL - }, - { - 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL, - 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL, - 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL, - 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL, - 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL, - 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL, - 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL, - 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL, - 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL, - 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL, - 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL, - 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL, - 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL, - 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL, - 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL, - 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL, - 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL, - 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL, - 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL, - 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL, - 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL, - 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL, - 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL, - 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL, - 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL, - 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL, - 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL, - 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL, - 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL, - 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL, - 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL, - 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL, - 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL, - 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL, - 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL, - 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL, - 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL, - 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL, - 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL, - 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL, - 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL, - 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL, - 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL, - 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL, - 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL, - 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL, - 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL, - 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL, - 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL, - 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL, - 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL, - 0x8def022dUL - }, - { - 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL, - 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL, - 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL, - 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL, - 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL, - 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL, - 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL, - 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL, - 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL, - 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL, - 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL, - 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL, - 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL, - 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL, - 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL, - 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL, - 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL, - 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL, - 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL, - 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL, - 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL, - 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL, - 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL, - 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL, - 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL, - 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL, - 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL, - 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL, - 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL, - 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL, - 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL, - 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL, - 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL, - 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL, - 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL, - 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL, - 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL, - 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL, - 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL, - 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL, - 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL, - 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL, - 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL, - 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL, - 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL, - 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL, - 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL, - 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL, - 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL, - 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL, - 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL, - 0x72fd2493UL - }, - { - 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL, - 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL, - 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL, - 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL, - 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL, - 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL, - 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL, - 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL, - 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL, - 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL, - 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL, - 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL, - 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL, - 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL, - 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL, - 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL, - 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL, - 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL, - 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL, - 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL, - 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL, - 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL, - 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL, - 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL, - 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL, - 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL, - 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL, - 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL, - 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL, - 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL, - 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL, - 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL, - 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL, - 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL, - 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL, - 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL, - 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL, - 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL, - 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL, - 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL, - 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL, - 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL, - 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL, - 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL, - 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL, - 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL, - 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL, - 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL, - 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL, - 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL, - 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL, - 0xed3498beUL - }, - { - 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL, - 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL, - 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL, - 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL, - 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL, - 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL, - 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL, - 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL, - 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL, - 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL, - 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL, - 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL, - 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL, - 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL, - 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL, - 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL, - 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL, - 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL, - 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL, - 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL, - 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL, - 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL, - 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL, - 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL, - 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL, - 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL, - 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL, - 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL, - 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL, - 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL, - 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL, - 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL, - 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL, - 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL, - 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL, - 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL, - 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL, - 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL, - 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL, - 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL, - 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL, - 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL, - 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL, - 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL, - 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL, - 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL, - 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL, - 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL, - 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL, - 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL, - 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL, - 0xf10605deUL -#endif - } -}; diff --git a/vendor/libgit2/deps/zlib/deflate.c b/vendor/libgit2/deps/zlib/deflate.c deleted file mode 100644 index 5c4022f3d..000000000 --- a/vendor/libgit2/deps/zlib/deflate.c +++ /dev/null @@ -1,1834 +0,0 @@ -/* deflate.c -- compress data using the deflation algorithm - * Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * ALGORITHM - * - * The "deflation" process depends on being able to identify portions - * of the input text which are identical to earlier input (within a - * sliding window trailing behind the input currently being processed). - * - * The most straightforward technique turns out to be the fastest for - * most input files: try all possible matches and select the longest. - * The key feature of this algorithm is that insertions into the string - * dictionary are very simple and thus fast, and deletions are avoided - * completely. Insertions are performed at each input character, whereas - * string matches are performed only when the previous match ends. So it - * is preferable to spend more time in matches to allow very fast string - * insertions and avoid deletions. The matching algorithm for small - * strings is inspired from that of Rabin & Karp. A brute force approach - * is used to find longer strings when a small match has been found. - * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze - * (by Leonid Broukhis). - * A previous version of this file used a more sophisticated algorithm - * (by Fiala and Greene) which is guaranteed to run in linear amortized - * time, but has a larger average cost, uses more memory and is patented. - * However the F&G algorithm may be faster for some highly redundant - * files if the parameter max_chain_length (described below) is too large. - * - * ACKNOWLEDGEMENTS - * - * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and - * I found it in 'freeze' written by Leonid Broukhis. - * Thanks to many people for bug reports and testing. - * - * REFERENCES - * - * Deutsch, L.P.,"DEFLATE Compressed Data Format Specification". - * Available in http://www.ietf.org/rfc/rfc1951.txt - * - * A description of the Rabin and Karp algorithm is given in the book - * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. - * - * Fiala,E.R., and Greene,D.H. - * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 - * - */ - -/* @(#) $Id$ */ - -#include "deflate.h" - -const char deflate_copyright[] = - " deflate 1.2.5 Copyright 1995-2010 Jean-loup Gailly and Mark Adler "; -/* - If you use the zlib library in a product, an acknowledgment is welcome - in the documentation of your product. If for some reason you cannot - include such an acknowledgment, I would appreciate that you keep this - copyright string in the executable of your product. - */ - -/* =========================================================================== - * Function prototypes. - */ -typedef enum { - need_more, /* block not completed, need more input or more output */ - block_done, /* block flush performed */ - finish_started, /* finish started, need only more output at next deflate */ - finish_done /* finish done, accept no more input or output */ -} block_state; - -typedef block_state (*compress_func) OF((deflate_state *s, int flush)); -/* Compression function. Returns the block state after the call. */ - -local void fill_window OF((deflate_state *s)); -local block_state deflate_stored OF((deflate_state *s, int flush)); -local block_state deflate_fast OF((deflate_state *s, int flush)); -#ifndef FASTEST -local block_state deflate_slow OF((deflate_state *s, int flush)); -#endif -local block_state deflate_rle OF((deflate_state *s, int flush)); -local block_state deflate_huff OF((deflate_state *s, int flush)); -local void lm_init OF((deflate_state *s)); -local void putShortMSB OF((deflate_state *s, uInt b)); -local void flush_pending OF((z_streamp strm)); -local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size)); -#ifdef ASMV - void match_init OF((void)); /* asm code initialization */ - uInt longest_match OF((deflate_state *s, IPos cur_match)); -#else -local uInt longest_match OF((deflate_state *s, IPos cur_match)); -#endif - -#ifdef DEBUG -local void check_match OF((deflate_state *s, IPos start, IPos match, - int length)); -#endif - -/* =========================================================================== - * Local data - */ - -#define NIL 0 -/* Tail of hash chains */ - -#ifndef TOO_FAR -# define TOO_FAR 4096 -#endif -/* Matches of length 3 are discarded if their distance exceeds TOO_FAR */ - -/* Values for max_lazy_match, good_match and max_chain_length, depending on - * the desired pack level (0..9). The values given below have been tuned to - * exclude worst case performance for pathological files. Better values may be - * found for specific files. - */ -typedef struct config_s { - ush good_length; /* reduce lazy search above this match length */ - ush max_lazy; /* do not perform lazy search above this match length */ - ush nice_length; /* quit search above this match length */ - ush max_chain; - compress_func func; -} config; - -#ifdef FASTEST -local const config configuration_table[2] = { -/* good lazy nice chain */ -/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ -/* 1 */ {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */ -#else -local const config configuration_table[10] = { -/* good lazy nice chain */ -/* 0 */ {0, 0, 0, 0, deflate_stored}, /* store only */ -/* 1 */ {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */ -/* 2 */ {4, 5, 16, 8, deflate_fast}, -/* 3 */ {4, 6, 32, 32, deflate_fast}, - -/* 4 */ {4, 4, 16, 16, deflate_slow}, /* lazy matches */ -/* 5 */ {8, 16, 32, 32, deflate_slow}, -/* 6 */ {8, 16, 128, 128, deflate_slow}, -/* 7 */ {8, 32, 128, 256, deflate_slow}, -/* 8 */ {32, 128, 258, 1024, deflate_slow}, -/* 9 */ {32, 258, 258, 4096, deflate_slow}}; /* max compression */ -#endif - -/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 - * For deflate_fast() (levels <= 3) good is ignored and lazy has a different - * meaning. - */ - -#define EQUAL 0 -/* result of memcmp for equal strings */ - -#ifndef NO_DUMMY_DECL -struct static_tree_desc_s {int dummy;}; /* for buggy compilers */ -#endif - -/* =========================================================================== - * Update a hash value with the given input byte - * IN assertion: all calls to to UPDATE_HASH are made with consecutive - * input characters, so that a running hash key can be computed from the - * previous key instead of complete recalculation each time. - */ -#define UPDATE_HASH(s,h,c) (h = (((h)<hash_shift) ^ (c)) & s->hash_mask) - - -/* =========================================================================== - * Insert string str in the dictionary and set match_head to the previous head - * of the hash chain (the most recent string with same hash key). Return - * the previous length of the hash chain. - * If this file is compiled with -DFASTEST, the compression level is forced - * to 1, and no hash chains are maintained. - * IN assertion: all calls to to INSERT_STRING are made with consecutive - * input characters and the first MIN_MATCH bytes of str are valid - * (except for the last MIN_MATCH-1 bytes of the input file). - */ -#ifdef FASTEST -#define INSERT_STRING(s, str, match_head) \ - (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ - match_head = s->head[s->ins_h], \ - s->head[s->ins_h] = (Pos)(str)) -#else -#define INSERT_STRING(s, str, match_head) \ - (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \ - match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \ - s->head[s->ins_h] = (Pos)(str)) -#endif - -/* =========================================================================== - * Initialize the hash table (avoiding 64K overflow for 16 bit systems). - * prev[] will be initialized on the fly. - */ -#define CLEAR_HASH(s) \ - s->head[s->hash_size-1] = NIL; \ - zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head)); - -/* ========================================================================= */ -int ZEXPORT deflateInit_(strm, level, version, stream_size) - z_streamp strm; - int level; - const char *version; - int stream_size; -{ - return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL, - Z_DEFAULT_STRATEGY, version, stream_size); - /* To do: ignore strm->next_in if we use it as window */ -} - -/* ========================================================================= */ -int ZEXPORT deflateInit2_(strm, level, method, windowBits, memLevel, strategy, - version, stream_size) - z_streamp strm; - int level; - int method; - int windowBits; - int memLevel; - int strategy; - const char *version; - int stream_size; -{ - deflate_state *s; - int wrap = 1; - static const char my_version[] = ZLIB_VERSION; - - ushf *overlay; - /* We overlay pending_buf and d_buf+l_buf. This works since the average - * output size for (length,distance) codes is <= 24 bits. - */ - - if (version == Z_NULL || version[0] != my_version[0] || - stream_size != sizeof(z_stream)) { - return Z_VERSION_ERROR; - } - if (strm == Z_NULL) return Z_STREAM_ERROR; - - strm->msg = Z_NULL; - if (strm->zalloc == (alloc_func)0) { - strm->zalloc = zcalloc; - strm->opaque = (voidpf)0; - } - if (strm->zfree == (free_func)0) strm->zfree = zcfree; - -#ifdef FASTEST - if (level != 0) level = 1; -#else - if (level == Z_DEFAULT_COMPRESSION) level = 6; -#endif - - if (windowBits < 0) { /* suppress zlib wrapper */ - wrap = 0; - windowBits = -windowBits; - } -#ifdef GZIP - else if (windowBits > 15) { - wrap = 2; /* write gzip wrapper instead */ - windowBits -= 16; - } -#endif - if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || - windowBits < 8 || windowBits > 15 || level < 0 || level > 9 || - strategy < 0 || strategy > Z_FIXED) { - return Z_STREAM_ERROR; - } - if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */ - s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state)); - if (s == Z_NULL) return Z_MEM_ERROR; - strm->state = (struct internal_state FAR *)s; - s->strm = strm; - - s->wrap = wrap; - s->gzhead = Z_NULL; - s->w_bits = windowBits; - s->w_size = 1 << s->w_bits; - s->w_mask = s->w_size - 1; - - s->hash_bits = memLevel + 7; - s->hash_size = 1 << s->hash_bits; - s->hash_mask = s->hash_size - 1; - s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH); - - s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte)); - s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos)); - s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos)); - - s->high_water = 0; /* nothing written to s->window yet */ - - s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */ - - overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2); - s->pending_buf = (uchf *) overlay; - s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L); - - if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL || - s->pending_buf == Z_NULL) { - s->status = FINISH_STATE; - strm->msg = (char*)ERR_MSG(Z_MEM_ERROR); - deflateEnd (strm); - return Z_MEM_ERROR; - } - s->d_buf = overlay + s->lit_bufsize/sizeof(ush); - s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize; - - s->level = level; - s->strategy = strategy; - s->method = (Byte)method; - - return deflateReset(strm); -} - -/* ========================================================================= */ -int ZEXPORT deflateSetDictionary (strm, dictionary, dictLength) - z_streamp strm; - const Bytef *dictionary; - uInt dictLength; -{ - deflate_state *s; - uInt length = dictLength; - uInt n; - IPos hash_head = 0; - - if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL || - strm->state->wrap == 2 || - (strm->state->wrap == 1 && strm->state->status != INIT_STATE)) - return Z_STREAM_ERROR; - - s = strm->state; - if (s->wrap) - strm->adler = adler32(strm->adler, dictionary, dictLength); - - if (length < MIN_MATCH) return Z_OK; - if (length > s->w_size) { - length = s->w_size; - dictionary += dictLength - length; /* use the tail of the dictionary */ - } - zmemcpy(s->window, dictionary, length); - s->strstart = length; - s->block_start = (long)length; - - /* Insert all strings in the hash table (except for the last two bytes). - * s->lookahead stays null, so s->ins_h will be recomputed at the next - * call of fill_window. - */ - s->ins_h = s->window[0]; - UPDATE_HASH(s, s->ins_h, s->window[1]); - for (n = 0; n <= length - MIN_MATCH; n++) { - INSERT_STRING(s, n, hash_head); - } - if (hash_head) hash_head = 0; /* to make compiler happy */ - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateReset (strm) - z_streamp strm; -{ - deflate_state *s; - - if (strm == Z_NULL || strm->state == Z_NULL || - strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) { - return Z_STREAM_ERROR; - } - - strm->total_in = strm->total_out = 0; - strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */ - strm->data_type = Z_UNKNOWN; - - s = (deflate_state *)strm->state; - s->pending = 0; - s->pending_out = s->pending_buf; - - if (s->wrap < 0) { - s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */ - } - s->status = s->wrap ? INIT_STATE : BUSY_STATE; - strm->adler = -#ifdef GZIP - s->wrap == 2 ? crc32(0L, Z_NULL, 0) : -#endif - adler32(0L, Z_NULL, 0); - s->last_flush = Z_NO_FLUSH; - - _tr_init(s); - lm_init(s); - - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateSetHeader (strm, head) - z_streamp strm; - gz_headerp head; -{ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - if (strm->state->wrap != 2) return Z_STREAM_ERROR; - strm->state->gzhead = head; - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflatePrime (strm, bits, value) - z_streamp strm; - int bits; - int value; -{ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - strm->state->bi_valid = bits; - strm->state->bi_buf = (ush)(value & ((1 << bits) - 1)); - return Z_OK; -} - -/* ========================================================================= */ -int ZEXPORT deflateParams(strm, level, strategy) - z_streamp strm; - int level; - int strategy; -{ - deflate_state *s; - compress_func func; - int err = Z_OK; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - s = strm->state; - -#ifdef FASTEST - if (level != 0) level = 1; -#else - if (level == Z_DEFAULT_COMPRESSION) level = 6; -#endif - if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) { - return Z_STREAM_ERROR; - } - func = configuration_table[s->level].func; - - if ((strategy != s->strategy || func != configuration_table[level].func) && - strm->total_in != 0) { - /* Flush the last buffer: */ - err = deflate(strm, Z_BLOCK); - } - if (s->level != level) { - s->level = level; - s->max_lazy_match = configuration_table[level].max_lazy; - s->good_match = configuration_table[level].good_length; - s->nice_match = configuration_table[level].nice_length; - s->max_chain_length = configuration_table[level].max_chain; - } - s->strategy = strategy; - return err; -} - -/* ========================================================================= */ -int ZEXPORT deflateTune(strm, good_length, max_lazy, nice_length, max_chain) - z_streamp strm; - int good_length; - int max_lazy; - int nice_length; - int max_chain; -{ - deflate_state *s; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - s = strm->state; - s->good_match = good_length; - s->max_lazy_match = max_lazy; - s->nice_match = nice_length; - s->max_chain_length = max_chain; - return Z_OK; -} - -/* ========================================================================= - * For the default windowBits of 15 and memLevel of 8, this function returns - * a close to exact, as well as small, upper bound on the compressed size. - * They are coded as constants here for a reason--if the #define's are - * changed, then this function needs to be changed as well. The return - * value for 15 and 8 only works for those exact settings. - * - * For any setting other than those defaults for windowBits and memLevel, - * the value returned is a conservative worst case for the maximum expansion - * resulting from using fixed blocks instead of stored blocks, which deflate - * can emit on compressed data for some combinations of the parameters. - * - * This function could be more sophisticated to provide closer upper bounds for - * every combination of windowBits and memLevel. But even the conservative - * upper bound of about 14% expansion does not seem onerous for output buffer - * allocation. - */ -uLong ZEXPORT deflateBound(strm, sourceLen) - z_streamp strm; - uLong sourceLen; -{ - deflate_state *s; - uLong complen, wraplen; - Bytef *str; - - /* conservative upper bound for compressed data */ - complen = sourceLen + - ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 5; - - /* if can't get parameters, return conservative bound plus zlib wrapper */ - if (strm == Z_NULL || strm->state == Z_NULL) - return complen + 6; - - /* compute wrapper length */ - s = strm->state; - switch (s->wrap) { - case 0: /* raw deflate */ - wraplen = 0; - break; - case 1: /* zlib wrapper */ - wraplen = 6 + (s->strstart ? 4 : 0); - break; - case 2: /* gzip wrapper */ - wraplen = 18; - if (s->gzhead != Z_NULL) { /* user-supplied gzip header */ - if (s->gzhead->extra != Z_NULL) - wraplen += 2 + s->gzhead->extra_len; - str = s->gzhead->name; - if (str != Z_NULL) - do { - wraplen++; - } while (*str++); - str = s->gzhead->comment; - if (str != Z_NULL) - do { - wraplen++; - } while (*str++); - if (s->gzhead->hcrc) - wraplen += 2; - } - break; - default: /* for compiler happiness */ - wraplen = 6; - } - - /* if not default parameters, return conservative bound */ - if (s->w_bits != 15 || s->hash_bits != 8 + 7) - return complen + wraplen; - - /* default settings: return tight bound for that case */ - return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + - (sourceLen >> 25) + 13 - 6 + wraplen; -} - -/* ========================================================================= - * Put a short in the pending buffer. The 16-bit value is put in MSB order. - * IN assertion: the stream state is correct and there is enough room in - * pending_buf. - */ -local void putShortMSB (s, b) - deflate_state *s; - uInt b; -{ - put_byte(s, (Byte)(b >> 8)); - put_byte(s, (Byte)(b & 0xff)); -} - -/* ========================================================================= - * Flush as much pending output as possible. All deflate() output goes - * through this function so some applications may wish to modify it - * to avoid allocating a large strm->next_out buffer and copying into it. - * (See also read_buf()). - */ -local void flush_pending(strm) - z_streamp strm; -{ - unsigned len = strm->state->pending; - - if (len > strm->avail_out) len = strm->avail_out; - if (len == 0) return; - - zmemcpy(strm->next_out, strm->state->pending_out, len); - strm->next_out += len; - strm->state->pending_out += len; - strm->total_out += len; - strm->avail_out -= len; - strm->state->pending -= len; - if (strm->state->pending == 0) { - strm->state->pending_out = strm->state->pending_buf; - } -} - -/* ========================================================================= */ -int ZEXPORT deflate (strm, flush) - z_streamp strm; - int flush; -{ - int old_flush; /* value of flush param for previous deflate call */ - deflate_state *s; - - if (strm == Z_NULL || strm->state == Z_NULL || - flush > Z_BLOCK || flush < 0) { - return Z_STREAM_ERROR; - } - s = strm->state; - - if (strm->next_out == Z_NULL || - (strm->next_in == Z_NULL && strm->avail_in != 0) || - (s->status == FINISH_STATE && flush != Z_FINISH)) { - ERR_RETURN(strm, Z_STREAM_ERROR); - } - if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR); - - s->strm = strm; /* just in case */ - old_flush = s->last_flush; - s->last_flush = flush; - - /* Write the header */ - if (s->status == INIT_STATE) { -#ifdef GZIP - if (s->wrap == 2) { - strm->adler = crc32(0L, Z_NULL, 0); - put_byte(s, 31); - put_byte(s, 139); - put_byte(s, 8); - if (s->gzhead == Z_NULL) { - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, 0); - put_byte(s, s->level == 9 ? 2 : - (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? - 4 : 0)); - put_byte(s, OS_CODE); - s->status = BUSY_STATE; - } - else { - put_byte(s, (s->gzhead->text ? 1 : 0) + - (s->gzhead->hcrc ? 2 : 0) + - (s->gzhead->extra == Z_NULL ? 0 : 4) + - (s->gzhead->name == Z_NULL ? 0 : 8) + - (s->gzhead->comment == Z_NULL ? 0 : 16) - ); - put_byte(s, (Byte)(s->gzhead->time & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff)); - put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff)); - put_byte(s, s->level == 9 ? 2 : - (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ? - 4 : 0)); - put_byte(s, s->gzhead->os & 0xff); - if (s->gzhead->extra != Z_NULL) { - put_byte(s, s->gzhead->extra_len & 0xff); - put_byte(s, (s->gzhead->extra_len >> 8) & 0xff); - } - if (s->gzhead->hcrc) - strm->adler = crc32(strm->adler, s->pending_buf, - s->pending); - s->gzindex = 0; - s->status = EXTRA_STATE; - } - } - else -#endif - { - uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8; - uInt level_flags; - - if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2) - level_flags = 0; - else if (s->level < 6) - level_flags = 1; - else if (s->level == 6) - level_flags = 2; - else - level_flags = 3; - header |= (level_flags << 6); - if (s->strstart != 0) header |= PRESET_DICT; - header += 31 - (header % 31); - - s->status = BUSY_STATE; - putShortMSB(s, header); - - /* Save the adler32 of the preset dictionary: */ - if (s->strstart != 0) { - putShortMSB(s, (uInt)(strm->adler >> 16)); - putShortMSB(s, (uInt)(strm->adler & 0xffff)); - } - strm->adler = adler32(0L, Z_NULL, 0); - } - } -#ifdef GZIP - if (s->status == EXTRA_STATE) { - if (s->gzhead->extra != Z_NULL) { - uInt beg = s->pending; /* start of bytes to update crc */ - - while (s->gzindex < (s->gzhead->extra_len & 0xffff)) { - if (s->pending == s->pending_buf_size) { - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - flush_pending(strm); - beg = s->pending; - if (s->pending == s->pending_buf_size) - break; - } - put_byte(s, s->gzhead->extra[s->gzindex]); - s->gzindex++; - } - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - if (s->gzindex == s->gzhead->extra_len) { - s->gzindex = 0; - s->status = NAME_STATE; - } - } - else - s->status = NAME_STATE; - } - if (s->status == NAME_STATE) { - if (s->gzhead->name != Z_NULL) { - uInt beg = s->pending; /* start of bytes to update crc */ - int val; - - do { - if (s->pending == s->pending_buf_size) { - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - flush_pending(strm); - beg = s->pending; - if (s->pending == s->pending_buf_size) { - val = 1; - break; - } - } - val = s->gzhead->name[s->gzindex++]; - put_byte(s, val); - } while (val != 0); - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - if (val == 0) { - s->gzindex = 0; - s->status = COMMENT_STATE; - } - } - else - s->status = COMMENT_STATE; - } - if (s->status == COMMENT_STATE) { - if (s->gzhead->comment != Z_NULL) { - uInt beg = s->pending; /* start of bytes to update crc */ - int val; - - do { - if (s->pending == s->pending_buf_size) { - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - flush_pending(strm); - beg = s->pending; - if (s->pending == s->pending_buf_size) { - val = 1; - break; - } - } - val = s->gzhead->comment[s->gzindex++]; - put_byte(s, val); - } while (val != 0); - if (s->gzhead->hcrc && s->pending > beg) - strm->adler = crc32(strm->adler, s->pending_buf + beg, - s->pending - beg); - if (val == 0) - s->status = HCRC_STATE; - } - else - s->status = HCRC_STATE; - } - if (s->status == HCRC_STATE) { - if (s->gzhead->hcrc) { - if (s->pending + 2 > s->pending_buf_size) - flush_pending(strm); - if (s->pending + 2 <= s->pending_buf_size) { - put_byte(s, (Byte)(strm->adler & 0xff)); - put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); - strm->adler = crc32(0L, Z_NULL, 0); - s->status = BUSY_STATE; - } - } - else - s->status = BUSY_STATE; - } -#endif - - /* Flush as much pending output as possible */ - if (s->pending != 0) { - flush_pending(strm); - if (strm->avail_out == 0) { - /* Since avail_out is 0, deflate will be called again with - * more output space, but possibly with both pending and - * avail_in equal to zero. There won't be anything to do, - * but this is not an error situation so make sure we - * return OK instead of BUF_ERROR at next call of deflate: - */ - s->last_flush = -1; - return Z_OK; - } - - /* Make sure there is something to do and avoid duplicate consecutive - * flushes. For repeated and useless calls with Z_FINISH, we keep - * returning Z_STREAM_END instead of Z_BUF_ERROR. - */ - } else if (strm->avail_in == 0 && flush <= old_flush && - flush != Z_FINISH) { - ERR_RETURN(strm, Z_BUF_ERROR); - } - - /* User must not provide more input after the first FINISH: */ - if (s->status == FINISH_STATE && strm->avail_in != 0) { - ERR_RETURN(strm, Z_BUF_ERROR); - } - - /* Start a new block or continue the current one. - */ - if (strm->avail_in != 0 || s->lookahead != 0 || - (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) { - block_state bstate; - - bstate = s->strategy == Z_HUFFMAN_ONLY ? deflate_huff(s, flush) : - (s->strategy == Z_RLE ? deflate_rle(s, flush) : - (*(configuration_table[s->level].func))(s, flush)); - - if (bstate == finish_started || bstate == finish_done) { - s->status = FINISH_STATE; - } - if (bstate == need_more || bstate == finish_started) { - if (strm->avail_out == 0) { - s->last_flush = -1; /* avoid BUF_ERROR next call, see above */ - } - return Z_OK; - /* If flush != Z_NO_FLUSH && avail_out == 0, the next call - * of deflate should use the same flush parameter to make sure - * that the flush is complete. So we don't have to output an - * empty block here, this will be done at next call. This also - * ensures that for a very small output buffer, we emit at most - * one empty block. - */ - } - if (bstate == block_done) { - if (flush == Z_PARTIAL_FLUSH) { - _tr_align(s); - } else if (flush != Z_BLOCK) { /* FULL_FLUSH or SYNC_FLUSH */ - _tr_stored_block(s, (char*)0, 0L, 0); - /* For a full flush, this empty block will be recognized - * as a special marker by inflate_sync(). - */ - if (flush == Z_FULL_FLUSH) { - CLEAR_HASH(s); /* forget history */ - if (s->lookahead == 0) { - s->strstart = 0; - s->block_start = 0L; - } - } - } - flush_pending(strm); - if (strm->avail_out == 0) { - s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */ - return Z_OK; - } - } - } - Assert(strm->avail_out > 0, "bug2"); - - if (flush != Z_FINISH) return Z_OK; - if (s->wrap <= 0) return Z_STREAM_END; - - /* Write the trailer */ -#ifdef GZIP - if (s->wrap == 2) { - put_byte(s, (Byte)(strm->adler & 0xff)); - put_byte(s, (Byte)((strm->adler >> 8) & 0xff)); - put_byte(s, (Byte)((strm->adler >> 16) & 0xff)); - put_byte(s, (Byte)((strm->adler >> 24) & 0xff)); - put_byte(s, (Byte)(strm->total_in & 0xff)); - put_byte(s, (Byte)((strm->total_in >> 8) & 0xff)); - put_byte(s, (Byte)((strm->total_in >> 16) & 0xff)); - put_byte(s, (Byte)((strm->total_in >> 24) & 0xff)); - } - else -#endif - { - putShortMSB(s, (uInt)(strm->adler >> 16)); - putShortMSB(s, (uInt)(strm->adler & 0xffff)); - } - flush_pending(strm); - /* If avail_out is zero, the application will call deflate again - * to flush the rest. - */ - if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */ - return s->pending != 0 ? Z_OK : Z_STREAM_END; -} - -/* ========================================================================= */ -int ZEXPORT deflateEnd (strm) - z_streamp strm; -{ - int status; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - - status = strm->state->status; - if (status != INIT_STATE && - status != EXTRA_STATE && - status != NAME_STATE && - status != COMMENT_STATE && - status != HCRC_STATE && - status != BUSY_STATE && - status != FINISH_STATE) { - return Z_STREAM_ERROR; - } - - /* Deallocate in reverse order of allocations: */ - TRY_FREE(strm, strm->state->pending_buf); - TRY_FREE(strm, strm->state->head); - TRY_FREE(strm, strm->state->prev); - TRY_FREE(strm, strm->state->window); - - ZFREE(strm, strm->state); - strm->state = Z_NULL; - - return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK; -} - -/* ========================================================================= - * Copy the source state to the destination state. - * To simplify the source, this is not supported for 16-bit MSDOS (which - * doesn't have enough memory anyway to duplicate compression states). - */ -int ZEXPORT deflateCopy (dest, source) - z_streamp dest; - z_streamp source; -{ -#ifdef MAXSEG_64K - return Z_STREAM_ERROR; -#else - deflate_state *ds; - deflate_state *ss; - ushf *overlay; - - - if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) { - return Z_STREAM_ERROR; - } - - ss = source->state; - - zmemcpy(dest, source, sizeof(z_stream)); - - ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state)); - if (ds == Z_NULL) return Z_MEM_ERROR; - dest->state = (struct internal_state FAR *) ds; - zmemcpy(ds, ss, sizeof(deflate_state)); - ds->strm = dest; - - ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte)); - ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos)); - ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos)); - overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2); - ds->pending_buf = (uchf *) overlay; - - if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL || - ds->pending_buf == Z_NULL) { - deflateEnd (dest); - return Z_MEM_ERROR; - } - /* following zmemcpy do not work for 16-bit MSDOS */ - zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte)); - zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos)); - zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos)); - zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size); - - ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf); - ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush); - ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize; - - ds->l_desc.dyn_tree = ds->dyn_ltree; - ds->d_desc.dyn_tree = ds->dyn_dtree; - ds->bl_desc.dyn_tree = ds->bl_tree; - - return Z_OK; -#endif /* MAXSEG_64K */ -} - -/* =========================================================================== - * Read a new buffer from the current input stream, update the adler32 - * and total number of bytes read. All deflate() input goes through - * this function so some applications may wish to modify it to avoid - * allocating a large strm->next_in buffer and copying from it. - * (See also flush_pending()). - */ -local int read_buf(strm, buf, size) - z_streamp strm; - Bytef *buf; - unsigned size; -{ - unsigned len = strm->avail_in; - - if (len > size) len = size; - if (len == 0) return 0; - - strm->avail_in -= len; - - if (strm->state->wrap == 1) { - strm->adler = adler32(strm->adler, strm->next_in, len); - } -#ifdef GZIP - else if (strm->state->wrap == 2) { - strm->adler = crc32(strm->adler, strm->next_in, len); - } -#endif - zmemcpy(buf, strm->next_in, len); - strm->next_in += len; - strm->total_in += len; - - return (int)len; -} - -/* =========================================================================== - * Initialize the "longest match" routines for a new zlib stream - */ -local void lm_init (s) - deflate_state *s; -{ - s->window_size = (ulg)2L*s->w_size; - - CLEAR_HASH(s); - - /* Set the default configuration parameters: - */ - s->max_lazy_match = configuration_table[s->level].max_lazy; - s->good_match = configuration_table[s->level].good_length; - s->nice_match = configuration_table[s->level].nice_length; - s->max_chain_length = configuration_table[s->level].max_chain; - - s->strstart = 0; - s->block_start = 0L; - s->lookahead = 0; - s->match_length = s->prev_length = MIN_MATCH-1; - s->match_available = 0; - s->ins_h = 0; -#ifndef FASTEST -#ifdef ASMV - match_init(); /* initialize the asm code */ -#endif -#endif -} - -#ifndef FASTEST -/* =========================================================================== - * Set match_start to the longest match starting at the given string and - * return its length. Matches shorter or equal to prev_length are discarded, - * in which case the result is equal to prev_length and match_start is - * garbage. - * IN assertions: cur_match is the head of the hash chain for the current - * string (strstart) and its distance is <= MAX_DIST, and prev_length >= 1 - * OUT assertion: the match length is not greater than s->lookahead. - */ -#ifndef ASMV -/* For 80x86 and 680x0, an optimized version will be provided in match.asm or - * match.S. The code will be functionally equivalent. - */ -local uInt longest_match(s, cur_match) - deflate_state *s; - IPos cur_match; /* current match */ -{ - unsigned chain_length = s->max_chain_length;/* max hash chain length */ - register Bytef *scan = s->window + s->strstart; /* current string */ - register Bytef *match; /* matched string */ - register int len; /* length of current match */ - int best_len = s->prev_length; /* best match length so far */ - int nice_match = s->nice_match; /* stop if match long enough */ - IPos limit = s->strstart > (IPos)MAX_DIST(s) ? - s->strstart - (IPos)MAX_DIST(s) : NIL; - /* Stop when cur_match becomes <= limit. To simplify the code, - * we prevent matches with the string of window index 0. - */ - Posf *prev = s->prev; - uInt wmask = s->w_mask; - -#ifdef UNALIGNED_OK - /* Compare two bytes at a time. Note: this is not always beneficial. - * Try with and without -DUNALIGNED_OK to check. - */ - register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1; - register ush scan_start = *(ushf*)scan; - register ush scan_end = *(ushf*)(scan+best_len-1); -#else - register Bytef *strend = s->window + s->strstart + MAX_MATCH; - register Byte scan_end1 = scan[best_len-1]; - register Byte scan_end = scan[best_len]; -#endif - - /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. - * It is easy to get rid of this optimization if necessary. - */ - Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); - - /* Do not waste too much time if we already have a good match: */ - if (s->prev_length >= s->good_match) { - chain_length >>= 2; - } - /* Do not look for matches beyond the end of the input. This is necessary - * to make deflate deterministic. - */ - if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead; - - Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); - - do { - Assert(cur_match < s->strstart, "no future"); - match = s->window + cur_match; - - /* Skip to next match if the match length cannot increase - * or if the match length is less than 2. Note that the checks below - * for insufficient lookahead only occur occasionally for performance - * reasons. Therefore uninitialized memory will be accessed, and - * conditional jumps will be made that depend on those values. - * However the length of the match is limited to the lookahead, so - * the output of deflate is not affected by the uninitialized values. - */ -#if (defined(UNALIGNED_OK) && MAX_MATCH == 258) - /* This code assumes sizeof(unsigned short) == 2. Do not use - * UNALIGNED_OK if your compiler uses a different size. - */ - if (*(ushf*)(match+best_len-1) != scan_end || - *(ushf*)match != scan_start) continue; - - /* It is not necessary to compare scan[2] and match[2] since they are - * always equal when the other bytes match, given that the hash keys - * are equal and that HASH_BITS >= 8. Compare 2 bytes at a time at - * strstart+3, +5, ... up to strstart+257. We check for insufficient - * lookahead only every 4th comparison; the 128th check will be made - * at strstart+257. If MAX_MATCH-2 is not a multiple of 8, it is - * necessary to put more guard bytes at the end of the window, or - * to check more often for insufficient lookahead. - */ - Assert(scan[2] == match[2], "scan[2]?"); - scan++, match++; - do { - } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) && - *(ushf*)(scan+=2) == *(ushf*)(match+=2) && - *(ushf*)(scan+=2) == *(ushf*)(match+=2) && - *(ushf*)(scan+=2) == *(ushf*)(match+=2) && - scan < strend); - /* The funny "do {}" generates better code on most compilers */ - - /* Here, scan <= window+strstart+257 */ - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); - if (*scan == *match) scan++; - - len = (MAX_MATCH - 1) - (int)(strend-scan); - scan = strend - (MAX_MATCH-1); - -#else /* UNALIGNED_OK */ - - if (match[best_len] != scan_end || - match[best_len-1] != scan_end1 || - *match != *scan || - *++match != scan[1]) continue; - - /* The check at best_len-1 can be removed because it will be made - * again later. (This heuristic is not always a win.) - * It is not necessary to compare scan[2] and match[2] since they - * are always equal when the other bytes match, given that - * the hash keys are equal and that HASH_BITS >= 8. - */ - scan += 2, match++; - Assert(*scan == *match, "match[2]?"); - - /* We check for insufficient lookahead only every 8th comparison; - * the 256th check will be made at strstart+258. - */ - do { - } while (*++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - scan < strend); - - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); - - len = MAX_MATCH - (int)(strend - scan); - scan = strend - MAX_MATCH; - -#endif /* UNALIGNED_OK */ - - if (len > best_len) { - s->match_start = cur_match; - best_len = len; - if (len >= nice_match) break; -#ifdef UNALIGNED_OK - scan_end = *(ushf*)(scan+best_len-1); -#else - scan_end1 = scan[best_len-1]; - scan_end = scan[best_len]; -#endif - } - } while ((cur_match = prev[cur_match & wmask]) > limit - && --chain_length != 0); - - if ((uInt)best_len <= s->lookahead) return (uInt)best_len; - return s->lookahead; -} -#endif /* ASMV */ - -#else /* FASTEST */ - -/* --------------------------------------------------------------------------- - * Optimized version for FASTEST only - */ -local uInt longest_match(s, cur_match) - deflate_state *s; - IPos cur_match; /* current match */ -{ - register Bytef *scan = s->window + s->strstart; /* current string */ - register Bytef *match; /* matched string */ - register int len; /* length of current match */ - register Bytef *strend = s->window + s->strstart + MAX_MATCH; - - /* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. - * It is easy to get rid of this optimization if necessary. - */ - Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever"); - - Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead"); - - Assert(cur_match < s->strstart, "no future"); - - match = s->window + cur_match; - - /* Return failure if the match length is less than 2: - */ - if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1; - - /* The check at best_len-1 can be removed because it will be made - * again later. (This heuristic is not always a win.) - * It is not necessary to compare scan[2] and match[2] since they - * are always equal when the other bytes match, given that - * the hash keys are equal and that HASH_BITS >= 8. - */ - scan += 2, match += 2; - Assert(*scan == *match, "match[2]?"); - - /* We check for insufficient lookahead only every 8th comparison; - * the 256th check will be made at strstart+258. - */ - do { - } while (*++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - *++scan == *++match && *++scan == *++match && - scan < strend); - - Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan"); - - len = MAX_MATCH - (int)(strend - scan); - - if (len < MIN_MATCH) return MIN_MATCH - 1; - - s->match_start = cur_match; - return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead; -} - -#endif /* FASTEST */ - -#ifdef DEBUG -/* =========================================================================== - * Check that the match at match_start is indeed a match. - */ -local void check_match(s, start, match, length) - deflate_state *s; - IPos start, match; - int length; -{ - /* check that the match is indeed a match */ - if (zmemcmp(s->window + match, - s->window + start, length) != EQUAL) { - fprintf(stderr, " start %u, match %u, length %d\n", - start, match, length); - do { - fprintf(stderr, "%c%c", s->window[match++], s->window[start++]); - } while (--length != 0); - z_error("invalid match"); - } - if (z_verbose > 1) { - fprintf(stderr,"\\[%d,%d]", start-match, length); - do { putc(s->window[start++], stderr); } while (--length != 0); - } -} -#else -# define check_match(s, start, match, length) -#endif /* DEBUG */ - -/* =========================================================================== - * Fill the window when the lookahead becomes insufficient. - * Updates strstart and lookahead. - * - * IN assertion: lookahead < MIN_LOOKAHEAD - * OUT assertions: strstart <= window_size-MIN_LOOKAHEAD - * At least one byte has been read, or avail_in == 0; reads are - * performed for at least two bytes (required for the zip translate_eol - * option -- not supported here). - */ -local void fill_window(s) - deflate_state *s; -{ - register unsigned n, m; - register Posf *p; - unsigned more; /* Amount of free space at the end of the window. */ - uInt wsize = s->w_size; - - do { - more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart); - - /* Deal with !@#$% 64K limit: */ - if (sizeof(int) <= 2) { - if (more == 0 && s->strstart == 0 && s->lookahead == 0) { - more = wsize; - - } else if (more == (unsigned)(-1)) { - /* Very unlikely, but possible on 16 bit machine if - * strstart == 0 && lookahead == 1 (input done a byte at time) - */ - more--; - } - } - - /* If the window is almost full and there is insufficient lookahead, - * move the upper half to the lower one to make room in the upper half. - */ - if (s->strstart >= wsize+MAX_DIST(s)) { - - zmemcpy(s->window, s->window+wsize, (unsigned)wsize); - s->match_start -= wsize; - s->strstart -= wsize; /* we now have strstart >= MAX_DIST */ - s->block_start -= (long) wsize; - - /* Slide the hash table (could be avoided with 32 bit values - at the expense of memory usage). We slide even when level == 0 - to keep the hash table consistent if we switch back to level > 0 - later. (Using level 0 permanently is not an optimal usage of - zlib, so we don't care about this pathological case.) - */ - n = s->hash_size; - p = &s->head[n]; - do { - m = *--p; - *p = (Pos)(m >= wsize ? m-wsize : NIL); - } while (--n); - - n = wsize; -#ifndef FASTEST - p = &s->prev[n]; - do { - m = *--p; - *p = (Pos)(m >= wsize ? m-wsize : NIL); - /* If n is not on any hash chain, prev[n] is garbage but - * its value will never be used. - */ - } while (--n); -#endif - more += wsize; - } - if (s->strm->avail_in == 0) return; - - /* If there was no sliding: - * strstart <= WSIZE+MAX_DIST-1 && lookahead <= MIN_LOOKAHEAD - 1 && - * more == window_size - lookahead - strstart - * => more >= window_size - (MIN_LOOKAHEAD-1 + WSIZE + MAX_DIST-1) - * => more >= window_size - 2*WSIZE + 2 - * In the BIG_MEM or MMAP case (not yet supported), - * window_size == input_size + MIN_LOOKAHEAD && - * strstart + s->lookahead <= input_size => more >= MIN_LOOKAHEAD. - * Otherwise, window_size == 2*WSIZE so more >= 2. - * If there was sliding, more >= WSIZE. So in all cases, more >= 2. - */ - Assert(more >= 2, "more < 2"); - - n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more); - s->lookahead += n; - - /* Initialize the hash value now that we have some input: */ - if (s->lookahead >= MIN_MATCH) { - s->ins_h = s->window[s->strstart]; - UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - } - /* If the whole input has less than MIN_MATCH bytes, ins_h is garbage, - * but this is not important since only literal bytes will be emitted. - */ - - } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0); - - /* If the WIN_INIT bytes after the end of the current data have never been - * written, then zero those bytes in order to avoid memory check reports of - * the use of uninitialized (or uninitialised as Julian writes) bytes by - * the longest match routines. Update the high water mark for the next - * time through here. WIN_INIT is set to MAX_MATCH since the longest match - * routines allow scanning to strstart + MAX_MATCH, ignoring lookahead. - */ - if (s->high_water < s->window_size) { - ulg curr = s->strstart + (ulg)(s->lookahead); - ulg init; - - if (s->high_water < curr) { - /* Previous high water mark below current data -- zero WIN_INIT - * bytes or up to end of window, whichever is less. - */ - init = s->window_size - curr; - if (init > WIN_INIT) - init = WIN_INIT; - zmemzero(s->window + curr, (unsigned)init); - s->high_water = curr + init; - } - else if (s->high_water < (ulg)curr + WIN_INIT) { - /* High water mark at or above current data, but below current data - * plus WIN_INIT -- zero out to current data plus WIN_INIT, or up - * to end of window, whichever is less. - */ - init = (ulg)curr + WIN_INIT - s->high_water; - if (init > s->window_size - s->high_water) - init = s->window_size - s->high_water; - zmemzero(s->window + s->high_water, (unsigned)init); - s->high_water += init; - } - } -} - -/* =========================================================================== - * Flush the current block, with given end-of-file flag. - * IN assertion: strstart is set to the end of the current match. - */ -#define FLUSH_BLOCK_ONLY(s, last) { \ - _tr_flush_block(s, (s->block_start >= 0L ? \ - (charf *)&s->window[(unsigned)s->block_start] : \ - (charf *)Z_NULL), \ - (ulg)((long)s->strstart - s->block_start), \ - (last)); \ - s->block_start = s->strstart; \ - flush_pending(s->strm); \ - Tracev((stderr,"[FLUSH]")); \ -} - -/* Same but force premature exit if necessary. */ -#define FLUSH_BLOCK(s, last) { \ - FLUSH_BLOCK_ONLY(s, last); \ - if (s->strm->avail_out == 0) return (last) ? finish_started : need_more; \ -} - -/* =========================================================================== - * Copy without compression as much as possible from the input stream, return - * the current block state. - * This function does not insert new strings in the dictionary since - * uncompressible data is probably not useful. This function is used - * only for the level=0 compression option. - * NOTE: this function should be optimized to avoid extra copying from - * window to pending_buf. - */ -local block_state deflate_stored(s, flush) - deflate_state *s; - int flush; -{ - /* Stored blocks are limited to 0xffff bytes, pending_buf is limited - * to pending_buf_size, and each stored block has a 5 byte header: - */ - ulg max_block_size = 0xffff; - ulg max_start; - - if (max_block_size > s->pending_buf_size - 5) { - max_block_size = s->pending_buf_size - 5; - } - - /* Copy as much as possible from input to output: */ - for (;;) { - /* Fill the window as much as possible: */ - if (s->lookahead <= 1) { - - Assert(s->strstart < s->w_size+MAX_DIST(s) || - s->block_start >= (long)s->w_size, "slide too late"); - - fill_window(s); - if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more; - - if (s->lookahead == 0) break; /* flush the current block */ - } - Assert(s->block_start >= 0L, "block gone"); - - s->strstart += s->lookahead; - s->lookahead = 0; - - /* Emit a stored block if pending_buf will be full: */ - max_start = s->block_start + max_block_size; - if (s->strstart == 0 || (ulg)s->strstart >= max_start) { - /* strstart == 0 is possible when wraparound on 16-bit machine */ - s->lookahead = (uInt)(s->strstart - max_start); - s->strstart = (uInt)max_start; - FLUSH_BLOCK(s, 0); - } - /* Flush if we may have to slide, otherwise block_start may become - * negative and the data will be gone: - */ - if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) { - FLUSH_BLOCK(s, 0); - } - } - FLUSH_BLOCK(s, flush == Z_FINISH); - return flush == Z_FINISH ? finish_done : block_done; -} - -/* =========================================================================== - * Compress as much as possible from the input stream, return the current - * block state. - * This function does not perform lazy evaluation of matches and inserts - * new strings in the dictionary only for unmatched strings or for short - * matches. It is used only for the fast compression options. - */ -local block_state deflate_fast(s, flush) - deflate_state *s; - int flush; -{ - IPos hash_head; /* head of the hash chain */ - int bflush; /* set if current block must be flushed */ - - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the next match, plus MIN_MATCH bytes to insert the - * string following the next match. - */ - if (s->lookahead < MIN_LOOKAHEAD) { - fill_window(s); - if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* Insert the string window[strstart .. strstart+2] in the - * dictionary, and set hash_head to the head of the hash chain: - */ - hash_head = NIL; - if (s->lookahead >= MIN_MATCH) { - INSERT_STRING(s, s->strstart, hash_head); - } - - /* Find the longest match, discarding those <= prev_length. - * At this point we have always match_length < MIN_MATCH - */ - if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) { - /* To simplify the code, we prevent matches with the string - * of window index 0 (in particular we have to avoid a match - * of the string with itself at the start of the input file). - */ - s->match_length = longest_match (s, hash_head); - /* longest_match() sets match_start */ - } - if (s->match_length >= MIN_MATCH) { - check_match(s, s->strstart, s->match_start, s->match_length); - - _tr_tally_dist(s, s->strstart - s->match_start, - s->match_length - MIN_MATCH, bflush); - - s->lookahead -= s->match_length; - - /* Insert new strings in the hash table only if the match length - * is not too large. This saves time but degrades compression. - */ -#ifndef FASTEST - if (s->match_length <= s->max_insert_length && - s->lookahead >= MIN_MATCH) { - s->match_length--; /* string at strstart already in table */ - do { - s->strstart++; - INSERT_STRING(s, s->strstart, hash_head); - /* strstart never exceeds WSIZE-MAX_MATCH, so there are - * always MIN_MATCH bytes ahead. - */ - } while (--s->match_length != 0); - s->strstart++; - } else -#endif - { - s->strstart += s->match_length; - s->match_length = 0; - s->ins_h = s->window[s->strstart]; - UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]); -#if MIN_MATCH != 3 - Call UPDATE_HASH() MIN_MATCH-3 more times -#endif - /* If lookahead < MIN_MATCH, ins_h is garbage, but it does not - * matter since it will be recomputed at next deflate call. - */ - } - } else { - /* No match, output a literal byte */ - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit (s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - } - if (bflush) FLUSH_BLOCK(s, 0); - } - FLUSH_BLOCK(s, flush == Z_FINISH); - return flush == Z_FINISH ? finish_done : block_done; -} - -#ifndef FASTEST -/* =========================================================================== - * Same as above, but achieves better compression. We use a lazy - * evaluation for matches: a match is finally adopted only if there is - * no better match at the next window position. - */ -local block_state deflate_slow(s, flush) - deflate_state *s; - int flush; -{ - IPos hash_head; /* head of hash chain */ - int bflush; /* set if current block must be flushed */ - - /* Process the input block. */ - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the next match, plus MIN_MATCH bytes to insert the - * string following the next match. - */ - if (s->lookahead < MIN_LOOKAHEAD) { - fill_window(s); - if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* Insert the string window[strstart .. strstart+2] in the - * dictionary, and set hash_head to the head of the hash chain: - */ - hash_head = NIL; - if (s->lookahead >= MIN_MATCH) { - INSERT_STRING(s, s->strstart, hash_head); - } - - /* Find the longest match, discarding those <= prev_length. - */ - s->prev_length = s->match_length, s->prev_match = s->match_start; - s->match_length = MIN_MATCH-1; - - if (hash_head != NIL && s->prev_length < s->max_lazy_match && - s->strstart - hash_head <= MAX_DIST(s)) { - /* To simplify the code, we prevent matches with the string - * of window index 0 (in particular we have to avoid a match - * of the string with itself at the start of the input file). - */ - s->match_length = longest_match (s, hash_head); - /* longest_match() sets match_start */ - - if (s->match_length <= 5 && (s->strategy == Z_FILTERED -#if TOO_FAR <= 32767 - || (s->match_length == MIN_MATCH && - s->strstart - s->match_start > TOO_FAR) -#endif - )) { - - /* If prev_match is also MIN_MATCH, match_start is garbage - * but we will ignore the current match anyway. - */ - s->match_length = MIN_MATCH-1; - } - } - /* If there was a match at the previous step and the current - * match is not better, output the previous match: - */ - if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) { - uInt max_insert = s->strstart + s->lookahead - MIN_MATCH; - /* Do not insert strings in hash table beyond this. */ - - check_match(s, s->strstart-1, s->prev_match, s->prev_length); - - _tr_tally_dist(s, s->strstart -1 - s->prev_match, - s->prev_length - MIN_MATCH, bflush); - - /* Insert in hash table all strings up to the end of the match. - * strstart-1 and strstart are already inserted. If there is not - * enough lookahead, the last two strings are not inserted in - * the hash table. - */ - s->lookahead -= s->prev_length-1; - s->prev_length -= 2; - do { - if (++s->strstart <= max_insert) { - INSERT_STRING(s, s->strstart, hash_head); - } - } while (--s->prev_length != 0); - s->match_available = 0; - s->match_length = MIN_MATCH-1; - s->strstart++; - - if (bflush) FLUSH_BLOCK(s, 0); - - } else if (s->match_available) { - /* If there was no match at the previous position, output a - * single literal. If there was a match but the current match - * is longer, truncate the previous match to a single literal. - */ - Tracevv((stderr,"%c", s->window[s->strstart-1])); - _tr_tally_lit(s, s->window[s->strstart-1], bflush); - if (bflush) { - FLUSH_BLOCK_ONLY(s, 0); - } - s->strstart++; - s->lookahead--; - if (s->strm->avail_out == 0) return need_more; - } else { - /* There is no previous match to compare with, wait for - * the next step to decide. - */ - s->match_available = 1; - s->strstart++; - s->lookahead--; - } - } - Assert (flush != Z_NO_FLUSH, "no flush?"); - if (s->match_available) { - Tracevv((stderr,"%c", s->window[s->strstart-1])); - _tr_tally_lit(s, s->window[s->strstart-1], bflush); - s->match_available = 0; - } - FLUSH_BLOCK(s, flush == Z_FINISH); - return flush == Z_FINISH ? finish_done : block_done; -} -#endif /* FASTEST */ - -/* =========================================================================== - * For Z_RLE, simply look for runs of bytes, generate matches only of distance - * one. Do not maintain a hash table. (It will be regenerated if this run of - * deflate switches away from Z_RLE.) - */ -local block_state deflate_rle(s, flush) - deflate_state *s; - int flush; -{ - int bflush; /* set if current block must be flushed */ - uInt prev; /* byte at distance one to match */ - Bytef *scan, *strend; /* scan goes up to strend for length of run */ - - for (;;) { - /* Make sure that we always have enough lookahead, except - * at the end of the input file. We need MAX_MATCH bytes - * for the longest encodable run. - */ - if (s->lookahead < MAX_MATCH) { - fill_window(s); - if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) { - return need_more; - } - if (s->lookahead == 0) break; /* flush the current block */ - } - - /* See how many times the previous byte repeats */ - s->match_length = 0; - if (s->lookahead >= MIN_MATCH && s->strstart > 0) { - scan = s->window + s->strstart - 1; - prev = *scan; - if (prev == *++scan && prev == *++scan && prev == *++scan) { - strend = s->window + s->strstart + MAX_MATCH; - do { - } while (prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - prev == *++scan && prev == *++scan && - scan < strend); - s->match_length = MAX_MATCH - (int)(strend - scan); - if (s->match_length > s->lookahead) - s->match_length = s->lookahead; - } - } - - /* Emit match if have run of MIN_MATCH or longer, else emit literal */ - if (s->match_length >= MIN_MATCH) { - check_match(s, s->strstart, s->strstart - 1, s->match_length); - - _tr_tally_dist(s, 1, s->match_length - MIN_MATCH, bflush); - - s->lookahead -= s->match_length; - s->strstart += s->match_length; - s->match_length = 0; - } else { - /* No match, output a literal byte */ - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit (s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - } - if (bflush) FLUSH_BLOCK(s, 0); - } - FLUSH_BLOCK(s, flush == Z_FINISH); - return flush == Z_FINISH ? finish_done : block_done; -} - -/* =========================================================================== - * For Z_HUFFMAN_ONLY, do not look for matches. Do not maintain a hash table. - * (It will be regenerated if this run of deflate switches away from Huffman.) - */ -local block_state deflate_huff(s, flush) - deflate_state *s; - int flush; -{ - int bflush; /* set if current block must be flushed */ - - for (;;) { - /* Make sure that we have a literal to write. */ - if (s->lookahead == 0) { - fill_window(s); - if (s->lookahead == 0) { - if (flush == Z_NO_FLUSH) - return need_more; - break; /* flush the current block */ - } - } - - /* Output a literal byte */ - s->match_length = 0; - Tracevv((stderr,"%c", s->window[s->strstart])); - _tr_tally_lit (s, s->window[s->strstart], bflush); - s->lookahead--; - s->strstart++; - if (bflush) FLUSH_BLOCK(s, 0); - } - FLUSH_BLOCK(s, flush == Z_FINISH); - return flush == Z_FINISH ? finish_done : block_done; -} diff --git a/vendor/libgit2/deps/zlib/deflate.h b/vendor/libgit2/deps/zlib/deflate.h deleted file mode 100644 index d7d26f8a9..000000000 --- a/vendor/libgit2/deps/zlib/deflate.h +++ /dev/null @@ -1,342 +0,0 @@ -/* deflate.h -- internal compression state - * Copyright (C) 1995-2010 Jean-loup Gailly - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* @(#) $Id$ */ - -#ifndef DEFLATE_H -#define DEFLATE_H - -#include "zutil.h" - -/* define NO_GZIP when compiling if you want to disable gzip header and - trailer creation by deflate(). NO_GZIP would be used to avoid linking in - the crc code when it is not needed. For shared libraries, gzip encoding - should be left enabled. */ -#ifndef NO_GZIP -# define GZIP -#endif - -/* =========================================================================== - * Internal compression state. - */ - -#define LENGTH_CODES 29 -/* number of length codes, not counting the special END_BLOCK code */ - -#define LITERALS 256 -/* number of literal bytes 0..255 */ - -#define L_CODES (LITERALS+1+LENGTH_CODES) -/* number of Literal or Length codes, including the END_BLOCK code */ - -#define D_CODES 30 -/* number of distance codes */ - -#define BL_CODES 19 -/* number of codes used to transfer the bit lengths */ - -#define HEAP_SIZE (2*L_CODES+1) -/* maximum heap size */ - -#define MAX_BITS 15 -/* All codes must not exceed MAX_BITS bits */ - -#define INIT_STATE 42 -#define EXTRA_STATE 69 -#define NAME_STATE 73 -#define COMMENT_STATE 91 -#define HCRC_STATE 103 -#define BUSY_STATE 113 -#define FINISH_STATE 666 -/* Stream status */ - - -/* Data structure describing a single value and its code string. */ -typedef struct ct_data_s { - union { - ush freq; /* frequency count */ - ush code; /* bit string */ - } fc; - union { - ush dad; /* father node in Huffman tree */ - ush len; /* length of bit string */ - } dl; -} FAR ct_data; - -#define Freq fc.freq -#define Code fc.code -#define Dad dl.dad -#define Len dl.len - -typedef struct static_tree_desc_s static_tree_desc; - -typedef struct tree_desc_s { - ct_data *dyn_tree; /* the dynamic tree */ - int max_code; /* largest code with non zero frequency */ - static_tree_desc *stat_desc; /* the corresponding static tree */ -} FAR tree_desc; - -typedef ush Pos; -typedef Pos FAR Posf; -typedef unsigned IPos; - -/* A Pos is an index in the character window. We use short instead of int to - * save space in the various tables. IPos is used only for parameter passing. - */ - -typedef struct internal_state { - z_streamp strm; /* pointer back to this zlib stream */ - int status; /* as the name implies */ - Bytef *pending_buf; /* output still pending */ - ulg pending_buf_size; /* size of pending_buf */ - Bytef *pending_out; /* next pending byte to output to the stream */ - uInt pending; /* nb of bytes in the pending buffer */ - int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ - gz_headerp gzhead; /* gzip header information to write */ - uInt gzindex; /* where in extra, name, or comment */ - Byte method; /* STORED (for zip only) or DEFLATED */ - int last_flush; /* value of flush param for previous deflate call */ - - /* used by deflate.c: */ - - uInt w_size; /* LZ77 window size (32K by default) */ - uInt w_bits; /* log2(w_size) (8..16) */ - uInt w_mask; /* w_size - 1 */ - - Bytef *window; - /* Sliding window. Input bytes are read into the second half of the window, - * and move to the first half later to keep a dictionary of at least wSize - * bytes. With this organization, matches are limited to a distance of - * wSize-MAX_MATCH bytes, but this ensures that IO is always - * performed with a length multiple of the block size. Also, it limits - * the window size to 64K, which is quite useful on MSDOS. - * To do: use the user input buffer as sliding window. - */ - - ulg window_size; - /* Actual size of window: 2*wSize, except when the user input buffer - * is directly used as sliding window. - */ - - Posf *prev; - /* Link to older string with same hash index. To limit the size of this - * array to 64K, this link is maintained only for the last 32K strings. - * An index in this array is thus a window index modulo 32K. - */ - - Posf *head; /* Heads of the hash chains or NIL. */ - - uInt ins_h; /* hash index of string to be inserted */ - uInt hash_size; /* number of elements in hash table */ - uInt hash_bits; /* log2(hash_size) */ - uInt hash_mask; /* hash_size-1 */ - - uInt hash_shift; - /* Number of bits by which ins_h must be shifted at each input - * step. It must be such that after MIN_MATCH steps, the oldest - * byte no longer takes part in the hash key, that is: - * hash_shift * MIN_MATCH >= hash_bits - */ - - long block_start; - /* Window position at the beginning of the current output block. Gets - * negative when the window is moved backwards. - */ - - uInt match_length; /* length of best match */ - IPos prev_match; /* previous match */ - int match_available; /* set if previous match exists */ - uInt strstart; /* start of string to insert */ - uInt match_start; /* start of matching string */ - uInt lookahead; /* number of valid bytes ahead in window */ - - uInt prev_length; - /* Length of the best match at previous step. Matches not greater than this - * are discarded. This is used in the lazy match evaluation. - */ - - uInt max_chain_length; - /* To speed up deflation, hash chains are never searched beyond this - * length. A higher limit improves compression ratio but degrades the - * speed. - */ - - uInt max_lazy_match; - /* Attempt to find a better match only when the current match is strictly - * smaller than this value. This mechanism is used only for compression - * levels >= 4. - */ -# define max_insert_length max_lazy_match - /* Insert new strings in the hash table only if the match length is not - * greater than this length. This saves time but degrades compression. - * max_insert_length is used only for compression levels <= 3. - */ - - int level; /* compression level (1..9) */ - int strategy; /* favor or force Huffman coding*/ - - uInt good_match; - /* Use a faster search when the previous match is longer than this */ - - int nice_match; /* Stop searching when current match exceeds this */ - - /* used by trees.c: */ - /* Didn't use ct_data typedef below to supress compiler warning */ - struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */ - struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */ - struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */ - - struct tree_desc_s l_desc; /* desc. for literal tree */ - struct tree_desc_s d_desc; /* desc. for distance tree */ - struct tree_desc_s bl_desc; /* desc. for bit length tree */ - - ush bl_count[MAX_BITS+1]; - /* number of codes at each bit length for an optimal tree */ - - int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */ - int heap_len; /* number of elements in the heap */ - int heap_max; /* element of largest frequency */ - /* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. - * The same heap array is used to build all trees. - */ - - uch depth[2*L_CODES+1]; - /* Depth of each subtree used as tie breaker for trees of equal frequency - */ - - uchf *l_buf; /* buffer for literals or lengths */ - - uInt lit_bufsize; - /* Size of match buffer for literals/lengths. There are 4 reasons for - * limiting lit_bufsize to 64K: - * - frequencies can be kept in 16 bit counters - * - if compression is not successful for the first block, all input - * data is still in the window so we can still emit a stored block even - * when input comes from standard input. (This can also be done for - * all blocks if lit_bufsize is not greater than 32K.) - * - if compression is not successful for a file smaller than 64K, we can - * even emit a stored file instead of a stored block (saving 5 bytes). - * This is applicable only for zip (not gzip or zlib). - * - creating new Huffman trees less frequently may not provide fast - * adaptation to changes in the input data statistics. (Take for - * example a binary file with poorly compressible code followed by - * a highly compressible string table.) Smaller buffer sizes give - * fast adaptation but have of course the overhead of transmitting - * trees more frequently. - * - I can't count above 4 - */ - - uInt last_lit; /* running index in l_buf */ - - ushf *d_buf; - /* Buffer for distances. To simplify the code, d_buf and l_buf have - * the same number of elements. To use different lengths, an extra flag - * array would be necessary. - */ - - ulg opt_len; /* bit length of current block with optimal trees */ - ulg static_len; /* bit length of current block with static trees */ - uInt matches; /* number of string matches in current block */ - int last_eob_len; /* bit length of EOB code for last block */ - -#ifdef DEBUG - ulg compressed_len; /* total bit length of compressed file mod 2^32 */ - ulg bits_sent; /* bit length of compressed data sent mod 2^32 */ -#endif - - ush bi_buf; - /* Output buffer. bits are inserted starting at the bottom (least - * significant bits). - */ - int bi_valid; - /* Number of valid bits in bi_buf. All bits above the last valid bit - * are always zero. - */ - - ulg high_water; - /* High water mark offset in window for initialized bytes -- bytes above - * this are set to zero in order to avoid memory check warnings when - * longest match routines access bytes past the input. This is then - * updated to the new high water mark. - */ - -} FAR deflate_state; - -/* Output a byte on the stream. - * IN assertion: there is enough room in pending_buf. - */ -#define put_byte(s, c) {s->pending_buf[s->pending++] = (c);} - - -#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) -/* Minimum amount of lookahead, except at the end of the input file. - * See deflate.c for comments about the MIN_MATCH+1. - */ - -#define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD) -/* In order to simplify the code, particularly on 16 bit machines, match - * distances are limited to MAX_DIST instead of WSIZE. - */ - -#define WIN_INIT MAX_MATCH -/* Number of bytes after end of data in window to initialize in order to avoid - memory checker errors from longest match routines */ - - /* in trees.c */ -void ZLIB_INTERNAL _tr_init OF((deflate_state *s)); -int ZLIB_INTERNAL _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc)); -void ZLIB_INTERNAL _tr_flush_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); -void ZLIB_INTERNAL _tr_align OF((deflate_state *s)); -void ZLIB_INTERNAL _tr_stored_block OF((deflate_state *s, charf *buf, - ulg stored_len, int last)); - -#define d_code(dist) \ - ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)]) -/* Mapping from a distance to a distance code. dist is the distance - 1 and - * must not have side effects. _dist_code[256] and _dist_code[257] are never - * used. - */ - -#ifndef DEBUG -/* Inline versions of _tr_tally for speed: */ - -#if defined(GEN_TREES_H) || !defined(STDC) - extern uch ZLIB_INTERNAL _length_code[]; - extern uch ZLIB_INTERNAL _dist_code[]; -#else - extern const uch ZLIB_INTERNAL _length_code[]; - extern const uch ZLIB_INTERNAL _dist_code[]; -#endif - -# define _tr_tally_lit(s, c, flush) \ - { uch cc = (uch)(c); \ - s->d_buf[s->last_lit] = 0; \ - s->l_buf[s->last_lit++] = cc; \ - s->dyn_ltree[cc].Freq++; \ - flush = (s->last_lit == s->lit_bufsize-1); \ - } -# define _tr_tally_dist(s, distance, length, flush) \ - { uch len = (uch)(length); \ - ush dist = (ush)(distance); \ - s->d_buf[s->last_lit] = dist; \ - s->l_buf[s->last_lit++] = len; \ - dist--; \ - s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \ - s->dyn_dtree[d_code(dist)].Freq++; \ - flush = (s->last_lit == s->lit_bufsize-1); \ - } -#else -# define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c) -# define _tr_tally_dist(s, distance, length, flush) \ - flush = _tr_tally(s, distance, length) -#endif - -#endif /* DEFLATE_H */ diff --git a/vendor/libgit2/deps/zlib/inffast.c b/vendor/libgit2/deps/zlib/inffast.c deleted file mode 100644 index 2f1d60b43..000000000 --- a/vendor/libgit2/deps/zlib/inffast.c +++ /dev/null @@ -1,340 +0,0 @@ -/* inffast.c -- fast decoding - * Copyright (C) 1995-2008, 2010 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "inftrees.h" -#include "inflate.h" -#include "inffast.h" - -#ifndef ASMINF - -/* Allow machine dependent optimization for post-increment or pre-increment. - Based on testing to date, - Pre-increment preferred for: - - PowerPC G3 (Adler) - - MIPS R5000 (Randers-Pehrson) - Post-increment preferred for: - - none - No measurable difference: - - Pentium III (Anderson) - - M68060 (Nikl) - */ -#ifdef POSTINC -# define OFF 0 -# define PUP(a) *(a)++ -#else -# define OFF 1 -# define PUP(a) *++(a) -#endif - -/* - Decode literal, length, and distance codes and write out the resulting - literal and match bytes until either not enough input or output is - available, an end-of-block is encountered, or a data error is encountered. - When large enough input and output buffers are supplied to inflate(), for - example, a 16K input buffer and a 64K output buffer, more than 95% of the - inflate execution time is spent in this routine. - - Entry assumptions: - - state->mode == LEN - strm->avail_in >= 6 - strm->avail_out >= 258 - start >= strm->avail_out - state->bits < 8 - - On return, state->mode is one of: - - LEN -- ran out of enough output space or enough available input - TYPE -- reached end of block code, inflate() to interpret next block - BAD -- error in block data - - Notes: - - - The maximum input bits used by a length/distance pair is 15 bits for the - length code, 5 bits for the length extra, 15 bits for the distance code, - and 13 bits for the distance extra. This totals 48 bits, or six bytes. - Therefore if strm->avail_in >= 6, then there is enough input to avoid - checking for available input while decoding. - - - The maximum bytes that a single length/distance pair can output is 258 - bytes, which is the maximum length that can be coded. inflate_fast() - requires strm->avail_out >= 258 for each loop to avoid checking for - output space. - */ -void ZLIB_INTERNAL inflate_fast(strm, start) -z_streamp strm; -unsigned start; /* inflate()'s starting value for strm->avail_out */ -{ - struct inflate_state FAR *state; - unsigned char FAR *in; /* local strm->next_in */ - unsigned char FAR *last; /* while in < last, enough input available */ - unsigned char FAR *out; /* local strm->next_out */ - unsigned char FAR *beg; /* inflate()'s initial strm->next_out */ - unsigned char FAR *end; /* while out < end, enough space available */ -#ifdef INFLATE_STRICT - unsigned dmax; /* maximum distance from zlib header */ -#endif - unsigned wsize; /* window size or zero if not using window */ - unsigned whave; /* valid bytes in the window */ - unsigned wnext; /* window write index */ - unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */ - unsigned long hold; /* local strm->hold */ - unsigned bits; /* local strm->bits */ - code const FAR *lcode; /* local strm->lencode */ - code const FAR *dcode; /* local strm->distcode */ - unsigned lmask; /* mask for first level of length codes */ - unsigned dmask; /* mask for first level of distance codes */ - code here; /* retrieved table entry */ - unsigned op; /* code bits, operation, extra bits, or */ - /* window position, window bytes to copy */ - unsigned len; /* match length, unused bytes */ - unsigned dist; /* match distance */ - unsigned char FAR *from; /* where to copy match from */ - - /* copy state to local variables */ - state = (struct inflate_state FAR *)strm->state; - in = strm->next_in - OFF; - last = in + (strm->avail_in - 5); - out = strm->next_out - OFF; - beg = out - (start - strm->avail_out); - end = out + (strm->avail_out - 257); -#ifdef INFLATE_STRICT - dmax = state->dmax; -#endif - wsize = state->wsize; - whave = state->whave; - wnext = state->wnext; - window = state->window; - hold = state->hold; - bits = state->bits; - lcode = state->lencode; - dcode = state->distcode; - lmask = (1U << state->lenbits) - 1; - dmask = (1U << state->distbits) - 1; - - /* decode literals and length/distances until end-of-block or not enough - input data or output space */ - do { - if (bits < 15) { - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - } - here = lcode[hold & lmask]; - dolen: - op = (unsigned)(here.bits); - hold >>= op; - bits -= op; - op = (unsigned)(here.op); - if (op == 0) { /* literal */ - Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? - "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", here.val)); - PUP(out) = (unsigned char)(here.val); - } - else if (op & 16) { /* length base */ - len = (unsigned)(here.val); - op &= 15; /* number of extra bits */ - if (op) { - if (bits < op) { - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - } - len += (unsigned)hold & ((1U << op) - 1); - hold >>= op; - bits -= op; - } - Tracevv((stderr, "inflate: length %u\n", len)); - if (bits < 15) { - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - } - here = dcode[hold & dmask]; - dodist: - op = (unsigned)(here.bits); - hold >>= op; - bits -= op; - op = (unsigned)(here.op); - if (op & 16) { /* distance base */ - dist = (unsigned)(here.val); - op &= 15; /* number of extra bits */ - if (bits < op) { - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - if (bits < op) { - hold += (unsigned long)(PUP(in)) << bits; - bits += 8; - } - } - dist += (unsigned)hold & ((1U << op) - 1); -#ifdef INFLATE_STRICT - if (dist > dmax) { - strm->msg = (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } -#endif - hold >>= op; - bits -= op; - Tracevv((stderr, "inflate: distance %u\n", dist)); - op = (unsigned)(out - beg); /* max distance in output */ - if (dist > op) { /* see if copy from window */ - op = dist - op; /* distance back in window */ - if (op > whave) { - if (state->sane) { - strm->msg = - (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } -#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR - if (len <= op - whave) { - do { - PUP(out) = 0; - } while (--len); - continue; - } - len -= op - whave; - do { - PUP(out) = 0; - } while (--op > whave); - if (op == 0) { - from = out - dist; - do { - PUP(out) = PUP(from); - } while (--len); - continue; - } -#endif - } - from = window - OFF; - if (wnext == 0) { /* very common case */ - from += wsize - op; - if (op < len) { /* some from window */ - len -= op; - do { - PUP(out) = PUP(from); - } while (--op); - from = out - dist; /* rest from output */ - } - } - else if (wnext < op) { /* wrap around window */ - from += wsize + wnext - op; - op -= wnext; - if (op < len) { /* some from end of window */ - len -= op; - do { - PUP(out) = PUP(from); - } while (--op); - from = window - OFF; - if (wnext < len) { /* some from start of window */ - op = wnext; - len -= op; - do { - PUP(out) = PUP(from); - } while (--op); - from = out - dist; /* rest from output */ - } - } - } - else { /* contiguous in window */ - from += wnext - op; - if (op < len) { /* some from window */ - len -= op; - do { - PUP(out) = PUP(from); - } while (--op); - from = out - dist; /* rest from output */ - } - } - while (len > 2) { - PUP(out) = PUP(from); - PUP(out) = PUP(from); - PUP(out) = PUP(from); - len -= 3; - } - if (len) { - PUP(out) = PUP(from); - if (len > 1) - PUP(out) = PUP(from); - } - } - else { - from = out - dist; /* copy direct from output */ - do { /* minimum length is three */ - PUP(out) = PUP(from); - PUP(out) = PUP(from); - PUP(out) = PUP(from); - len -= 3; - } while (len > 2); - if (len) { - PUP(out) = PUP(from); - if (len > 1) - PUP(out) = PUP(from); - } - } - } - else if ((op & 64) == 0) { /* 2nd level distance code */ - here = dcode[here.val + (hold & ((1U << op) - 1))]; - goto dodist; - } - else { - strm->msg = (char *)"invalid distance code"; - state->mode = BAD; - break; - } - } - else if ((op & 64) == 0) { /* 2nd level length code */ - here = lcode[here.val + (hold & ((1U << op) - 1))]; - goto dolen; - } - else if (op & 32) { /* end-of-block */ - Tracevv((stderr, "inflate: end of block\n")); - state->mode = TYPE; - break; - } - else { - strm->msg = (char *)"invalid literal/length code"; - state->mode = BAD; - break; - } - } while (in < last && out < end); - - /* return unused bytes (on entry, bits < 8, so in won't go too far back) */ - len = bits >> 3; - in -= len; - bits -= len << 3; - hold &= (1U << bits) - 1; - - /* update state and return */ - strm->next_in = in + OFF; - strm->next_out = out + OFF; - strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last)); - strm->avail_out = (unsigned)(out < end ? - 257 + (end - out) : 257 - (out - end)); - state->hold = hold; - state->bits = bits; - return; -} - -/* - inflate_fast() speedups that turned out slower (on a PowerPC G3 750CXe): - - Using bit fields for code structure - - Different op definition to avoid & for extra bits (do & for table bits) - - Three separate decoding do-loops for direct, window, and wnext == 0 - - Special case for distance > 1 copies to do overlapped load and store copy - - Explicit branch predictions (based on measured branch probabilities) - - Deferring match copy and interspersed it with decoding subsequent codes - - Swapping literal/length else - - Swapping window/direct else - - Larger unrolled copy loops (three is about right) - - Moving len -= 3 statement into middle of loop - */ - -#endif /* !ASMINF */ diff --git a/vendor/libgit2/deps/zlib/inffast.h b/vendor/libgit2/deps/zlib/inffast.h deleted file mode 100644 index e5c1aa4ca..000000000 --- a/vendor/libgit2/deps/zlib/inffast.h +++ /dev/null @@ -1,11 +0,0 @@ -/* inffast.h -- header to use inffast.c - * Copyright (C) 1995-2003, 2010 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); diff --git a/vendor/libgit2/deps/zlib/inffixed.h b/vendor/libgit2/deps/zlib/inffixed.h deleted file mode 100644 index 75ed4b597..000000000 --- a/vendor/libgit2/deps/zlib/inffixed.h +++ /dev/null @@ -1,94 +0,0 @@ - /* inffixed.h -- table for decoding fixed codes - * Generated automatically by makefixed(). - */ - - /* WARNING: this file should *not* be used by applications. It - is part of the implementation of the compression library and - is subject to change. Applications should only use zlib.h. - */ - - static const code lenfix[512] = { - {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48}, - {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128}, - {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59}, - {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176}, - {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20}, - {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100}, - {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8}, - {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216}, - {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76}, - {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114}, - {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2}, - {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148}, - {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42}, - {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86}, - {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15}, - {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236}, - {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62}, - {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142}, - {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31}, - {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162}, - {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25}, - {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105}, - {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4}, - {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202}, - {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69}, - {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125}, - {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13}, - {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195}, - {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35}, - {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91}, - {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19}, - {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246}, - {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55}, - {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135}, - {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99}, - {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190}, - {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16}, - {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96}, - {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6}, - {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209}, - {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72}, - {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116}, - {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4}, - {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153}, - {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44}, - {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82}, - {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11}, - {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229}, - {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58}, - {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138}, - {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51}, - {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173}, - {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30}, - {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110}, - {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0}, - {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195}, - {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65}, - {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121}, - {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9}, - {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258}, - {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37}, - {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93}, - {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23}, - {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251}, - {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51}, - {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131}, - {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67}, - {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183}, - {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23}, - {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103}, - {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9}, - {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223}, - {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79}, - {0,9,255} - }; - - static const code distfix[32] = { - {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025}, - {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193}, - {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385}, - {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577}, - {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073}, - {22,5,193},{64,5,0} - }; diff --git a/vendor/libgit2/deps/zlib/inflate.c b/vendor/libgit2/deps/zlib/inflate.c deleted file mode 100644 index a8431abea..000000000 --- a/vendor/libgit2/deps/zlib/inflate.c +++ /dev/null @@ -1,1480 +0,0 @@ -/* inflate.c -- zlib decompression - * Copyright (C) 1995-2010 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * Change history: - * - * 1.2.beta0 24 Nov 2002 - * - First version -- complete rewrite of inflate to simplify code, avoid - * creation of window when not needed, minimize use of window when it is - * needed, make inffast.c even faster, implement gzip decoding, and to - * improve code readability and style over the previous zlib inflate code - * - * 1.2.beta1 25 Nov 2002 - * - Use pointers for available input and output checking in inffast.c - * - Remove input and output counters in inffast.c - * - Change inffast.c entry and loop from avail_in >= 7 to >= 6 - * - Remove unnecessary second byte pull from length extra in inffast.c - * - Unroll direct copy to three copies per loop in inffast.c - * - * 1.2.beta2 4 Dec 2002 - * - Change external routine names to reduce potential conflicts - * - Correct filename to inffixed.h for fixed tables in inflate.c - * - Make hbuf[] unsigned char to match parameter type in inflate.c - * - Change strm->next_out[-state->offset] to *(strm->next_out - state->offset) - * to avoid negation problem on Alphas (64 bit) in inflate.c - * - * 1.2.beta3 22 Dec 2002 - * - Add comments on state->bits assertion in inffast.c - * - Add comments on op field in inftrees.h - * - Fix bug in reuse of allocated window after inflateReset() - * - Remove bit fields--back to byte structure for speed - * - Remove distance extra == 0 check in inflate_fast()--only helps for lengths - * - Change post-increments to pre-increments in inflate_fast(), PPC biased? - * - Add compile time option, POSTINC, to use post-increments instead (Intel?) - * - Make MATCH copy in inflate() much faster for when inflate_fast() not used - * - Use local copies of stream next and avail values, as well as local bit - * buffer and bit count in inflate()--for speed when inflate_fast() not used - * - * 1.2.beta4 1 Jan 2003 - * - Split ptr - 257 statements in inflate_table() to avoid compiler warnings - * - Move a comment on output buffer sizes from inffast.c to inflate.c - * - Add comments in inffast.c to introduce the inflate_fast() routine - * - Rearrange window copies in inflate_fast() for speed and simplification - * - Unroll last copy for window match in inflate_fast() - * - Use local copies of window variables in inflate_fast() for speed - * - Pull out common wnext == 0 case for speed in inflate_fast() - * - Make op and len in inflate_fast() unsigned for consistency - * - Add FAR to lcode and dcode declarations in inflate_fast() - * - Simplified bad distance check in inflate_fast() - * - Added inflateBackInit(), inflateBack(), and inflateBackEnd() in new - * source file infback.c to provide a call-back interface to inflate for - * programs like gzip and unzip -- uses window as output buffer to avoid - * window copying - * - * 1.2.beta5 1 Jan 2003 - * - Improved inflateBack() interface to allow the caller to provide initial - * input in strm. - * - Fixed stored blocks bug in inflateBack() - * - * 1.2.beta6 4 Jan 2003 - * - Added comments in inffast.c on effectiveness of POSTINC - * - Typecasting all around to reduce compiler warnings - * - Changed loops from while (1) or do {} while (1) to for (;;), again to - * make compilers happy - * - Changed type of window in inflateBackInit() to unsigned char * - * - * 1.2.beta7 27 Jan 2003 - * - Changed many types to unsigned or unsigned short to avoid warnings - * - Added inflateCopy() function - * - * 1.2.0 9 Mar 2003 - * - Changed inflateBack() interface to provide separate opaque descriptors - * for the in() and out() functions - * - Changed inflateBack() argument and in_func typedef to swap the length - * and buffer address return values for the input function - * - Check next_in and next_out for Z_NULL on entry to inflate() - * - * The history for versions after 1.2.0 are in ChangeLog in zlib distribution. - */ - -#include "zutil.h" -#include "inftrees.h" -#include "inflate.h" -#include "inffast.h" - -#ifdef MAKEFIXED -# ifndef BUILDFIXED -# define BUILDFIXED -# endif -#endif - -/* function prototypes */ -local void fixedtables OF((struct inflate_state FAR *state)); -local int updatewindow OF((z_streamp strm, unsigned out)); -#ifdef BUILDFIXED - void makefixed OF((void)); -#endif -local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf, - unsigned len)); - -int ZEXPORT inflateReset(strm) -z_streamp strm; -{ - struct inflate_state FAR *state; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - strm->total_in = strm->total_out = state->total = 0; - strm->msg = Z_NULL; - strm->adler = 1; /* to support ill-conceived Java test suite */ - state->mode = HEAD; - state->last = 0; - state->havedict = 0; - state->dmax = 32768U; - state->head = Z_NULL; - state->wsize = 0; - state->whave = 0; - state->wnext = 0; - state->hold = 0; - state->bits = 0; - state->lencode = state->distcode = state->next = state->codes; - state->sane = 1; - state->back = -1; - Tracev((stderr, "inflate: reset\n")); - return Z_OK; -} - -int ZEXPORT inflateReset2(strm, windowBits) -z_streamp strm; -int windowBits; -{ - int wrap; - struct inflate_state FAR *state; - - /* get the state */ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - - /* extract wrap request from windowBits parameter */ - if (windowBits < 0) { - wrap = 0; - windowBits = -windowBits; - } - else { - wrap = (windowBits >> 4) + 1; -#ifdef GUNZIP - if (windowBits < 48) - windowBits &= 15; -#endif - } - - /* set number of window bits, free window if different */ - if (windowBits && (windowBits < 8 || windowBits > 15)) - return Z_STREAM_ERROR; - if (state->window != Z_NULL && state->wbits != (unsigned)windowBits) { - ZFREE(strm, state->window); - state->window = Z_NULL; - } - - /* update state and reset the rest of it */ - state->wrap = wrap; - state->wbits = (unsigned)windowBits; - return inflateReset(strm); -} - -int ZEXPORT inflateInit2_(strm, windowBits, version, stream_size) -z_streamp strm; -int windowBits; -const char *version; -int stream_size; -{ - int ret; - struct inflate_state FAR *state; - - if (version == Z_NULL || version[0] != ZLIB_VERSION[0] || - stream_size != (int)(sizeof(z_stream))) - return Z_VERSION_ERROR; - if (strm == Z_NULL) return Z_STREAM_ERROR; - strm->msg = Z_NULL; /* in case we return an error */ - if (strm->zalloc == (alloc_func)0) { - strm->zalloc = zcalloc; - strm->opaque = (voidpf)0; - } - if (strm->zfree == (free_func)0) strm->zfree = zcfree; - state = (struct inflate_state FAR *) - ZALLOC(strm, 1, sizeof(struct inflate_state)); - if (state == Z_NULL) return Z_MEM_ERROR; - Tracev((stderr, "inflate: allocated\n")); - strm->state = (struct internal_state FAR *)state; - state->window = Z_NULL; - ret = inflateReset2(strm, windowBits); - if (ret != Z_OK) { - ZFREE(strm, state); - strm->state = Z_NULL; - } - return ret; -} - -int ZEXPORT inflateInit_(strm, version, stream_size) -z_streamp strm; -const char *version; -int stream_size; -{ - return inflateInit2_(strm, DEF_WBITS, version, stream_size); -} - -int ZEXPORT inflatePrime(strm, bits, value) -z_streamp strm; -int bits; -int value; -{ - struct inflate_state FAR *state; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if (bits < 0) { - state->hold = 0; - state->bits = 0; - return Z_OK; - } - if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR; - value &= (1L << bits) - 1; - state->hold += value << state->bits; - state->bits += bits; - return Z_OK; -} - -/* - Return state with length and distance decoding tables and index sizes set to - fixed code decoding. Normally this returns fixed tables from inffixed.h. - If BUILDFIXED is defined, then instead this routine builds the tables the - first time it's called, and returns those tables the first time and - thereafter. This reduces the size of the code by about 2K bytes, in - exchange for a little execution time. However, BUILDFIXED should not be - used for threaded applications, since the rewriting of the tables and virgin - may not be thread-safe. - */ -local void fixedtables(state) -struct inflate_state FAR *state; -{ -#ifdef BUILDFIXED - static int virgin = 1; - static code *lenfix, *distfix; - static code fixed[544]; - - /* build fixed huffman tables if first call (may not be thread safe) */ - if (virgin) { - unsigned sym, bits; - static code *next; - - /* literal/length table */ - sym = 0; - while (sym < 144) state->lens[sym++] = 8; - while (sym < 256) state->lens[sym++] = 9; - while (sym < 280) state->lens[sym++] = 7; - while (sym < 288) state->lens[sym++] = 8; - next = fixed; - lenfix = next; - bits = 9; - inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work); - - /* distance table */ - sym = 0; - while (sym < 32) state->lens[sym++] = 5; - distfix = next; - bits = 5; - inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work); - - /* do this just once */ - virgin = 0; - } -#else /* !BUILDFIXED */ -# include "inffixed.h" -#endif /* BUILDFIXED */ - state->lencode = lenfix; - state->lenbits = 9; - state->distcode = distfix; - state->distbits = 5; -} - -#ifdef MAKEFIXED -#include - -/* - Write out the inffixed.h that is #include'd above. Defining MAKEFIXED also - defines BUILDFIXED, so the tables are built on the fly. makefixed() writes - those tables to stdout, which would be piped to inffixed.h. A small program - can simply call makefixed to do this: - - void makefixed(void); - - int main(void) - { - makefixed(); - return 0; - } - - Then that can be linked with zlib built with MAKEFIXED defined and run: - - a.out > inffixed.h - */ -void makefixed() -{ - unsigned low, size; - struct inflate_state state; - - fixedtables(&state); - puts(" /* inffixed.h -- table for decoding fixed codes"); - puts(" * Generated automatically by makefixed()."); - puts(" */"); - puts(""); - puts(" /* WARNING: this file should *not* be used by applications."); - puts(" It is part of the implementation of this library and is"); - puts(" subject to change. Applications should only use zlib.h."); - puts(" */"); - puts(""); - size = 1U << 9; - printf(" static const code lenfix[%u] = {", size); - low = 0; - for (;;) { - if ((low % 7) == 0) printf("\n "); - printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits, - state.lencode[low].val); - if (++low == size) break; - putchar(','); - } - puts("\n };"); - size = 1U << 5; - printf("\n static const code distfix[%u] = {", size); - low = 0; - for (;;) { - if ((low % 6) == 0) printf("\n "); - printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits, - state.distcode[low].val); - if (++low == size) break; - putchar(','); - } - puts("\n };"); -} -#endif /* MAKEFIXED */ - -/* - Update the window with the last wsize (normally 32K) bytes written before - returning. If window does not exist yet, create it. This is only called - when a window is already in use, or when output has been written during this - inflate call, but the end of the deflate stream has not been reached yet. - It is also called to create a window for dictionary data when a dictionary - is loaded. - - Providing output buffers larger than 32K to inflate() should provide a speed - advantage, since only the last 32K of output is copied to the sliding window - upon return from inflate(), and since all distances after the first 32K of - output will fall in the output data, making match copies simpler and faster. - The advantage may be dependent on the size of the processor's data caches. - */ -local int updatewindow(strm, out) -z_streamp strm; -unsigned out; -{ - struct inflate_state FAR *state; - unsigned copy, dist; - - state = (struct inflate_state FAR *)strm->state; - - /* if it hasn't been done already, allocate space for the window */ - if (state->window == Z_NULL) { - state->window = (unsigned char FAR *) - ZALLOC(strm, 1U << state->wbits, - sizeof(unsigned char)); - if (state->window == Z_NULL) return 1; - } - - /* if window not in use yet, initialize */ - if (state->wsize == 0) { - state->wsize = 1U << state->wbits; - state->wnext = 0; - state->whave = 0; - } - - /* copy state->wsize or less output bytes into the circular window */ - copy = out - strm->avail_out; - if (copy >= state->wsize) { - zmemcpy(state->window, strm->next_out - state->wsize, state->wsize); - state->wnext = 0; - state->whave = state->wsize; - } - else { - dist = state->wsize - state->wnext; - if (dist > copy) dist = copy; - zmemcpy(state->window + state->wnext, strm->next_out - copy, dist); - copy -= dist; - if (copy) { - zmemcpy(state->window, strm->next_out - copy, copy); - state->wnext = copy; - state->whave = state->wsize; - } - else { - state->wnext += dist; - if (state->wnext == state->wsize) state->wnext = 0; - if (state->whave < state->wsize) state->whave += dist; - } - } - return 0; -} - -/* Macros for inflate(): */ - -/* check function to use adler32() for zlib or crc32() for gzip */ -#ifdef GUNZIP -# define UPDATE(check, buf, len) \ - (state->flags ? crc32(check, buf, len) : adler32(check, buf, len)) -#else -# define UPDATE(check, buf, len) adler32(check, buf, len) -#endif - -/* check macros for header crc */ -#ifdef GUNZIP -# define CRC2(check, word) \ - do { \ - hbuf[0] = (unsigned char)(word); \ - hbuf[1] = (unsigned char)((word) >> 8); \ - check = crc32(check, hbuf, 2); \ - } while (0) - -# define CRC4(check, word) \ - do { \ - hbuf[0] = (unsigned char)(word); \ - hbuf[1] = (unsigned char)((word) >> 8); \ - hbuf[2] = (unsigned char)((word) >> 16); \ - hbuf[3] = (unsigned char)((word) >> 24); \ - check = crc32(check, hbuf, 4); \ - } while (0) -#endif - -/* Load registers with state in inflate() for speed */ -#define LOAD() \ - do { \ - put = strm->next_out; \ - left = strm->avail_out; \ - next = strm->next_in; \ - have = strm->avail_in; \ - hold = state->hold; \ - bits = state->bits; \ - } while (0) - -/* Restore state from registers in inflate() */ -#define RESTORE() \ - do { \ - strm->next_out = put; \ - strm->avail_out = left; \ - strm->next_in = next; \ - strm->avail_in = have; \ - state->hold = hold; \ - state->bits = bits; \ - } while (0) - -/* Clear the input bit accumulator */ -#define INITBITS() \ - do { \ - hold = 0; \ - bits = 0; \ - } while (0) - -/* Get a byte of input into the bit accumulator, or return from inflate() - if there is no input available. */ -#define PULLBYTE() \ - do { \ - if (have == 0) goto inf_leave; \ - have--; \ - hold += (unsigned long)(*next++) << bits; \ - bits += 8; \ - } while (0) - -/* Assure that there are at least n bits in the bit accumulator. If there is - not enough available input to do that, then return from inflate(). */ -#define NEEDBITS(n) \ - do { \ - while (bits < (unsigned)(n)) \ - PULLBYTE(); \ - } while (0) - -/* Return the low n bits of the bit accumulator (n < 16) */ -#define BITS(n) \ - ((unsigned)hold & ((1U << (n)) - 1)) - -/* Remove n bits from the bit accumulator */ -#define DROPBITS(n) \ - do { \ - hold >>= (n); \ - bits -= (unsigned)(n); \ - } while (0) - -/* Remove zero to seven bits as needed to go to a byte boundary */ -#define BYTEBITS() \ - do { \ - hold >>= bits & 7; \ - bits -= bits & 7; \ - } while (0) - -/* Reverse the bytes in a 32-bit value */ -#define REVERSE(q) \ - ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \ - (((q) & 0xff00) << 8) + (((q) & 0xff) << 24)) - -/* - inflate() uses a state machine to process as much input data and generate as - much output data as possible before returning. The state machine is - structured roughly as follows: - - for (;;) switch (state) { - ... - case STATEn: - if (not enough input data or output space to make progress) - return; - ... make progress ... - state = STATEm; - break; - ... - } - - so when inflate() is called again, the same case is attempted again, and - if the appropriate resources are provided, the machine proceeds to the - next state. The NEEDBITS() macro is usually the way the state evaluates - whether it can proceed or should return. NEEDBITS() does the return if - the requested bits are not available. The typical use of the BITS macros - is: - - NEEDBITS(n); - ... do something with BITS(n) ... - DROPBITS(n); - - where NEEDBITS(n) either returns from inflate() if there isn't enough - input left to load n bits into the accumulator, or it continues. BITS(n) - gives the low n bits in the accumulator. When done, DROPBITS(n) drops - the low n bits off the accumulator. INITBITS() clears the accumulator - and sets the number of available bits to zero. BYTEBITS() discards just - enough bits to put the accumulator on a byte boundary. After BYTEBITS() - and a NEEDBITS(8), then BITS(8) would return the next byte in the stream. - - NEEDBITS(n) uses PULLBYTE() to get an available byte of input, or to return - if there is no input available. The decoding of variable length codes uses - PULLBYTE() directly in order to pull just enough bytes to decode the next - code, and no more. - - Some states loop until they get enough input, making sure that enough - state information is maintained to continue the loop where it left off - if NEEDBITS() returns in the loop. For example, want, need, and keep - would all have to actually be part of the saved state in case NEEDBITS() - returns: - - case STATEw: - while (want < need) { - NEEDBITS(n); - keep[want++] = BITS(n); - DROPBITS(n); - } - state = STATEx; - case STATEx: - - As shown above, if the next state is also the next case, then the break - is omitted. - - A state may also return if there is not enough output space available to - complete that state. Those states are copying stored data, writing a - literal byte, and copying a matching string. - - When returning, a "goto inf_leave" is used to update the total counters, - update the check value, and determine whether any progress has been made - during that inflate() call in order to return the proper return code. - Progress is defined as a change in either strm->avail_in or strm->avail_out. - When there is a window, goto inf_leave will update the window with the last - output written. If a goto inf_leave occurs in the middle of decompression - and there is no window currently, goto inf_leave will create one and copy - output to the window for the next call of inflate(). - - In this implementation, the flush parameter of inflate() only affects the - return code (per zlib.h). inflate() always writes as much as possible to - strm->next_out, given the space available and the provided input--the effect - documented in zlib.h of Z_SYNC_FLUSH. Furthermore, inflate() always defers - the allocation of and copying into a sliding window until necessary, which - provides the effect documented in zlib.h for Z_FINISH when the entire input - stream available. So the only thing the flush parameter actually does is: - when flush is set to Z_FINISH, inflate() cannot return Z_OK. Instead it - will return Z_BUF_ERROR if it has not reached the end of the stream. - */ - -int ZEXPORT inflate(strm, flush) -z_streamp strm; -int flush; -{ - struct inflate_state FAR *state; - unsigned char FAR *next; /* next input */ - unsigned char FAR *put; /* next output */ - unsigned have, left; /* available input and output */ - unsigned long hold; /* bit buffer */ - unsigned bits; /* bits in bit buffer */ - unsigned in, out; /* save starting available input and output */ - unsigned copy; /* number of stored or match bytes to copy */ - unsigned char FAR *from; /* where to copy match bytes from */ - code here; /* current decoding table entry */ - code last; /* parent table entry */ - unsigned len; /* length to copy for repeats, bits to drop */ - int ret; /* return code */ -#ifdef GUNZIP - unsigned char hbuf[4]; /* buffer for gzip header crc calculation */ -#endif - static const unsigned short order[19] = /* permutation of code lengths */ - {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; - - if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL || - (strm->next_in == Z_NULL && strm->avail_in != 0)) - return Z_STREAM_ERROR; - - state = (struct inflate_state FAR *)strm->state; - if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */ - LOAD(); - in = have; - out = left; - ret = Z_OK; - for (;;) - switch (state->mode) { - case HEAD: - if (state->wrap == 0) { - state->mode = TYPEDO; - break; - } - NEEDBITS(16); -#ifdef GUNZIP - if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */ - state->check = crc32(0L, Z_NULL, 0); - CRC2(state->check, hold); - INITBITS(); - state->mode = FLAGS; - break; - } - state->flags = 0; /* expect zlib header */ - if (state->head != Z_NULL) - state->head->done = -1; - if (!(state->wrap & 1) || /* check if zlib header allowed */ -#else - if ( -#endif - ((BITS(8) << 8) + (hold >> 8)) % 31) { - strm->msg = (char *)"incorrect header check"; - state->mode = BAD; - break; - } - if (BITS(4) != Z_DEFLATED) { - strm->msg = (char *)"unknown compression method"; - state->mode = BAD; - break; - } - DROPBITS(4); - len = BITS(4) + 8; - if (state->wbits == 0) - state->wbits = len; - else if (len > state->wbits) { - strm->msg = (char *)"invalid window size"; - state->mode = BAD; - break; - } - state->dmax = 1U << len; - Tracev((stderr, "inflate: zlib header ok\n")); - strm->adler = state->check = adler32(0L, Z_NULL, 0); - state->mode = hold & 0x200 ? DICTID : TYPE; - INITBITS(); - break; -#ifdef GUNZIP - case FLAGS: - NEEDBITS(16); - state->flags = (int)(hold); - if ((state->flags & 0xff) != Z_DEFLATED) { - strm->msg = (char *)"unknown compression method"; - state->mode = BAD; - break; - } - if (state->flags & 0xe000) { - strm->msg = (char *)"unknown header flags set"; - state->mode = BAD; - break; - } - if (state->head != Z_NULL) - state->head->text = (int)((hold >> 8) & 1); - if (state->flags & 0x0200) CRC2(state->check, hold); - INITBITS(); - state->mode = TIME; - case TIME: - NEEDBITS(32); - if (state->head != Z_NULL) - state->head->time = hold; - if (state->flags & 0x0200) CRC4(state->check, hold); - INITBITS(); - state->mode = OS; - case OS: - NEEDBITS(16); - if (state->head != Z_NULL) { - state->head->xflags = (int)(hold & 0xff); - state->head->os = (int)(hold >> 8); - } - if (state->flags & 0x0200) CRC2(state->check, hold); - INITBITS(); - state->mode = EXLEN; - case EXLEN: - if (state->flags & 0x0400) { - NEEDBITS(16); - state->length = (unsigned)(hold); - if (state->head != Z_NULL) - state->head->extra_len = (unsigned)hold; - if (state->flags & 0x0200) CRC2(state->check, hold); - INITBITS(); - } - else if (state->head != Z_NULL) - state->head->extra = Z_NULL; - state->mode = EXTRA; - case EXTRA: - if (state->flags & 0x0400) { - copy = state->length; - if (copy > have) copy = have; - if (copy) { - if (state->head != Z_NULL && - state->head->extra != Z_NULL) { - len = state->head->extra_len - state->length; - zmemcpy(state->head->extra + len, next, - len + copy > state->head->extra_max ? - state->head->extra_max - len : copy); - } - if (state->flags & 0x0200) - state->check = crc32(state->check, next, copy); - have -= copy; - next += copy; - state->length -= copy; - } - if (state->length) goto inf_leave; - } - state->length = 0; - state->mode = NAME; - case NAME: - if (state->flags & 0x0800) { - if (have == 0) goto inf_leave; - copy = 0; - do { - len = (unsigned)(next[copy++]); - if (state->head != Z_NULL && - state->head->name != Z_NULL && - state->length < state->head->name_max) - state->head->name[state->length++] = len; - } while (len && copy < have); - if (state->flags & 0x0200) - state->check = crc32(state->check, next, copy); - have -= copy; - next += copy; - if (len) goto inf_leave; - } - else if (state->head != Z_NULL) - state->head->name = Z_NULL; - state->length = 0; - state->mode = COMMENT; - case COMMENT: - if (state->flags & 0x1000) { - if (have == 0) goto inf_leave; - copy = 0; - do { - len = (unsigned)(next[copy++]); - if (state->head != Z_NULL && - state->head->comment != Z_NULL && - state->length < state->head->comm_max) - state->head->comment[state->length++] = len; - } while (len && copy < have); - if (state->flags & 0x0200) - state->check = crc32(state->check, next, copy); - have -= copy; - next += copy; - if (len) goto inf_leave; - } - else if (state->head != Z_NULL) - state->head->comment = Z_NULL; - state->mode = HCRC; - case HCRC: - if (state->flags & 0x0200) { - NEEDBITS(16); - if (hold != (state->check & 0xffff)) { - strm->msg = (char *)"header crc mismatch"; - state->mode = BAD; - break; - } - INITBITS(); - } - if (state->head != Z_NULL) { - state->head->hcrc = (int)((state->flags >> 9) & 1); - state->head->done = 1; - } - strm->adler = state->check = crc32(0L, Z_NULL, 0); - state->mode = TYPE; - break; -#endif - case DICTID: - NEEDBITS(32); - strm->adler = state->check = REVERSE(hold); - INITBITS(); - state->mode = DICT; - case DICT: - if (state->havedict == 0) { - RESTORE(); - return Z_NEED_DICT; - } - strm->adler = state->check = adler32(0L, Z_NULL, 0); - state->mode = TYPE; - case TYPE: - if (flush == Z_BLOCK || flush == Z_TREES) goto inf_leave; - case TYPEDO: - if (state->last) { - BYTEBITS(); - state->mode = CHECK; - break; - } - NEEDBITS(3); - state->last = BITS(1); - DROPBITS(1); - switch (BITS(2)) { - case 0: /* stored block */ - Tracev((stderr, "inflate: stored block%s\n", - state->last ? " (last)" : "")); - state->mode = STORED; - break; - case 1: /* fixed block */ - fixedtables(state); - Tracev((stderr, "inflate: fixed codes block%s\n", - state->last ? " (last)" : "")); - state->mode = LEN_; /* decode codes */ - if (flush == Z_TREES) { - DROPBITS(2); - goto inf_leave; - } - break; - case 2: /* dynamic block */ - Tracev((stderr, "inflate: dynamic codes block%s\n", - state->last ? " (last)" : "")); - state->mode = TABLE; - break; - case 3: - strm->msg = (char *)"invalid block type"; - state->mode = BAD; - } - DROPBITS(2); - break; - case STORED: - BYTEBITS(); /* go to byte boundary */ - NEEDBITS(32); - if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) { - strm->msg = (char *)"invalid stored block lengths"; - state->mode = BAD; - break; - } - state->length = (unsigned)hold & 0xffff; - Tracev((stderr, "inflate: stored length %u\n", - state->length)); - INITBITS(); - state->mode = COPY_; - if (flush == Z_TREES) goto inf_leave; - case COPY_: - state->mode = COPY; - case COPY: - copy = state->length; - if (copy) { - if (copy > have) copy = have; - if (copy > left) copy = left; - if (copy == 0) goto inf_leave; - zmemcpy(put, next, copy); - have -= copy; - next += copy; - left -= copy; - put += copy; - state->length -= copy; - break; - } - Tracev((stderr, "inflate: stored end\n")); - state->mode = TYPE; - break; - case TABLE: - NEEDBITS(14); - state->nlen = BITS(5) + 257; - DROPBITS(5); - state->ndist = BITS(5) + 1; - DROPBITS(5); - state->ncode = BITS(4) + 4; - DROPBITS(4); -#ifndef PKZIP_BUG_WORKAROUND - if (state->nlen > 286 || state->ndist > 30) { - strm->msg = (char *)"too many length or distance symbols"; - state->mode = BAD; - break; - } -#endif - Tracev((stderr, "inflate: table sizes ok\n")); - state->have = 0; - state->mode = LENLENS; - case LENLENS: - while (state->have < state->ncode) { - NEEDBITS(3); - state->lens[order[state->have++]] = (unsigned short)BITS(3); - DROPBITS(3); - } - while (state->have < 19) - state->lens[order[state->have++]] = 0; - state->next = state->codes; - state->lencode = (code const FAR *)(state->next); - state->lenbits = 7; - ret = inflate_table(CODES, state->lens, 19, &(state->next), - &(state->lenbits), state->work); - if (ret) { - strm->msg = (char *)"invalid code lengths set"; - state->mode = BAD; - break; - } - Tracev((stderr, "inflate: code lengths ok\n")); - state->have = 0; - state->mode = CODELENS; - case CODELENS: - while (state->have < state->nlen + state->ndist) { - for (;;) { - here = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if (here.val < 16) { - NEEDBITS(here.bits); - DROPBITS(here.bits); - state->lens[state->have++] = here.val; - } - else { - if (here.val == 16) { - NEEDBITS(here.bits + 2); - DROPBITS(here.bits); - if (state->have == 0) { - strm->msg = (char *)"invalid bit length repeat"; - state->mode = BAD; - break; - } - len = state->lens[state->have - 1]; - copy = 3 + BITS(2); - DROPBITS(2); - } - else if (here.val == 17) { - NEEDBITS(here.bits + 3); - DROPBITS(here.bits); - len = 0; - copy = 3 + BITS(3); - DROPBITS(3); - } - else { - NEEDBITS(here.bits + 7); - DROPBITS(here.bits); - len = 0; - copy = 11 + BITS(7); - DROPBITS(7); - } - if (state->have + copy > state->nlen + state->ndist) { - strm->msg = (char *)"invalid bit length repeat"; - state->mode = BAD; - break; - } - while (copy--) - state->lens[state->have++] = (unsigned short)len; - } - } - - /* handle error breaks in while */ - if (state->mode == BAD) break; - - /* check for end-of-block code (better have one) */ - if (state->lens[256] == 0) { - strm->msg = (char *)"invalid code -- missing end-of-block"; - state->mode = BAD; - break; - } - - /* build code tables -- note: do not change the lenbits or distbits - values here (9 and 6) without reading the comments in inftrees.h - concerning the ENOUGH constants, which depend on those values */ - state->next = state->codes; - state->lencode = (code const FAR *)(state->next); - state->lenbits = 9; - ret = inflate_table(LENS, state->lens, state->nlen, &(state->next), - &(state->lenbits), state->work); - if (ret) { - strm->msg = (char *)"invalid literal/lengths set"; - state->mode = BAD; - break; - } - state->distcode = (code const FAR *)(state->next); - state->distbits = 6; - ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist, - &(state->next), &(state->distbits), state->work); - if (ret) { - strm->msg = (char *)"invalid distances set"; - state->mode = BAD; - break; - } - Tracev((stderr, "inflate: codes ok\n")); - state->mode = LEN_; - if (flush == Z_TREES) goto inf_leave; - case LEN_: - state->mode = LEN; - case LEN: - if (have >= 6 && left >= 258) { - RESTORE(); - inflate_fast(strm, out); - LOAD(); - if (state->mode == TYPE) - state->back = -1; - break; - } - state->back = 0; - for (;;) { - here = state->lencode[BITS(state->lenbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if (here.op && (here.op & 0xf0) == 0) { - last = here; - for (;;) { - here = state->lencode[last.val + - (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + here.bits) <= bits) break; - PULLBYTE(); - } - DROPBITS(last.bits); - state->back += last.bits; - } - DROPBITS(here.bits); - state->back += here.bits; - state->length = (unsigned)here.val; - if ((int)(here.op) == 0) { - Tracevv((stderr, here.val >= 0x20 && here.val < 0x7f ? - "inflate: literal '%c'\n" : - "inflate: literal 0x%02x\n", here.val)); - state->mode = LIT; - break; - } - if (here.op & 32) { - Tracevv((stderr, "inflate: end of block\n")); - state->back = -1; - state->mode = TYPE; - break; - } - if (here.op & 64) { - strm->msg = (char *)"invalid literal/length code"; - state->mode = BAD; - break; - } - state->extra = (unsigned)(here.op) & 15; - state->mode = LENEXT; - case LENEXT: - if (state->extra) { - NEEDBITS(state->extra); - state->length += BITS(state->extra); - DROPBITS(state->extra); - state->back += state->extra; - } - Tracevv((stderr, "inflate: length %u\n", state->length)); - state->was = state->length; - state->mode = DIST; - case DIST: - for (;;) { - here = state->distcode[BITS(state->distbits)]; - if ((unsigned)(here.bits) <= bits) break; - PULLBYTE(); - } - if ((here.op & 0xf0) == 0) { - last = here; - for (;;) { - here = state->distcode[last.val + - (BITS(last.bits + last.op) >> last.bits)]; - if ((unsigned)(last.bits + here.bits) <= bits) break; - PULLBYTE(); - } - DROPBITS(last.bits); - state->back += last.bits; - } - DROPBITS(here.bits); - state->back += here.bits; - if (here.op & 64) { - strm->msg = (char *)"invalid distance code"; - state->mode = BAD; - break; - } - state->offset = (unsigned)here.val; - state->extra = (unsigned)(here.op) & 15; - state->mode = DISTEXT; - case DISTEXT: - if (state->extra) { - NEEDBITS(state->extra); - state->offset += BITS(state->extra); - DROPBITS(state->extra); - state->back += state->extra; - } -#ifdef INFLATE_STRICT - if (state->offset > state->dmax) { - strm->msg = (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } -#endif - Tracevv((stderr, "inflate: distance %u\n", state->offset)); - state->mode = MATCH; - case MATCH: - if (left == 0) goto inf_leave; - copy = out - left; - if (state->offset > copy) { /* copy from window */ - copy = state->offset - copy; - if (copy > state->whave) { - if (state->sane) { - strm->msg = (char *)"invalid distance too far back"; - state->mode = BAD; - break; - } -#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR - Trace((stderr, "inflate.c too far\n")); - copy -= state->whave; - if (copy > state->length) copy = state->length; - if (copy > left) copy = left; - left -= copy; - state->length -= copy; - do { - *put++ = 0; - } while (--copy); - if (state->length == 0) state->mode = LEN; - break; -#endif - } - if (copy > state->wnext) { - copy -= state->wnext; - from = state->window + (state->wsize - copy); - } - else - from = state->window + (state->wnext - copy); - if (copy > state->length) copy = state->length; - } - else { /* copy from output */ - from = put - state->offset; - copy = state->length; - } - if (copy > left) copy = left; - left -= copy; - state->length -= copy; - do { - *put++ = *from++; - } while (--copy); - if (state->length == 0) state->mode = LEN; - break; - case LIT: - if (left == 0) goto inf_leave; - *put++ = (unsigned char)(state->length); - left--; - state->mode = LEN; - break; - case CHECK: - if (state->wrap) { - NEEDBITS(32); - out -= left; - strm->total_out += out; - state->total += out; - if (out) - strm->adler = state->check = - UPDATE(state->check, put - out, out); - out = left; - if (( -#ifdef GUNZIP - state->flags ? hold : -#endif - REVERSE(hold)) != state->check) { - strm->msg = (char *)"incorrect data check"; - state->mode = BAD; - break; - } - INITBITS(); - Tracev((stderr, "inflate: check matches trailer\n")); - } -#ifdef GUNZIP - state->mode = LENGTH; - case LENGTH: - if (state->wrap && state->flags) { - NEEDBITS(32); - if (hold != (state->total & 0xffffffffUL)) { - strm->msg = (char *)"incorrect length check"; - state->mode = BAD; - break; - } - INITBITS(); - Tracev((stderr, "inflate: length matches trailer\n")); - } -#endif - state->mode = DONE; - case DONE: - ret = Z_STREAM_END; - goto inf_leave; - case BAD: - ret = Z_DATA_ERROR; - goto inf_leave; - case MEM: - return Z_MEM_ERROR; - case SYNC: - default: - return Z_STREAM_ERROR; - } - - /* - Return from inflate(), updating the total counts and the check value. - If there was no progress during the inflate() call, return a buffer - error. Call updatewindow() to create and/or update the window state. - Note: a memory error from inflate() is non-recoverable. - */ - inf_leave: - RESTORE(); - if (state->wsize || (state->mode < CHECK && out != strm->avail_out)) - if (updatewindow(strm, out)) { - state->mode = MEM; - return Z_MEM_ERROR; - } - in -= strm->avail_in; - out -= strm->avail_out; - strm->total_in += in; - strm->total_out += out; - state->total += out; - if (state->wrap && out) - strm->adler = state->check = - UPDATE(state->check, strm->next_out - out, out); - strm->data_type = state->bits + (state->last ? 64 : 0) + - (state->mode == TYPE ? 128 : 0) + - (state->mode == LEN_ || state->mode == COPY_ ? 256 : 0); - if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK) - ret = Z_BUF_ERROR; - return ret; -} - -int ZEXPORT inflateEnd(strm) -z_streamp strm; -{ - struct inflate_state FAR *state; - if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0) - return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if (state->window != Z_NULL) ZFREE(strm, state->window); - ZFREE(strm, strm->state); - strm->state = Z_NULL; - Tracev((stderr, "inflate: end\n")); - return Z_OK; -} - -int ZEXPORT inflateSetDictionary(strm, dictionary, dictLength) -z_streamp strm; -const Bytef *dictionary; -uInt dictLength; -{ - struct inflate_state FAR *state; - unsigned long id; - - /* check state */ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if (state->wrap != 0 && state->mode != DICT) - return Z_STREAM_ERROR; - - /* check for correct dictionary id */ - if (state->mode == DICT) { - id = adler32(0L, Z_NULL, 0); - id = adler32(id, dictionary, dictLength); - if (id != state->check) - return Z_DATA_ERROR; - } - - /* copy dictionary to window */ - if (updatewindow(strm, strm->avail_out)) { - state->mode = MEM; - return Z_MEM_ERROR; - } - if (dictLength > state->wsize) { - zmemcpy(state->window, dictionary + dictLength - state->wsize, - state->wsize); - state->whave = state->wsize; - } - else { - zmemcpy(state->window + state->wsize - dictLength, dictionary, - dictLength); - state->whave = dictLength; - } - state->havedict = 1; - Tracev((stderr, "inflate: dictionary set\n")); - return Z_OK; -} - -int ZEXPORT inflateGetHeader(strm, head) -z_streamp strm; -gz_headerp head; -{ - struct inflate_state FAR *state; - - /* check state */ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if ((state->wrap & 2) == 0) return Z_STREAM_ERROR; - - /* save header structure */ - state->head = head; - head->done = 0; - return Z_OK; -} - -/* - Search buf[0..len-1] for the pattern: 0, 0, 0xff, 0xff. Return when found - or when out of input. When called, *have is the number of pattern bytes - found in order so far, in 0..3. On return *have is updated to the new - state. If on return *have equals four, then the pattern was found and the - return value is how many bytes were read including the last byte of the - pattern. If *have is less than four, then the pattern has not been found - yet and the return value is len. In the latter case, syncsearch() can be - called again with more data and the *have state. *have is initialized to - zero for the first call. - */ -local unsigned syncsearch(have, buf, len) -unsigned FAR *have; -unsigned char FAR *buf; -unsigned len; -{ - unsigned got; - unsigned next; - - got = *have; - next = 0; - while (next < len && got < 4) { - if ((int)(buf[next]) == (got < 2 ? 0 : 0xff)) - got++; - else if (buf[next]) - got = 0; - else - got = 4 - got; - next++; - } - *have = got; - return next; -} - -int ZEXPORT inflateSync(strm) -z_streamp strm; -{ - unsigned len; /* number of bytes to look at or looked at */ - unsigned long in, out; /* temporary to save total_in and total_out */ - unsigned char buf[4]; /* to restore bit buffer to byte string */ - struct inflate_state FAR *state; - - /* check parameters */ - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR; - - /* if first time, start search in bit buffer */ - if (state->mode != SYNC) { - state->mode = SYNC; - state->hold <<= state->bits & 7; - state->bits -= state->bits & 7; - len = 0; - while (state->bits >= 8) { - buf[len++] = (unsigned char)(state->hold); - state->hold >>= 8; - state->bits -= 8; - } - state->have = 0; - syncsearch(&(state->have), buf, len); - } - - /* search available input */ - len = syncsearch(&(state->have), strm->next_in, strm->avail_in); - strm->avail_in -= len; - strm->next_in += len; - strm->total_in += len; - - /* return no joy or set up to restart inflate() on a new block */ - if (state->have != 4) return Z_DATA_ERROR; - in = strm->total_in; out = strm->total_out; - inflateReset(strm); - strm->total_in = in; strm->total_out = out; - state->mode = TYPE; - return Z_OK; -} - -/* - Returns true if inflate is currently at the end of a block generated by - Z_SYNC_FLUSH or Z_FULL_FLUSH. This function is used by one PPP - implementation to provide an additional safety check. PPP uses - Z_SYNC_FLUSH but removes the length bytes of the resulting empty stored - block. When decompressing, PPP checks that at the end of input packet, - inflate is waiting for these length bytes. - */ -int ZEXPORT inflateSyncPoint(strm) -z_streamp strm; -{ - struct inflate_state FAR *state; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - return state->mode == STORED && state->bits == 0; -} - -int ZEXPORT inflateCopy(dest, source) -z_streamp dest; -z_streamp source; -{ - struct inflate_state FAR *state; - struct inflate_state FAR *copy; - unsigned char FAR *window; - unsigned wsize; - - /* check input */ - if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL || - source->zalloc == (alloc_func)0 || source->zfree == (free_func)0) - return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)source->state; - - /* allocate space */ - copy = (struct inflate_state FAR *) - ZALLOC(source, 1, sizeof(struct inflate_state)); - if (copy == Z_NULL) return Z_MEM_ERROR; - window = Z_NULL; - if (state->window != Z_NULL) { - window = (unsigned char FAR *) - ZALLOC(source, 1U << state->wbits, sizeof(unsigned char)); - if (window == Z_NULL) { - ZFREE(source, copy); - return Z_MEM_ERROR; - } - } - - /* copy state */ - zmemcpy(dest, source, sizeof(z_stream)); - zmemcpy(copy, state, sizeof(struct inflate_state)); - if (state->lencode >= state->codes && - state->lencode <= state->codes + ENOUGH - 1) { - copy->lencode = copy->codes + (state->lencode - state->codes); - copy->distcode = copy->codes + (state->distcode - state->codes); - } - copy->next = copy->codes + (state->next - state->codes); - if (window != Z_NULL) { - wsize = 1U << state->wbits; - zmemcpy(window, state->window, wsize); - } - copy->window = window; - dest->state = (struct internal_state FAR *)copy; - return Z_OK; -} - -int ZEXPORT inflateUndermine(strm, subvert) -z_streamp strm; -int subvert; -{ - struct inflate_state FAR *state; - - if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR; - state = (struct inflate_state FAR *)strm->state; - state->sane = !subvert; -#ifdef INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR - return Z_OK; -#else - state->sane = 1; - return Z_DATA_ERROR; -#endif -} - -long ZEXPORT inflateMark(strm) -z_streamp strm; -{ - struct inflate_state FAR *state; - - if (strm == Z_NULL || strm->state == Z_NULL) return -1L << 16; - state = (struct inflate_state FAR *)strm->state; - return ((long)(state->back) << 16) + - (state->mode == COPY ? state->length : - (state->mode == MATCH ? state->was - state->length : 0)); -} diff --git a/vendor/libgit2/deps/zlib/inflate.h b/vendor/libgit2/deps/zlib/inflate.h deleted file mode 100644 index 95f4986d4..000000000 --- a/vendor/libgit2/deps/zlib/inflate.h +++ /dev/null @@ -1,122 +0,0 @@ -/* inflate.h -- internal inflate state definition - * Copyright (C) 1995-2009 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* define NO_GZIP when compiling if you want to disable gzip header and - trailer decoding by inflate(). NO_GZIP would be used to avoid linking in - the crc code when it is not needed. For shared libraries, gzip decoding - should be left enabled. */ -#ifndef NO_GZIP -# define GUNZIP -#endif - -/* Possible inflate modes between inflate() calls */ -typedef enum { - HEAD, /* i: waiting for magic header */ - FLAGS, /* i: waiting for method and flags (gzip) */ - TIME, /* i: waiting for modification time (gzip) */ - OS, /* i: waiting for extra flags and operating system (gzip) */ - EXLEN, /* i: waiting for extra length (gzip) */ - EXTRA, /* i: waiting for extra bytes (gzip) */ - NAME, /* i: waiting for end of file name (gzip) */ - COMMENT, /* i: waiting for end of comment (gzip) */ - HCRC, /* i: waiting for header crc (gzip) */ - DICTID, /* i: waiting for dictionary check value */ - DICT, /* waiting for inflateSetDictionary() call */ - TYPE, /* i: waiting for type bits, including last-flag bit */ - TYPEDO, /* i: same, but skip check to exit inflate on new block */ - STORED, /* i: waiting for stored size (length and complement) */ - COPY_, /* i/o: same as COPY below, but only first time in */ - COPY, /* i/o: waiting for input or output to copy stored block */ - TABLE, /* i: waiting for dynamic block table lengths */ - LENLENS, /* i: waiting for code length code lengths */ - CODELENS, /* i: waiting for length/lit and distance code lengths */ - LEN_, /* i: same as LEN below, but only first time in */ - LEN, /* i: waiting for length/lit/eob code */ - LENEXT, /* i: waiting for length extra bits */ - DIST, /* i: waiting for distance code */ - DISTEXT, /* i: waiting for distance extra bits */ - MATCH, /* o: waiting for output space to copy string */ - LIT, /* o: waiting for output space to write literal */ - CHECK, /* i: waiting for 32-bit check value */ - LENGTH, /* i: waiting for 32-bit length (gzip) */ - DONE, /* finished check, done -- remain here until reset */ - BAD, /* got a data error -- remain here until reset */ - MEM, /* got an inflate() memory error -- remain here until reset */ - SYNC /* looking for synchronization bytes to restart inflate() */ -} inflate_mode; - -/* - State transitions between above modes - - - (most modes can go to BAD or MEM on error -- not shown for clarity) - - Process header: - HEAD -> (gzip) or (zlib) or (raw) - (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME -> COMMENT -> - HCRC -> TYPE - (zlib) -> DICTID or TYPE - DICTID -> DICT -> TYPE - (raw) -> TYPEDO - Read deflate blocks: - TYPE -> TYPEDO -> STORED or TABLE or LEN_ or CHECK - STORED -> COPY_ -> COPY -> TYPE - TABLE -> LENLENS -> CODELENS -> LEN_ - LEN_ -> LEN - Read deflate codes in fixed or dynamic block: - LEN -> LENEXT or LIT or TYPE - LENEXT -> DIST -> DISTEXT -> MATCH -> LEN - LIT -> LEN - Process trailer: - CHECK -> LENGTH -> DONE - */ - -/* state maintained between inflate() calls. Approximately 10K bytes. */ -struct inflate_state { - inflate_mode mode; /* current inflate mode */ - int last; /* true if processing last block */ - int wrap; /* bit 0 true for zlib, bit 1 true for gzip */ - int havedict; /* true if dictionary provided */ - int flags; /* gzip header method and flags (0 if zlib) */ - unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */ - unsigned long check; /* protected copy of check value */ - unsigned long total; /* protected copy of output count */ - gz_headerp head; /* where to save gzip header information */ - /* sliding window */ - unsigned wbits; /* log base 2 of requested window size */ - unsigned wsize; /* window size or zero if not using window */ - unsigned whave; /* valid bytes in the window */ - unsigned wnext; /* window write index */ - unsigned char FAR *window; /* allocated sliding window, if needed */ - /* bit accumulator */ - unsigned long hold; /* input bit accumulator */ - unsigned bits; /* number of bits in "in" */ - /* for string and stored block copying */ - unsigned length; /* literal or length of data to copy */ - unsigned offset; /* distance back to copy string from */ - /* for table and code decoding */ - unsigned extra; /* extra bits needed */ - /* fixed and dynamic code tables */ - code const FAR *lencode; /* starting table for length/literal codes */ - code const FAR *distcode; /* starting table for distance codes */ - unsigned lenbits; /* index bits for lencode */ - unsigned distbits; /* index bits for distcode */ - /* dynamic table building */ - unsigned ncode; /* number of code length code lengths */ - unsigned nlen; /* number of length code lengths */ - unsigned ndist; /* number of distance code lengths */ - unsigned have; /* number of code lengths in lens[] */ - code FAR *next; /* next available space in codes[] */ - unsigned short lens[320]; /* temporary storage for code lengths */ - unsigned short work[288]; /* work area for code table building */ - code codes[ENOUGH]; /* space for code tables */ - int sane; /* if false, allow invalid distance too far */ - int back; /* bits back of last unprocessed length/lit */ - unsigned was; /* initial length of match */ -}; diff --git a/vendor/libgit2/deps/zlib/inftrees.c b/vendor/libgit2/deps/zlib/inftrees.c deleted file mode 100644 index 11e9c52ac..000000000 --- a/vendor/libgit2/deps/zlib/inftrees.c +++ /dev/null @@ -1,330 +0,0 @@ -/* inftrees.c -- generate Huffman trees for efficient decoding - * Copyright (C) 1995-2010 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -#include "zutil.h" -#include "inftrees.h" - -#define MAXBITS 15 - -const char inflate_copyright[] = - " inflate 1.2.5 Copyright 1995-2010 Mark Adler "; -/* - If you use the zlib library in a product, an acknowledgment is welcome - in the documentation of your product. If for some reason you cannot - include such an acknowledgment, I would appreciate that you keep this - copyright string in the executable of your product. - */ - -/* - Build a set of tables to decode the provided canonical Huffman code. - The code lengths are lens[0..codes-1]. The result starts at *table, - whose indices are 0..2^bits-1. work is a writable array of at least - lens shorts, which is used as a work area. type is the type of code - to be generated, CODES, LENS, or DISTS. On return, zero is success, - -1 is an invalid code, and +1 means that ENOUGH isn't enough. table - on return points to the next available entry's address. bits is the - requested root table index bits, and on return it is the actual root - table index bits. It will differ if the request is greater than the - longest code or if it is less than the shortest code. - */ -int ZLIB_INTERNAL inflate_table(type, lens, codes, table, bits, work) -codetype type; -unsigned short FAR *lens; -unsigned codes; -code FAR * FAR *table; -unsigned FAR *bits; -unsigned short FAR *work; -{ - unsigned len; /* a code's length in bits */ - unsigned sym; /* index of code symbols */ - unsigned min, max; /* minimum and maximum code lengths */ - unsigned root; /* number of index bits for root table */ - unsigned curr; /* number of index bits for current table */ - unsigned drop; /* code bits to drop for sub-table */ - int left; /* number of prefix codes available */ - unsigned used; /* code entries in table used */ - unsigned huff; /* Huffman code */ - unsigned incr; /* for incrementing code, index */ - unsigned fill; /* index for replicating entries */ - unsigned low; /* low bits for current root entry */ - unsigned mask; /* mask for low root bits */ - code here; /* table entry for duplication */ - code FAR *next; /* next available space in table */ - const unsigned short FAR *base; /* base value table to use */ - const unsigned short FAR *extra; /* extra bits table to use */ - int end; /* use base and extra for symbol > end */ - unsigned short count[MAXBITS+1]; /* number of codes of each length */ - unsigned short offs[MAXBITS+1]; /* offsets in table for each length */ - static const unsigned short lbase[31] = { /* Length codes 257..285 base */ - 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, - 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0}; - static const unsigned short lext[31] = { /* Length codes 257..285 extra */ - 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18, - 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 73, 195}; - static const unsigned short dbase[32] = { /* Distance codes 0..29 base */ - 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, - 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, - 8193, 12289, 16385, 24577, 0, 0}; - static const unsigned short dext[32] = { /* Distance codes 0..29 extra */ - 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22, - 23, 23, 24, 24, 25, 25, 26, 26, 27, 27, - 28, 28, 29, 29, 64, 64}; - - /* - Process a set of code lengths to create a canonical Huffman code. The - code lengths are lens[0..codes-1]. Each length corresponds to the - symbols 0..codes-1. The Huffman code is generated by first sorting the - symbols by length from short to long, and retaining the symbol order - for codes with equal lengths. Then the code starts with all zero bits - for the first code of the shortest length, and the codes are integer - increments for the same length, and zeros are appended as the length - increases. For the deflate format, these bits are stored backwards - from their more natural integer increment ordering, and so when the - decoding tables are built in the large loop below, the integer codes - are incremented backwards. - - This routine assumes, but does not check, that all of the entries in - lens[] are in the range 0..MAXBITS. The caller must assure this. - 1..MAXBITS is interpreted as that code length. zero means that that - symbol does not occur in this code. - - The codes are sorted by computing a count of codes for each length, - creating from that a table of starting indices for each length in the - sorted table, and then entering the symbols in order in the sorted - table. The sorted table is work[], with that space being provided by - the caller. - - The length counts are used for other purposes as well, i.e. finding - the minimum and maximum length codes, determining if there are any - codes at all, checking for a valid set of lengths, and looking ahead - at length counts to determine sub-table sizes when building the - decoding tables. - */ - - /* accumulate lengths for codes (assumes lens[] all in 0..MAXBITS) */ - for (len = 0; len <= MAXBITS; len++) - count[len] = 0; - for (sym = 0; sym < codes; sym++) - count[lens[sym]]++; - - /* bound code lengths, force root to be within code lengths */ - root = *bits; - for (max = MAXBITS; max >= 1; max--) - if (count[max] != 0) break; - if (root > max) root = max; - if (max == 0) { /* no symbols to code at all */ - here.op = (unsigned char)64; /* invalid code marker */ - here.bits = (unsigned char)1; - here.val = (unsigned short)0; - *(*table)++ = here; /* make a table to force an error */ - *(*table)++ = here; - *bits = 1; - return 0; /* no symbols, but wait for decoding to report error */ - } - for (min = 1; min < max; min++) - if (count[min] != 0) break; - if (root < min) root = min; - - /* check for an over-subscribed or incomplete set of lengths */ - left = 1; - for (len = 1; len <= MAXBITS; len++) { - left <<= 1; - left -= count[len]; - if (left < 0) return -1; /* over-subscribed */ - } - if (left > 0 && (type == CODES || max != 1)) - return -1; /* incomplete set */ - - /* generate offsets into symbol table for each length for sorting */ - offs[1] = 0; - for (len = 1; len < MAXBITS; len++) - offs[len + 1] = offs[len] + count[len]; - - /* sort symbols by length, by symbol order within each length */ - for (sym = 0; sym < codes; sym++) - if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym; - - /* - Create and fill in decoding tables. In this loop, the table being - filled is at next and has curr index bits. The code being used is huff - with length len. That code is converted to an index by dropping drop - bits off of the bottom. For codes where len is less than drop + curr, - those top drop + curr - len bits are incremented through all values to - fill the table with replicated entries. - - root is the number of index bits for the root table. When len exceeds - root, sub-tables are created pointed to by the root entry with an index - of the low root bits of huff. This is saved in low to check for when a - new sub-table should be started. drop is zero when the root table is - being filled, and drop is root when sub-tables are being filled. - - When a new sub-table is needed, it is necessary to look ahead in the - code lengths to determine what size sub-table is needed. The length - counts are used for this, and so count[] is decremented as codes are - entered in the tables. - - used keeps track of how many table entries have been allocated from the - provided *table space. It is checked for LENS and DIST tables against - the constants ENOUGH_LENS and ENOUGH_DISTS to guard against changes in - the initial root table size constants. See the comments in inftrees.h - for more information. - - sym increments through all symbols, and the loop terminates when - all codes of length max, i.e. all codes, have been processed. This - routine permits incomplete codes, so another loop after this one fills - in the rest of the decoding tables with invalid code markers. - */ - - /* set up for code type */ - switch (type) { - case CODES: - base = extra = work; /* dummy value--not used */ - end = 19; - break; - case LENS: - base = lbase; - base -= 257; - extra = lext; - extra -= 257; - end = 256; - break; - default: /* DISTS */ - base = dbase; - extra = dext; - end = -1; - } - - /* initialize state for loop */ - huff = 0; /* starting code */ - sym = 0; /* starting code symbol */ - len = min; /* starting code length */ - next = *table; /* current table to fill in */ - curr = root; /* current table index bits */ - drop = 0; /* current bits to drop from code for index */ - low = (unsigned)(-1); /* trigger new sub-table when len > root */ - used = 1U << root; /* use root table entries */ - mask = used - 1; /* mask for comparing low */ - - /* check available table space */ - if ((type == LENS && used >= ENOUGH_LENS) || - (type == DISTS && used >= ENOUGH_DISTS)) - return 1; - - /* process all codes and make table entries */ - for (;;) { - /* create table entry */ - here.bits = (unsigned char)(len - drop); - if ((int)(work[sym]) < end) { - here.op = (unsigned char)0; - here.val = work[sym]; - } - else if ((int)(work[sym]) > end) { - here.op = (unsigned char)(extra[work[sym]]); - here.val = base[work[sym]]; - } - else { - here.op = (unsigned char)(32 + 64); /* end of block */ - here.val = 0; - } - - /* replicate for those indices with low len bits equal to huff */ - incr = 1U << (len - drop); - fill = 1U << curr; - min = fill; /* save offset to next table */ - do { - fill -= incr; - next[(huff >> drop) + fill] = here; - } while (fill != 0); - - /* backwards increment the len-bit code huff */ - incr = 1U << (len - 1); - while (huff & incr) - incr >>= 1; - if (incr != 0) { - huff &= incr - 1; - huff += incr; - } - else - huff = 0; - - /* go to next symbol, update count, len */ - sym++; - if (--(count[len]) == 0) { - if (len == max) break; - len = lens[work[sym]]; - } - - /* create new sub-table if needed */ - if (len > root && (huff & mask) != low) { - /* if first time, transition to sub-tables */ - if (drop == 0) - drop = root; - - /* increment past last table */ - next += min; /* here min is 1 << curr */ - - /* determine length of next table */ - curr = len - drop; - left = (int)(1 << curr); - while (curr + drop < max) { - left -= count[curr + drop]; - if (left <= 0) break; - curr++; - left <<= 1; - } - - /* check for enough space */ - used += 1U << curr; - if ((type == LENS && used >= ENOUGH_LENS) || - (type == DISTS && used >= ENOUGH_DISTS)) - return 1; - - /* point entry in root table to sub-table */ - low = huff & mask; - (*table)[low].op = (unsigned char)curr; - (*table)[low].bits = (unsigned char)root; - (*table)[low].val = (unsigned short)(next - *table); - } - } - - /* - Fill in rest of table for incomplete codes. This loop is similar to the - loop above in incrementing huff for table indices. It is assumed that - len is equal to curr + drop, so there is no loop needed to increment - through high index bits. When the current sub-table is filled, the loop - drops back to the root table to fill in any remaining entries there. - */ - here.op = (unsigned char)64; /* invalid code marker */ - here.bits = (unsigned char)(len - drop); - here.val = (unsigned short)0; - while (huff != 0) { - /* when done with sub-table, drop back to root table */ - if (drop != 0 && (huff & mask) != low) { - drop = 0; - len = root; - next = *table; - here.bits = (unsigned char)len; - } - - /* put invalid code marker in table */ - next[huff >> drop] = here; - - /* backwards increment the len-bit code huff */ - incr = 1U << (len - 1); - while (huff & incr) - incr >>= 1; - if (incr != 0) { - huff &= incr - 1; - huff += incr; - } - else - huff = 0; - } - - /* set return parameters */ - *table += used; - *bits = root; - return 0; -} diff --git a/vendor/libgit2/deps/zlib/inftrees.h b/vendor/libgit2/deps/zlib/inftrees.h deleted file mode 100644 index baa53a0b1..000000000 --- a/vendor/libgit2/deps/zlib/inftrees.h +++ /dev/null @@ -1,62 +0,0 @@ -/* inftrees.h -- header to use inftrees.c - * Copyright (C) 1995-2005, 2010 Mark Adler - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* Structure for decoding tables. Each entry provides either the - information needed to do the operation requested by the code that - indexed that table entry, or it provides a pointer to another - table that indexes more bits of the code. op indicates whether - the entry is a pointer to another table, a literal, a length or - distance, an end-of-block, or an invalid code. For a table - pointer, the low four bits of op is the number of index bits of - that table. For a length or distance, the low four bits of op - is the number of extra bits to get after the code. bits is - the number of bits in this code or part of the code to drop off - of the bit buffer. val is the actual byte to output in the case - of a literal, the base length or distance, or the offset from - the current table to the next table. Each entry is four bytes. */ -typedef struct { - unsigned char op; /* operation, extra bits, table bits */ - unsigned char bits; /* bits in this part of the code */ - unsigned short val; /* offset in table or code value */ -} code; - -/* op values as set by inflate_table(): - 00000000 - literal - 0000tttt - table link, tttt != 0 is the number of table index bits - 0001eeee - length or distance, eeee is the number of extra bits - 01100000 - end of block - 01000000 - invalid code - */ - -/* Maximum size of the dynamic table. The maximum number of code structures is - 1444, which is the sum of 852 for literal/length codes and 592 for distance - codes. These values were found by exhaustive searches using the program - examples/enough.c found in the zlib distribtution. The arguments to that - program are the number of symbols, the initial root table size, and the - maximum bit length of a code. "enough 286 9 15" for literal/length codes - returns returns 852, and "enough 30 6 15" for distance codes returns 592. - The initial root table size (9 or 6) is found in the fifth argument of the - inflate_table() calls in inflate.c and infback.c. If the root table size is - changed, then these maximum sizes would be need to be recalculated and - updated. */ -#define ENOUGH_LENS 852 -#define ENOUGH_DISTS 592 -#define ENOUGH (ENOUGH_LENS+ENOUGH_DISTS) - -/* Type of code to build for inflate_table() */ -typedef enum { - CODES, - LENS, - DISTS -} codetype; - -int ZLIB_INTERNAL inflate_table OF((codetype type, unsigned short FAR *lens, - unsigned codes, code FAR * FAR *table, - unsigned FAR *bits, unsigned short FAR *work)); diff --git a/vendor/libgit2/deps/zlib/trees.c b/vendor/libgit2/deps/zlib/trees.c deleted file mode 100644 index 3e9a138c7..000000000 --- a/vendor/libgit2/deps/zlib/trees.c +++ /dev/null @@ -1,1244 +0,0 @@ -/* trees.c -- output deflated data using Huffman coding - * Copyright (C) 1995-2010 Jean-loup Gailly - * detect_data_type() function provided freely by Cosmin Truta, 2006 - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* - * ALGORITHM - * - * The "deflation" process uses several Huffman trees. The more - * common source values are represented by shorter bit sequences. - * - * Each code tree is stored in a compressed form which is itself - * a Huffman encoding of the lengths of all the code strings (in - * ascending order by source values). The actual code strings are - * reconstructed from the lengths in the inflate process, as described - * in the deflate specification. - * - * REFERENCES - * - * Deutsch, L.P.,"'Deflate' Compressed Data Format Specification". - * Available in ftp.uu.net:/pub/archiving/zip/doc/deflate-1.1.doc - * - * Storer, James A. - * Data Compression: Methods and Theory, pp. 49-50. - * Computer Science Press, 1988. ISBN 0-7167-8156-5. - * - * Sedgewick, R. - * Algorithms, p290. - * Addison-Wesley, 1983. ISBN 0-201-06672-6. - */ - -/* @(#) $Id$ */ - -/* #define GEN_TREES_H */ - -#include "deflate.h" - -#ifdef DEBUG -# include -#endif - -/* =========================================================================== - * Constants - */ - -#define MAX_BL_BITS 7 -/* Bit length codes must not exceed MAX_BL_BITS bits */ - -#define END_BLOCK 256 -/* end of block literal code */ - -#define REP_3_6 16 -/* repeat previous bit length 3-6 times (2 bits of repeat count) */ - -#define REPZ_3_10 17 -/* repeat a zero length 3-10 times (3 bits of repeat count) */ - -#define REPZ_11_138 18 -/* repeat a zero length 11-138 times (7 bits of repeat count) */ - -local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */ - = {0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0}; - -local const int extra_dbits[D_CODES] /* extra bits for each distance code */ - = {0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13}; - -local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */ - = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7}; - -local const uch bl_order[BL_CODES] - = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15}; -/* The lengths of the bit length codes are sent in order of decreasing - * probability, to avoid transmitting the lengths for unused bit length codes. - */ - -#define Buf_size (8 * 2*sizeof(char)) -/* Number of bits used within bi_buf. (bi_buf might be implemented on - * more than 16 bits on some systems.) - */ - -/* =========================================================================== - * Local data. These are initialized only once. - */ - -#define DIST_CODE_LEN 512 /* see definition of array dist_code below */ - -#if defined(GEN_TREES_H) || !defined(STDC) -/* non ANSI compilers may not accept trees.h */ - -local ct_data static_ltree[L_CODES+2]; -/* The static literal tree. Since the bit lengths are imposed, there is no - * need for the L_CODES extra codes used during heap construction. However - * The codes 286 and 287 are needed to build a canonical tree (see _tr_init - * below). - */ - -local ct_data static_dtree[D_CODES]; -/* The static distance tree. (Actually a trivial tree since all codes use - * 5 bits.) - */ - -uch _dist_code[DIST_CODE_LEN]; -/* Distance codes. The first 256 values correspond to the distances - * 3 .. 258, the last 256 values correspond to the top 8 bits of - * the 15 bit distances. - */ - -uch _length_code[MAX_MATCH-MIN_MATCH+1]; -/* length code for each normalized match length (0 == MIN_MATCH) */ - -local int base_length[LENGTH_CODES]; -/* First normalized length for each code (0 = MIN_MATCH) */ - -local int base_dist[D_CODES]; -/* First normalized distance for each code (0 = distance of 1) */ - -#else -# include "trees.h" -#endif /* GEN_TREES_H */ - -struct static_tree_desc_s { - const ct_data *static_tree; /* static tree or NULL */ - const intf *extra_bits; /* extra bits for each code or NULL */ - int extra_base; /* base index for extra_bits */ - int elems; /* max number of elements in the tree */ - int max_length; /* max bit length for the codes */ -}; - -local static_tree_desc static_l_desc = -{static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS}; - -local static_tree_desc static_d_desc = -{static_dtree, extra_dbits, 0, D_CODES, MAX_BITS}; - -local static_tree_desc static_bl_desc = -{(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS}; - -/* =========================================================================== - * Local (static) routines in this file. - */ - -local void tr_static_init OF((void)); -local void init_block OF((deflate_state *s)); -local void pqdownheap OF((deflate_state *s, ct_data *tree, int k)); -local void gen_bitlen OF((deflate_state *s, tree_desc *desc)); -local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count)); -local void build_tree OF((deflate_state *s, tree_desc *desc)); -local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local void send_tree OF((deflate_state *s, ct_data *tree, int max_code)); -local int build_bl_tree OF((deflate_state *s)); -local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes, - int blcodes)); -local void compress_block OF((deflate_state *s, ct_data *ltree, - ct_data *dtree)); -local int detect_data_type OF((deflate_state *s)); -local unsigned bi_reverse OF((unsigned value, int length)); -local void bi_windup OF((deflate_state *s)); -local void bi_flush OF((deflate_state *s)); -local void copy_block OF((deflate_state *s, charf *buf, unsigned len, - int header)); - -#ifdef GEN_TREES_H -local void gen_trees_header OF((void)); -#endif - -#ifndef DEBUG -# define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len) - /* Send a code of the given tree. c and tree must not have side effects */ - -#else /* DEBUG */ -# define send_code(s, c, tree) \ - { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \ - send_bits(s, tree[c].Code, tree[c].Len); } -#endif - -/* =========================================================================== - * Output a short LSB first on the stream. - * IN assertion: there is enough room in pendingBuf. - */ -#define put_short(s, w) { \ - put_byte(s, (uch)((w) & 0xff)); \ - put_byte(s, (uch)((ush)(w) >> 8)); \ -} - -/* =========================================================================== - * Send a value on a given number of bits. - * IN assertion: length <= 16 and value fits in length bits. - */ -#ifdef DEBUG -local void send_bits OF((deflate_state *s, int value, int length)); - -local void send_bits(s, value, length) - deflate_state *s; - int value; /* value to send */ - int length; /* number of bits */ -{ - Tracevv((stderr," l %2d v %4x ", length, value)); - Assert(length > 0 && length <= 15, "invalid length"); - s->bits_sent += (ulg)length; - - /* If not enough room in bi_buf, use (valid) bits from bi_buf and - * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid)) - * unused bits in value. - */ - if (s->bi_valid > (int)Buf_size - length) { - s->bi_buf |= (ush)value << s->bi_valid; - put_short(s, s->bi_buf); - s->bi_buf = (ush)value >> (Buf_size - s->bi_valid); - s->bi_valid += length - Buf_size; - } else { - s->bi_buf |= (ush)value << s->bi_valid; - s->bi_valid += length; - } -} -#else /* !DEBUG */ - -#define send_bits(s, value, length) \ -{ int len = length;\ - if (s->bi_valid > (int)Buf_size - len) {\ - int val = value;\ - s->bi_buf |= (ush)val << s->bi_valid;\ - put_short(s, s->bi_buf);\ - s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\ - s->bi_valid += len - Buf_size;\ - } else {\ - s->bi_buf |= (ush)(value) << s->bi_valid;\ - s->bi_valid += len;\ - }\ -} -#endif /* DEBUG */ - - -/* the arguments must not have side effects */ - -/* =========================================================================== - * Initialize the various 'constant' tables. - */ -local void tr_static_init() -{ -#if defined(GEN_TREES_H) || !defined(STDC) - static int static_init_done = 0; - int n; /* iterates over tree elements */ - int bits; /* bit counter */ - int length; /* length value */ - int code; /* code value */ - int dist; /* distance index */ - ush bl_count[MAX_BITS+1]; - /* number of codes at each bit length for an optimal tree */ - - if (static_init_done) return; - - /* For some embedded targets, global variables are not initialized: */ -#ifdef NO_INIT_GLOBAL_POINTERS - static_l_desc.static_tree = static_ltree; - static_l_desc.extra_bits = extra_lbits; - static_d_desc.static_tree = static_dtree; - static_d_desc.extra_bits = extra_dbits; - static_bl_desc.extra_bits = extra_blbits; -#endif - - /* Initialize the mapping length (0..255) -> length code (0..28) */ - length = 0; - for (code = 0; code < LENGTH_CODES-1; code++) { - base_length[code] = length; - for (n = 0; n < (1< dist code (0..29) */ - dist = 0; - for (code = 0 ; code < 16; code++) { - base_dist[code] = dist; - for (n = 0; n < (1<>= 7; /* from now on, all distances are divided by 128 */ - for ( ; code < D_CODES; code++) { - base_dist[code] = dist << 7; - for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) { - _dist_code[256 + dist++] = (uch)code; - } - } - Assert (dist == 256, "tr_static_init: 256+dist != 512"); - - /* Construct the codes of the static literal tree */ - for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0; - n = 0; - while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++; - while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++; - while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++; - while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++; - /* Codes 286 and 287 do not exist, but we must include them in the - * tree construction to get a canonical Huffman tree (longest code - * all ones) - */ - gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count); - - /* The static distance tree is trivial: */ - for (n = 0; n < D_CODES; n++) { - static_dtree[n].Len = 5; - static_dtree[n].Code = bi_reverse((unsigned)n, 5); - } - static_init_done = 1; - -# ifdef GEN_TREES_H - gen_trees_header(); -# endif -#endif /* defined(GEN_TREES_H) || !defined(STDC) */ -} - -/* =========================================================================== - * Genererate the file trees.h describing the static trees. - */ -#ifdef GEN_TREES_H -# ifndef DEBUG -# include -# endif - -# define SEPARATOR(i, last, width) \ - ((i) == (last)? "\n};\n\n" : \ - ((i) % (width) == (width)-1 ? ",\n" : ", ")) - -void gen_trees_header() -{ - FILE *header = fopen("trees.h", "w"); - int i; - - Assert (header != NULL, "Can't open trees.h"); - fprintf(header, - "/* header created automatically with -DGEN_TREES_H */\n\n"); - - fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n"); - for (i = 0; i < L_CODES+2; i++) { - fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code, - static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5)); - } - - fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n"); - for (i = 0; i < D_CODES; i++) { - fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code, - static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5)); - } - - fprintf(header, "const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = {\n"); - for (i = 0; i < DIST_CODE_LEN; i++) { - fprintf(header, "%2u%s", _dist_code[i], - SEPARATOR(i, DIST_CODE_LEN-1, 20)); - } - - fprintf(header, - "const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= {\n"); - for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) { - fprintf(header, "%2u%s", _length_code[i], - SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20)); - } - - fprintf(header, "local const int base_length[LENGTH_CODES] = {\n"); - for (i = 0; i < LENGTH_CODES; i++) { - fprintf(header, "%1u%s", base_length[i], - SEPARATOR(i, LENGTH_CODES-1, 20)); - } - - fprintf(header, "local const int base_dist[D_CODES] = {\n"); - for (i = 0; i < D_CODES; i++) { - fprintf(header, "%5u%s", base_dist[i], - SEPARATOR(i, D_CODES-1, 10)); - } - - fclose(header); -} -#endif /* GEN_TREES_H */ - -/* =========================================================================== - * Initialize the tree data structures for a new zlib stream. - */ -void ZLIB_INTERNAL _tr_init(s) - deflate_state *s; -{ - tr_static_init(); - - s->l_desc.dyn_tree = s->dyn_ltree; - s->l_desc.stat_desc = &static_l_desc; - - s->d_desc.dyn_tree = s->dyn_dtree; - s->d_desc.stat_desc = &static_d_desc; - - s->bl_desc.dyn_tree = s->bl_tree; - s->bl_desc.stat_desc = &static_bl_desc; - - s->bi_buf = 0; - s->bi_valid = 0; - s->last_eob_len = 8; /* enough lookahead for inflate */ -#ifdef DEBUG - s->compressed_len = 0L; - s->bits_sent = 0L; -#endif - - /* Initialize the first block of the first file: */ - init_block(s); -} - -/* =========================================================================== - * Initialize a new block. - */ -local void init_block(s) - deflate_state *s; -{ - int n; /* iterates over tree elements */ - - /* Initialize the trees. */ - for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0; - for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0; - for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0; - - s->dyn_ltree[END_BLOCK].Freq = 1; - s->opt_len = s->static_len = 0L; - s->last_lit = s->matches = 0; -} - -#define SMALLEST 1 -/* Index within the heap array of least frequent node in the Huffman tree */ - - -/* =========================================================================== - * Remove the smallest element from the heap and recreate the heap with - * one less element. Updates heap and heap_len. - */ -#define pqremove(s, tree, top) \ -{\ - top = s->heap[SMALLEST]; \ - s->heap[SMALLEST] = s->heap[s->heap_len--]; \ - pqdownheap(s, tree, SMALLEST); \ -} - -/* =========================================================================== - * Compares to subtrees, using the tree depth as tie breaker when - * the subtrees have equal frequency. This minimizes the worst case length. - */ -#define smaller(tree, n, m, depth) \ - (tree[n].Freq < tree[m].Freq || \ - (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) - -/* =========================================================================== - * Restore the heap property by moving down the tree starting at node k, - * exchanging a node with the smallest of its two sons if necessary, stopping - * when the heap property is re-established (each father smaller than its - * two sons). - */ -local void pqdownheap(s, tree, k) - deflate_state *s; - ct_data *tree; /* the tree to restore */ - int k; /* node to move down */ -{ - int v = s->heap[k]; - int j = k << 1; /* left son of k */ - while (j <= s->heap_len) { - /* Set j to the smallest of the two sons: */ - if (j < s->heap_len && - smaller(tree, s->heap[j+1], s->heap[j], s->depth)) { - j++; - } - /* Exit if v is smaller than both sons */ - if (smaller(tree, v, s->heap[j], s->depth)) break; - - /* Exchange v with the smallest son */ - s->heap[k] = s->heap[j]; k = j; - - /* And continue down the tree, setting j to the left son of k */ - j <<= 1; - } - s->heap[k] = v; -} - -/* =========================================================================== - * Compute the optimal bit lengths for a tree and update the total bit length - * for the current block. - * IN assertion: the fields freq and dad are set, heap[heap_max] and - * above are the tree nodes sorted by increasing frequency. - * OUT assertions: the field len is set to the optimal bit length, the - * array bl_count contains the frequencies for each bit length. - * The length opt_len is updated; static_len is also updated if stree is - * not null. - */ -local void gen_bitlen(s, desc) - deflate_state *s; - tree_desc *desc; /* the tree descriptor */ -{ - ct_data *tree = desc->dyn_tree; - int max_code = desc->max_code; - const ct_data *stree = desc->stat_desc->static_tree; - const intf *extra = desc->stat_desc->extra_bits; - int base = desc->stat_desc->extra_base; - int max_length = desc->stat_desc->max_length; - int h; /* heap index */ - int n, m; /* iterate over the tree elements */ - int bits; /* bit length */ - int xbits; /* extra bits */ - ush f; /* frequency */ - int overflow = 0; /* number of elements with bit length too large */ - - for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0; - - /* In a first pass, compute the optimal bit lengths (which may - * overflow in the case of the bit length tree). - */ - tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */ - - for (h = s->heap_max+1; h < HEAP_SIZE; h++) { - n = s->heap[h]; - bits = tree[tree[n].Dad].Len + 1; - if (bits > max_length) bits = max_length, overflow++; - tree[n].Len = (ush)bits; - /* We overwrite tree[n].Dad which is no longer needed */ - - if (n > max_code) continue; /* not a leaf node */ - - s->bl_count[bits]++; - xbits = 0; - if (n >= base) xbits = extra[n-base]; - f = tree[n].Freq; - s->opt_len += (ulg)f * (bits + xbits); - if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits); - } - if (overflow == 0) return; - - Trace((stderr,"\nbit length overflow\n")); - /* This happens for example on obj2 and pic of the Calgary corpus */ - - /* Find the first bit length which could increase: */ - do { - bits = max_length-1; - while (s->bl_count[bits] == 0) bits--; - s->bl_count[bits]--; /* move one leaf down the tree */ - s->bl_count[bits+1] += 2; /* move one overflow item as its brother */ - s->bl_count[max_length]--; - /* The brother of the overflow item also moves one step up, - * but this does not affect bl_count[max_length] - */ - overflow -= 2; - } while (overflow > 0); - - /* Now recompute all bit lengths, scanning in increasing frequency. - * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all - * lengths instead of fixing only the wrong ones. This idea is taken - * from 'ar' written by Haruhiko Okumura.) - */ - for (bits = max_length; bits != 0; bits--) { - n = s->bl_count[bits]; - while (n != 0) { - m = s->heap[--h]; - if (m > max_code) continue; - if ((unsigned) tree[m].Len != (unsigned) bits) { - Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits)); - s->opt_len += ((long)bits - (long)tree[m].Len) - *(long)tree[m].Freq; - tree[m].Len = (ush)bits; - } - n--; - } - } -} - -/* =========================================================================== - * Generate the codes for a given tree and bit counts (which need not be - * optimal). - * IN assertion: the array bl_count contains the bit length statistics for - * the given tree and the field len is set for all tree elements. - * OUT assertion: the field code is set for all tree elements of non - * zero code length. - */ -local void gen_codes (tree, max_code, bl_count) - ct_data *tree; /* the tree to decorate */ - int max_code; /* largest code with non zero frequency */ - ushf *bl_count; /* number of codes at each bit length */ -{ - ush next_code[MAX_BITS+1]; /* next code value for each bit length */ - ush code = 0; /* running code value */ - int bits; /* bit index */ - int n; /* code index */ - - /* The distribution counts are first used to generate the code values - * without bit reversal. - */ - for (bits = 1; bits <= MAX_BITS; bits++) { - next_code[bits] = code = (code + bl_count[bits-1]) << 1; - } - /* Check that the bit counts in bl_count are consistent. The last code - * must be all ones. - */ - Assert (code + bl_count[MAX_BITS]-1 == (1<dyn_tree; - const ct_data *stree = desc->stat_desc->static_tree; - int elems = desc->stat_desc->elems; - int n, m; /* iterate over heap elements */ - int max_code = -1; /* largest code with non zero frequency */ - int node; /* new node being created */ - - /* Construct the initial heap, with least frequent element in - * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. - * heap[0] is not used. - */ - s->heap_len = 0, s->heap_max = HEAP_SIZE; - - for (n = 0; n < elems; n++) { - if (tree[n].Freq != 0) { - s->heap[++(s->heap_len)] = max_code = n; - s->depth[n] = 0; - } else { - tree[n].Len = 0; - } - } - - /* The pkzip format requires that at least one distance code exists, - * and that at least one bit should be sent even if there is only one - * possible code. So to avoid special checks later on we force at least - * two codes of non zero frequency. - */ - while (s->heap_len < 2) { - node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0); - tree[node].Freq = 1; - s->depth[node] = 0; - s->opt_len--; if (stree) s->static_len -= stree[node].Len; - /* node is 0 or 1 so it does not have extra bits */ - } - desc->max_code = max_code; - - /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, - * establish sub-heaps of increasing lengths: - */ - for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n); - - /* Construct the Huffman tree by repeatedly combining the least two - * frequent nodes. - */ - node = elems; /* next internal node of the tree */ - do { - pqremove(s, tree, n); /* n = node of least frequency */ - m = s->heap[SMALLEST]; /* m = node of next least frequency */ - - s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */ - s->heap[--(s->heap_max)] = m; - - /* Create a new node father of n and m */ - tree[node].Freq = tree[n].Freq + tree[m].Freq; - s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ? - s->depth[n] : s->depth[m]) + 1); - tree[n].Dad = tree[m].Dad = (ush)node; -#ifdef DUMP_BL_TREE - if (tree == s->bl_tree) { - fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)", - node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq); - } -#endif - /* and insert the new node in the heap */ - s->heap[SMALLEST] = node++; - pqdownheap(s, tree, SMALLEST); - - } while (s->heap_len >= 2); - - s->heap[--(s->heap_max)] = s->heap[SMALLEST]; - - /* At this point, the fields freq and dad are set. We can now - * generate the bit lengths. - */ - gen_bitlen(s, (tree_desc *)desc); - - /* The field len is now set, we can generate the bit codes */ - gen_codes ((ct_data *)tree, max_code, s->bl_count); -} - -/* =========================================================================== - * Scan a literal or distance tree to determine the frequencies of the codes - * in the bit length tree. - */ -local void scan_tree (s, tree, max_code) - deflate_state *s; - ct_data *tree; /* the tree to be scanned */ - int max_code; /* and its largest code of non zero frequency */ -{ - int n; /* iterates over all tree elements */ - int prevlen = -1; /* last emitted length */ - int curlen; /* length of current code */ - int nextlen = tree[0].Len; /* length of next code */ - int count = 0; /* repeat count of the current code */ - int max_count = 7; /* max repeat count */ - int min_count = 4; /* min repeat count */ - - if (nextlen == 0) max_count = 138, min_count = 3; - tree[max_code+1].Len = (ush)0xffff; /* guard */ - - for (n = 0; n <= max_code; n++) { - curlen = nextlen; nextlen = tree[n+1].Len; - if (++count < max_count && curlen == nextlen) { - continue; - } else if (count < min_count) { - s->bl_tree[curlen].Freq += (ush)count; - } else if (curlen != 0) { - if (curlen != prevlen) s->bl_tree[curlen].Freq++; - s->bl_tree[REP_3_6].Freq++; - } else if (count <= 10) { - s->bl_tree[REPZ_3_10].Freq++; - } else { - s->bl_tree[REPZ_11_138].Freq++; - } - count = 0; prevlen = curlen; - if (nextlen == 0) { - max_count = 138, min_count = 3; - } else if (curlen == nextlen) { - max_count = 6, min_count = 3; - } else { - max_count = 7, min_count = 4; - } - } -} - -/* =========================================================================== - * Send a literal or distance tree in compressed form, using the codes in - * bl_tree. - */ -local void send_tree (s, tree, max_code) - deflate_state *s; - ct_data *tree; /* the tree to be scanned */ - int max_code; /* and its largest code of non zero frequency */ -{ - int n; /* iterates over all tree elements */ - int prevlen = -1; /* last emitted length */ - int curlen; /* length of current code */ - int nextlen = tree[0].Len; /* length of next code */ - int count = 0; /* repeat count of the current code */ - int max_count = 7; /* max repeat count */ - int min_count = 4; /* min repeat count */ - - /* tree[max_code+1].Len = -1; */ /* guard already set */ - if (nextlen == 0) max_count = 138, min_count = 3; - - for (n = 0; n <= max_code; n++) { - curlen = nextlen; nextlen = tree[n+1].Len; - if (++count < max_count && curlen == nextlen) { - continue; - } else if (count < min_count) { - do { send_code(s, curlen, s->bl_tree); } while (--count != 0); - - } else if (curlen != 0) { - if (curlen != prevlen) { - send_code(s, curlen, s->bl_tree); count--; - } - Assert(count >= 3 && count <= 6, " 3_6?"); - send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2); - - } else if (count <= 10) { - send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3); - - } else { - send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7); - } - count = 0; prevlen = curlen; - if (nextlen == 0) { - max_count = 138, min_count = 3; - } else if (curlen == nextlen) { - max_count = 6, min_count = 3; - } else { - max_count = 7, min_count = 4; - } - } -} - -/* =========================================================================== - * Construct the Huffman tree for the bit lengths and return the index in - * bl_order of the last bit length code to send. - */ -local int build_bl_tree(s) - deflate_state *s; -{ - int max_blindex; /* index of last bit length code of non zero freq */ - - /* Determine the bit length frequencies for literal and distance trees */ - scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code); - scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code); - - /* Build the bit length tree: */ - build_tree(s, (tree_desc *)(&(s->bl_desc))); - /* opt_len now includes the length of the tree representations, except - * the lengths of the bit lengths codes and the 5+5+4 bits for the counts. - */ - - /* Determine the number of bit length codes to send. The pkzip format - * requires that at least 4 bit length codes be sent. (appnote.txt says - * 3 but the actual value used is 4.) - */ - for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) { - if (s->bl_tree[bl_order[max_blindex]].Len != 0) break; - } - /* Update opt_len to include the bit length tree and counts */ - s->opt_len += 3*(max_blindex+1) + 5+5+4; - Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", - s->opt_len, s->static_len)); - - return max_blindex; -} - -/* =========================================================================== - * Send the header for a block using dynamic Huffman trees: the counts, the - * lengths of the bit length codes, the literal tree and the distance tree. - * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. - */ -local void send_all_trees(s, lcodes, dcodes, blcodes) - deflate_state *s; - int lcodes, dcodes, blcodes; /* number of codes for each tree */ -{ - int rank; /* index in bl_order */ - - Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); - Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES, - "too many codes"); - Tracev((stderr, "\nbl counts: ")); - send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */ - send_bits(s, dcodes-1, 5); - send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */ - for (rank = 0; rank < blcodes; rank++) { - Tracev((stderr, "\nbl code %2d ", bl_order[rank])); - send_bits(s, s->bl_tree[bl_order[rank]].Len, 3); - } - Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent)); - - send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */ - Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent)); - - send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */ - Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent)); -} - -/* =========================================================================== - * Send a stored block - */ -void ZLIB_INTERNAL _tr_stored_block(s, buf, stored_len, last) - deflate_state *s; - charf *buf; /* input block */ - ulg stored_len; /* length of input block */ - int last; /* one if this is the last block for a file */ -{ - send_bits(s, (STORED_BLOCK<<1)+last, 3); /* send block type */ -#ifdef DEBUG - s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L; - s->compressed_len += (stored_len + 4) << 3; -#endif - copy_block(s, buf, (unsigned)stored_len, 1); /* with header */ -} - -/* =========================================================================== - * Send one empty static block to give enough lookahead for inflate. - * This takes 10 bits, of which 7 may remain in the bit buffer. - * The current inflate code requires 9 bits of lookahead. If the - * last two codes for the previous block (real code plus EOB) were coded - * on 5 bits or less, inflate may have only 5+3 bits of lookahead to decode - * the last real code. In this case we send two empty static blocks instead - * of one. (There are no problems if the previous block is stored or fixed.) - * To simplify the code, we assume the worst case of last real code encoded - * on one bit only. - */ -void ZLIB_INTERNAL _tr_align(s) - deflate_state *s; -{ - send_bits(s, STATIC_TREES<<1, 3); - send_code(s, END_BLOCK, static_ltree); -#ifdef DEBUG - s->compressed_len += 10L; /* 3 for block type, 7 for EOB */ -#endif - bi_flush(s); - /* Of the 10 bits for the empty block, we have already sent - * (10 - bi_valid) bits. The lookahead for the last real code (before - * the EOB of the previous block) was thus at least one plus the length - * of the EOB plus what we have just sent of the empty static block. - */ - if (1 + s->last_eob_len + 10 - s->bi_valid < 9) { - send_bits(s, STATIC_TREES<<1, 3); - send_code(s, END_BLOCK, static_ltree); -#ifdef DEBUG - s->compressed_len += 10L; -#endif - bi_flush(s); - } - s->last_eob_len = 7; -} - -/* =========================================================================== - * Determine the best encoding for the current block: dynamic trees, static - * trees or store, and output the encoded block to the zip file. - */ -void ZLIB_INTERNAL _tr_flush_block(s, buf, stored_len, last) - deflate_state *s; - charf *buf; /* input block, or NULL if too old */ - ulg stored_len; /* length of input block */ - int last; /* one if this is the last block for a file */ -{ - ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ - int max_blindex = 0; /* index of last bit length code of non zero freq */ - - /* Build the Huffman trees unless a stored block is forced */ - if (s->level > 0) { - - /* Check if the file is binary or text */ - if (s->strm->data_type == Z_UNKNOWN) - s->strm->data_type = detect_data_type(s); - - /* Construct the literal and distance trees */ - build_tree(s, (tree_desc *)(&(s->l_desc))); - Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len, - s->static_len)); - - build_tree(s, (tree_desc *)(&(s->d_desc))); - Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len, - s->static_len)); - /* At this point, opt_len and static_len are the total bit lengths of - * the compressed block data, excluding the tree representations. - */ - - /* Build the bit length tree for the above two trees, and get the index - * in bl_order of the last bit length code to send. - */ - max_blindex = build_bl_tree(s); - - /* Determine the best encoding. Compute the block lengths in bytes. */ - opt_lenb = (s->opt_len+3+7)>>3; - static_lenb = (s->static_len+3+7)>>3; - - Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ", - opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len, - s->last_lit)); - - if (static_lenb <= opt_lenb) opt_lenb = static_lenb; - - } else { - Assert(buf != (char*)0, "lost buf"); - opt_lenb = static_lenb = stored_len + 5; /* force a stored block */ - } - -#ifdef FORCE_STORED - if (buf != (char*)0) { /* force stored block */ -#else - if (stored_len+4 <= opt_lenb && buf != (char*)0) { - /* 4: two words for the lengths */ -#endif - /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. - * Otherwise we can't have processed more than WSIZE input bytes since - * the last block flush, because compression would have been - * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to - * transform a block into a stored block. - */ - _tr_stored_block(s, buf, stored_len, last); - -#ifdef FORCE_STATIC - } else if (static_lenb >= 0) { /* force static trees */ -#else - } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) { -#endif - send_bits(s, (STATIC_TREES<<1)+last, 3); - compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree); -#ifdef DEBUG - s->compressed_len += 3 + s->static_len; -#endif - } else { - send_bits(s, (DYN_TREES<<1)+last, 3); - send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1, - max_blindex+1); - compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree); -#ifdef DEBUG - s->compressed_len += 3 + s->opt_len; -#endif - } - Assert (s->compressed_len == s->bits_sent, "bad compressed size"); - /* The above check is made mod 2^32, for files larger than 512 MB - * and uLong implemented on 32 bits. - */ - init_block(s); - - if (last) { - bi_windup(s); -#ifdef DEBUG - s->compressed_len += 7; /* align on byte boundary */ -#endif - } - Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3, - s->compressed_len-7*last)); -} - -/* =========================================================================== - * Save the match info and tally the frequency counts. Return true if - * the current block must be flushed. - */ -int ZLIB_INTERNAL _tr_tally (s, dist, lc) - deflate_state *s; - unsigned dist; /* distance of matched string */ - unsigned lc; /* match length-MIN_MATCH or unmatched char (if dist==0) */ -{ - s->d_buf[s->last_lit] = (ush)dist; - s->l_buf[s->last_lit++] = (uch)lc; - if (dist == 0) { - /* lc is the unmatched char */ - s->dyn_ltree[lc].Freq++; - } else { - s->matches++; - /* Here, lc is the match length - MIN_MATCH */ - dist--; /* dist = match distance - 1 */ - Assert((ush)dist < (ush)MAX_DIST(s) && - (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) && - (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match"); - - s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++; - s->dyn_dtree[d_code(dist)].Freq++; - } - -#ifdef TRUNCATE_BLOCK - /* Try to guess if it is profitable to stop the current block here */ - if ((s->last_lit & 0x1fff) == 0 && s->level > 2) { - /* Compute an upper bound for the compressed length */ - ulg out_length = (ulg)s->last_lit*8L; - ulg in_length = (ulg)((long)s->strstart - s->block_start); - int dcode; - for (dcode = 0; dcode < D_CODES; dcode++) { - out_length += (ulg)s->dyn_dtree[dcode].Freq * - (5L+extra_dbits[dcode]); - } - out_length >>= 3; - Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ", - s->last_lit, in_length, out_length, - 100L - out_length*100L/in_length)); - if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1; - } -#endif - return (s->last_lit == s->lit_bufsize-1); - /* We avoid equality with lit_bufsize because of wraparound at 64K - * on 16 bit machines and because stored blocks are restricted to - * 64K-1 bytes. - */ -} - -/* =========================================================================== - * Send the block data compressed using the given Huffman trees - */ -local void compress_block(s, ltree, dtree) - deflate_state *s; - ct_data *ltree; /* literal tree */ - ct_data *dtree; /* distance tree */ -{ - unsigned dist; /* distance of matched string */ - int lc; /* match length or unmatched char (if dist == 0) */ - unsigned lx = 0; /* running index in l_buf */ - unsigned code; /* the code to send */ - int extra; /* number of extra bits to send */ - - if (s->last_lit != 0) do { - dist = s->d_buf[lx]; - lc = s->l_buf[lx++]; - if (dist == 0) { - send_code(s, lc, ltree); /* send a literal byte */ - Tracecv(isgraph(lc), (stderr," '%c' ", lc)); - } else { - /* Here, lc is the match length - MIN_MATCH */ - code = _length_code[lc]; - send_code(s, code+LITERALS+1, ltree); /* send the length code */ - extra = extra_lbits[code]; - if (extra != 0) { - lc -= base_length[code]; - send_bits(s, lc, extra); /* send the extra length bits */ - } - dist--; /* dist is now the match distance - 1 */ - code = d_code(dist); - Assert (code < D_CODES, "bad d_code"); - - send_code(s, code, dtree); /* send the distance code */ - extra = extra_dbits[code]; - if (extra != 0) { - dist -= base_dist[code]; - send_bits(s, dist, extra); /* send the extra distance bits */ - } - } /* literal or match pair ? */ - - /* Check that the overlay between pending_buf and d_buf+l_buf is ok: */ - Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx, - "pendingBuf overflow"); - - } while (lx < s->last_lit); - - send_code(s, END_BLOCK, ltree); - s->last_eob_len = ltree[END_BLOCK].Len; -} - -/* =========================================================================== - * Check if the data type is TEXT or BINARY, using the following algorithm: - * - TEXT if the two conditions below are satisfied: - * a) There are no non-portable control characters belonging to the - * "black list" (0..6, 14..25, 28..31). - * b) There is at least one printable character belonging to the - * "white list" (9 {TAB}, 10 {LF}, 13 {CR}, 32..255). - * - BINARY otherwise. - * - The following partially-portable control characters form a - * "gray list" that is ignored in this detection algorithm: - * (7 {BEL}, 8 {BS}, 11 {VT}, 12 {FF}, 26 {SUB}, 27 {ESC}). - * IN assertion: the fields Freq of dyn_ltree are set. - */ -local int detect_data_type(s) - deflate_state *s; -{ - /* black_mask is the bit mask of black-listed bytes - * set bits 0..6, 14..25, and 28..31 - * 0xf3ffc07f = binary 11110011111111111100000001111111 - */ - unsigned long black_mask = 0xf3ffc07fUL; - int n; - - /* Check for non-textual ("black-listed") bytes. */ - for (n = 0; n <= 31; n++, black_mask >>= 1) - if ((black_mask & 1) && (s->dyn_ltree[n].Freq != 0)) - return Z_BINARY; - - /* Check for textual ("white-listed") bytes. */ - if (s->dyn_ltree[9].Freq != 0 || s->dyn_ltree[10].Freq != 0 - || s->dyn_ltree[13].Freq != 0) - return Z_TEXT; - for (n = 32; n < LITERALS; n++) - if (s->dyn_ltree[n].Freq != 0) - return Z_TEXT; - - /* There are no "black-listed" or "white-listed" bytes: - * this stream either is empty or has tolerated ("gray-listed") bytes only. - */ - return Z_BINARY; -} - -/* =========================================================================== - * Reverse the first len bits of a code, using straightforward code (a faster - * method would use a table) - * IN assertion: 1 <= len <= 15 - */ -local unsigned bi_reverse(code, len) - unsigned code; /* the value to invert */ - int len; /* its bit length */ -{ - register unsigned res = 0; - do { - res |= code & 1; - code >>= 1, res <<= 1; - } while (--len > 0); - return res >> 1; -} - -/* =========================================================================== - * Flush the bit buffer, keeping at most 7 bits in it. - */ -local void bi_flush(s) - deflate_state *s; -{ - if (s->bi_valid == 16) { - put_short(s, s->bi_buf); - s->bi_buf = 0; - s->bi_valid = 0; - } else if (s->bi_valid >= 8) { - put_byte(s, (Byte)s->bi_buf); - s->bi_buf >>= 8; - s->bi_valid -= 8; - } -} - -/* =========================================================================== - * Flush the bit buffer and align the output on a byte boundary - */ -local void bi_windup(s) - deflate_state *s; -{ - if (s->bi_valid > 8) { - put_short(s, s->bi_buf); - } else if (s->bi_valid > 0) { - put_byte(s, (Byte)s->bi_buf); - } - s->bi_buf = 0; - s->bi_valid = 0; -#ifdef DEBUG - s->bits_sent = (s->bits_sent+7) & ~7; -#endif -} - -/* =========================================================================== - * Copy a stored block, storing first the length and its - * one's complement if requested. - */ -local void copy_block(s, buf, len, header) - deflate_state *s; - charf *buf; /* the input data */ - unsigned len; /* its length */ - int header; /* true if block header must be written */ -{ - bi_windup(s); /* align on byte boundary */ - s->last_eob_len = 8; /* enough lookahead for inflate */ - - if (header) { - put_short(s, (ush)len); - put_short(s, (ush)~len); -#ifdef DEBUG - s->bits_sent += 2*16; -#endif - } -#ifdef DEBUG - s->bits_sent += (ulg)len<<3; -#endif - while (len--) { - put_byte(s, *buf++); - } -} diff --git a/vendor/libgit2/deps/zlib/trees.h b/vendor/libgit2/deps/zlib/trees.h deleted file mode 100644 index d35639d82..000000000 --- a/vendor/libgit2/deps/zlib/trees.h +++ /dev/null @@ -1,128 +0,0 @@ -/* header created automatically with -DGEN_TREES_H */ - -local const ct_data static_ltree[L_CODES+2] = { -{{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}}, -{{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}}, -{{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}}, -{{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}}, -{{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}}, -{{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}}, -{{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}}, -{{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}}, -{{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}}, -{{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}}, -{{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}}, -{{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}}, -{{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}}, -{{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}}, -{{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}}, -{{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}}, -{{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}}, -{{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}}, -{{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}}, -{{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}}, -{{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}}, -{{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}}, -{{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}}, -{{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}}, -{{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}}, -{{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}}, -{{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}}, -{{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}}, -{{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}}, -{{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}}, -{{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}}, -{{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}}, -{{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}}, -{{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}}, -{{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}}, -{{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}}, -{{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}}, -{{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}}, -{{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}}, -{{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}}, -{{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}}, -{{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}}, -{{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}}, -{{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}}, -{{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}}, -{{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}}, -{{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}}, -{{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}}, -{{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}}, -{{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}}, -{{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}}, -{{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}}, -{{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}}, -{{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}}, -{{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}}, -{{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}}, -{{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}}, -{{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}} -}; - -local const ct_data static_dtree[D_CODES] = { -{{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}}, -{{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}}, -{{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}}, -{{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}}, -{{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}}, -{{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}} -}; - -const uch ZLIB_INTERNAL _dist_code[DIST_CODE_LEN] = { - 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, - 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, -10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, -11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, -12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, -13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, -13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, -14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, -14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, -14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, -15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, -15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, -15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17, -18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22, -23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, -24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, -26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, -26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, -27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, -27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, -28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, -28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, -28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, -29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, -29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, -29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29 -}; - -const uch ZLIB_INTERNAL _length_code[MAX_MATCH-MIN_MATCH+1]= { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12, -13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16, -17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19, -19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, -21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22, -22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23, -23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, -24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, -25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, -25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26, -26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, -26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, -27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28 -}; - -local const int base_length[LENGTH_CODES] = { -0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56, -64, 80, 96, 112, 128, 160, 192, 224, 0 -}; - -local const int base_dist[D_CODES] = { - 0, 1, 2, 3, 4, 6, 8, 12, 16, 24, - 32, 48, 64, 96, 128, 192, 256, 384, 512, 768, - 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576 -}; - diff --git a/vendor/libgit2/deps/zlib/zconf.h b/vendor/libgit2/deps/zlib/zconf.h deleted file mode 100644 index 150814361..000000000 --- a/vendor/libgit2/deps/zlib/zconf.h +++ /dev/null @@ -1,54 +0,0 @@ -/* zconf.h -- configuration of the zlib compression library - * Copyright (C) 1995-2010 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#ifndef ZCONF_H -#define ZCONF_H - -#include "../../src/common.h" - -/* Jeez, don't complain about non-prototype - * forms, we didn't write zlib */ -#if defined(_MSC_VER) -# pragma warning( disable : 4131 ) -#endif - -/* Maximum value for memLevel in deflateInit2 */ -#define MAX_MEM_LEVEL 9 - -/* Maximum value for windowBits in deflateInit2 and inflateInit2. - * WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files - * created by gzip. (Files created by minigzip can still be extracted by - * gzip.) - */ -#define MAX_WBITS 15 /* 32K LZ77 window */ - -#define ZEXTERN extern -#define ZEXPORT -#define ZEXPORTVA -#ifndef FAR -# define FAR -#endif -#define OF(args) args - -typedef unsigned char Byte; /* 8 bits */ -typedef unsigned int uInt; /* 16 bits or more */ -typedef unsigned long uLong; /* 32 bits or more */ - -typedef Byte FAR Bytef; -typedef char FAR charf; -typedef int FAR intf; -typedef uInt FAR uIntf; -typedef uLong FAR uLongf; - -typedef void const *voidpc; -typedef void FAR *voidpf; -typedef void *voidp; - -#define z_off_t git_off_t -#define z_off64_t z_off_t - -#endif /* ZCONF_H */ diff --git a/vendor/libgit2/deps/zlib/zlib.h b/vendor/libgit2/deps/zlib/zlib.h deleted file mode 100644 index bfbba83e8..000000000 --- a/vendor/libgit2/deps/zlib/zlib.h +++ /dev/null @@ -1,1613 +0,0 @@ -/* zlib.h -- interface of the 'zlib' general purpose compression library - version 1.2.5, April 19th, 2010 - - Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - Jean-loup Gailly Mark Adler - jloup@gzip.org madler@alumni.caltech.edu - - - The data format used by the zlib library is described by RFCs (Request for - Comments) 1950 to 1952 in the files http://www.ietf.org/rfc/rfc1950.txt - (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). -*/ - -#ifndef ZLIB_H -#define ZLIB_H - -#include "zconf.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define ZLIB_VERSION "1.2.5" -#define ZLIB_VERNUM 0x1250 -#define ZLIB_VER_MAJOR 1 -#define ZLIB_VER_MINOR 2 -#define ZLIB_VER_REVISION 5 -#define ZLIB_VER_SUBREVISION 0 - -/* - The 'zlib' compression library provides in-memory compression and - decompression functions, including integrity checks of the uncompressed data. - This version of the library supports only one compression method (deflation) - but other algorithms will be added later and will have the same stream - interface. - - Compression can be done in a single step if the buffers are large enough, - or can be done by repeated calls of the compression function. In the latter - case, the application must provide more input and/or consume the output - (providing more output space) before each call. - - The compressed data format used by default by the in-memory functions is - the zlib format, which is a zlib wrapper documented in RFC 1950, wrapped - around a deflate stream, which is itself documented in RFC 1951. - - The library also supports reading and writing files in gzip (.gz) format - with an interface similar to that of stdio using the functions that start - with "gz". The gzip format is different from the zlib format. gzip is a - gzip wrapper, documented in RFC 1952, wrapped around a deflate stream. - - This library can optionally read and write gzip streams in memory as well. - - The zlib format was designed to be compact and fast for use in memory - and on communications channels. The gzip format was designed for single- - file compression on file systems, has a larger header than zlib to maintain - directory information, and uses a different, slower check method than zlib. - - The library does not install any signal handler. The decoder checks - the consistency of the compressed data, so the library should never crash - even in case of corrupted input. -*/ - -typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size)); -typedef void (*free_func) OF((voidpf opaque, voidpf address)); - -struct internal_state; - -typedef struct z_stream_s { - Bytef *next_in; /* next input byte */ - uInt avail_in; /* number of bytes available at next_in */ - uLong total_in; /* total nb of input bytes read so far */ - - Bytef *next_out; /* next output byte should be put there */ - uInt avail_out; /* remaining free space at next_out */ - uLong total_out; /* total nb of bytes output so far */ - - char *msg; /* last error message, NULL if no error */ - struct internal_state FAR *state; /* not visible by applications */ - - alloc_func zalloc; /* used to allocate the internal state */ - free_func zfree; /* used to free the internal state */ - voidpf opaque; /* private data object passed to zalloc and zfree */ - - int data_type; /* best guess about the data type: binary or text */ - uLong adler; /* adler32 value of the uncompressed data */ - uLong reserved; /* reserved for future use */ -} z_stream; - -typedef z_stream FAR *z_streamp; - -/* - gzip header information passed to and from zlib routines. See RFC 1952 - for more details on the meanings of these fields. -*/ -typedef struct gz_header_s { - int text; /* true if compressed data believed to be text */ - uLong time; /* modification time */ - int xflags; /* extra flags (not used when writing a gzip file) */ - int os; /* operating system */ - Bytef *extra; /* pointer to extra field or Z_NULL if none */ - uInt extra_len; /* extra field length (valid if extra != Z_NULL) */ - uInt extra_max; /* space at extra (only when reading header) */ - Bytef *name; /* pointer to zero-terminated file name or Z_NULL */ - uInt name_max; /* space at name (only when reading header) */ - Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */ - uInt comm_max; /* space at comment (only when reading header) */ - int hcrc; /* true if there was or will be a header crc */ - int done; /* true when done reading gzip header (not used - when writing a gzip file) */ -} gz_header; - -typedef gz_header FAR *gz_headerp; - -/* - The application must update next_in and avail_in when avail_in has dropped - to zero. It must update next_out and avail_out when avail_out has dropped - to zero. The application must initialize zalloc, zfree and opaque before - calling the init function. All other fields are set by the compression - library and must not be updated by the application. - - The opaque value provided by the application will be passed as the first - parameter for calls of zalloc and zfree. This can be useful for custom - memory management. The compression library attaches no meaning to the - opaque value. - - zalloc must return Z_NULL if there is not enough memory for the object. - If zlib is used in a multi-threaded application, zalloc and zfree must be - thread safe. - - On 16-bit systems, the functions zalloc and zfree must be able to allocate - exactly 65536 bytes, but will not be required to allocate more than this if - the symbol MAXSEG_64K is defined (see zconf.h). WARNING: On MSDOS, pointers - returned by zalloc for objects of exactly 65536 bytes *must* have their - offset normalized to zero. The default allocation function provided by this - library ensures this (see zutil.c). To reduce memory requirements and avoid - any allocation of 64K objects, at the expense of compression ratio, compile - the library with -DMAX_WBITS=14 (see zconf.h). - - The fields total_in and total_out can be used for statistics or progress - reports. After compression, total_in holds the total size of the - uncompressed data and may be saved for use in the decompressor (particularly - if the decompressor wants to decompress everything in a single step). -*/ - - /* constants */ - -#define Z_NO_FLUSH 0 -#define Z_PARTIAL_FLUSH 1 -#define Z_SYNC_FLUSH 2 -#define Z_FULL_FLUSH 3 -#define Z_FINISH 4 -#define Z_BLOCK 5 -#define Z_TREES 6 -/* Allowed flush values; see deflate() and inflate() below for details */ - -#define Z_OK 0 -#define Z_STREAM_END 1 -#define Z_NEED_DICT 2 -#define Z_ERRNO (-1) -#define Z_STREAM_ERROR (-2) -#define Z_DATA_ERROR (-3) -#define Z_MEM_ERROR (-4) -#define Z_BUF_ERROR (-5) -#define Z_VERSION_ERROR (-6) -/* Return codes for the compression/decompression functions. Negative values - * are errors, positive values are used for special but normal events. - */ - -#define Z_NO_COMPRESSION 0 -#define Z_BEST_SPEED 1 -#define Z_BEST_COMPRESSION 9 -#define Z_DEFAULT_COMPRESSION (-1) -/* compression levels */ - -#define Z_FILTERED 1 -#define Z_HUFFMAN_ONLY 2 -#define Z_RLE 3 -#define Z_FIXED 4 -#define Z_DEFAULT_STRATEGY 0 -/* compression strategy; see deflateInit2() below for details */ - -#define Z_BINARY 0 -#define Z_TEXT 1 -#define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */ -#define Z_UNKNOWN 2 -/* Possible values of the data_type field (though see inflate()) */ - -#define Z_DEFLATED 8 -/* The deflate compression method (the only one supported in this version) */ - -#define Z_NULL 0 /* for initializing zalloc, zfree, opaque */ - -#define zlib_version zlibVersion() -/* for compatibility with versions < 1.0.2 */ - - - /* basic functions */ - -ZEXTERN const char * ZEXPORT zlibVersion OF((void)); -/* The application can compare zlibVersion and ZLIB_VERSION for consistency. - If the first character differs, the library code actually used is not - compatible with the zlib.h header file used by the application. This check - is automatically made by deflateInit and inflateInit. - */ - -/* -ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level)); - - Initializes the internal stream state for compression. The fields - zalloc, zfree and opaque must be initialized before by the caller. If - zalloc and zfree are set to Z_NULL, deflateInit updates them to use default - allocation functions. - - The compression level must be Z_DEFAULT_COMPRESSION, or between 0 and 9: - 1 gives best speed, 9 gives best compression, 0 gives no compression at all - (the input data is simply copied a block at a time). Z_DEFAULT_COMPRESSION - requests a default compromise between speed and compression (currently - equivalent to level 6). - - deflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if level is not a valid compression level, or - Z_VERSION_ERROR if the zlib library version (zlib_version) is incompatible - with the version assumed by the caller (ZLIB_VERSION). msg is set to null - if there is no error message. deflateInit does not perform any compression: - this will be done by deflate(). -*/ - - -ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush)); -/* - deflate compresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may introduce - some output latency (reading input without producing any output) except when - forced to flush. - - The detailed semantics are as follows. deflate performs one or both of the - following actions: - - - Compress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), next_in and avail_in are updated and - processing will resume at this point for the next call of deflate(). - - - Provide more output starting at next_out and update next_out and avail_out - accordingly. This action is forced if the parameter flush is non zero. - Forcing flush frequently degrades the compression ratio, so this parameter - should be set only when necessary (in interactive applications). Some - output may be provided even if flush is not set. - - Before the call of deflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming more - output, and updating avail_in or avail_out accordingly; avail_out should - never be zero before the call. The application can consume the compressed - output when it wants, for example when the output buffer is full (avail_out - == 0), or after each call of deflate(). If deflate returns Z_OK and with - zero avail_out, it must be called again after making room in the output - buffer because there might be more output pending. - - Normally the parameter flush is set to Z_NO_FLUSH, which allows deflate to - decide how much data to accumulate before producing output, in order to - maximize compression. - - If the parameter flush is set to Z_SYNC_FLUSH, all pending output is - flushed to the output buffer and the output is aligned on a byte boundary, so - that the decompressor can get all input data available so far. (In - particular avail_in is zero after the call if enough output space has been - provided before the call.) Flushing may degrade compression for some - compression algorithms and so it should be used only when necessary. This - completes the current deflate block and follows it with an empty stored block - that is three bits plus filler bits to the next byte, followed by four bytes - (00 00 ff ff). - - If flush is set to Z_PARTIAL_FLUSH, all pending output is flushed to the - output buffer, but the output is not aligned to a byte boundary. All of the - input data so far will be available to the decompressor, as for Z_SYNC_FLUSH. - This completes the current deflate block and follows it with an empty fixed - codes block that is 10 bits long. This assures that enough bytes are output - in order for the decompressor to finish the block before the empty fixed code - block. - - If flush is set to Z_BLOCK, a deflate block is completed and emitted, as - for Z_SYNC_FLUSH, but the output is not aligned on a byte boundary, and up to - seven bits of the current block are held to be written as the next byte after - the next deflate block is completed. In this case, the decompressor may not - be provided enough bits at this point in order to complete decompression of - the data provided so far to the compressor. It may need to wait for the next - block to be emitted. This is for advanced applications that need to control - the emission of deflate blocks. - - If flush is set to Z_FULL_FLUSH, all output is flushed as with - Z_SYNC_FLUSH, and the compression state is reset so that decompression can - restart from this point if previous compressed data has been damaged or if - random access is desired. Using Z_FULL_FLUSH too often can seriously degrade - compression. - - If deflate returns with avail_out == 0, this function must be called again - with the same value of the flush parameter and more output space (updated - avail_out), until the flush is complete (deflate returns with non-zero - avail_out). In the case of a Z_FULL_FLUSH or Z_SYNC_FLUSH, make sure that - avail_out is greater than six to avoid repeated flush markers due to - avail_out == 0 on return. - - If the parameter flush is set to Z_FINISH, pending input is processed, - pending output is flushed and deflate returns with Z_STREAM_END if there was - enough output space; if deflate returns with Z_OK, this function must be - called again with Z_FINISH and more output space (updated avail_out) but no - more input data, until it returns with Z_STREAM_END or an error. After - deflate has returned Z_STREAM_END, the only possible operations on the stream - are deflateReset or deflateEnd. - - Z_FINISH can be used immediately after deflateInit if all the compression - is to be done in a single step. In this case, avail_out must be at least the - value returned by deflateBound (see below). If deflate does not return - Z_STREAM_END, then it must be called again as described above. - - deflate() sets strm->adler to the adler32 checksum of all input read - so far (that is, total_in bytes). - - deflate() may update strm->data_type if it can make a good guess about - the input data type (Z_BINARY or Z_TEXT). In doubt, the data is considered - binary. This field is only for information purposes and does not affect the - compression algorithm in any manner. - - deflate() returns Z_OK if some progress has been made (more input - processed or more output produced), Z_STREAM_END if all input has been - consumed and all output has been produced (only when flush is set to - Z_FINISH), Z_STREAM_ERROR if the stream state was inconsistent (for example - if next_in or next_out was Z_NULL), Z_BUF_ERROR if no progress is possible - (for example avail_in or avail_out was zero). Note that Z_BUF_ERROR is not - fatal, and deflate() can be called again with more input and more output - space to continue compressing. -*/ - - -ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm)); -/* - All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any pending - output. - - deflateEnd returns Z_OK if success, Z_STREAM_ERROR if the - stream state was inconsistent, Z_DATA_ERROR if the stream was freed - prematurely (some input or output was discarded). In the error case, msg - may be set but then points to a static string (which must not be - deallocated). -*/ - - -/* -ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm)); - - Initializes the internal stream state for decompression. The fields - next_in, avail_in, zalloc, zfree and opaque must be initialized before by - the caller. If next_in is not Z_NULL and avail_in is large enough (the - exact value depends on the compression method), inflateInit determines the - compression method from the zlib header and allocates all data structures - accordingly; otherwise the allocation will be deferred to the first call of - inflate. If zalloc and zfree are set to Z_NULL, inflateInit updates them to - use default allocation functions. - - inflateInit returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_VERSION_ERROR if the zlib library version is incompatible with the - version assumed by the caller, or Z_STREAM_ERROR if the parameters are - invalid, such as a null pointer to the structure. msg is set to null if - there is no error message. inflateInit does not perform any decompression - apart from possibly reading the zlib header if present: actual decompression - will be done by inflate(). (So next_in and avail_in may be modified, but - next_out and avail_out are unused and unchanged.) The current implementation - of inflateInit() does not process any header information -- that is deferred - until inflate() is called. -*/ - - -ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush)); -/* - inflate decompresses as much data as possible, and stops when the input - buffer becomes empty or the output buffer becomes full. It may introduce - some output latency (reading input without producing any output) except when - forced to flush. - - The detailed semantics are as follows. inflate performs one or both of the - following actions: - - - Decompress more input starting at next_in and update next_in and avail_in - accordingly. If not all input can be processed (because there is not - enough room in the output buffer), next_in is updated and processing will - resume at this point for the next call of inflate(). - - - Provide more output starting at next_out and update next_out and avail_out - accordingly. inflate() provides as much output as possible, until there is - no more input data or no more space in the output buffer (see below about - the flush parameter). - - Before the call of inflate(), the application should ensure that at least - one of the actions is possible, by providing more input and/or consuming more - output, and updating the next_* and avail_* values accordingly. The - application can consume the uncompressed output when it wants, for example - when the output buffer is full (avail_out == 0), or after each call of - inflate(). If inflate returns Z_OK and with zero avail_out, it must be - called again after making room in the output buffer because there might be - more output pending. - - The flush parameter of inflate() can be Z_NO_FLUSH, Z_SYNC_FLUSH, Z_FINISH, - Z_BLOCK, or Z_TREES. Z_SYNC_FLUSH requests that inflate() flush as much - output as possible to the output buffer. Z_BLOCK requests that inflate() - stop if and when it gets to the next deflate block boundary. When decoding - the zlib or gzip format, this will cause inflate() to return immediately - after the header and before the first block. When doing a raw inflate, - inflate() will go ahead and process the first block, and will return when it - gets to the end of that block, or when it runs out of data. - - The Z_BLOCK option assists in appending to or combining deflate streams. - Also to assist in this, on return inflate() will set strm->data_type to the - number of unused bits in the last byte taken from strm->next_in, plus 64 if - inflate() is currently decoding the last block in the deflate stream, plus - 128 if inflate() returned immediately after decoding an end-of-block code or - decoding the complete header up to just before the first byte of the deflate - stream. The end-of-block will not be indicated until all of the uncompressed - data from that block has been written to strm->next_out. The number of - unused bits may in general be greater than seven, except when bit 7 of - data_type is set, in which case the number of unused bits will be less than - eight. data_type is set as noted here every time inflate() returns for all - flush options, and so can be used to determine the amount of currently - consumed input in bits. - - The Z_TREES option behaves as Z_BLOCK does, but it also returns when the - end of each deflate block header is reached, before any actual data in that - block is decoded. This allows the caller to determine the length of the - deflate block header for later use in random access within a deflate block. - 256 is added to the value of strm->data_type when inflate() returns - immediately after reaching the end of the deflate block header. - - inflate() should normally be called until it returns Z_STREAM_END or an - error. However if all decompression is to be performed in a single step (a - single call of inflate), the parameter flush should be set to Z_FINISH. In - this case all pending input is processed and all pending output is flushed; - avail_out must be large enough to hold all the uncompressed data. (The size - of the uncompressed data may have been saved by the compressor for this - purpose.) The next operation on this stream must be inflateEnd to deallocate - the decompression state. The use of Z_FINISH is never required, but can be - used to inform inflate that a faster approach may be used for the single - inflate() call. - - In this implementation, inflate() always flushes as much output as - possible to the output buffer, and always uses the faster approach on the - first call. So the only effect of the flush parameter in this implementation - is on the return value of inflate(), as noted below, or when it returns early - because Z_BLOCK or Z_TREES is used. - - If a preset dictionary is needed after this call (see inflateSetDictionary - below), inflate sets strm->adler to the adler32 checksum of the dictionary - chosen by the compressor and returns Z_NEED_DICT; otherwise it sets - strm->adler to the adler32 checksum of all output produced so far (that is, - total_out bytes) and returns Z_OK, Z_STREAM_END or an error code as described - below. At the end of the stream, inflate() checks that its computed adler32 - checksum is equal to that saved by the compressor and returns Z_STREAM_END - only if the checksum is correct. - - inflate() can decompress and check either zlib-wrapped or gzip-wrapped - deflate data. The header type is detected automatically, if requested when - initializing with inflateInit2(). Any information contained in the gzip - header is not retained, so applications that need that information should - instead use raw inflate, see inflateInit2() below, or inflateBack() and - perform their own processing of the gzip header and trailer. - - inflate() returns Z_OK if some progress has been made (more input processed - or more output produced), Z_STREAM_END if the end of the compressed data has - been reached and all uncompressed output has been produced, Z_NEED_DICT if a - preset dictionary is needed at this point, Z_DATA_ERROR if the input data was - corrupted (input stream not conforming to the zlib format or incorrect check - value), Z_STREAM_ERROR if the stream structure was inconsistent (for example - next_in or next_out was Z_NULL), Z_MEM_ERROR if there was not enough memory, - Z_BUF_ERROR if no progress is possible or if there was not enough room in the - output buffer when Z_FINISH is used. Note that Z_BUF_ERROR is not fatal, and - inflate() can be called again with more input and more output space to - continue decompressing. If Z_DATA_ERROR is returned, the application may - then call inflateSync() to look for a good compression block if a partial - recovery of the data is desired. -*/ - - -ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm)); -/* - All dynamically allocated data structures for this stream are freed. - This function discards any unprocessed input and does not flush any pending - output. - - inflateEnd returns Z_OK if success, Z_STREAM_ERROR if the stream state - was inconsistent. In the error case, msg may be set but then points to a - static string (which must not be deallocated). -*/ - - - /* Advanced functions */ - -/* - The following functions are needed only in some special applications. -*/ - -/* -ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm, - int level, - int method, - int windowBits, - int memLevel, - int strategy)); - - This is another version of deflateInit with more compression options. The - fields next_in, zalloc, zfree and opaque must be initialized before by the - caller. - - The method parameter is the compression method. It must be Z_DEFLATED in - this version of the library. - - The windowBits parameter is the base two logarithm of the window size - (the size of the history buffer). It should be in the range 8..15 for this - version of the library. Larger values of this parameter result in better - compression at the expense of memory usage. The default value is 15 if - deflateInit is used instead. - - windowBits can also be -8..-15 for raw deflate. In this case, -windowBits - determines the window size. deflate() will then generate raw deflate data - with no zlib header or trailer, and will not compute an adler32 check value. - - windowBits can also be greater than 15 for optional gzip encoding. Add - 16 to windowBits to write a simple gzip header and trailer around the - compressed data instead of a zlib wrapper. The gzip header will have no - file name, no extra data, no comment, no modification time (set to zero), no - header crc, and the operating system will be set to 255 (unknown). If a - gzip stream is being written, strm->adler is a crc32 instead of an adler32. - - The memLevel parameter specifies how much memory should be allocated - for the internal compression state. memLevel=1 uses minimum memory but is - slow and reduces compression ratio; memLevel=9 uses maximum memory for - optimal speed. The default value is 8. See zconf.h for total memory usage - as a function of windowBits and memLevel. - - The strategy parameter is used to tune the compression algorithm. Use the - value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a - filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no - string match), or Z_RLE to limit match distances to one (run-length - encoding). Filtered data consists mostly of small values with a somewhat - random distribution. In this case, the compression algorithm is tuned to - compress them better. The effect of Z_FILTERED is to force more Huffman - coding and less string matching; it is somewhat intermediate between - Z_DEFAULT_STRATEGY and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as - fast as Z_HUFFMAN_ONLY, but give better compression for PNG image data. The - strategy parameter only affects the compression ratio but not the - correctness of the compressed output even if it is not set appropriately. - Z_FIXED prevents the use of dynamic Huffman codes, allowing for a simpler - decoder for special applications. - - deflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_STREAM_ERROR if any parameter is invalid (such as an invalid - method), or Z_VERSION_ERROR if the zlib library version (zlib_version) is - incompatible with the version assumed by the caller (ZLIB_VERSION). msg is - set to null if there is no error message. deflateInit2 does not perform any - compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); -/* - Initializes the compression dictionary from the given byte sequence - without producing any compressed output. This function must be called - immediately after deflateInit, deflateInit2 or deflateReset, before any call - of deflate. The compressor and decompressor must use exactly the same - dictionary (see inflateSetDictionary). - - The dictionary should consist of strings (byte sequences) that are likely - to be encountered later in the data to be compressed, with the most commonly - used strings preferably put towards the end of the dictionary. Using a - dictionary is most useful when the data to be compressed is short and can be - predicted with good accuracy; the data can then be compressed better than - with the default empty dictionary. - - Depending on the size of the compression data structures selected by - deflateInit or deflateInit2, a part of the dictionary may in effect be - discarded, for example if the dictionary is larger than the window size - provided in deflateInit or deflateInit2. Thus the strings most likely to be - useful should be put at the end of the dictionary, not at the front. In - addition, the current implementation of deflate will use at most the window - size minus 262 bytes of the provided dictionary. - - Upon return of this function, strm->adler is set to the adler32 value - of the dictionary; the decompressor may later use this value to determine - which dictionary has been used by the compressor. (The adler32 value - applies to the whole dictionary even if only a subset of the dictionary is - actually used by the compressor.) If a raw deflate was requested, then the - adler32 value is not computed and strm->adler is not set. - - deflateSetDictionary returns Z_OK if success, or Z_STREAM_ERROR if a - parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is - inconsistent (for example if deflate has already been called for this stream - or if the compression method is bsort). deflateSetDictionary does not - perform any compression: this will be done by deflate(). -*/ - -ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest, - z_streamp source)); -/* - Sets the destination stream as a complete copy of the source stream. - - This function can be useful when several compression strategies will be - tried, for example when there are several ways of pre-processing the input - data with a filter. The streams that will be discarded should then be freed - by calling deflateEnd. Note that deflateCopy duplicates the internal - compression state which can be quite large, so this strategy is slow and can - consume lots of memory. - - deflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if the source stream state was inconsistent - (such as zalloc being Z_NULL). msg is left unchanged in both source and - destination. -*/ - -ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm)); -/* - This function is equivalent to deflateEnd followed by deflateInit, - but does not free and reallocate all the internal compression state. The - stream will keep the same compression level and any other attributes that - may have been set by deflateInit2. - - deflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being Z_NULL). -*/ - -ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm, - int level, - int strategy)); -/* - Dynamically update the compression level and compression strategy. The - interpretation of level and strategy is as in deflateInit2. This can be - used to switch between compression and straight copy of the input data, or - to switch to a different kind of input data requiring a different strategy. - If the compression level is changed, the input available so far is - compressed with the old level (and may be flushed); the new level will take - effect only at the next call of deflate(). - - Before the call of deflateParams, the stream state must be set as for - a call of deflate(), since the currently available input may have to be - compressed and flushed. In particular, strm->avail_out must be non-zero. - - deflateParams returns Z_OK if success, Z_STREAM_ERROR if the source - stream state was inconsistent or if a parameter was invalid, Z_BUF_ERROR if - strm->avail_out was zero. -*/ - -ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm, - int good_length, - int max_lazy, - int nice_length, - int max_chain)); -/* - Fine tune deflate's internal compression parameters. This should only be - used by someone who understands the algorithm used by zlib's deflate for - searching for the best matching string, and even then only by the most - fanatic optimizer trying to squeeze out the last compressed bit for their - specific input data. Read the deflate.c source code for the meaning of the - max_lazy, good_length, nice_length, and max_chain parameters. - - deflateTune() can be called after deflateInit() or deflateInit2(), and - returns Z_OK on success, or Z_STREAM_ERROR for an invalid deflate stream. - */ - -ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm, - uLong sourceLen)); -/* - deflateBound() returns an upper bound on the compressed size after - deflation of sourceLen bytes. It must be called after deflateInit() or - deflateInit2(), and after deflateSetHeader(), if used. This would be used - to allocate an output buffer for deflation in a single pass, and so would be - called before deflate(). -*/ - -ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm, - int bits, - int value)); -/* - deflatePrime() inserts bits in the deflate output stream. The intent - is that this function is used to start off the deflate output with the bits - leftover from a previous deflate stream when appending to it. As such, this - function can only be used for raw deflate, and must be used before the first - deflate() call after a deflateInit2() or deflateReset(). bits must be less - than or equal to 16, and that many of the least significant bits of value - will be inserted in the output. - - deflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. -*/ - -ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm, - gz_headerp head)); -/* - deflateSetHeader() provides gzip header information for when a gzip - stream is requested by deflateInit2(). deflateSetHeader() may be called - after deflateInit2() or deflateReset() and before the first call of - deflate(). The text, time, os, extra field, name, and comment information - in the provided gz_header structure are written to the gzip header (xflag is - ignored -- the extra flags are set according to the compression level). The - caller must assure that, if not Z_NULL, name and comment are terminated with - a zero byte, and that if extra is not Z_NULL, that extra_len bytes are - available there. If hcrc is true, a gzip header crc is included. Note that - the current versions of the command-line version of gzip (up through version - 1.3.x) do not support header crc's, and will report that it is a "multi-part - gzip file" and give up. - - If deflateSetHeader is not used, the default gzip header has text false, - the time set to zero, and os set to 255, with no extra, name, or comment - fields. The gzip header is returned to the default state by deflateReset(). - - deflateSetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. -*/ - -/* -ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm, - int windowBits)); - - This is another version of inflateInit with an extra parameter. The - fields next_in, avail_in, zalloc, zfree and opaque must be initialized - before by the caller. - - The windowBits parameter is the base two logarithm of the maximum window - size (the size of the history buffer). It should be in the range 8..15 for - this version of the library. The default value is 15 if inflateInit is used - instead. windowBits must be greater than or equal to the windowBits value - provided to deflateInit2() while compressing, or it must be equal to 15 if - deflateInit2() was not used. If a compressed stream with a larger window - size is given as input, inflate() will return with the error code - Z_DATA_ERROR instead of trying to allocate a larger window. - - windowBits can also be zero to request that inflate use the window size in - the zlib header of the compressed stream. - - windowBits can also be -8..-15 for raw inflate. In this case, -windowBits - determines the window size. inflate() will then process raw deflate data, - not looking for a zlib or gzip header, not generating a check value, and not - looking for any check values for comparison at the end of the stream. This - is for use with other formats that use the deflate compressed data format - such as zip. Those formats provide their own check values. If a custom - format is developed using the raw deflate format for compressed data, it is - recommended that a check value such as an adler32 or a crc32 be applied to - the uncompressed data as is done in the zlib, gzip, and zip formats. For - most applications, the zlib format should be used as is. Note that comments - above on the use in deflateInit2() applies to the magnitude of windowBits. - - windowBits can also be greater than 15 for optional gzip decoding. Add - 32 to windowBits to enable zlib and gzip decoding with automatic header - detection, or add 16 to decode only the gzip format (the zlib format will - return a Z_DATA_ERROR). If a gzip stream is being decoded, strm->adler is a - crc32 instead of an adler32. - - inflateInit2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_VERSION_ERROR if the zlib library version is incompatible with the - version assumed by the caller, or Z_STREAM_ERROR if the parameters are - invalid, such as a null pointer to the structure. msg is set to null if - there is no error message. inflateInit2 does not perform any decompression - apart from possibly reading the zlib header if present: actual decompression - will be done by inflate(). (So next_in and avail_in may be modified, but - next_out and avail_out are unused and unchanged.) The current implementation - of inflateInit2() does not process any header information -- that is - deferred until inflate() is called. -*/ - -ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm, - const Bytef *dictionary, - uInt dictLength)); -/* - Initializes the decompression dictionary from the given uncompressed byte - sequence. This function must be called immediately after a call of inflate, - if that call returned Z_NEED_DICT. The dictionary chosen by the compressor - can be determined from the adler32 value returned by that call of inflate. - The compressor and decompressor must use exactly the same dictionary (see - deflateSetDictionary). For raw inflate, this function can be called - immediately after inflateInit2() or inflateReset() and before any call of - inflate() to set the dictionary. The application must insure that the - dictionary that was used for compression is provided. - - inflateSetDictionary returns Z_OK if success, Z_STREAM_ERROR if a - parameter is invalid (e.g. dictionary being Z_NULL) or the stream state is - inconsistent, Z_DATA_ERROR if the given dictionary doesn't match the - expected one (incorrect adler32 value). inflateSetDictionary does not - perform any decompression: this will be done by subsequent calls of - inflate(). -*/ - -ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm)); -/* - Skips invalid compressed data until a full flush point (see above the - description of deflate with Z_FULL_FLUSH) can be found, or until all - available input is skipped. No output is provided. - - inflateSync returns Z_OK if a full flush point has been found, Z_BUF_ERROR - if no more input was provided, Z_DATA_ERROR if no flush point has been - found, or Z_STREAM_ERROR if the stream structure was inconsistent. In the - success case, the application may save the current current value of total_in - which indicates where valid compressed data was found. In the error case, - the application may repeatedly call inflateSync, providing more input each - time, until success or end of the input data. -*/ - -ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest, - z_streamp source)); -/* - Sets the destination stream as a complete copy of the source stream. - - This function can be useful when randomly accessing a large stream. The - first pass through the stream can periodically record the inflate state, - allowing restarting inflate at those points when randomly accessing the - stream. - - inflateCopy returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_STREAM_ERROR if the source stream state was inconsistent - (such as zalloc being Z_NULL). msg is left unchanged in both source and - destination. -*/ - -ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm)); -/* - This function is equivalent to inflateEnd followed by inflateInit, - but does not free and reallocate all the internal decompression state. The - stream will keep attributes that may have been set by inflateInit2. - - inflateReset returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being Z_NULL). -*/ - -ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm, - int windowBits)); -/* - This function is the same as inflateReset, but it also permits changing - the wrap and window size requests. The windowBits parameter is interpreted - the same as it is for inflateInit2. - - inflateReset2 returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent (such as zalloc or state being Z_NULL), or if - the windowBits parameter is invalid. -*/ - -ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm, - int bits, - int value)); -/* - This function inserts bits in the inflate input stream. The intent is - that this function is used to start inflating at a bit position in the - middle of a byte. The provided bits will be used before any bytes are used - from next_in. This function should only be used with raw inflate, and - should be used before the first inflate() call after inflateInit2() or - inflateReset(). bits must be less than or equal to 16, and that many of the - least significant bits of value will be inserted in the input. - - If bits is negative, then the input stream bit buffer is emptied. Then - inflatePrime() can be called again to put bits in the buffer. This is used - to clear out bits leftover after feeding inflate a block description prior - to feeding inflate codes. - - inflatePrime returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. -*/ - -ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm)); -/* - This function returns two values, one in the lower 16 bits of the return - value, and the other in the remaining upper bits, obtained by shifting the - return value down 16 bits. If the upper value is -1 and the lower value is - zero, then inflate() is currently decoding information outside of a block. - If the upper value is -1 and the lower value is non-zero, then inflate is in - the middle of a stored block, with the lower value equaling the number of - bytes from the input remaining to copy. If the upper value is not -1, then - it is the number of bits back from the current bit position in the input of - the code (literal or length/distance pair) currently being processed. In - that case the lower value is the number of bytes already emitted for that - code. - - A code is being processed if inflate is waiting for more input to complete - decoding of the code, or if it has completed decoding but is waiting for - more output space to write the literal or match data. - - inflateMark() is used to mark locations in the input data for random - access, which may be at bit positions, and to note those cases where the - output of a code may span boundaries of random access blocks. The current - location in the input stream can be determined from avail_in and data_type - as noted in the description for the Z_BLOCK flush parameter for inflate. - - inflateMark returns the value noted above or -1 << 16 if the provided - source stream state was inconsistent. -*/ - -ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm, - gz_headerp head)); -/* - inflateGetHeader() requests that gzip header information be stored in the - provided gz_header structure. inflateGetHeader() may be called after - inflateInit2() or inflateReset(), and before the first call of inflate(). - As inflate() processes the gzip stream, head->done is zero until the header - is completed, at which time head->done is set to one. If a zlib stream is - being decoded, then head->done is set to -1 to indicate that there will be - no gzip header information forthcoming. Note that Z_BLOCK or Z_TREES can be - used to force inflate() to return immediately after header processing is - complete and before any actual data is decompressed. - - The text, time, xflags, and os fields are filled in with the gzip header - contents. hcrc is set to true if there is a header CRC. (The header CRC - was valid if done is set to one.) If extra is not Z_NULL, then extra_max - contains the maximum number of bytes to write to extra. Once done is true, - extra_len contains the actual extra field length, and extra contains the - extra field, or that field truncated if extra_max is less than extra_len. - If name is not Z_NULL, then up to name_max characters are written there, - terminated with a zero unless the length is greater than name_max. If - comment is not Z_NULL, then up to comm_max characters are written there, - terminated with a zero unless the length is greater than comm_max. When any - of extra, name, or comment are not Z_NULL and the respective field is not - present in the header, then that field is set to Z_NULL to signal its - absence. This allows the use of deflateSetHeader() with the returned - structure to duplicate the header. However if those fields are set to - allocated memory, then the application will need to save those pointers - elsewhere so that they can be eventually freed. - - If inflateGetHeader is not used, then the header information is simply - discarded. The header is always checked for validity, including the header - CRC if present. inflateReset() will reset the process to discard the header - information. The application would need to call inflateGetHeader() again to - retrieve the header from the next gzip stream. - - inflateGetHeader returns Z_OK if success, or Z_STREAM_ERROR if the source - stream state was inconsistent. -*/ - -/* -ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits, - unsigned char FAR *window)); - - Initialize the internal stream state for decompression using inflateBack() - calls. The fields zalloc, zfree and opaque in strm must be initialized - before the call. If zalloc and zfree are Z_NULL, then the default library- - derived memory allocation routines are used. windowBits is the base two - logarithm of the window size, in the range 8..15. window is a caller - supplied buffer of that size. Except for special applications where it is - assured that deflate was used with small window sizes, windowBits must be 15 - and a 32K byte window must be supplied to be able to decompress general - deflate streams. - - See inflateBack() for the usage of these routines. - - inflateBackInit will return Z_OK on success, Z_STREAM_ERROR if any of - the paramaters are invalid, Z_MEM_ERROR if the internal state could not be - allocated, or Z_VERSION_ERROR if the version of the library does not match - the version of the header file. -*/ - -typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *)); -typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned)); - -ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm, - in_func in, void FAR *in_desc, - out_func out, void FAR *out_desc)); -/* - inflateBack() does a raw inflate with a single call using a call-back - interface for input and output. This is more efficient than inflate() for - file i/o applications in that it avoids copying between the output and the - sliding window by simply making the window itself the output buffer. This - function trusts the application to not change the output buffer passed by - the output function, at least until inflateBack() returns. - - inflateBackInit() must be called first to allocate the internal state - and to initialize the state with the user-provided window buffer. - inflateBack() may then be used multiple times to inflate a complete, raw - deflate stream with each call. inflateBackEnd() is then called to free the - allocated state. - - A raw deflate stream is one with no zlib or gzip header or trailer. - This routine would normally be used in a utility that reads zip or gzip - files and writes out uncompressed files. The utility would decode the - header and process the trailer on its own, hence this routine expects only - the raw deflate stream to decompress. This is different from the normal - behavior of inflate(), which expects either a zlib or gzip header and - trailer around the deflate stream. - - inflateBack() uses two subroutines supplied by the caller that are then - called by inflateBack() for input and output. inflateBack() calls those - routines until it reads a complete deflate stream and writes out all of the - uncompressed data, or until it encounters an error. The function's - parameters and return types are defined above in the in_func and out_func - typedefs. inflateBack() will call in(in_desc, &buf) which should return the - number of bytes of provided input, and a pointer to that input in buf. If - there is no input available, in() must return zero--buf is ignored in that - case--and inflateBack() will return a buffer error. inflateBack() will call - out(out_desc, buf, len) to write the uncompressed data buf[0..len-1]. out() - should return zero on success, or non-zero on failure. If out() returns - non-zero, inflateBack() will return with an error. Neither in() nor out() - are permitted to change the contents of the window provided to - inflateBackInit(), which is also the buffer that out() uses to write from. - The length written by out() will be at most the window size. Any non-zero - amount of input may be provided by in(). - - For convenience, inflateBack() can be provided input on the first call by - setting strm->next_in and strm->avail_in. If that input is exhausted, then - in() will be called. Therefore strm->next_in must be initialized before - calling inflateBack(). If strm->next_in is Z_NULL, then in() will be called - immediately for input. If strm->next_in is not Z_NULL, then strm->avail_in - must also be initialized, and then if strm->avail_in is not zero, input will - initially be taken from strm->next_in[0 .. strm->avail_in - 1]. - - The in_desc and out_desc parameters of inflateBack() is passed as the - first parameter of in() and out() respectively when they are called. These - descriptors can be optionally used to pass any information that the caller- - supplied in() and out() functions need to do their job. - - On return, inflateBack() will set strm->next_in and strm->avail_in to - pass back any unused input that was provided by the last in() call. The - return values of inflateBack() can be Z_STREAM_END on success, Z_BUF_ERROR - if in() or out() returned an error, Z_DATA_ERROR if there was a format error - in the deflate stream (in which case strm->msg is set to indicate the nature - of the error), or Z_STREAM_ERROR if the stream was not properly initialized. - In the case of Z_BUF_ERROR, an input or output error can be distinguished - using strm->next_in which will be Z_NULL only if in() returned an error. If - strm->next_in is not Z_NULL, then the Z_BUF_ERROR was due to out() returning - non-zero. (in() will always be called before out(), so strm->next_in is - assured to be defined if out() returns non-zero.) Note that inflateBack() - cannot return Z_OK. -*/ - -ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm)); -/* - All memory allocated by inflateBackInit() is freed. - - inflateBackEnd() returns Z_OK on success, or Z_STREAM_ERROR if the stream - state was inconsistent. -*/ - -ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void)); -/* Return flags indicating compile-time options. - - Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = other: - 1.0: size of uInt - 3.2: size of uLong - 5.4: size of voidpf (pointer) - 7.6: size of z_off_t - - Compiler, assembler, and debug options: - 8: DEBUG - 9: ASMV or ASMINF -- use ASM code - 10: ZLIB_WINAPI -- exported functions use the WINAPI calling convention - 11: 0 (reserved) - - One-time table building (smaller code, but not thread-safe if true): - 12: BUILDFIXED -- build static block decoding tables when needed - 13: DYNAMIC_CRC_TABLE -- build CRC calculation tables when needed - 14,15: 0 (reserved) - - Library content (indicates missing functionality): - 16: NO_GZCOMPRESS -- gz* functions cannot compress (to avoid linking - deflate code when not needed) - 17: NO_GZIP -- deflate can't write gzip streams, and inflate can't detect - and decode gzip streams (to avoid linking crc code) - 18-19: 0 (reserved) - - Operation variations (changes in library functionality): - 20: PKZIP_BUG_WORKAROUND -- slightly more permissive inflate - 21: FASTEST -- deflate algorithm with only one, lowest compression level - 22,23: 0 (reserved) - - The sprintf variant used by gzprintf (zero is best): - 24: 0 = vs*, 1 = s* -- 1 means limited to 20 arguments after the format - 25: 0 = *nprintf, 1 = *printf -- 1 means gzprintf() not secure! - 26: 0 = returns value, 1 = void -- 1 means inferred string length returned - - Remainder: - 27-31: 0 (reserved) - */ - - - /* utility functions */ - -/* - The following utility functions are implemented on top of the basic - stream-oriented functions. To simplify the interface, some default options - are assumed (compression level and memory usage, standard memory allocation - functions). The source code of these utility functions can be modified if - you need special options. -*/ - -ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); -/* - Compresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total size - of the destination buffer, which must be at least the value returned by - compressBound(sourceLen). Upon exit, destLen is the actual size of the - compressed buffer. - - compress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer. -*/ - -ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen, - int level)); -/* - Compresses the source buffer into the destination buffer. The level - parameter has the same meaning as in deflateInit. sourceLen is the byte - length of the source buffer. Upon entry, destLen is the total size of the - destination buffer, which must be at least the value returned by - compressBound(sourceLen). Upon exit, destLen is the actual size of the - compressed buffer. - - compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough - memory, Z_BUF_ERROR if there was not enough room in the output buffer, - Z_STREAM_ERROR if the level parameter is invalid. -*/ - -ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen)); -/* - compressBound() returns an upper bound on the compressed size after - compress() or compress2() on sourceLen bytes. It would be used before a - compress() or compress2() call to allocate the destination buffer. -*/ - -ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen, - const Bytef *source, uLong sourceLen)); -/* - Decompresses the source buffer into the destination buffer. sourceLen is - the byte length of the source buffer. Upon entry, destLen is the total size - of the destination buffer, which must be large enough to hold the entire - uncompressed data. (The size of the uncompressed data must have been saved - previously by the compressor and transmitted to the decompressor by some - mechanism outside the scope of this compression library.) Upon exit, destLen - is the actual size of the uncompressed buffer. - - uncompress returns Z_OK if success, Z_MEM_ERROR if there was not - enough memory, Z_BUF_ERROR if there was not enough room in the output - buffer, or Z_DATA_ERROR if the input data was corrupted or incomplete. -*/ - - - /* gzip file access functions */ - -/* - This library supports reading and writing files in gzip (.gz) format with - an interface similar to that of stdio, using the functions that start with - "gz". The gzip format is different from the zlib format. gzip is a gzip - wrapper, documented in RFC 1952, wrapped around a deflate stream. -*/ - -typedef voidp gzFile; /* opaque gzip file descriptor */ - -/* -ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode)); - - Opens a gzip (.gz) file for reading or writing. The mode parameter is as - in fopen ("rb" or "wb") but can also include a compression level ("wb9") or - a strategy: 'f' for filtered data as in "wb6f", 'h' for Huffman-only - compression as in "wb1h", 'R' for run-length encoding as in "wb1R", or 'F' - for fixed code compression as in "wb9F". (See the description of - deflateInit2 for more information about the strategy parameter.) Also "a" - can be used instead of "w" to request that the gzip stream that will be - written be appended to the file. "+" will result in an error, since reading - and writing to the same gzip file is not supported. - - gzopen can be used to read a file which is not in gzip format; in this - case gzread will directly read from the file without decompression. - - gzopen returns NULL if the file could not be opened, if there was - insufficient memory to allocate the gzFile state, or if an invalid mode was - specified (an 'r', 'w', or 'a' was not provided, or '+' was provided). - errno can be checked to determine if the reason gzopen failed was that the - file could not be opened. -*/ - -ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode)); -/* - gzdopen associates a gzFile with the file descriptor fd. File descriptors - are obtained from calls like open, dup, creat, pipe or fileno (if the file - has been previously opened with fopen). The mode parameter is as in gzopen. - - The next call of gzclose on the returned gzFile will also close the file - descriptor fd, just like fclose(fdopen(fd, mode)) closes the file descriptor - fd. If you want to keep fd open, use fd = dup(fd_keep); gz = gzdopen(fd, - mode);. The duplicated descriptor should be saved to avoid a leak, since - gzdopen does not close fd if it fails. - - gzdopen returns NULL if there was insufficient memory to allocate the - gzFile state, if an invalid mode was specified (an 'r', 'w', or 'a' was not - provided, or '+' was provided), or if fd is -1. The file descriptor is not - used until the next gz* read, write, seek, or close operation, so gzdopen - will not detect if fd is invalid (unless fd is -1). -*/ - -ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size)); -/* - Set the internal buffer size used by this library's functions. The - default buffer size is 8192 bytes. This function must be called after - gzopen() or gzdopen(), and before any other calls that read or write the - file. The buffer memory allocation is always deferred to the first read or - write. Two buffers are allocated, either both of the specified size when - writing, or one of the specified size and the other twice that size when - reading. A larger buffer size of, for example, 64K or 128K bytes will - noticeably increase the speed of decompression (reading). - - The new buffer size also affects the maximum length for gzprintf(). - - gzbuffer() returns 0 on success, or -1 on failure, such as being called - too late. -*/ - -ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy)); -/* - Dynamically update the compression level or strategy. See the description - of deflateInit2 for the meaning of these parameters. - - gzsetparams returns Z_OK if success, or Z_STREAM_ERROR if the file was not - opened for writing. -*/ - -ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len)); -/* - Reads the given number of uncompressed bytes from the compressed file. If - the input file was not in gzip format, gzread copies the given number of - bytes into the buffer. - - After reaching the end of a gzip stream in the input, gzread will continue - to read, looking for another gzip stream, or failing that, reading the rest - of the input file directly without decompression. The entire input file - will be read if gzread is called until it returns less than the requested - len. - - gzread returns the number of uncompressed bytes actually read, less than - len for end of file, or -1 for error. -*/ - -ZEXTERN int ZEXPORT gzwrite OF((gzFile file, - voidpc buf, unsigned len)); -/* - Writes the given number of uncompressed bytes into the compressed file. - gzwrite returns the number of uncompressed bytes written or 0 in case of - error. -*/ - -ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...)); -/* - Converts, formats, and writes the arguments to the compressed file under - control of the format string, as in fprintf. gzprintf returns the number of - uncompressed bytes actually written, or 0 in case of error. The number of - uncompressed bytes written is limited to 8191, or one less than the buffer - size given to gzbuffer(). The caller should assure that this limit is not - exceeded. If it is exceeded, then gzprintf() will return an error (0) with - nothing written. In this case, there may also be a buffer overflow with - unpredictable consequences, which is possible only if zlib was compiled with - the insecure functions sprintf() or vsprintf() because the secure snprintf() - or vsnprintf() functions were not available. This can be determined using - zlibCompileFlags(). -*/ - -ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s)); -/* - Writes the given null-terminated string to the compressed file, excluding - the terminating null character. - - gzputs returns the number of characters written, or -1 in case of error. -*/ - -ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len)); -/* - Reads bytes from the compressed file until len-1 characters are read, or a - newline character is read and transferred to buf, or an end-of-file - condition is encountered. If any characters are read or if len == 1, the - string is terminated with a null character. If no characters are read due - to an end-of-file or len < 1, then the buffer is left untouched. - - gzgets returns buf which is a null-terminated string, or it returns NULL - for end-of-file or in case of error. If there was an error, the contents at - buf are indeterminate. -*/ - -ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c)); -/* - Writes c, converted to an unsigned char, into the compressed file. gzputc - returns the value that was written, or -1 in case of error. -*/ - -ZEXTERN int ZEXPORT gzgetc OF((gzFile file)); -/* - Reads one byte from the compressed file. gzgetc returns this byte or -1 - in case of end of file or error. -*/ - -ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file)); -/* - Push one character back onto the stream to be read as the first character - on the next read. At least one character of push-back is allowed. - gzungetc() returns the character pushed, or -1 on failure. gzungetc() will - fail if c is -1, and may fail if a character has been pushed but not read - yet. If gzungetc is used immediately after gzopen or gzdopen, at least the - output buffer size of pushed characters is allowed. (See gzbuffer above.) - The pushed character will be discarded if the stream is repositioned with - gzseek() or gzrewind(). -*/ - -ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush)); -/* - Flushes all pending output into the compressed file. The parameter flush - is as in the deflate() function. The return value is the zlib error number - (see function gzerror below). gzflush is only permitted when writing. - - If the flush parameter is Z_FINISH, the remaining data is written and the - gzip stream is completed in the output. If gzwrite() is called again, a new - gzip stream will be started in the output. gzread() is able to read such - concatented gzip streams. - - gzflush should be called only when strictly necessary because it will - degrade compression if called too often. -*/ - -/* -ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file, - z_off_t offset, int whence)); - - Sets the starting position for the next gzread or gzwrite on the given - compressed file. The offset represents a number of bytes in the - uncompressed data stream. The whence parameter is defined as in lseek(2); - the value SEEK_END is not supported. - - If the file is opened for reading, this function is emulated but can be - extremely slow. If the file is opened for writing, only forward seeks are - supported; gzseek then compresses a sequence of zeroes up to the new - starting position. - - gzseek returns the resulting offset location as measured in bytes from - the beginning of the uncompressed stream, or -1 in case of error, in - particular if the file is opened for writing and the new starting position - would be before the current position. -*/ - -ZEXTERN int ZEXPORT gzrewind OF((gzFile file)); -/* - Rewinds the given file. This function is supported only for reading. - - gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET) -*/ - -/* -ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file)); - - Returns the starting position for the next gzread or gzwrite on the given - compressed file. This position represents a number of bytes in the - uncompressed data stream, and is zero when starting, even if appending or - reading a gzip stream from the middle of a file using gzdopen(). - - gztell(file) is equivalent to gzseek(file, 0L, SEEK_CUR) -*/ - -/* -ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file)); - - Returns the current offset in the file being read or written. This offset - includes the count of bytes that precede the gzip stream, for example when - appending or when using gzdopen() for reading. When reading, the offset - does not include as yet unused buffered input. This information can be used - for a progress indicator. On error, gzoffset() returns -1. -*/ - -ZEXTERN int ZEXPORT gzeof OF((gzFile file)); -/* - Returns true (1) if the end-of-file indicator has been set while reading, - false (0) otherwise. Note that the end-of-file indicator is set only if the - read tried to go past the end of the input, but came up short. Therefore, - just like feof(), gzeof() may return false even if there is no more data to - read, in the event that the last read request was for the exact number of - bytes remaining in the input file. This will happen if the input file size - is an exact multiple of the buffer size. - - If gzeof() returns true, then the read functions will return no more data, - unless the end-of-file indicator is reset by gzclearerr() and the input file - has grown since the previous end of file was detected. -*/ - -ZEXTERN int ZEXPORT gzdirect OF((gzFile file)); -/* - Returns true (1) if file is being copied directly while reading, or false - (0) if file is a gzip stream being decompressed. This state can change from - false to true while reading the input file if the end of a gzip stream is - reached, but is followed by data that is not another gzip stream. - - If the input file is empty, gzdirect() will return true, since the input - does not contain a gzip stream. - - If gzdirect() is used immediately after gzopen() or gzdopen() it will - cause buffers to be allocated to allow reading the file to determine if it - is a gzip file. Therefore if gzbuffer() is used, it should be called before - gzdirect(). -*/ - -ZEXTERN int ZEXPORT gzclose OF((gzFile file)); -/* - Flushes all pending output if necessary, closes the compressed file and - deallocates the (de)compression state. Note that once file is closed, you - cannot call gzerror with file, since its structures have been deallocated. - gzclose must not be called more than once on the same file, just as free - must not be called more than once on the same allocation. - - gzclose will return Z_STREAM_ERROR if file is not valid, Z_ERRNO on a - file operation error, or Z_OK on success. -*/ - -ZEXTERN int ZEXPORT gzclose_r OF((gzFile file)); -ZEXTERN int ZEXPORT gzclose_w OF((gzFile file)); -/* - Same as gzclose(), but gzclose_r() is only for use when reading, and - gzclose_w() is only for use when writing or appending. The advantage to - using these instead of gzclose() is that they avoid linking in zlib - compression or decompression code that is not used when only reading or only - writing respectively. If gzclose() is used, then both compression and - decompression code will be included the application when linking to a static - zlib library. -*/ - -ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum)); -/* - Returns the error message for the last error which occurred on the given - compressed file. errnum is set to zlib error number. If an error occurred - in the file system and not in the compression library, errnum is set to - Z_ERRNO and the application may consult errno to get the exact error code. - - The application must not modify the returned string. Future calls to - this function may invalidate the previously returned string. If file is - closed, then the string previously returned by gzerror will no longer be - available. - - gzerror() should be used to distinguish errors from end-of-file for those - functions above that do not distinguish those cases in their return values. -*/ - -ZEXTERN void ZEXPORT gzclearerr OF((gzFile file)); -/* - Clears the error and end-of-file flags for file. This is analogous to the - clearerr() function in stdio. This is useful for continuing to read a gzip - file that is being written concurrently. -*/ - - - /* checksum functions */ - -/* - These functions are not related to compression but are exported - anyway because they might be useful in applications using the compression - library. -*/ - -ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len)); -/* - Update a running Adler-32 checksum with the bytes buf[0..len-1] and - return the updated checksum. If buf is Z_NULL, this function returns the - required initial value for the checksum. - - An Adler-32 checksum is almost as reliable as a CRC32 but can be computed - much faster. - - Usage example: - - uLong adler = adler32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - adler = adler32(adler, buffer, length); - } - if (adler != original_adler) error(); -*/ - -/* -ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2, - z_off_t len2)); - - Combine two Adler-32 checksums into one. For two sequences of bytes, seq1 - and seq2 with lengths len1 and len2, Adler-32 checksums were calculated for - each, adler1 and adler2. adler32_combine() returns the Adler-32 checksum of - seq1 and seq2 concatenated, requiring only adler1, adler2, and len2. -*/ - -ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len)); -/* - Update a running CRC-32 with the bytes buf[0..len-1] and return the - updated CRC-32. If buf is Z_NULL, this function returns the required - initial value for the for the crc. Pre- and post-conditioning (one's - complement) is performed within this function so it shouldn't be done by the - application. - - Usage example: - - uLong crc = crc32(0L, Z_NULL, 0); - - while (read_buffer(buffer, length) != EOF) { - crc = crc32(crc, buffer, length); - } - if (crc != original_crc) error(); -*/ - -/* -ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2)); - - Combine two CRC-32 check values into one. For two sequences of bytes, - seq1 and seq2 with lengths len1 and len2, CRC-32 check values were - calculated for each, crc1 and crc2. crc32_combine() returns the CRC-32 - check value of seq1 and seq2 concatenated, requiring only crc1, crc2, and - len2. -*/ - - - /* various hacks, don't look :) */ - -/* deflateInit and inflateInit are macros to allow checking the zlib version - * and the compiler's view of z_stream: - */ -ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method, - int windowBits, int memLevel, - int strategy, const char *version, - int stream_size)); -ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits, - const char *version, int stream_size)); -ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits, - unsigned char FAR *window, - const char *version, - int stream_size)); -#define deflateInit(strm, level) \ - deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream)) -#define inflateInit(strm) \ - inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream)) -#define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \ - deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\ - (strategy), ZLIB_VERSION, sizeof(z_stream)) -#define inflateInit2(strm, windowBits) \ - inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream)) -#define inflateBackInit(strm, windowBits, window) \ - inflateBackInit_((strm), (windowBits), (window), \ - ZLIB_VERSION, sizeof(z_stream)) - -/* provide 64-bit offset functions if _LARGEFILE64_SOURCE defined, and/or - * change the regular functions to 64 bits if _FILE_OFFSET_BITS is 64 (if - * both are true, the application gets the *64 functions, and the regular - * functions are changed to 64 bits) -- in case these are set on systems - * without large file support, _LFS64_LARGEFILE must also be true - */ -#if defined(_LARGEFILE64_SOURCE) && _LFS64_LARGEFILE-0 - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off64_t ZEXPORT gzseek64 OF((gzFile, z_off64_t, int)); - ZEXTERN z_off64_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off64_t ZEXPORT gzoffset64 OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off64_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off64_t)); -#endif - -#if !defined(ZLIB_INTERNAL) && _FILE_OFFSET_BITS-0 == 64 && _LFS64_LARGEFILE-0 -# define gzopen gzopen64 -# define gzseek gzseek64 -# define gztell gztell64 -# define gzoffset gzoffset64 -# define adler32_combine adler32_combine64 -# define crc32_combine crc32_combine64 -# ifdef _LARGEFILE64_SOURCE - ZEXTERN gzFile ZEXPORT gzopen64 OF((const char *, const char *)); - ZEXTERN z_off_t ZEXPORT gzseek64 OF((gzFile, z_off_t, int)); - ZEXTERN z_off_t ZEXPORT gztell64 OF((gzFile)); - ZEXTERN z_off_t ZEXPORT gzoffset64 OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); -# endif -#else - ZEXTERN gzFile ZEXPORT gzopen OF((const char *, const char *)); - ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile, z_off_t, int)); - ZEXTERN z_off_t ZEXPORT gztell OF((gzFile)); - ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile)); - ZEXTERN uLong ZEXPORT adler32_combine OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine OF((uLong, uLong, z_off_t)); -#endif - -/* hack for buggy compilers */ -#if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL) - struct internal_state {int dummy;}; -#endif - -/* undocumented functions */ -ZEXTERN const char * ZEXPORT zError OF((int)); -ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp)); -ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void)); -ZEXTERN int ZEXPORT inflateUndermine OF((z_streamp, int)); - -#ifdef __cplusplus -} -#endif - -#endif /* ZLIB_H */ diff --git a/vendor/libgit2/deps/zlib/zutil.c b/vendor/libgit2/deps/zlib/zutil.c deleted file mode 100644 index 898ed345b..000000000 --- a/vendor/libgit2/deps/zlib/zutil.c +++ /dev/null @@ -1,318 +0,0 @@ -/* zutil.c -- target dependent utility functions for the compression library - * Copyright (C) 1995-2005, 2010 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* @(#) $Id$ */ - -#include "zutil.h" - -#ifndef NO_DUMMY_DECL -struct internal_state {int dummy;}; /* for buggy compilers */ -#endif - -const char * const z_errmsg[10] = { -"need dictionary", /* Z_NEED_DICT 2 */ -"stream end", /* Z_STREAM_END 1 */ -"", /* Z_OK 0 */ -"file error", /* Z_ERRNO (-1) */ -"stream error", /* Z_STREAM_ERROR (-2) */ -"data error", /* Z_DATA_ERROR (-3) */ -"insufficient memory", /* Z_MEM_ERROR (-4) */ -"buffer error", /* Z_BUF_ERROR (-5) */ -"incompatible version",/* Z_VERSION_ERROR (-6) */ -""}; - - -const char * ZEXPORT zlibVersion() -{ - return ZLIB_VERSION; -} - -uLong ZEXPORT zlibCompileFlags() -{ - uLong flags; - - flags = 0; - switch ((int)(sizeof(uInt))) { - case 2: break; - case 4: flags += 1; break; - case 8: flags += 2; break; - default: flags += 3; - } - switch ((int)(sizeof(uLong))) { - case 2: break; - case 4: flags += 1 << 2; break; - case 8: flags += 2 << 2; break; - default: flags += 3 << 2; - } - switch ((int)(sizeof(voidpf))) { - case 2: break; - case 4: flags += 1 << 4; break; - case 8: flags += 2 << 4; break; - default: flags += 3 << 4; - } - switch ((int)(sizeof(z_off_t))) { - case 2: break; - case 4: flags += 1 << 6; break; - case 8: flags += 2 << 6; break; - default: flags += 3 << 6; - } -#ifdef DEBUG - flags += 1 << 8; -#endif -#if defined(ASMV) || defined(ASMINF) - flags += 1 << 9; -#endif -#ifdef ZLIB_WINAPI - flags += 1 << 10; -#endif -#ifdef BUILDFIXED - flags += 1 << 12; -#endif -#ifdef DYNAMIC_CRC_TABLE - flags += 1 << 13; -#endif -#ifdef NO_GZCOMPRESS - flags += 1L << 16; -#endif -#ifdef NO_GZIP - flags += 1L << 17; -#endif -#ifdef PKZIP_BUG_WORKAROUND - flags += 1L << 20; -#endif -#ifdef FASTEST - flags += 1L << 21; -#endif -#ifdef STDC -# ifdef NO_vsnprintf - flags += 1L << 25; -# ifdef HAS_vsprintf_void - flags += 1L << 26; -# endif -# else -# ifdef HAS_vsnprintf_void - flags += 1L << 26; -# endif -# endif -#else - flags += 1L << 24; -# ifdef NO_snprintf - flags += 1L << 25; -# ifdef HAS_sprintf_void - flags += 1L << 26; -# endif -# else -# ifdef HAS_snprintf_void - flags += 1L << 26; -# endif -# endif -#endif - return flags; -} - -#ifdef DEBUG - -# ifndef verbose -# define verbose 0 -# endif -int ZLIB_INTERNAL z_verbose = verbose; - -void ZLIB_INTERNAL z_error (m) - char *m; -{ - fprintf(stderr, "%s\n", m); - exit(1); -} -#endif - -/* exported to allow conversion of error code to string for compress() and - * uncompress() - */ -const char * ZEXPORT zError(err) - int err; -{ - return ERR_MSG(err); -} - -#if defined(_WIN32_WCE) - /* The Microsoft C Run-Time Library for Windows CE doesn't have - * errno. We define it as a global variable to simplify porting. - * Its value is always 0 and should not be used. - */ - int errno = 0; -#endif - -#ifndef HAVE_MEMCPY - -void ZLIB_INTERNAL zmemcpy(dest, source, len) - Bytef* dest; - const Bytef* source; - uInt len; -{ - if (len == 0) return; - do { - *dest++ = *source++; /* ??? to be unrolled */ - } while (--len != 0); -} - -int ZLIB_INTERNAL zmemcmp(s1, s2, len) - const Bytef* s1; - const Bytef* s2; - uInt len; -{ - uInt j; - - for (j = 0; j < len; j++) { - if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1; - } - return 0; -} - -void ZLIB_INTERNAL zmemzero(dest, len) - Bytef* dest; - uInt len; -{ - if (len == 0) return; - do { - *dest++ = 0; /* ??? to be unrolled */ - } while (--len != 0); -} -#endif - - -#ifdef SYS16BIT - -#ifdef __TURBOC__ -/* Turbo C in 16-bit mode */ - -# define MY_ZCALLOC - -/* Turbo C malloc() does not allow dynamic allocation of 64K bytes - * and farmalloc(64K) returns a pointer with an offset of 8, so we - * must fix the pointer. Warning: the pointer must be put back to its - * original form in order to free it, use zcfree(). - */ - -#define MAX_PTR 10 -/* 10*64K = 640K */ - -local int next_ptr = 0; - -typedef struct ptr_table_s { - voidpf org_ptr; - voidpf new_ptr; -} ptr_table; - -local ptr_table table[MAX_PTR]; -/* This table is used to remember the original form of pointers - * to large buffers (64K). Such pointers are normalized with a zero offset. - * Since MSDOS is not a preemptive multitasking OS, this table is not - * protected from concurrent access. This hack doesn't work anyway on - * a protected system like OS/2. Use Microsoft C instead. - */ - -voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, unsigned items, unsigned size) -{ - voidpf buf = opaque; /* just to make some compilers happy */ - ulg bsize = (ulg)items*size; - - /* If we allocate less than 65520 bytes, we assume that farmalloc - * will return a usable pointer which doesn't have to be normalized. - */ - if (bsize < 65520L) { - buf = farmalloc(bsize); - if (*(ush*)&buf != 0) return buf; - } else { - buf = farmalloc(bsize + 16L); - } - if (buf == NULL || next_ptr >= MAX_PTR) return NULL; - table[next_ptr].org_ptr = buf; - - /* Normalize the pointer to seg:0 */ - *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4; - *(ush*)&buf = 0; - table[next_ptr++].new_ptr = buf; - return buf; -} - -void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) -{ - int n; - if (*(ush*)&ptr != 0) { /* object < 64K */ - farfree(ptr); - return; - } - /* Find the original pointer */ - for (n = 0; n < next_ptr; n++) { - if (ptr != table[n].new_ptr) continue; - - farfree(table[n].org_ptr); - while (++n < next_ptr) { - table[n-1] = table[n]; - } - next_ptr--; - return; - } - ptr = opaque; /* just to make some compilers happy */ - Assert(0, "zcfree: ptr not found"); -} - -#endif /* __TURBOC__ */ - - -#ifdef M_I86 -/* Microsoft C in 16-bit mode */ - -# define MY_ZCALLOC - -#if (!defined(_MSC_VER) || (_MSC_VER <= 600)) -# define _halloc halloc -# define _hfree hfree -#endif - -voidpf ZLIB_INTERNAL zcalloc (voidpf opaque, uInt items, uInt size) -{ - if (opaque) opaque = 0; /* to make compiler happy */ - return _halloc((long)items, size); -} - -void ZLIB_INTERNAL zcfree (voidpf opaque, voidpf ptr) -{ - if (opaque) opaque = 0; /* to make compiler happy */ - _hfree(ptr); -} - -#endif /* M_I86 */ - -#endif /* SYS16BIT */ - - -#ifndef MY_ZCALLOC /* Any system without a special alloc function */ - -#ifndef STDC -extern voidp malloc OF((uInt size)); -extern voidp calloc OF((uInt items, uInt size)); -extern void free OF((voidpf ptr)); -#endif - -voidpf ZLIB_INTERNAL zcalloc (opaque, items, size) - voidpf opaque; - unsigned items; - unsigned size; -{ - if (opaque) items += size - size; /* make compiler happy */ - return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) : - (voidpf)calloc(items, size); -} - -void ZLIB_INTERNAL zcfree (opaque, ptr) - voidpf opaque; - voidpf ptr; -{ - free(ptr); - if (opaque) return; /* make compiler happy */ -} - -#endif /* MY_ZCALLOC */ diff --git a/vendor/libgit2/deps/zlib/zutil.h b/vendor/libgit2/deps/zlib/zutil.h deleted file mode 100644 index 258fa8879..000000000 --- a/vendor/libgit2/deps/zlib/zutil.h +++ /dev/null @@ -1,274 +0,0 @@ -/* zutil.h -- internal interface and configuration of the compression library - * Copyright (C) 1995-2010 Jean-loup Gailly. - * For conditions of distribution and use, see copyright notice in zlib.h - */ - -/* WARNING: this file should *not* be used by applications. It is - part of the implementation of the compression library and is - subject to change. Applications should only use zlib.h. - */ - -/* @(#) $Id$ */ - -#ifndef ZUTIL_H -#define ZUTIL_H - -#if ((__GNUC__-0) * 10 + __GNUC_MINOR__-0 >= 33) && !defined(NO_VIZ) -# define ZLIB_INTERNAL __attribute__((visibility ("hidden"))) -#else -# define ZLIB_INTERNAL -#endif - -#include "zlib.h" - -#ifdef STDC -# if !(defined(_WIN32_WCE) && defined(_MSC_VER)) -# include -# endif -# include -# include -#endif - -#ifndef local -# define local static -#endif -/* compile with -Dlocal if your debugger can't find static symbols */ - -typedef unsigned char uch; -typedef uch FAR uchf; -typedef unsigned short ush; -typedef ush FAR ushf; -typedef unsigned long ulg; - -extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */ -/* (size given to avoid silly warnings with Visual C++) */ - -#define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)] - -#define ERR_RETURN(strm,err) \ - return (strm->msg = (char*)ERR_MSG(err), (err)) -/* To be used only when the state is known to be valid */ - - /* common constants */ - -#ifndef DEF_WBITS -# define DEF_WBITS MAX_WBITS -#endif -/* default windowBits for decompression. MAX_WBITS is for compression only */ - -#if MAX_MEM_LEVEL >= 8 -# define DEF_MEM_LEVEL 8 -#else -# define DEF_MEM_LEVEL MAX_MEM_LEVEL -#endif -/* default memLevel */ - -#define STORED_BLOCK 0 -#define STATIC_TREES 1 -#define DYN_TREES 2 -/* The three kinds of block type */ - -#define MIN_MATCH 3 -#define MAX_MATCH 258 -/* The minimum and maximum match lengths */ - -#define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */ - - /* target dependencies */ - -#if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32)) -# define OS_CODE 0x00 -# if defined(__TURBOC__) || defined(__BORLANDC__) -# if (__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__)) - /* Allow compilation with ANSI keywords only enabled */ - void _Cdecl farfree( void *block ); - void *_Cdecl farmalloc( unsigned long nbytes ); -# else -# include -# endif -# else /* MSC or DJGPP */ -# include -# endif -#endif - -#ifdef AMIGA -# define OS_CODE 0x01 -#endif - -#if defined(VAXC) || defined(VMS) -# define OS_CODE 0x02 -# define F_OPEN(name, mode) \ - fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512") -#endif - -#if defined(ATARI) || defined(atarist) -# define OS_CODE 0x05 -#endif - -#ifdef OS2 -# define OS_CODE 0x06 -# ifdef M_I86 -# include -# endif -#endif - -#if defined(MACOS) || defined(TARGET_OS_MAC) -# define OS_CODE 0x07 -# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os -# include /* for fdopen */ -# else -# ifndef fdopen -# define fdopen(fd,mode) NULL /* No fdopen() */ -# endif -# endif -#endif - -#ifdef TOPS20 -# define OS_CODE 0x0a -#endif - -#ifdef WIN32 -# ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */ -# define OS_CODE 0x0b -# endif -#endif - -#ifdef __50SERIES /* Prime/PRIMOS */ -# define OS_CODE 0x0f -#endif - -#if defined(_BEOS_) || defined(RISCOS) -# define fdopen(fd,mode) NULL /* No fdopen() */ -#endif - -#if (defined(_MSC_VER) && (_MSC_VER > 600)) && !defined __INTERIX -# if defined(_WIN32_WCE) -# define fdopen(fd,mode) NULL /* No fdopen() */ -# ifndef _PTRDIFF_T_DEFINED - typedef int ptrdiff_t; -# define _PTRDIFF_T_DEFINED -# endif -# else -# define fdopen(fd,type) _fdopen(fd,type) -# endif -#endif - -#if defined(__BORLANDC__) - #pragma warn -8004 - #pragma warn -8008 - #pragma warn -8066 -#endif - -/* provide prototypes for these when building zlib without LFS */ -#if !defined(_LARGEFILE64_SOURCE) || _LFS64_LARGEFILE-0 == 0 - ZEXTERN uLong ZEXPORT adler32_combine64 OF((uLong, uLong, z_off_t)); - ZEXTERN uLong ZEXPORT crc32_combine64 OF((uLong, uLong, z_off_t)); -#endif - - /* common defaults */ - -#ifndef OS_CODE -# define OS_CODE 0x03 /* assume Unix */ -#endif - -#ifndef F_OPEN -# define F_OPEN(name, mode) fopen((name), (mode)) -#endif - - /* functions */ - -#if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550) -# ifndef HAVE_VSNPRINTF -# define HAVE_VSNPRINTF -# endif -#endif -#if defined(__CYGWIN__) -# ifndef HAVE_VSNPRINTF -# define HAVE_VSNPRINTF -# endif -#endif -#ifndef HAVE_VSNPRINTF -# ifdef MSDOS - /* vsnprintf may exist on some MS-DOS compilers (DJGPP?), - but for now we just assume it doesn't. */ -# define NO_vsnprintf -# endif -# ifdef __TURBOC__ -# define NO_vsnprintf -# endif -# ifdef WIN32 - /* In Win32, vsnprintf is available as the "non-ANSI" _vsnprintf. */ -# if !defined(vsnprintf) && !defined(NO_vsnprintf) -# if !defined(_MSC_VER) || ( defined(_MSC_VER) && _MSC_VER < 1500 ) -# define vsnprintf _vsnprintf -# endif -# endif -# endif -# ifdef __SASC -# define NO_vsnprintf -# endif -#endif -#ifdef VMS -# define NO_vsnprintf -#endif - -#if defined(pyr) -# define NO_MEMCPY -#endif -#if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__) - /* Use our own functions for small and medium model with MSC <= 5.0. - * You may have to use the same strategy for Borland C (untested). - * The __SC__ check is for Symantec. - */ -# define NO_MEMCPY -#endif -#if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY) -# define HAVE_MEMCPY -#endif -#ifdef HAVE_MEMCPY -# ifdef SMALL_MEDIUM /* MSDOS small or medium model */ -# define zmemcpy _fmemcpy -# define zmemcmp _fmemcmp -# define zmemzero(dest, len) _fmemset(dest, 0, len) -# else -# define zmemcpy memcpy -# define zmemcmp memcmp -# define zmemzero(dest, len) memset(dest, 0, len) -# endif -#else - void ZLIB_INTERNAL zmemcpy OF((Bytef* dest, const Bytef* source, uInt len)); - int ZLIB_INTERNAL zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len)); - void ZLIB_INTERNAL zmemzero OF((Bytef* dest, uInt len)); -#endif - -/* Diagnostic functions */ -#ifdef DEBUG -# include - extern int ZLIB_INTERNAL z_verbose; - extern void ZLIB_INTERNAL z_error OF((char *m)); -# define Assert(cond,msg) {if(!(cond)) z_error(msg);} -# define Trace(x) {if (z_verbose>=0) fprintf x ;} -# define Tracev(x) {if (z_verbose>0) fprintf x ;} -# define Tracevv(x) {if (z_verbose>1) fprintf x ;} -# define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;} -# define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;} -#else -# define Assert(cond,msg) -# define Trace(x) -# define Tracev(x) -# define Tracevv(x) -# define Tracec(c,x) -# define Tracecv(c,x) -#endif - - -voidpf ZLIB_INTERNAL zcalloc OF((voidpf opaque, unsigned items, - unsigned size)); -void ZLIB_INTERNAL zcfree OF((voidpf opaque, voidpf ptr)); - -#define ZALLOC(strm, items, size) \ - (*((strm)->zalloc))((strm)->opaque, (items), (size)) -#define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr)) -#define TRY_FREE(s, p) {if (p) ZFREE(s, p);} - -#endif /* ZUTIL_H */ diff --git a/vendor/libgit2/examples/.gitignore b/vendor/libgit2/examples/.gitignore deleted file mode 100644 index 4c34e4ab5..000000000 --- a/vendor/libgit2/examples/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -general -showindex diff --git a/vendor/libgit2/examples/Makefile b/vendor/libgit2/examples/Makefile deleted file mode 100644 index f7bf469a5..000000000 --- a/vendor/libgit2/examples/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -all: general showindex - -general : general.c - gcc -lgit2 -o general general.c - -showindex : showindex.c - gcc -lgit2 -o showindex showindex.c - -clean: - rm general showindex diff --git a/vendor/libgit2/examples/general.c b/vendor/libgit2/examples/general.c deleted file mode 100644 index 91b6ee859..000000000 --- a/vendor/libgit2/examples/general.c +++ /dev/null @@ -1,447 +0,0 @@ -// [**libgit2**][lg] is a portable, pure C implementation of the Git core methods -// provided as a re-entrant linkable library with a solid API, allowing you -// to write native speed custom Git applications in any language which -// supports C bindings. -// -// This file is an example of using that API in a real, compilable C file. -// As the API is updated, this file will be updated to demonstrate the -// new functionality. -// -// If you're trying to write something in C using [libgit2][lg], you will also want -// to check out the generated [API documentation][ap] and the [Usage Guide][ug]. We've -// tried to link to the relevant sections of the API docs in each section in this file. -// -// **libgit2** only implements the core plumbing functions, not really the higher -// level porcelain stuff. For a primer on Git Internals that you will need to know -// to work with Git at this level, check out [Chapter 9][pg] of the Pro Git book. -// -// [lg]: http://libgit2.github.com -// [ap]: http://libgit2.github.com/libgit2 -// [ug]: http://libgit2.github.com/api.html -// [pg]: http://progit.org/book/ch9-0.html - -// ### Includes - -// Including the `git2.h` header will include all the other libgit2 headers that you need. -// It should be the only thing you need to include in order to compile properly and get -// all the libgit2 API. -#include -#include - -int main (int argc, char** argv) -{ - // ### Opening the Repository - - // There are a couple of methods for opening a repository, this being the simplest. - // There are also [methods][me] for specifying the index file and work tree locations, here - // we are assuming they are in the normal places. - // - // [me]: http://libgit2.github.com/libgit2/#HEAD/group/repository - git_repository *repo; - git_repository_open(&repo, "/opt/libgit2-test/.git"); - - // ### SHA-1 Value Conversions - - // For our first example, we will convert a 40 character hex value to the 20 byte raw SHA1 value. - printf("*Hex to Raw*\n"); - char hex[] = "fd6e612585290339ea8bf39c692a7ff6a29cb7c3"; - - // The `git_oid` is the structure that keeps the SHA value. We will use this throughout the example - // for storing the value of the current SHA key we're working with. - git_oid oid; - git_oid_fromstr(&oid, hex); - - // Once we've converted the string into the oid value, we can get the raw value of the SHA. - printf("Raw 20 bytes: [%s]\n", (&oid)->id); - - // Next we will convert the 20 byte raw SHA1 value to a human readable 40 char hex value. - printf("\n*Raw to Hex*\n"); - char out[41]; - out[40] = '\0'; - - // If you have a oid, you can easily get the hex value of the SHA as well. - git_oid_fmt(out, &oid); - printf("SHA hex string: %s\n", out); - - // ### Working with the Object Database - // **libgit2** provides [direct access][odb] to the object database. - // The object database is where the actual objects are stored in Git. For - // working with raw objects, we'll need to get this structure from the - // repository. - // [odb]: http://libgit2.github.com/libgit2/#HEAD/group/odb - git_odb *odb; - odb = git_repository_database(repo); - - // #### Raw Object Reading - - printf("\n*Raw Object Read*\n"); - git_odb_object *obj; - git_otype otype; - const unsigned char *data; - const char *str_type; - int error; - - // We can read raw objects directly from the object database if we have the oid (SHA) - // of the object. This allows us to access objects without knowing thier type and inspect - // the raw bytes unparsed. - error = git_odb_read(&obj, odb, &oid); - - // A raw object only has three properties - the type (commit, blob, tree or tag), the size - // of the raw data and the raw, unparsed data itself. For a commit or tag, that raw data - // is human readable plain ASCII text. For a blob it is just file contents, so it could be - // text or binary data. For a tree it is a special binary format, so it's unlikely to be - // hugely helpful as a raw object. - data = (const unsigned char *)git_odb_object_data(obj); - otype = git_odb_object_type(obj); - - // We provide methods to convert from the object type which is an enum, to a string - // representation of that value (and vice-versa). - str_type = git_object_type2string(otype); - printf("object length and type: %d, %s\n", - (int)git_odb_object_size(obj), - str_type); - - // For proper memory management, close the object when you are done with it or it will leak - // memory. - git_odb_object_close(obj); - - // #### Raw Object Writing - - printf("\n*Raw Object Write*\n"); - - // You can also write raw object data to Git. This is pretty cool because it gives you - // direct access to the key/value properties of Git. Here we'll write a new blob object - // that just contains a simple string. Notice that we have to specify the object type as - // the `git_otype` enum. - git_odb_write(&oid, odb, "test data", sizeof("test data") - 1, GIT_OBJ_BLOB); - - // Now that we've written the object, we can check out what SHA1 was generated when the - // object was written to our database. - git_oid_fmt(out, &oid); - printf("Written Object: %s\n", out); - - // ### Object Parsing - // libgit2 has methods to parse every object type in Git so you don't have to work directly - // with the raw data. This is much faster and simpler than trying to deal with the raw data - // yourself. - - // #### Commit Parsing - // [Parsing commit objects][pco] is simple and gives you access to all the data in the commit - // - the // author (name, email, datetime), committer (same), tree, message, encoding and parent(s). - // [pco]: http://libgit2.github.com/libgit2/#HEAD/group/commit - - printf("\n*Commit Parsing*\n"); - - git_commit *commit; - git_oid_fromstr(&oid, "f0877d0b841d75172ec404fc9370173dfffc20d1"); - - error = git_commit_lookup(&commit, repo, &oid); - - const git_signature *author, *cmtter; - const char *message, *message_short; - time_t ctime; - unsigned int parents, p; - - // Each of the properties of the commit object are accessible via methods, including commonly - // needed variations, such as `git_commit_time` which returns the author time and `_message_short` - // which gives you just the first line of the commit message. - message = git_commit_message(commit); - message_short = git_commit_message_short(commit); - author = git_commit_author(commit); - cmtter = git_commit_committer(commit); - ctime = git_commit_time(commit); - - // The author and committer methods return [git_signature] structures, which give you name, email - // and `when`, which is a `git_time` structure, giving you a timestamp and timezone offset. - printf("Author: %s (%s)\n", author->name, author->email); - - // Commits can have zero or more parents. The first (root) commit will have no parents, most commits - // will have one, which is the commit it was based on, and merge commits will have two or more. - // Commits can technically have any number, though it's pretty rare to have more than two. - parents = git_commit_parentcount(commit); - for (p = 0;p < parents;p++) { - git_commit *parent; - git_commit_parent(&parent, commit, p); - git_oid_fmt(out, git_commit_id(parent)); - printf("Parent: %s\n", out); - git_commit_close(parent); - } - - // Don't forget to close the object to prevent memory leaks. You will have to do this for - // all the objects you open and parse. - git_commit_close(commit); - - // #### Writing Commits - // - // libgit2 provides a couple of methods to create commit objects easily as well. There are four - // different create signatures, we'll just show one of them here. You can read about the other - // ones in the [commit API docs][cd]. - // [cd]: http://libgit2.github.com/libgit2/#HEAD/group/commit - - printf("\n*Commit Writing*\n"); - git_oid tree_id, parent_id, commit_id; - git_tree *tree; - git_commit *parent; - - // Creating signatures for an authoring identity and time is pretty simple - you will need to have - // this to create a commit in order to specify who created it and when. Default values for the name - // and email should be found in the `user.name` and `user.email` configuration options. See the `config` - // section of this example file to see how to access config values. - author = git_signature_new("Scott Chacon", "schacon@gmail.com", - 123456789, 60); - cmtter = git_signature_new("Scott A Chacon", "scott@github.com", - 987654321, 90); - - // Commit objects need a tree to point to and optionally one or more parents. Here we're creating oid - // objects to create the commit with, but you can also use - git_oid_fromstr(&tree_id, "28873d96b4e8f4e33ea30f4c682fd325f7ba56ac"); - git_tree_lookup(&tree, repo, &tree_id); - git_oid_fromstr(&parent_id, "f0877d0b841d75172ec404fc9370173dfffc20d1"); - git_commit_lookup(&parent, repo, &parent_id); - - // Here we actually create the commit object with a single call with all the values we need to create - // the commit. The SHA key is written to the `commit_id` variable here. - git_commit_create_v( - &commit_id, /* out id */ - repo, - NULL, /* do not update the HEAD */ - author, - cmtter, - "example commit", - tree, - 1, parent); - - // Now we can take a look at the commit SHA we've generated. - git_oid_fmt(out, &commit_id); - printf("New Commit: %s\n", out); - - // #### Tag Parsing - // You can parse and create tags with the [tag management API][tm], which functions very similarly - // to the commit lookup, parsing and creation methods, since the objects themselves are very similar. - // [tm]: http://libgit2.github.com/libgit2/#HEAD/group/tag - printf("\n*Tag Parsing*\n"); - git_tag *tag; - const char *tmessage, *tname; - git_otype ttype; - - // We create an oid for the tag object if we know the SHA and look it up in the repository the same - // way that we would a commit (or any other) object. - git_oid_fromstr(&oid, "bc422d45275aca289c51d79830b45cecebff7c3a"); - - error = git_tag_lookup(&tag, repo, &oid); - - // Now that we have the tag object, we can extract the information it generally contains: the target - // (usually a commit object), the type of the target object (usually 'commit'), the name ('v1.0'), - // the tagger (a git_signature - name, email, timestamp), and the tag message. - git_tag_target((git_object **)&commit, tag); - tname = git_tag_name(tag); // "test" - ttype = git_tag_type(tag); // GIT_OBJ_COMMIT (otype enum) - tmessage = git_tag_message(tag); // "tag message\n" - printf("Tag Message: %s\n", tmessage); - - git_commit_close(commit); - - // #### Tree Parsing - // [Tree parsing][tp] is a bit different than the other objects, in that we have a subtype which is the - // tree entry. This is not an actual object type in Git, but a useful structure for parsing and - // traversing tree entries. - // - // [tp]: http://libgit2.github.com/libgit2/#HEAD/group/tree - printf("\n*Tree Parsing*\n"); - - const git_tree_entry *entry; - git_object *objt; - - // Create the oid and lookup the tree object just like the other objects. - git_oid_fromstr(&oid, "2a741c18ac5ff082a7caaec6e74db3075a1906b5"); - git_tree_lookup(&tree, repo, &oid); - - // Getting the count of entries in the tree so you can iterate over them if you want to. - int cnt = git_tree_entrycount(tree); // 3 - printf("tree entries: %d\n", cnt); - - entry = git_tree_entry_byindex(tree, 0); - printf("Entry name: %s\n", git_tree_entry_name(entry)); // "hello.c" - - // You can also access tree entries by name if you know the name of the entry you're looking for. - entry = git_tree_entry_byname(tree, "hello.c"); - git_tree_entry_name(entry); // "hello.c" - - // Once you have the entry object, you can access the content or subtree (or commit, in the case - // of submodules) that it points to. You can also get the mode if you want. - git_tree_entry_2object(&objt, repo, entry); // blob - - // Remember to close the looked-up object once you are done using it - git_object_close(objt); - - // #### Blob Parsing - // - // The last object type is the simplest and requires the least parsing help. Blobs are just file - // contents and can contain anything, there is no structure to it. The main advantage to using the - // [simple blob api][ba] is that when you're creating blobs you don't have to calculate the size - // of the content. There is also a helper for reading a file from disk and writing it to the db and - // getting the oid back so you don't have to do all those steps yourself. - // - // [ba]: http://libgit2.github.com/libgit2/#HEAD/group/blob - - printf("\n*Blob Parsing*\n"); - git_blob *blob; - - git_oid_fromstr(&oid, "af7574ea73f7b166f869ef1a39be126d9a186ae0"); - git_blob_lookup(&blob, repo, &oid); - - // You can access a buffer with the raw contents of the blob directly. - // Note that this buffer may not be contain ASCII data for certain blobs (e.g. binary files): - // do not consider the buffer a NULL-terminated string, and use the `git_blob_rawsize` attribute to - // find out its exact size in bytes - printf("Blob Size: %d\n", git_blob_rawsize(blob)); // 8 - git_blob_rawcontent(blob); // "content" - - // ### Revwalking - // - // The libgit2 [revision walking api][rw] provides methods to traverse the directed graph created - // by the parent pointers of the commit objects. Since all commits point back to the commit that - // came directly before them, you can walk this parentage as a graph and find all the commits that - // were ancestors of (reachable from) a given starting point. This can allow you to create `git log` - // type functionality. - // - // [rw]: http://libgit2.github.com/libgit2/#HEAD/group/revwalk - - printf("\n*Revwalking*\n"); - git_revwalk *walk; - git_commit *wcommit; - - git_oid_fromstr(&oid, "f0877d0b841d75172ec404fc9370173dfffc20d1"); - - // To use the revwalker, create a new walker, tell it how you want to sort the output and then push - // one or more starting points onto the walker. If you want to emulate the output of `git log` you - // would push the SHA of the commit that HEAD points to into the walker and then start traversing them. - // You can also 'hide' commits that you want to stop at or not see any of their ancestors. So if you - // want to emulate `git log branch1..branch2`, you would push the oid of `branch2` and hide the oid - // of `branch1`. - git_revwalk_new(&walk, repo); - git_revwalk_sorting(walk, GIT_SORT_TOPOLOGICAL | GIT_SORT_REVERSE); - git_revwalk_push(walk, &oid); - - const git_signature *cauth; - const char *cmsg; - - // Now that we have the starting point pushed onto the walker, we can start asking for ancestors. It - // will return them in the sorting order we asked for as commit oids. - // We can then lookup and parse the commited pointed at by the returned OID; - // note that this operation is specially fast since the raw contents of the commit object will - // be cached in memory - while ((git_revwalk_next(&oid, walk)) == GIT_SUCCESS) { - error = git_commit_lookup(&wcommit, repo, &oid); - cmsg = git_commit_message_short(wcommit); - cauth = git_commit_author(wcommit); - printf("%s (%s)\n", cmsg, cauth->email); - git_commit_close(wcommit); - } - - // Like the other objects, be sure to free the revwalker when you're done to prevent memory leaks. - // Also, make sure that the repository being walked it not deallocated while the walk is in - // progress, or it will result in undefined behavior - git_revwalk_free(walk); - - // ### Index File Manipulation - // - // The [index file API][gi] allows you to read, traverse, update and write the Git index file - // (sometimes thought of as the staging area). - // - // [gi]: http://libgit2.github.com/libgit2/#HEAD/group/index - - printf("\n*Index Walking*\n"); - - git_index *index; - unsigned int i, ecount; - - // You can either open the index from the standard location in an open repository, as we're doing - // here, or you can open and manipulate any index file with `git_index_open_bare()`. The index - // for the repository will be located and loaded from disk. - git_repository_index(&index, repo); - - // For each entry in the index, you can get a bunch of information including the SHA (oid), path - // and mode which map to the tree objects that are written out. It also has filesystem properties - // to help determine what to inspect for changes (ctime, mtime, dev, ino, uid, gid, file_size and flags) - // All these properties are exported publicly in the `git_index_entry` struct - ecount = git_index_entrycount(index); - for (i = 0; i < ecount; ++i) { - git_index_entry *e = git_index_get(index, i); - - printf("path: %s\n", e->path); - printf("mtime: %d\n", (int)e->mtime.seconds); - printf("fs: %d\n", (int)e->file_size); - } - - git_index_free(index); - - // ### References - // - // The [reference API][ref] allows you to list, resolve, create and update references such as - // branches, tags and remote references (everything in the .git/refs directory). - // - // [ref]: http://libgit2.github.com/libgit2/#HEAD/group/reference - - printf("\n*Reference Listing*\n"); - - // Here we will implement something like `git for-each-ref` simply listing out all available - // references and the object SHA they resolve to. - git_strarray ref_list; - git_reference_listall(&ref_list, repo, GIT_REF_LISTALL); - - const char *refname; - git_reference *ref; - - // Now that we have the list of reference names, we can lookup each ref one at a time and - // resolve them to the SHA, then print both values out. - for (i = 0; i < ref_list.count; ++i) { - refname = ref_list.strings[i]; - git_reference_lookup(&ref, repo, refname); - - switch (git_reference_type(ref)) { - case GIT_REF_OID: - git_oid_fmt(out, git_reference_oid(ref)); - printf("%s [%s]\n", refname, out); - break; - - case GIT_REF_SYMBOLIC: - printf("%s => %s\n", refname, git_reference_target(ref)); - break; - default: - fprintf(stderr, "Unexpected reference type\n"); - exit(1); - } - } - - git_strarray_free(&ref_list); - - // ### Config Files - // - // The [config API][config] allows you to list and updatee config values in - // any of the accessible config file locations (system, global, local). - // - // [config]: http://libgit2.github.com/libgit2/#HEAD/group/config - - printf("\n*Config Listing*\n"); - - const char *email; - int j; - - git_config *cfg; - - // Open a config object so we can read global values from it. - git_config_open_ondisk(&cfg, "~/.gitconfig"); - - git_config_get_int(cfg, "help.autocorrect", &j); - printf("Autocorrect: %d\n", j); - - git_config_get_string(cfg, "user.email", &email); - printf("Email: %s\n", email); - - // Finally, when you're done with the repository, you can free it as well. - git_repository_free(repo); - - return 0; -} - diff --git a/vendor/libgit2/examples/showindex.c b/vendor/libgit2/examples/showindex.c deleted file mode 100644 index 7f2130b90..000000000 --- a/vendor/libgit2/examples/showindex.c +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include - -int main (int argc, char** argv) -{ - git_repository *repo; - git_index *index; - unsigned int i, e, ecount; - git_index_entry **entries; - git_oid oid; - - char out[41]; - out[40] = '\0'; - - git_repository_open(&repo, "/opt/libgit2-test/.git"); - - git_repository_index(&index, repo); - git_index_read(index); - - ecount = git_index_entrycount(index); - for (i = 0; i < ecount; ++i) { - git_index_entry *e = git_index_get(index, i); - - oid = e->oid; - git_oid_fmt(out, &oid); - - printf("File Path: %s\n", e->path); - printf(" Blob SHA: %s\n", out); - printf("File Size: %d\n", (int)e->file_size); - printf(" Device: %d\n", (int)e->dev); - printf(" Inode: %d\n", (int)e->ino); - printf(" UID: %d\n", (int)e->uid); - printf(" GID: %d\n", (int)e->gid); - printf(" ctime: %d\n", (int)e->ctime.seconds); - printf(" mtime: %d\n", (int)e->mtime.seconds); - printf("\n"); - } - - git_index_free(index); - - git_repository_free(repo); -} - diff --git a/vendor/libgit2/git.git-authors b/vendor/libgit2/git.git-authors deleted file mode 100644 index 086ab3e18..000000000 --- a/vendor/libgit2/git.git-authors +++ /dev/null @@ -1,66 +0,0 @@ -# This document lists the authors that have given voice to -# their decision regarding relicensing the GPL'd code from -# git.git to the GPL + gcc-exception license used by libgit2. -# -# Note that the permission is given for libgit2 use only. For -# other uses, you must ask each of the contributors yourself. -# -# To show the owners of a file in git.git, one can run the -# following command: -# -# git blame -C -C -M -- file | \ -# sed -e 's/[^(]*(\([^0-9]*\).*/\1/' -e 's/[\t ]*$//' | \ -# sort | uniq -c | sort -nr -# -# If everyone on the list that produces are on the list in -# the recently added file "git.git-authors", it *should* be -# safe to include that code in libgit2, but make sure to -# read the file to ensure the code doesn't originate from -# somewhere else. -# -# The format of this list is -# "ok/no/ask/???""Author""" -# -# "ok" means the author consents to relicensing all their -# contributed code (possibly with some exceptions) -# "no" means the author does not consent -# "ask" means that the contributor wants to give/withhold -# his/her consent on a patch-by-patch basis. -# "???" means the person is a prominent contributor who has -# not yet made his/her standpoint clear. -# "ign" means the authors consent is ignored for the purpose -# of libification. This is because the author has contributed -# to areas that aren't interesting for the library. -# -# Please try to keep the list alphabetically ordered. It will -# help in case we get all 600-ish git.git authors on it. -# -# (Paul Kocher is the author of the mozilla-sha1 implementation -# but has otherwise not contributed to git.) -# -ok Adam Simpkins (http transport) -ok Andreas Ericsson -ok Boyd Lynn Gerber -ok Brian Gernhardt -ok Christian Couder -ok Daniel Barkalow -ok Jeff King -ok Johannes Schindelin -ok Johannes Sixt -ok Junio C Hamano -ok Kristian Høgsberg -ok Linus Torvalds -ok Lukas Sandström -ok Matthieu Moy -ign Mike McCormack (imap-send) -ok Nicolas Pitre -ok Paolo Bonzini -ok Paul Kocher -ok Peter Hagervall -ok Pierre Habouzit -ok Pieter de Bie -ok René Scharfe -ign Robert Shearman (imap-send) -ok Shawn O. Pearce -ok Steffen Prohaska -ok Sven Verdoolaege diff --git a/vendor/libgit2/include/git2.h b/vendor/libgit2/include/git2.h deleted file mode 100644 index 96de524e7..000000000 --- a/vendor/libgit2/include/git2.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDE_git_git_h__ -#define INCLUDE_git_git_h__ - -#define LIBGIT2_VERSION "0.14.0" -#define LIBGIT2_VER_MAJOR 0 -#define LIBGIT2_VER_MINOR 14 -#define LIBGIT2_VER_REVISION 0 - -#include "git2/common.h" -#include "git2/errors.h" -#include "git2/zlib.h" - -#include "git2/types.h" - -#include "git2/oid.h" -#include "git2/signature.h" -#include "git2/odb.h" - -#include "git2/repository.h" -#include "git2/revwalk.h" -#include "git2/refs.h" -#include "git2/reflog.h" - -#include "git2/object.h" -#include "git2/blob.h" -#include "git2/commit.h" -#include "git2/tag.h" -#include "git2/tree.h" - -#include "git2/index.h" -#include "git2/config.h" -#include "git2/remote.h" - -#include "git2/refspec.h" -#include "git2/net.h" -#include "git2/transport.h" -#include "git2/status.h" -#include "git2/indexer.h" - -#endif diff --git a/vendor/libgit2/include/git2/blob.h b/vendor/libgit2/include/git2/blob.h deleted file mode 100644 index e366ce880..000000000 --- a/vendor/libgit2/include/git2/blob.h +++ /dev/null @@ -1,138 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_blob_h__ -#define INCLUDE_git_blob_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "object.h" - -/** - * @file git2/blob.h - * @brief Git blob load and write routines - * @defgroup git_blob Git blob load and write routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Lookup a blob object from a repository. - * - * @param blob pointer to the looked up blob - * @param repo the repo to use when locating the blob. - * @param id identity of the blob to locate. - * @return 0 on success; error code otherwise - */ -GIT_INLINE(int) git_blob_lookup(git_blob **blob, git_repository *repo, const git_oid *id) -{ - return git_object_lookup((git_object **)blob, repo, id, GIT_OBJ_BLOB); -} - -/** - * Lookup a blob object from a repository, - * given a prefix of its identifier (short id). - * - * @see git_object_lookup_prefix - * - * @param blob pointer to the looked up blob - * @param repo the repo to use when locating the blob. - * @param id identity of the blob to locate. - * @param len the length of the short identifier - * @return 0 on success; error code otherwise - */ -GIT_INLINE(int) git_blob_lookup_prefix(git_blob **blob, git_repository *repo, const git_oid *id, unsigned int len) -{ - return git_object_lookup_prefix((git_object **)blob, repo, id, len, GIT_OBJ_BLOB); -} - -/** - * Close an open blob - * - * This is a wrapper around git_object_close() - * - * IMPORTANT: - * It *is* necessary to call this method when you stop - * using a blob. Failure to do so will cause a memory leak. - * - * @param blob the blob to close - */ - -GIT_INLINE(void) git_blob_close(git_blob *blob) -{ - git_object_close((git_object *) blob); -} - - -/** - * Get a read-only buffer with the raw content of a blob. - * - * A pointer to the raw content of a blob is returned; - * this pointer is owned internally by the object and shall - * not be free'd. The pointer may be invalidated at a later - * time. - * - * @param blob pointer to the blob - * @return the pointer; NULL if the blob has no contents - */ -GIT_EXTERN(const void *) git_blob_rawcontent(git_blob *blob); - -/** - * Get the size in bytes of the contents of a blob - * - * @param blob pointer to the blob - * @return size on bytes - */ -GIT_EXTERN(int) git_blob_rawsize(git_blob *blob); - -/** - * Read a file from the working folder of a repository - * and write it to the Object Database as a loose blob - * - * @param oid return the id of the written blob - * @param repo repository where the blob will be written. - * this repository cannot be bare - * @param path file from which the blob will be created, - * relative to the repository's working dir - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path); - - -/** - * Write an in-memory buffer to the ODB as a blob - * - * @param oid return the oid of the written blob - * @param repo repository where to blob will be written - * @param buffer data to be written into the blob - * @param len length of the data - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_blob_create_frombuffer(git_oid *oid, git_repository *repo, const void *buffer, size_t len); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/branch.h b/vendor/libgit2/include/git2/branch.h deleted file mode 100644 index 456b7d1ac..000000000 --- a/vendor/libgit2/include/git2/branch.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef INCLUDE_branch_h__ -#define INCLUDE_branch_h__ - -struct git_branch { - char *remote; /* TODO: Make this a git_remote */ - char *merge; -}; - -#endif diff --git a/vendor/libgit2/include/git2/commit.h b/vendor/libgit2/include/git2/commit.h deleted file mode 100644 index 12646cf58..000000000 --- a/vendor/libgit2/include/git2/commit.h +++ /dev/null @@ -1,281 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_commit_h__ -#define INCLUDE_git_commit_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "object.h" - -/** - * @file git2/commit.h - * @brief Git commit parsing, formatting routines - * @defgroup git_commit Git commit parsing, formatting routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Lookup a commit object from a repository. - * - * @param commit pointer to the looked up commit - * @param repo the repo to use when locating the commit. - * @param id identity of the commit to locate. If the object is - * an annotated tag it will be peeled back to the commit. - * @return 0 on success; error code otherwise - */ -GIT_INLINE(int) git_commit_lookup(git_commit **commit, git_repository *repo, const git_oid *id) -{ - return git_object_lookup((git_object **)commit, repo, id, GIT_OBJ_COMMIT); -} - -/** - * Lookup a commit object from a repository, - * given a prefix of its identifier (short id). - * - * @see git_object_lookup_prefix - * - * @param commit pointer to the looked up commit - * @param repo the repo to use when locating the commit. - * @param id identity of the commit to locate. If the object is - * an annotated tag it will be peeled back to the commit. - * @param len the length of the short identifier - * @return 0 on success; error code otherwise - */ -GIT_INLINE(int) git_commit_lookup_prefix(git_commit **commit, git_repository *repo, const git_oid *id, unsigned len) -{ - return git_object_lookup_prefix((git_object **)commit, repo, id, len, GIT_OBJ_COMMIT); -} - -/** - * Close an open commit - * - * This is a wrapper around git_object_close() - * - * IMPORTANT: - * It *is* necessary to call this method when you stop - * using a commit. Failure to do so will cause a memory leak. - * - * @param commit the commit to close - */ - -GIT_INLINE(void) git_commit_close(git_commit *commit) -{ - git_object_close((git_object *) commit); -} - -/** - * Get the id of a commit. - * - * @param commit a previously loaded commit. - * @return object identity for the commit. - */ -GIT_EXTERN(const git_oid *) git_commit_id(git_commit *commit); - -/** - * Get the encoding for the message of a commit, - * as a string representing a standard encoding name. - * - * The encoding may be NULL if the `encoding` header - * in the commit is missing; in that case UTF-8 is assumed. - * - * @param commit a previously loaded commit. - * @return NULL, or the encoding - */ -GIT_EXTERN(const char *) git_commit_message_encoding(git_commit *commit); - -/** - * Get the full message of a commit. - * - * @param commit a previously loaded commit. - * @return the message of a commit - */ -GIT_EXTERN(const char *) git_commit_message(git_commit *commit); - -/** - * Get the commit time (i.e. committer time) of a commit. - * - * @param commit a previously loaded commit. - * @return the time of a commit - */ -GIT_EXTERN(git_time_t) git_commit_time(git_commit *commit); - -/** - * Get the commit timezone offset (i.e. committer's preferred timezone) of a commit. - * - * @param commit a previously loaded commit. - * @return positive or negative timezone offset, in minutes from UTC - */ -GIT_EXTERN(int) git_commit_time_offset(git_commit *commit); - -/** - * Get the committer of a commit. - * - * @param commit a previously loaded commit. - * @return the committer of a commit - */ -GIT_EXTERN(const git_signature *) git_commit_committer(git_commit *commit); - -/** - * Get the author of a commit. - * - * @param commit a previously loaded commit. - * @return the author of a commit - */ -GIT_EXTERN(const git_signature *) git_commit_author(git_commit *commit); - -/** - * Get the tree pointed to by a commit. - * - * @param tree_out pointer where to store the tree object - * @param commit a previously loaded commit. - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_commit_tree(git_tree **tree_out, git_commit *commit); - -/** - * Get the id of the tree pointed to by a commit. This differs from - * `git_commit_tree` in that no attempts are made to fetch an object - * from the ODB. - * - * @param commit a previously loaded commit. - * @return the id of tree pointed to by commit. - */ -GIT_EXTERN(const git_oid *) git_commit_tree_oid(git_commit *commit); - -/** - * Get the number of parents of this commit - * - * @param commit a previously loaded commit. - * @return integer of count of parents - */ -GIT_EXTERN(unsigned int) git_commit_parentcount(git_commit *commit); - -/** - * Get the specified parent of the commit. - * - * @param parent Pointer where to store the parent commit - * @param commit a previously loaded commit. - * @param n the position of the parent (from 0 to `parentcount`) - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_commit_parent(git_commit **parent, git_commit *commit, unsigned int n); - -/** - * Get the oid of a specified parent for a commit. This is different from - * `git_commit_parent`, which will attempt to load the parent commit from - * the ODB. - * - * @param commit a previously loaded commit. - * @param n the position of the parent (from 0 to `parentcount`) - * @return the id of the parent, NULL on error. - */ -GIT_EXTERN(const git_oid *) git_commit_parent_oid(git_commit *commit, unsigned int n); - -/** - * Create a new commit in the repository using `git_object` - * instances as parameters. - * - * @param oid Pointer where to store the OID of the - * newly created commit - * - * @param repo Repository where to store the commit - * - * @param update_ref If not NULL, name of the reference that - * will be updated to point to this commit. If the reference - * is not direct, it will be resolved to a direct reference. - * Use "HEAD" to update the HEAD of the current branch and - * make it point to this commit - * - * @param author Signature representing the author and the authory - * time of this commit - * - * @param committer Signature representing the committer and the - * commit time of this commit - * - * @param message_encoding The encoding for the message in the - * commit, represented with a standard encoding name. - * E.g. "UTF-8". If NULL, no encoding header is written and - * UTF-8 is assumed. - * - * @param message Full message for this commit - * - * @param tree An instance of a `git_tree` object that will - * be used as the tree for the commit. This tree object must - * also be owned by the given `repo`. - * - * @param parent_count Number of parents for this commit - * - * @param parents[] Array of `parent_count` pointers to `git_commit` - * objects that will be used as the parents for this commit. This - * array may be NULL if `parent_count` is 0 (root commit). All the - * given commits must be owned by the `repo`. - * - * @return 0 on success; error code otherwise - * The created commit will be written to the Object Database and - * the given reference will be updated to point to it - */ -GIT_EXTERN(int) git_commit_create( - git_oid *oid, - git_repository *repo, - const char *update_ref, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_tree *tree, - int parent_count, - const git_commit *parents[]); - -/** - * Create a new commit in the repository using a variable - * argument list. - * - * The parents for the commit are specified as a variable - * list of pointers to `const git_commit *`. Note that this - * is a convenience method which may not be safe to export - * for certain languages or compilers - * - * All other parameters remain the same - * - * @see git_commit_create - */ -GIT_EXTERN(int) git_commit_create_v( - git_oid *oid, - git_repository *repo, - const char *update_ref, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_tree *tree, - int parent_count, - ...); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/common.h b/vendor/libgit2/include/git2/common.h deleted file mode 100644 index 58cb1f200..000000000 --- a/vendor/libgit2/include/git2/common.h +++ /dev/null @@ -1,128 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_common_h__ -#define INCLUDE_git_common_h__ - -#include "thread-utils.h" -#include -#include - -#ifdef __cplusplus -# define GIT_BEGIN_DECL extern "C" { -# define GIT_END_DECL } -#else - /** Start declarations in C mode */ -# define GIT_BEGIN_DECL /* empty */ - /** End declarations in C mode */ -# define GIT_END_DECL /* empty */ -#endif - -/** Declare a public function exported for application use. */ -#ifdef __GNUC__ -# define GIT_EXTERN(type) extern \ - __attribute__((visibility("default"))) \ - type -#elif defined(_MSC_VER) -# define GIT_EXTERN(type) __declspec(dllexport) type -#else -# define GIT_EXTERN(type) extern type -#endif - -/** Declare a public TLS symbol exported for application use. */ -#ifdef __GNUC__ -# define GIT_EXTERN_TLS(type) extern \ - __attribute__((visibility("default"))) \ - GIT_TLS \ - type -#elif defined(_MSC_VER) -# define GIT_EXTERN_TLS(type) __declspec(dllexport) GIT_TLS type -#else -# define GIT_EXTERN_TLS(type) extern GIT_TLS type -#endif - -/** Declare a function as always inlined. */ -#if defined(_MSC_VER) -# define GIT_INLINE(type) static __inline type -#else -# define GIT_INLINE(type) static inline type -#endif - -/** Declare a function's takes printf style arguments. */ -#ifdef __GNUC__ -# define GIT_FORMAT_PRINTF(a,b) __attribute__((format (printf, a, b))) -#else -# define GIT_FORMAT_PRINTF(a,b) /* empty */ -#endif - -#if defined(_WIN32) && !defined(__CYGWIN__) -#define GIT_WIN32 1 -#endif - -/** - * @file git2/common.h - * @brief Git common platform definitions - * @defgroup git_common Git common platform definitions - * @ingroup Git - * @{ - */ - -GIT_BEGIN_DECL - -/** - * The separator used in path list strings (ie like in the PATH - * environment variable). A semi-colon ";" is used on Windows, and - * a colon ":" for all other systems. - */ -#ifdef GIT_WIN32 -#define GIT_PATH_LIST_SEPARATOR ';' -#else -#define GIT_PATH_LIST_SEPARATOR ':' -#endif - -/** - * The maximum length of a git valid git path. - */ -#define GIT_PATH_MAX 4096 - -typedef struct { - char **strings; - size_t count; -} git_strarray; - -GIT_EXTERN(void) git_strarray_free(git_strarray *array); - -/** - * Return the version of the libgit2 library - * being currently used. - * - * @param major Store the major version number - * @param minor Store the minor version number - * @param rev Store the revision (patch) number - */ -GIT_EXTERN(void) git_libgit2_version(int *major, int *minor, int *rev); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/config.h b/vendor/libgit2/include/git2/config.h deleted file mode 100644 index e05d23694..000000000 --- a/vendor/libgit2/include/git2/config.h +++ /dev/null @@ -1,284 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_config_h__ -#define INCLUDE_git_config_h__ - -#include "common.h" -#include "types.h" - -/** - * @file git2/config.h - * @brief Git config management routines - * @defgroup git_config Git config management routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Generic backend that implements the interface to - * access a configuration file - */ -struct git_config_file { - struct git_config *cfg; - - /* Open means open the file/database and parse if necessary */ - int (*open)(struct git_config_file *); - int (*get)(struct git_config_file *, const char *key, const char **value); - int (*set)(struct git_config_file *, const char *key, const char *value); - int (*foreach)(struct git_config_file *, int (*fn)(const char *, const char *, void *), void *data); - void (*free)(struct git_config_file *); -}; - -/** - * Locate the path to the global configuration file - * - * The user or global configuration file is usually - * located in `$HOME/.gitconfig`. - * - * This method will try to guess the full path to that - * file, if the file exists. The returned path - * may be used on any `git_config` call to load the - * global configuration file. - * - * @param global_config_path Buffer of GIT_PATH_MAX length to store the path - * @return GIT_SUCCESS if a global configuration file has been - * found. Its path will be stored in `buffer`. - */ -GIT_EXTERN(int) git_config_find_global(char *global_config_path); - -/** - * Open the global configuration file - * - * Utility wrapper that calls `git_config_find_global` - * and opens the located file, if it exists. - * - * @param out Pointer to store the config instance - * @return GIT_SUCCESS on success; error code otherwise - */ -GIT_EXTERN(int) git_config_open_global(git_config **out); - -/** - * Create a configuration file backend for ondisk files - * - * These are the normal `.gitconfig` files that Core Git - * processes. Note that you first have to add this file to a - * configuration object before you can query it for configuration - * variables. - * - * @param out the new backend - * @param path where the config file is located - */ -GIT_EXTERN(int) git_config_file__ondisk(struct git_config_file **out, const char *path); - -/** - * Allocate a new configuration object - * - * This object is empty, so you have to add a file to it before you - * can do anything with it. - * - * @param out pointer to the new configuration - * @return GIT_SUCCESS on success; error code otherwise - */ -GIT_EXTERN(int) git_config_new(git_config **out); - -/** - * Add a generic config file instance to an existing config - * - * Note that the configuration object will free the file - * automatically. - * - * Further queries on this config object will access each - * of the config file instances in order (instances with - * a higher priority will be accessed first). - * - * @param cfg the configuration to add the file to - * @param file the configuration file (backend) to add - * @param priority the priority the backend should have - * @return GIT_SUCCESS on success; error code otherwise - */ -GIT_EXTERN(int) git_config_add_file(git_config *cfg, git_config_file *file, int priority); - -/** - * Add an on-disk config file instance to an existing config - * - * The on-disk file pointed at by `path` will be opened and - * parsed; it's expected to be a native Git config file following - * the default Git config syntax (see man git-config). - * - * Note that the configuration object will free the file - * automatically. - * - * Further queries on this config object will access each - * of the config file instances in order (instances with - * a higher priority will be accessed first). - * - * @param cfg the configuration to add the file to - * @param path path to the configuration file (backend) to add - * @param priority the priority the backend should have - * @return GIT_SUCCESS on success; error code otherwise - */ -GIT_EXTERN(int) git_config_add_file_ondisk(git_config *cfg, const char *path, int priority); - - -/** - * Create a new config instance containing a single on-disk file - * - * This method is a simple utility wrapper for the following sequence - * of calls: - * - git_config_new - * - git_config_add_file_ondisk - * - * @param cfg The configuration instance to create - * @param path Path to the on-disk file to open - * @return GIT_SUCCESS on success; error code otherwise - */ -GIT_EXTERN(int) git_config_open_ondisk(git_config **cfg, const char *path); - -/** - * Free the configuration and its associated memory and files - * - * @param cfg the configuration to free - */ -GIT_EXTERN(void) git_config_free(git_config *cfg); - -/** - * Get the value of an integer config variable. - * - * @param cfg where to look for the variable - * @param name the variable's name - * @param out pointer to the variable where the value should be stored - * @return GIT_SUCCESS on success; error code otherwise - */ -GIT_EXTERN(int) git_config_get_int(git_config *cfg, const char *name, int *out); - -/** - * Get the value of a long integer config variable. - * - * @param cfg where to look for the variable - * @param name the variable's name - * @param out pointer to the variable where the value should be stored - * @return GIT_SUCCESS on success; error code otherwise - */ -GIT_EXTERN(int) git_config_get_long(git_config *cfg, const char *name, long int *out); - -/** - * Get the value of a boolean config variable. - * - * This function uses the usual C convention of 0 being false and - * anything else true. - * - * @param cfg where to look for the variable - * @param name the variable's name - * @param out pointer to the variable where the value should be stored - * @return GIT_SUCCESS on success; error code otherwise - */ -GIT_EXTERN(int) git_config_get_bool(git_config *cfg, const char *name, int *out); - -/** - * Get the value of a string config variable. - * - * The string is owned by the variable and should not be freed by the - * user. - * - * @param cfg where to look for the variable - * @param name the variable's name - * @param out pointer to the variable's value - * @return GIT_SUCCESS on success; error code otherwise - */ -GIT_EXTERN(int) git_config_get_string(git_config *cfg, const char *name, const char **out); - -/** - * Set the value of an integer config variable. - * - * @param cfg where to look for the variable - * @param name the variable's name - * @param value Integer value for the variable - * @return GIT_SUCCESS on success; error code otherwise - */ -GIT_EXTERN(int) git_config_set_int(git_config *cfg, const char *name, int value); - -/** - * Set the value of a long integer config variable. - * - * @param cfg where to look for the variable - * @param name the variable's name - * @param value Long integer value for the variable - * @return GIT_SUCCESS on success; error code otherwise - */ -GIT_EXTERN(int) git_config_set_long(git_config *cfg, const char *name, long int value); - -/** - * Set the value of a boolean config variable. - * - * @param cfg where to look for the variable - * @param name the variable's name - * @param value the value to store - * @return GIT_SUCCESS on success; error code otherwise - */ -GIT_EXTERN(int) git_config_set_bool(git_config *cfg, const char *name, int value); - -/** - * Set the value of a string config variable. - * - * A copy of the string is made and the user is free to use it - * afterwards. - * - * @param cfg where to look for the variable - * @param name the variable's name - * @param value the string to store. - * @return GIT_SUCCESS on success; error code otherwise - */ -GIT_EXTERN(int) git_config_set_string(git_config *cfg, const char *name, const char *value); - -/** - * Delete a config variable - * - * @param cfg the configuration - * @param name the variable to delete - */ -GIT_EXTERN(int) git_config_delete(git_config *cfg, const char *name); - -/** - * Perform an operation on each config variable. - * - * The callback receives the normalized name and value of each variable - * in the config backend, and the data pointer passed to this function. - * As soon as one of the callback functions returns something other than 0, - * this function returns that value. - * - * @param cfg where to get the variables from - * @param callback the function to call on each variable - * @param payload the data to pass to the callback - * @return GIT_SUCCESS or the return value of the callback which didn't return 0 - */ -GIT_EXTERN(int) git_config_foreach( - git_config *cfg, - int (*callback)(const char *var_name, const char *value, void *payload), - void *payload); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/errors.h b/vendor/libgit2/include/git2/errors.h deleted file mode 100644 index 710ac244b..000000000 --- a/vendor/libgit2/include/git2/errors.h +++ /dev/null @@ -1,162 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_errors_h__ -#define INCLUDE_git_errors_h__ - -#include "common.h" - -/** - * @file git2/errors.h - * @brief Git error handling routines and variables - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -typedef enum { - GIT_SUCCESS = 0, - GIT_ERROR = -1, - - /** Input was not a properly formatted Git object id. */ - GIT_ENOTOID = -2, - - /** Input does not exist in the scope searched. */ - GIT_ENOTFOUND = -3, - - /** Not enough space available. */ - GIT_ENOMEM = -4, - - /** Consult the OS error information. */ - GIT_EOSERR = -5, - - /** The specified object is of invalid type */ - GIT_EOBJTYPE = -6, - - /** The specified repository is invalid */ - GIT_ENOTAREPO = -7, - - /** The object type is invalid or doesn't match */ - GIT_EINVALIDTYPE = -8, - - /** The object cannot be written because it's missing internal data */ - GIT_EMISSINGOBJDATA = -9, - - /** The packfile for the ODB is corrupted */ - GIT_EPACKCORRUPTED = -10, - - /** Failed to acquire or release a file lock */ - GIT_EFLOCKFAIL = -11, - - /** The Z library failed to inflate/deflate an object's data */ - GIT_EZLIB = -12, - - /** The queried object is currently busy */ - GIT_EBUSY = -13, - - /** The index file is not backed up by an existing repository */ - GIT_EBAREINDEX = -14, - - /** The name of the reference is not valid */ - GIT_EINVALIDREFNAME = -15, - - /** The specified reference has its data corrupted */ - GIT_EREFCORRUPTED = -16, - - /** The specified symbolic reference is too deeply nested */ - GIT_ETOONESTEDSYMREF = -17, - - /** The pack-refs file is either corrupted or its format is not currently supported */ - GIT_EPACKEDREFSCORRUPTED = -18, - - /** The path is invalid */ - GIT_EINVALIDPATH = -19, - - /** The revision walker is empty; there are no more commits left to iterate */ - GIT_EREVWALKOVER = -20, - - /** The state of the reference is not valid */ - GIT_EINVALIDREFSTATE = -21, - - /** This feature has not been implemented yet */ - GIT_ENOTIMPLEMENTED = -22, - - /** A reference with this name already exists */ - GIT_EEXISTS = -23, - - /** The given integer literal is too large to be parsed */ - GIT_EOVERFLOW = -24, - - /** The given literal is not a valid number */ - GIT_ENOTNUM = -25, - - /** Streaming error */ - GIT_ESTREAM = -26, - - /** invalid arguments to function */ - GIT_EINVALIDARGS = -27, - - /** The specified object has its data corrupted */ - GIT_EOBJCORRUPTED = -28, - - /** The given short oid is ambiguous */ - GIT_EAMBIGUOUSOIDPREFIX = -29, - - /** Skip and passthrough the given ODB backend */ - GIT_EPASSTHROUGH = -30, - - /** The path pattern and string did not match */ - GIT_ENOMATCH = -31, - - /** The buffer is too short to satisfy the request */ - GIT_ESHORTBUFFER = -32, -} git_error; - -/** - * Return a detailed error string with the latest error - * that occurred in the library. - * @return a string explaining the error - */ -GIT_EXTERN(const char *) git_lasterror(void); - -/** - * strerror() for the Git library - * - * Get a string description for a given error code. - * NOTE: This method will be eventually deprecated in favor - * of the new `git_lasterror`. - * - * @param num The error code to explain - * @return a string explaining the error code - */ -GIT_EXTERN(const char *) git_strerror(int num); - -/** - * Clear the latest library error - */ -GIT_EXTERN(void) git_clearerror(void); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/index.h b/vendor/libgit2/include/git2/index.h deleted file mode 100644 index 18ab9b858..000000000 --- a/vendor/libgit2/include/git2/index.h +++ /dev/null @@ -1,324 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_index_h__ -#define INCLUDE_git_index_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" - -/** - * @file git2/index.h - * @brief Git index parsing and manipulation routines - * @defgroup git_index Git index parsing and manipulation routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -#define GIT_IDXENTRY_NAMEMASK (0x0fff) -#define GIT_IDXENTRY_STAGEMASK (0x3000) -#define GIT_IDXENTRY_EXTENDED (0x4000) -#define GIT_IDXENTRY_VALID (0x8000) -#define GIT_IDXENTRY_STAGESHIFT 12 - -/* - * Flags are divided into two parts: in-memory flags and - * on-disk ones. Flags in GIT_IDXENTRY_EXTENDED_FLAGS - * will get saved on-disk. - * - * In-memory only flags: - */ -#define GIT_IDXENTRY_UPDATE (1 << 0) -#define GIT_IDXENTRY_REMOVE (1 << 1) -#define GIT_IDXENTRY_UPTODATE (1 << 2) -#define GIT_IDXENTRY_ADDED (1 << 3) - -#define GIT_IDXENTRY_HASHED (1 << 4) -#define GIT_IDXENTRY_UNHASHED (1 << 5) -#define GIT_IDXENTRY_WT_REMOVE (1 << 6) /* remove in work directory */ -#define GIT_IDXENTRY_CONFLICTED (1 << 7) - -#define GIT_IDXENTRY_UNPACKED (1 << 8) -#define GIT_IDXENTRY_NEW_SKIP_WORKTREE (1 << 9) - -/* - * Extended on-disk flags: - */ -#define GIT_IDXENTRY_INTENT_TO_ADD (1 << 13) -#define GIT_IDXENTRY_SKIP_WORKTREE (1 << 14) -/* GIT_IDXENTRY_EXTENDED2 is for future extension */ -#define GIT_IDXENTRY_EXTENDED2 (1 << 15) - -#define GIT_IDXENTRY_EXTENDED_FLAGS (GIT_IDXENTRY_INTENT_TO_ADD | GIT_IDXENTRY_SKIP_WORKTREE) - -/** Time used in a git index entry */ -typedef struct { - git_time_t seconds; - /* nsec should not be stored as time_t compatible */ - unsigned int nanoseconds; -} git_index_time; - -/** Memory representation of a file entry in the index. */ -typedef struct git_index_entry { - git_index_time ctime; - git_index_time mtime; - - unsigned int dev; - unsigned int ino; - unsigned int mode; - unsigned int uid; - unsigned int gid; - git_off_t file_size; - - git_oid oid; - - unsigned short flags; - unsigned short flags_extended; - - char *path; -} git_index_entry; - -/** Representation of an unmerged file entry in the index. */ -typedef struct git_index_entry_unmerged { - unsigned int mode[3]; - git_oid oid[3]; - char *path; -} git_index_entry_unmerged; - -/** - * Create a new bare Git index object as a memory representation - * of the Git index file in 'index_path', without a repository - * to back it. - * - * Since there is no ODB or working directory behind this index, - * any Index methods which rely on these (e.g. index_add) will - * fail with the GIT_EBAREINDEX error code. - * - * If you need to access the index of an actual repository, - * use the `git_repository_index` wrapper. - * - * The index must be freed once it's no longer in use. - * - * @param index the pointer for the new index - * @param index_path the path to the index file in disk - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_index_open(git_index **index, const char *index_path); - -/** - * Clear the contents (all the entries) of an index object. - * This clears the index object in memory; changes must be manually - * written to disk for them to take effect. - * - * @param index an existing index object - */ -GIT_EXTERN(void) git_index_clear(git_index *index); - -/** - * Free an existing index object. - * - * @param index an existing index object - */ -GIT_EXTERN(void) git_index_free(git_index *index); - -/** - * Update the contents of an existing index object in memory - * by reading from the hard disk. - * - * @param index an existing index object - * @return 0 on success, otherwise an error code - */ -GIT_EXTERN(int) git_index_read(git_index *index); - -/** - * Write an existing index object from memory back to disk - * using an atomic file lock. - * - * @param index an existing index object - * @return 0 on success, otherwise an error code - */ -GIT_EXTERN(int) git_index_write(git_index *index); - -/** - * Find the first index of any entries which point to given - * path in the Git index. - * - * @param index an existing index object - * @param path path to search - * @return an index >= 0 if found, -1 otherwise - */ -GIT_EXTERN(int) git_index_find(git_index *index, const char *path); - -/** - * Remove all entries with equal path except last added - * - * @param index an existing index object - */ -GIT_EXTERN(void) git_index_uniq(git_index *index); - -/** - * Add or update an index entry from a file in disk - * - * The file `path` must be relative to the repository's - * working folder and must be readable. - * - * This method will fail in bare index instances. - * - * @param index an existing index object - * @param path filename to add - * @param stage stage for the entry - * @return 0 on success, otherwise an error code - */ -GIT_EXTERN(int) git_index_add(git_index *index, const char *path, int stage); - -/** - * Add or update an index entry from an in-memory struct - * - * A full copy (including the 'path' string) of the given - * 'source_entry' will be inserted on the index. - * - * @param index an existing index object - * @param source_entry new entry object - * @return 0 on success, otherwise an error code - */ -GIT_EXTERN(int) git_index_add2(git_index *index, const git_index_entry *source_entry); - -/** - * Add (append) an index entry from a file in disk - * - * A new entry will always be inserted into the index; - * if the index already contains an entry for such - * path, the old entry will **not** be replaced. - * - * The file `path` must be relative to the repository's - * working folder and must be readable. - * - * This method will fail in bare index instances. - * - * @param index an existing index object - * @param path filename to add - * @param stage stage for the entry - * @return 0 on success, otherwise an error code - */ -GIT_EXTERN(int) git_index_append(git_index *index, const char *path, int stage); - -/** - * Add (append) an index entry from an in-memory struct - * - * A new entry will always be inserted into the index; - * if the index already contains an entry for the path - * in the `entry` struct, the old entry will **not** be - * replaced. - * - * A full copy (including the 'path' string) of the given - * 'source_entry' will be inserted on the index. - * - * @param index an existing index object - * @param source_entry new entry object - * @return 0 on success, otherwise an error code - */ -GIT_EXTERN(int) git_index_append2(git_index *index, const git_index_entry *source_entry); - -/** - * Remove an entry from the index - * - * @param index an existing index object - * @param position position of the entry to remove - * @return 0 on success, otherwise an error code - */ -GIT_EXTERN(int) git_index_remove(git_index *index, int position); - - -/** - * Get a pointer to one of the entries in the index - * - * This entry can be modified, and the changes will be written - * back to disk on the next write() call. - * - * The entry should not be freed by the caller. - * - * @param index an existing index object - * @param n the position of the entry - * @return a pointer to the entry; NULL if out of bounds - */ -GIT_EXTERN(git_index_entry *) git_index_get(git_index *index, unsigned int n); - -/** - * Get the count of entries currently in the index - * - * @param index an existing index object - * @return integer of count of current entries - */ -GIT_EXTERN(unsigned int) git_index_entrycount(git_index *index); - -/** - * Get the count of unmerged entries currently in the index - * - * @param index an existing index object - * @return integer of count of current unmerged entries - */ -GIT_EXTERN(unsigned int) git_index_entrycount_unmerged(git_index *index); - -/** - * Get an unmerged entry from the index. - * - * The returned entry is read-only and should not be modified - * of freed by the caller. - * - * @param index an existing index object - * @param path path to search - * @return the unmerged entry; NULL if not found - */ -GIT_EXTERN(const git_index_entry_unmerged *) git_index_get_unmerged_bypath(git_index *index, const char *path); - -/** - * Get an unmerged entry from the index. - * - * The returned entry is read-only and should not be modified - * of freed by the caller. - * - * @param index an existing index object - * @param n the position of the entry - * @return a pointer to the unmerged entry; NULL if out of bounds - */ -GIT_EXTERN(const git_index_entry_unmerged *) git_index_get_unmerged_byindex(git_index *index, unsigned int n); - -/** - * Return the stage number from a git index entry - * - * This entry is calculated from the entrie's flag - * attribute like this: - * - * (entry->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT - * - * @param entry The entry - * @returns the stage number - */ -GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/indexer.h b/vendor/libgit2/include/git2/indexer.h deleted file mode 100644 index 2852d7e6f..000000000 --- a/vendor/libgit2/include/git2/indexer.h +++ /dev/null @@ -1,70 +0,0 @@ -#ifndef _INCLUDE_git_indexer_h__ -#define _INCLUDE_git_indexer_h__ - -#include "git2/common.h" -#include "git2/oid.h" - -GIT_BEGIN_DECL - -/** - * This is passed as the first argument to the callback to allow the - * user to see the progress. - */ -typedef struct git_indexer_stats { - unsigned int total; - unsigned int processed; -} git_indexer_stats; - - -typedef struct git_indexer git_indexer; - -/** - * Create a new indexer instance - * - * @param out where to store the indexer instance - * @param packname the absolute filename of the packfile to index - */ -GIT_EXTERN(int) git_indexer_new(git_indexer **out, const char *packname); - -/** - * Iterate over the objects in the packfile and extract the information - * - * Indexing a packfile can be very expensive so this function is - * expected to be run in a worker thread and the stats used to provide - * feedback the user. - * - * @param idx the indexer instance - * @param stats storage for the running state - */ -GIT_EXTERN(int) git_indexer_run(git_indexer *idx, git_indexer_stats *stats); - -/** - * Write the index file to disk. - * - * The file will be stored as pack-$hash.idx in the same directory as - * the packfile. - * - * @param idx the indexer instance - */ -GIT_EXTERN(int) git_indexer_write(git_indexer *idx); - -/** - * Get the packfile's hash - * - * A packfile's name is derived from the sorted hashing of all object - * names. This is only correct after the index has been written to disk. - * - * @param idx the indexer instance - */ -GIT_EXTERN(const git_oid *) git_indexer_hash(git_indexer *idx); - -/** - * Free the indexer and its resources - * - * @param idx the indexer to free - */ -GIT_EXTERN(void) git_indexer_free(git_indexer *idx); - -GIT_END_DECL - -#endif diff --git a/vendor/libgit2/include/git2/net.h b/vendor/libgit2/include/git2/net.h deleted file mode 100644 index d4f475527..000000000 --- a/vendor/libgit2/include/git2/net.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_net_h__ -#define INCLUDE_net_h__ - -#include "common.h" -#include "oid.h" -#include "types.h" - -/** - * @file git2/net.h - * @brief Git networking declarations - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -#define GIT_DEFAULT_PORT "9418" - -/* - * We need this because we need to know whether we should call - * git-upload-pack or git-receive-pack on the remote end when get_refs - * gets called. - */ - -#define GIT_DIR_FETCH 0 -#define GIT_DIR_PUSH 1 - -/** - * Remote head description, given out on `ls` calls. - */ -struct git_remote_head { - int local:1; /* available locally */ - git_oid oid; - git_oid loid; - char *name; -}; - -/** - * Array of remote heads - */ -struct git_headarray { - unsigned int len; - struct git_remote_head **heads; -}; - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/object.h b/vendor/libgit2/include/git2/object.h deleted file mode 100644 index 07ba1a1c7..000000000 --- a/vendor/libgit2/include/git2/object.h +++ /dev/null @@ -1,191 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_object_h__ -#define INCLUDE_git_object_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" - -/** - * @file git2/object.h - * @brief Git revision object management routines - * @defgroup git_object Git revision object management routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Lookup a reference to one of the objects in a repostory. - * - * The generated reference is owned by the repository and - * should be closed with the `git_object_close` method - * instead of free'd manually. - * - * The 'type' parameter must match the type of the object - * in the odb; the method will fail otherwise. - * The special value 'GIT_OBJ_ANY' may be passed to let - * the method guess the object's type. - * - * @param object pointer to the looked-up object - * @param repo the repository to look up the object - * @param id the unique identifier for the object - * @param type the type of the object - * @return a reference to the object - */ -GIT_EXTERN(int) git_object_lookup( - git_object **object, - git_repository *repo, - const git_oid *id, - git_otype type); - -/** - * Lookup a reference to one of the objects in a repostory, - * given a prefix of its identifier (short id). - * - * The object obtained will be so that its identifier - * matches the first 'len' hexadecimal characters - * (packets of 4 bits) of the given 'id'. - * 'len' must be at least GIT_OID_MINPREFIXLEN, and - * long enough to identify a unique object matching - * the prefix; otherwise the method will fail. - * - * The generated reference is owned by the repository and - * should be closed with the `git_object_close` method - * instead of free'd manually. - * - * The 'type' parameter must match the type of the object - * in the odb; the method will fail otherwise. - * The special value 'GIT_OBJ_ANY' may be passed to let - * the method guess the object's type. - * - * @param object_out pointer where to store the looked-up object - * @param repo the repository to look up the object - * @param id a short identifier for the object - * @param len the length of the short identifier - * @param type the type of the object - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_object_lookup_prefix( - git_object **object_out, - git_repository *repo, - const git_oid *id, - unsigned int len, - git_otype type); - -/** - * Get the id (SHA1) of a repository object - * - * @param obj the repository object - * @return the SHA1 id - */ -GIT_EXTERN(const git_oid *) git_object_id(const git_object *obj); - -/** - * Get the object type of an object - * - * @param obj the repository object - * @return the object's type - */ -GIT_EXTERN(git_otype) git_object_type(const git_object *obj); - -/** - * Get the repository that owns this object - * - * Freeing or calling `git_repository_close` on the - * returned pointer will invalidate the actual object. - * - * Any other operation may be run on the repository without - * affecting the object. - * - * @param obj the object - * @return the repository who owns this object - */ -GIT_EXTERN(git_repository *) git_object_owner(const git_object *obj); - -/** - * Close an open object - * - * This method instructs the library to close an existing - * object; note that git_objects are owned and cached by the repository - * so the object may or may not be freed after this library call, - * depending on how agressive is the caching mechanism used - * by the repository. - * - * IMPORTANT: - * It *is* necessary to call this method when you stop using - * an object. Failure to do so will cause a memory leak. - * - * @param object the object to close - */ -GIT_EXTERN(void) git_object_close(git_object *object); - -/** - * Convert an object type to it's string representation. - * - * The result is a pointer to a string in static memory and - * should not be free()'ed. - * - * @param type object type to convert. - * @return the corresponding string representation. - */ -GIT_EXTERN(const char *) git_object_type2string(git_otype type); - -/** - * Convert a string object type representation to it's git_otype. - * - * @param str the string to convert. - * @return the corresponding git_otype. - */ -GIT_EXTERN(git_otype) git_object_string2type(const char *str); - -/** - * Determine if the given git_otype is a valid loose object type. - * - * @param type object type to test. - * @return true if the type represents a valid loose object type, - * false otherwise. - */ -GIT_EXTERN(int) git_object_typeisloose(git_otype type); - -/** - * Get the size in bytes for the structure which - * acts as an in-memory representation of any given - * object type. - * - * For all the core types, this would the equivalent - * of calling `sizeof(git_commit)` if the core types - * were not opaque on the external API. - * - * @param type object type to get its size - * @return size in bytes of the object - */ -GIT_EXTERN(size_t) git_object__size(git_otype type); - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2/include/git2/odb.h b/vendor/libgit2/include/git2/odb.h deleted file mode 100644 index d0c369055..000000000 --- a/vendor/libgit2/include/git2/odb.h +++ /dev/null @@ -1,351 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_odb_h__ -#define INCLUDE_git_odb_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "odb_backend.h" - -/** - * @file git2/odb.h - * @brief Git object database routines - * @defgroup git_odb Git object database routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Create a new object database with no backends. - * - * Before the ODB can be used for read/writing, a custom database - * backend must be manually added using `git_odb_add_backend()` - * - * @param out location to store the database pointer, if opened. - * Set to NULL if the open failed. - * @return GIT_SUCCESS if the database was created; otherwise an error - * code describing why the open was not possible. - */ -GIT_EXTERN(int) git_odb_new(git_odb **out); - -/** - * Create a new object database and automatically add - * the two default backends: - * - * - git_odb_backend_loose: read and write loose object files - * from disk, assuming `objects_dir` as the Objects folder - * - * - git_odb_backend_pack: read objects from packfiles, - * assuming `objects_dir` as the Objects folder which - * contains a 'pack/' folder with the corresponding data - * - * @param out location to store the database pointer, if opened. - * Set to NULL if the open failed. - * @param objects_dir path of the backends' "objects" directory. - * @return GIT_SUCCESS if the database opened; otherwise an error - * code describing why the open was not possible. - */ -GIT_EXTERN(int) git_odb_open(git_odb **out, const char *objects_dir); - -/** - * Add a custom backend to an existing Object DB - * - * The backends are checked in relative ordering, based on the - * value of the `priority` parameter. - * - * Read for more information. - * - * @param odb database to add the backend to - * @param backend pointer to a git_odb_backend instance - * @param priority Value for ordering the backends queue - * @return 0 on sucess; error code otherwise - */ -GIT_EXTERN(int) git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int priority); - -/** - * Add a custom backend to an existing Object DB; this - * backend will work as an alternate. - * - * Alternate backends are always checked for objects *after* - * all the main backends have been exhausted. - * - * The backends are checked in relative ordering, based on the - * value of the `priority` parameter. - * - * Writing is disabled on alternate backends. - * - * Read for more information. - * - * @param odb database to add the backend to - * @param backend pointer to a git_odb_backend instance - * @param priority Value for ordering the backends queue - * @return 0 on sucess; error code otherwise - */ -GIT_EXTERN(int) git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority); - -/** - * Close an open object database. - * - * @param db database pointer to close. If NULL no action is taken. - */ -GIT_EXTERN(void) git_odb_close(git_odb *db); - -/** - * Read an object from the database. - * - * This method queries all available ODB backends - * trying to read the given OID. - * - * The returned object is reference counted and - * internally cached, so it should be closed - * by the user once it's no longer in use. - * - * @param out pointer where to store the read object - * @param db database to search for the object in. - * @param id identity of the object to read. - * @return - * - GIT_SUCCESS if the object was read; - * - GIT_ENOTFOUND if the object is not in the database. - */ -GIT_EXTERN(int) git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id); - -/** - * Read an object from the database, given a prefix - * of its identifier. - * - * This method queries all available ODB backends - * trying to match the 'len' first hexadecimal - * characters of the 'short_id'. - * The remaining (GIT_OID_HEXSZ-len)*4 bits of - * 'short_id' must be 0s. - * 'len' must be at least GIT_OID_MINPREFIXLEN, - * and the prefix must be long enough to identify - * a unique object in all the backends; the - * method will fail otherwise. - * - * The returned object is reference counted and - * internally cached, so it should be closed - * by the user once it's no longer in use. - * - * @param out pointer where to store the read object - * @param db database to search for the object in. - * @param short_id a prefix of the id of the object to read. - * @param len the length of the prefix - * @return GIT_SUCCESS if the object was read; - * GIT_ENOTFOUND if the object is not in the database. - * GIT_EAMBIGUOUS if the prefix is ambiguous (several objects match the prefix) - */ -GIT_EXTERN(int) git_odb_read_prefix(git_odb_object **out, git_odb *db, const git_oid *short_id, unsigned int len); - -/** - * Read the header of an object from the database, without - * reading its full contents. - * - * The header includes the length and the type of an object. - * - * Note that most backends do not support reading only the header - * of an object, so the whole object will be read and then the - * header will be returned. - * - * @param len_p pointer where to store the length - * @param type_p pointer where to store the type - * @param db database to search for the object in. - * @param id identity of the object to read. - * @return - * - GIT_SUCCESS if the object was read; - * - GIT_ENOTFOUND if the object is not in the database. - */ -GIT_EXTERN(int) git_odb_read_header(size_t *len_p, git_otype *type_p, git_odb *db, const git_oid *id); - -/** - * Determine if the given object can be found in the object database. - * - * @param db database to be searched for the given object. - * @param id the object to search for. - * @return - * - 1, if the object was found - * - 0, otherwise - */ -GIT_EXTERN(int) git_odb_exists(git_odb *db, const git_oid *id); - -/** - * Write an object directly into the ODB - * - * This method writes a full object straight into the ODB. - * For most cases, it is preferred to write objects through a write - * stream, which is both faster and less memory intensive, specially - * for big objects. - * - * This method is provided for compatibility with custom backends - * which are not able to support streaming writes - * - * @param oid pointer to store the OID result of the write - * @param odb object database where to store the object - * @param data buffer with the data to storr - * @param len size of the buffer - * @param type type of the data to store - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_odb_write(git_oid *oid, git_odb *odb, const void *data, size_t len, git_otype type); - -/** - * Open a stream to write an object into the ODB - * - * The type and final length of the object must be specified - * when opening the stream. - * - * The returned stream will be of type `GIT_STREAM_WRONLY` and - * will have the following methods: - * - * - stream->write: write `n` bytes into the stream - * - stream->finalize_write: close the stream and store the object in - * the odb - * - stream->free: free the stream - * - * The streaming write won't be effective until `stream->finalize_write` - * is called and returns without an error - * - * The stream must always be free'd or will leak memory. - * - * @see git_odb_stream - * - * @param stream pointer where to store the stream - * @param db object database where the stream will write - * @param size final size of the object that will be written - * @param type type of the object that will be written - * @return 0 if the stream was created; error code otherwise - */ -GIT_EXTERN(int) git_odb_open_wstream(git_odb_stream **stream, git_odb *db, size_t size, git_otype type); - -/** - * Open a stream to read an object from the ODB - * - * Note that most backends do *not* support streaming reads - * because they store their objects as compressed/delta'ed blobs. - * - * It's recommended to use `git_odb_read` instead, which is - * assured to work on all backends. - * - * The returned stream will be of type `GIT_STREAM_RDONLY` and - * will have the following methods: - * - * - stream->read: read `n` bytes from the stream - * - stream->free: free the stream - * - * The stream must always be free'd or will leak memory. - * - * @see git_odb_stream - * - * @param stream pointer where to store the stream - * @param db object database where the stream will read from - * @param oid oid of the object the stream will read from - * @return 0 if the stream was created; error code otherwise - */ -GIT_EXTERN(int) git_odb_open_rstream(git_odb_stream **stream, git_odb *db, const git_oid *oid); - -/** - * Determine the object-ID (sha1 hash) of a data buffer - * - * The resulting SHA-1 OID will the itentifier for the data - * buffer as if the data buffer it were to written to the ODB. - * - * @param id the resulting object-ID. - * @param data data to hash - * @param len size of the data - * @param type of the data to hash - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_odb_hash(git_oid *id, const void *data, size_t len, git_otype type); - -/** - * Read a file from disk and fill a git_oid with the object id - * that the file would have if it were written to the Object - * Database as an object of the given type. Similar functionality - * to git.git's `git hash-object` without the `-w` flag. - * - * @param out oid structure the result is written into. - * @param path file to read and determine object id for - * @param type the type of the object that will be hashed - * @return GIT_SUCCESS if valid; error code otherwise - */ -GIT_EXTERN(int) git_odb_hashfile(git_oid *out, const char *path, git_otype type); - -/** - * Close an ODB object - * - * This method must always be called once a `git_odb_object` is no - * longer needed, otherwise memory will leak. - * - * @param object object to close - */ -GIT_EXTERN(void) git_odb_object_close(git_odb_object *object); - -/** - * Return the OID of an ODB object - * - * This is the OID from which the object was read from - * - * @param object the object - * @return a pointer to the OID - */ -GIT_EXTERN(const git_oid *) git_odb_object_id(git_odb_object *object); - -/** - * Return the data of an ODB object - * - * This is the uncompressed, raw data as read from the ODB, - * without the leading header. - * - * This pointer is owned by the object and shall not be free'd. - * - * @param object the object - * @return a pointer to the data - */ -GIT_EXTERN(const void *) git_odb_object_data(git_odb_object *object); - -/** - * Return the size of an ODB object - * - * This is the real size of the `data` buffer, not the - * actual size of the object. - * - * @param object the object - * @return the size - */ -GIT_EXTERN(size_t) git_odb_object_size(git_odb_object *object); - -/** - * Return the type of an ODB object - * - * @param object the object - * @return the type - */ -GIT_EXTERN(git_otype) git_odb_object_type(git_odb_object *object); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/odb_backend.h b/vendor/libgit2/include/git2/odb_backend.h deleted file mode 100644 index 43a1c2d21..000000000 --- a/vendor/libgit2/include/git2/odb_backend.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_odb_backend_h__ -#define INCLUDE_git_odb_backend_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" - -/** - * @file git2/backend.h - * @brief Git custom backend functions - * @defgroup git_backend Git custom backend API - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -struct git_odb_stream; - -/** An instance for a custom backend */ -struct git_odb_backend { - git_odb *odb; - - int (* read)( - void **, size_t *, git_otype *, - struct git_odb_backend *, - const git_oid *); - - /* To find a unique object given a prefix - * of its oid. - * The oid given must be so that the - * remaining (GIT_OID_HEXSZ - len)*4 bits - * are 0s. - */ - int (* read_prefix)( - git_oid *, - void **, size_t *, git_otype *, - struct git_odb_backend *, - const git_oid *, - unsigned int); - - int (* read_header)( - size_t *, git_otype *, - struct git_odb_backend *, - const git_oid *); - - int (* write)( - git_oid *, - struct git_odb_backend *, - const void *, - size_t, - git_otype); - - int (* writestream)( - struct git_odb_stream **, - struct git_odb_backend *, - size_t, - git_otype); - - int (* readstream)( - struct git_odb_stream **, - struct git_odb_backend *, - const git_oid *); - - int (* exists)( - struct git_odb_backend *, - const git_oid *); - - void (* free)(struct git_odb_backend *); -}; - -/** A stream to read/write from a backend */ -struct git_odb_stream { - struct git_odb_backend *backend; - int mode; - - int (*read)(struct git_odb_stream *stream, char *buffer, size_t len); - int (*write)(struct git_odb_stream *stream, const char *buffer, size_t len); - int (*finalize_write)(git_oid *oid_p, struct git_odb_stream *stream); - void (*free)(struct git_odb_stream *stream); -}; - -/** Streaming mode */ -typedef enum { - GIT_STREAM_RDONLY = (1 << 1), - GIT_STREAM_WRONLY = (1 << 2), - GIT_STREAM_RW = (GIT_STREAM_RDONLY | GIT_STREAM_WRONLY), -} git_odb_streammode; - -GIT_EXTERN(int) git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir); -GIT_EXTERN(int) git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir); - -GIT_END_DECL - -#endif diff --git a/vendor/libgit2/include/git2/oid.h b/vendor/libgit2/include/git2/oid.h deleted file mode 100644 index 8a0f134b9..000000000 --- a/vendor/libgit2/include/git2/oid.h +++ /dev/null @@ -1,226 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_oid_h__ -#define INCLUDE_git_oid_h__ - -#include "common.h" -#include "types.h" - -/** - * @file git2/oid.h - * @brief Git object id routines - * @defgroup git_oid Git object id routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** Size (in bytes) of a raw/binary oid */ -#define GIT_OID_RAWSZ 20 - -/** Size (in bytes) of a hex formatted oid */ -#define GIT_OID_HEXSZ (GIT_OID_RAWSZ * 2) - -/** Minimum length (in number of hex characters, - * i.e. packets of 4 bits) of an oid prefix */ -#define GIT_OID_MINPREFIXLEN 4 - -/** Unique identity of any object (commit, tree, blob, tag). */ -typedef struct _git_oid git_oid; -struct _git_oid { - /** raw binary formatted id */ - unsigned char id[GIT_OID_RAWSZ]; -}; - -/** - * Parse a hex formatted object id into a git_oid. - * - * @param out oid structure the result is written into. - * @param str input hex string; must be pointing at the start of - * the hex sequence and have at least the number of bytes - * needed for an oid encoded in hex (40 bytes). - * @return GIT_SUCCESS if valid; GIT_ENOTOID on failure. - */ -GIT_EXTERN(int) git_oid_fromstr(git_oid *out, const char *str); - -/** - * Parse N characters of a hex formatted object id into a git_oid - * - * If N is odd, N-1 characters will be parsed instead. - * The remaining space in the git_oid will be set to zero. - * - * @param out oid structure the result is written into. - * @param str input hex string of at least size `length` - * @param length length of the input string - * @return GIT_SUCCESS if valid; GIT_ENOTOID on failure. - */ -GIT_EXTERN(int) git_oid_fromstrn(git_oid *out, const char *str, size_t length); - -/** - * Copy an already raw oid into a git_oid structure. - * - * @param out oid structure the result is written into. - * @param raw the raw input bytes to be copied. - */ -GIT_EXTERN(void) git_oid_fromraw(git_oid *out, const unsigned char *raw); - -/** - * Format a git_oid into a hex string. - * - * @param str output hex string; must be pointing at the start of - * the hex sequence and have at least the number of bytes - * needed for an oid encoded in hex (40 bytes). Only the - * oid digits are written; a '\\0' terminator must be added - * by the caller if it is required. - * @param oid oid structure to format. - */ -GIT_EXTERN(void) git_oid_fmt(char *str, const git_oid *oid); - -/** - * Format a git_oid into a loose-object path string. - * - * The resulting string is "aa/...", where "aa" is the first two - * hex digitis of the oid and "..." is the remaining 38 digits. - * - * @param str output hex string; must be pointing at the start of - * the hex sequence and have at least the number of bytes - * needed for an oid encoded in hex (41 bytes). Only the - * oid digits are written; a '\\0' terminator must be added - * by the caller if it is required. - * @param oid oid structure to format. - */ -GIT_EXTERN(void) git_oid_pathfmt(char *str, const git_oid *oid); - -/** - * Format a git_oid into a newly allocated c-string. - * - * @param oid the oid structure to format - * @return the c-string; NULL if memory is exhausted. Caller must - * deallocate the string with free(). - */ -GIT_EXTERN(char *) git_oid_allocfmt(const git_oid *oid); - -/** - * Format a git_oid into a buffer as a hex format c-string. - * - * If the buffer is smaller than GIT_OID_HEXSZ+1, then the resulting - * oid c-string will be truncated to n-1 characters. If there are - * any input parameter errors (out == NULL, n == 0, oid == NULL), - * then a pointer to an empty string is returned, so that the return - * value can always be printed. - * - * @param out the buffer into which the oid string is output. - * @param n the size of the out buffer. - * @param oid the oid structure to format. - * @return the out buffer pointer, assuming no input parameter - * errors, otherwise a pointer to an empty string. - */ -GIT_EXTERN(char *) git_oid_to_string(char *out, size_t n, const git_oid *oid); - -/** - * Copy an oid from one structure to another. - * - * @param out oid structure the result is written into. - * @param src oid structure to copy from. - */ -GIT_EXTERN(void) git_oid_cpy(git_oid *out, const git_oid *src); - -/** - * Compare two oid structures. - * - * @param a first oid structure. - * @param b second oid structure. - * @return <0, 0, >0 if a < b, a == b, a > b. - */ -GIT_EXTERN(int) git_oid_cmp(const git_oid *a, const git_oid *b); - -/** - * Compare the first 'len' hexadecimal characters (packets of 4 bits) - * of two oid structures. - * - * @param a first oid structure. - * @param b second oid structure. - * @param len the number of hex chars to compare - * @return 0 in case of a match - */ -GIT_EXTERN(int) git_oid_ncmp(const git_oid *a, const git_oid *b, unsigned int len); - -/** - * OID Shortener object - */ -typedef struct git_oid_shorten git_oid_shorten; - -/** - * Create a new OID shortener. - * - * The OID shortener is used to process a list of OIDs - * in text form and return the shortest length that would - * uniquely identify all of them. - * - * E.g. look at the result of `git log --abbrev`. - * - * @param min_length The minimal length for all identifiers, - * which will be used even if shorter OIDs would still - * be unique. - * @return a `git_oid_shorten` instance, NULL if OOM - */ -git_oid_shorten *git_oid_shorten_new(size_t min_length); - -/** - * Add a new OID to set of shortened OIDs and calculate - * the minimal length to uniquely identify all the OIDs in - * the set. - * - * The OID is expected to be a 40-char hexadecimal string. - * The OID is owned by the user and will not be modified - * or freed. - * - * For performance reasons, there is a hard-limit of how many - * OIDs can be added to a single set (around ~22000, assuming - * a mostly randomized distribution), which should be enough - * for any kind of program, and keeps the algorithm fast and - * memory-efficient. - * - * Attempting to add more than those OIDs will result in a - * GIT_ENOMEM error - * - * @param os a `git_oid_shorten` instance - * @param text_oid an OID in text form - * @return the minimal length to uniquely identify all OIDs - * added so far to the set; or an error code (<0) if an - * error occurs. - */ -int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid); - -/** - * Free an OID shortener instance - * - * @param os a `git_oid_shorten` instance - */ -void git_oid_shorten_free(git_oid_shorten *os); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/reflog.h b/vendor/libgit2/include/git2/reflog.h deleted file mode 100644 index 53b344733..000000000 --- a/vendor/libgit2/include/git2/reflog.h +++ /dev/null @@ -1,129 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_reflog_h__ -#define INCLUDE_git_reflog_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" - -/** - * @file git2/reflog.h - * @brief Git reflog management routines - * @defgroup git_reflog Git reflog management routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Read the reflog for the given reference - * - * The reflog must be freed manually by using - * git_reflog_free(). - * - * @param reflog pointer to reflog - * @param ref reference to read the reflog for - * @return GIT_SUCCESS on success; error code otherwise - */ -GIT_EXTERN(int) git_reflog_read(git_reflog **reflog, git_reference *ref); - -/** - * Write a new reflog for the given reference - * - * If there is no reflog file for the given - * reference yet, it will be created. - * - * `oid_old` may be NULL in case it's a new reference. - * - * `msg` is optional and can be NULL. - * - * @param ref the changed reference - * @param oid_old the OID the reference was pointing to - * @param committer the signature of the committer - * @param msg the reflog message - * @return GIT_SUCCESS on success; error code otherwise - */ -GIT_EXTERN(int) git_reflog_write(git_reference *ref, const git_oid *oid_old, const git_signature *committer, const char *msg); - -/** - * Get the number of log entries in a reflog - * - * @param reflog the previously loaded reflog - * @return the number of log entries - */ -GIT_EXTERN(unsigned int) git_reflog_entrycount(git_reflog *reflog); - -/** - * Lookup an entry by its index - * - * @param reflog a previously loaded reflog - * @param idx the position to lookup - * @return the entry; NULL if not found - */ -GIT_EXTERN(const git_reflog_entry *) git_reflog_entry_byindex(git_reflog *reflog, unsigned int idx); - -/** - * Get the old oid - * - * @param entry a reflog entry - * @return the old oid - */ -GIT_EXTERN(const git_oid *) git_reflog_entry_oidold(const git_reflog_entry *entry); - -/** - * Get the new oid - * - * @param entry a reflog entry - * @return the new oid at this time - */ -GIT_EXTERN(const git_oid *) git_reflog_entry_oidnew(const git_reflog_entry *entry); - -/** - * Get the committer of this entry - * - * @param entry a reflog entry - * @return the committer - */ -GIT_EXTERN(git_signature *) git_reflog_entry_committer(const git_reflog_entry *entry); - -/** - * Get the log msg - * - * @param entry a reflog entry - * @return the log msg - */ -GIT_EXTERN(char *) git_reflog_entry_msg(const git_reflog_entry *entry); - -/** - * Free the reflog - * - * @param reflog reflog to free - */ -GIT_EXTERN(void) git_reflog_free(git_reflog *reflog); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/refs.h b/vendor/libgit2/include/git2/refs.h deleted file mode 100644 index ff2bc9d87..000000000 --- a/vendor/libgit2/include/git2/refs.h +++ /dev/null @@ -1,276 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_refs_h__ -#define INCLUDE_git_refs_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" - -/** - * @file git2/refs.h - * @brief Git reference management routines - * @defgroup git_reference Git reference management routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Lookup a reference by its name in a repository. - * - * The generated reference is owned by the repository and - * should not be freed by the user. - * - * @param reference_out pointer to the looked-up reference - * @param repo the repository to look up the reference - * @param name the long name for the reference (e.g. HEAD, ref/heads/master, refs/tags/v0.1.0, ...) - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_reference_lookup(git_reference **reference_out, git_repository *repo, const char *name); - -/** - * Create a new symbolic reference. - * - * The reference will be created in the repository and written - * to the disk. - * - * This reference is owned by the repository and shall not - * be free'd by the user. - * - * If `force` is true and there already exists a reference - * with the same name, it will be overwritten. - * - * @param ref_out Pointer to the newly created reference - * @param repo Repository where that reference will live - * @param name The name of the reference - * @param target The target of the reference - * @param force Overwrite existing references - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_reference_create_symbolic(git_reference **ref_out, git_repository *repo, const char *name, const char *target, int force); - -/** - * Create a new object id reference. - * - * The reference will be created in the repository and written - * to the disk. - * - * This reference is owned by the repository and shall not - * be free'd by the user. - * - * If `force` is true and there already exists a reference - * with the same name, it will be overwritten. - * - * @param ref_out Pointer to the newly created reference - * @param repo Repository where that reference will live - * @param name The name of the reference - * @param id The object id pointed to by the reference. - * @param force Overwrite existing references - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_reference_create_oid(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id, int force); - -/** - * Get the OID pointed to by a reference. - * - * Only available if the reference is direct (i.e. not symbolic) - * - * @param ref The reference - * @return a pointer to the oid if available, NULL otherwise - */ -GIT_EXTERN(const git_oid *) git_reference_oid(git_reference *ref); - -/** - * Get full name to the reference pointed by this reference - * - * Only available if the reference is symbolic - * - * @param ref The reference - * @return a pointer to the name if available, NULL otherwise - */ -GIT_EXTERN(const char *) git_reference_target(git_reference *ref); - -/** - * Get the type of a reference - * - * Either direct (GIT_REF_OID) or symbolic (GIT_REF_SYMBOLIC) - * - * @param ref The reference - * @return the type - */ -GIT_EXTERN(git_rtype) git_reference_type(git_reference *ref); - -/** - * Get the full name of a reference - * - * @param ref The reference - * @return the full name for the ref - */ -GIT_EXTERN(const char *) git_reference_name(git_reference *ref); - -/** - * Resolve a symbolic reference - * - * Thie method iteratively peels a symbolic reference - * until it resolves to a direct reference to an OID. - * - * If a direct reference is passed as an argument, - * that reference is returned immediately - * - * @param resolved_ref Pointer to the peeled reference - * @param ref The reference - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_reference_resolve(git_reference **resolved_ref, git_reference *ref); - -/** - * Get the repository where a reference resides - * - * @param ref The reference - * @return a pointer to the repo - */ -GIT_EXTERN(git_repository *) git_reference_owner(git_reference *ref); - -/** - * Set the symbolic target of a reference. - * - * The reference must be a symbolic reference, otherwise - * this method will fail. - * - * The reference will be automatically updated in - * memory and on disk. - * - * @param ref The reference - * @param target The new target for the reference - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_reference_set_target(git_reference *ref, const char *target); - -/** - * Set the OID target of a reference. - * - * The reference must be a direct reference, otherwise - * this method will fail. - * - * The reference will be automatically updated in - * memory and on disk. - * - * @param ref The reference - * @param id The new target OID for the reference - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_reference_set_oid(git_reference *ref, const git_oid *id); - -/** - * Rename an existing reference - * - * This method works for both direct and symbolic references. - * The new name will be checked for validity and may be - * modified into a normalized form. - * - * The refernece will be immediately renamed in-memory - * and on disk. - * - */ -GIT_EXTERN(int) git_reference_rename(git_reference *ref, const char *new_name, int force); - -/** - * Delete an existing reference - * - * This method works for both direct and symbolic references. - * - * The reference will be immediately removed on disk and from - * memory. The given reference pointer will no longer be valid. - * - */ -GIT_EXTERN(int) git_reference_delete(git_reference *ref); - -/** - * Pack all the loose references in the repository - * - * This method will load into the cache all the loose - * references on the repository and update the - * `packed-refs` file with them. - * - * Once the `packed-refs` file has been written properly, - * the loose references will be removed from disk. - * - * WARNING: calling this method may invalidate any existing - * references previously loaded on the cache. - * - * @param repo Repository where the loose refs will be packed - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_reference_packall(git_repository *repo); - -/** - * Fill a list with all the references that can be found - * in a repository. - * - * The listed references may be filtered by type, or using - * a bitwise OR of several types. Use the magic value - * `GIT_REF_LISTALL` to obtain all references, including - * packed ones. - * - * The string array will be filled with the names of all - * references; these values are owned by the user and - * should be free'd manually when no longer needed, using - * `git_strarray_free`. - * - * @param array Pointer to a git_strarray structure where - * the reference names will be stored - * @param repo Repository where to find the refs - * @param list_flags Filtering flags for the reference - * listing. - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_reference_listall(git_strarray *array, git_repository *repo, unsigned int list_flags); - - -/** - * Perform an operation on each reference in the repository - * - * The processed references may be filtered by type, or using - * a bitwise OR of several types. Use the magic value - * `GIT_REF_LISTALL` to obtain all references, including - * packed ones. - * - * The `callback` function will be called for each of the references - * in the repository, and will receive the name of the reference and - * the `payload` value passed to this method. - * - * @param repo Repository where to find the refs - * @param list_flags Filtering flags for the reference - * listing. - * @param callback Function which will be called for every listed ref - * @param payload Additional data to pass to the callback - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_reference_foreach(git_repository *repo, unsigned int list_flags, int (*callback)(const char *, void *), void *payload); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/refspec.h b/vendor/libgit2/include/git2/refspec.h deleted file mode 100644 index dd0dc5873..000000000 --- a/vendor/libgit2/include/git2/refspec.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_refspec_h__ -#define INCLUDE_git_refspec_h__ - -#include "git2/types.h" - -/** - * @file git2/refspec.h - * @brief Git refspec attributes - * @defgroup git_refspec Git refspec attributes - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Get the source specifier - * - * @param refspec the refspec - * @return the refspec's source specifier - */ -const char *git_refspec_src(const git_refspec *refspec); - -/** - * Get the destination specifier - * - * @param refspec the refspec - * @return the refspec's destination specifier - */ -const char *git_refspec_dst(const git_refspec *refspec); - -/** - * Match a refspec's source descriptor with a reference name - * - * @param refspec the refspec - * @param refname the name of the reference to check - * @return GIT_SUCCESS on successful match; GIT_ENOMACH on match - * failure or an error code on other failure - */ -int git_refspec_src_match(const git_refspec *refspec, const char *refname); - -/** - * Transform a reference to its target following the refspec's rules - * - * @param out where to store the target name - * @param outlen the size ouf the `out` buffer - * @param spec the refspec - * @param name the name of the reference to transform - * @preturn GIT_SUCCESS, GIT_ESHORTBUFFER or another error - */ -int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, const char *name); - -GIT_END_DECL - -#endif diff --git a/vendor/libgit2/include/git2/remote.h b/vendor/libgit2/include/git2/remote.h deleted file mode 100644 index 5ce876e07..000000000 --- a/vendor/libgit2/include/git2/remote.h +++ /dev/null @@ -1,168 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_remote_h__ -#define INCLUDE_git_remote_h__ - -#include "git2/common.h" -#include "git2/repository.h" -#include "refspec.h" -/** - * @file git2/remote.h - * @brief Git remote management functions - * @defgroup git_remote remote management functions - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/* - * TODO: This functions still need to be implemented: - * - _listcb/_foreach - * - _add - * - _rename - * - _del (needs support from config) - */ - -/** - * Create a new unnamed remote - * - * Useful when you don't want to store the remote - * - * @param out pointer to the new remote object - * @param repo the associtated repository - * @param url the remote repository's URL - * @return GIT_SUCCESS or an error message - */ -int git_remote_new(git_remote **out, git_repository *repo, const char *url); - -/** - * Get the information for a particular remote - * - * @param out pointer to the new remote object - * @param cfg the repository's configuration - * @param name the remote's name - * @return 0 on success; error value otherwise - */ -GIT_EXTERN(int) git_remote_get(struct git_remote **out, struct git_config *cfg, const char *name); - -/** - * Get the remote's name - * - * @param remote the remote - * @return a pointer to the name - */ -GIT_EXTERN(const char *) git_remote_name(struct git_remote *remote); - -/** - * Get the remote's url - * - * @param remote the remote - * @return a pointer to the url - */ -GIT_EXTERN(const char *) git_remote_url(struct git_remote *remote); - -/** - * Get the fetch refspec - * - * @param remote the remote - * @return a pointer to the fetch refspec or NULL if it doesn't exist - */ -GIT_EXTERN(const git_refspec *) git_remote_fetchspec(struct git_remote *remote); - -/** - * Get the push refspec - * - * @param remote the remote - * @return a pointer to the push refspec or NULL if it doesn't exist - */ - -GIT_EXTERN(const git_refspec *) git_remote_pushspec(struct git_remote *remote); - -/** - * Open a connection to a remote - * - * The transport is selected based on the URL. The direction argument - * is due to a limitation of the git protocol (over TCP or SSH) which - * starts up a specific binary which can only do the one or the other. - * - * @param remote the remote to connect to - * @param direction whether you want to receive or send data - * @return GIT_SUCCESS or an error code - */ -GIT_EXTERN(int) git_remote_connect(struct git_remote *remote, int direction); - -/** - * Get a list of refs at the remote - * - * The remote (or more exactly its transport) must be connected. - * - * @param refs where to store the refs - * @param remote the remote - * @return GIT_SUCCESS or an error code - */ -GIT_EXTERN(int) git_remote_ls(git_remote *remote, git_headarray *refs); - -/** - * Negotiate what data needs to be exchanged to synchroize the remtoe - * and local references - * - * @param remote the remote you want to negotiate with - */ -GIT_EXTERN(int) git_remote_negotiate(git_remote *remote); - -/** - * Download the packfile - * - * The packfile is downloaded with a temporary filename, as it's final - * name is not known yet. If there was no packfile needed (all the - * objects were available locally), filename will be NULL and the - * function will return success. - * - * @param remote the remote to download from - * @param filename where to store the temproray filename - * @return GIT_SUCCESS or an error code - */ -GIT_EXTERN(int) git_remote_download(char **filename, git_remote *remote); - -/** - * Free the memory associated with a remote - * - * @param remote the remote to free - */ -GIT_EXTERN(void) git_remote_free(struct git_remote *remote); - -/** - * Update the tips to the new state - * - * Make sure that you only call this once you've successfully indexed - * or expanded the packfile. - * - * @param remote the remote to update - */ -GIT_EXTERN(int) git_remote_update_tips(struct git_remote *remote); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/repository.h b/vendor/libgit2/include/git2/repository.h deleted file mode 100644 index 4088ff7f9..000000000 --- a/vendor/libgit2/include/git2/repository.h +++ /dev/null @@ -1,332 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_repository_h__ -#define INCLUDE_git_repository_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" - -/** - * @file git2/repository.h - * @brief Git repository management routines - * @defgroup git_repository Git repository management routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Open a git repository. - * - * The 'path' argument must point to an existing git repository - * folder, e.g. - * - * /path/to/my_repo/.git/ (normal repository) - * objects/ - * index - * HEAD - * - * /path/to/bare_repo/ (bare repository) - * objects/ - * index - * HEAD - * - * The method will automatically detect if 'path' is a normal - * or bare repository or fail is 'path' is neither. - * - * @param repository pointer to the repo which will be opened - * @param path the path to the repository - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_repository_open(git_repository **repository, const char *path); - - -/** - * Open a git repository by manually specifying all its paths - * - * @param repository pointer to the repo which will be opened - * - * @param git_dir The full path to the repository folder - * e.g. a '.git' folder for live repos, any folder for bare - * Equivalent to $GIT_DIR. - * Cannot be NULL. - * - * @param git_object_directory The full path to the ODB folder. - * the folder where all the loose and packed objects are stored - * Equivalent to $GIT_OBJECT_DIRECTORY. - * If NULL, "$GIT_DIR/objects/" is assumed. - * - * @param git_index_file The full path to the index (dircache) file - * Equivalent to $GIT_INDEX_FILE. - * If NULL, "$GIT_DIR/index" is assumed. - * - * @param git_work_tree The full path to the working tree of the repository, - * if the repository is not bare. - * Equivalent to $GIT_WORK_TREE. - * If NULL, the repository is assumed to be bare. - * - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_repository_open2(git_repository **repository, - const char *git_dir, - const char *git_object_directory, - const char *git_index_file, - const char *git_work_tree); - - -/** - * Open a git repository by manually specifying its paths and - * the object database it will use. - * - * @param repository pointer to the repo which will be opened - * - * @param git_dir The full path to the repository folder - * e.g. a '.git' folder for live repos, any folder for bare - * Equivalent to $GIT_DIR. - * Cannot be NULL. - * - * @param object_database A pointer to a git_odb created & initialized - * by the user (e.g. with custom backends). This object database - * will be owned by the repository and will be automatically free'd. - * It should not be manually free'd by the user, or this - * git_repository object will become invalid. - * - * @param git_index_file The full path to the index (dircache) file - * Equivalent to $GIT_INDEX_FILE. - * If NULL, "$GIT_DIR/index" is assumed. - * - * @param git_work_tree The full path to the working tree of the repository, - * if the repository is not bare. - * Equivalent to $GIT_WORK_TREE. - * If NULL, the repository is assumed to be bare. - * - * @return 0 on success; error code otherwise - */ - -GIT_EXTERN(int) git_repository_open3(git_repository **repository, - const char *git_dir, - git_odb *object_database, - const char *git_index_file, - const char *git_work_tree); - -/** - * Look for a git repository and copy its path in the given buffer. The lookup start - * from base_path and walk across parent directories if nothing has been found. The - * lookup ends when the first repository is found, or when reaching a directory - * referenced in ceiling_dirs or when the filesystem changes (in case across_fs - * is true). - * - * The method will automatically detect if the repository is bare (if there is - * a repository). - * - * @param repository_path The user allocated buffer which will contain the found path. - * - * @param size repository_path size - * - * @param start_path The base path where the lookup starts. - * - * @param across_fs If true, then the lookup will not stop when a filesystem device change - * is detected while exploring parent directories. - * - * @param ceiling_dirs A GIT_PATH_LIST_SEPARATOR separated list of absolute symbolic link - * free paths. The lookup will stop when any of this paths is reached. Note that the - * lookup always performs on start_path no matter start_path appears in ceiling_dirs - * ceiling_dirs might be NULL (which is equivalent to an empty string) - * - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_repository_discover(char *repository_path, size_t size, const char *start_path, int across_fs, const char *ceiling_dirs); - -/** - * Get the object database behind a Git repository - * - * @param repo a repository object - * @return a pointer to the object db - */ -GIT_EXTERN(git_odb *) git_repository_database(git_repository *repo); - -/** - * Open the Index file of a Git repository - * - * This returns a new and unique `git_index` object representing the - * active index for the repository. - * - * This method may be called more than once (e.g. on different threads). - * - * Each returned `git_index` object is independent and suffers no race - * conditions: synchronization is done at the FS level. - * - * Each returned `git_index` object must be manually freed by the user, - * using `git_index_free`. - * - * @param index Pointer where to store the index - * @param repo a repository object - * @return 0 on success; error code if the index could not be opened - */ -GIT_EXTERN(int) git_repository_index(git_index **index, git_repository *repo); - -/** - * Free a previously allocated repository - * - * Note that after a repository is free'd, all the objects it has spawned - * will still exist until they are manually closed by the user - * with `git_object_close`, but accessing any of the attributes of - * an object without a backing repository will result in undefined - * behavior - * - * @param repo repository handle to close. If NULL nothing occurs. - */ -GIT_EXTERN(void) git_repository_free(git_repository *repo); - -/** - * Creates a new Git repository in the given folder. - * - * TODO: - * - Reinit the repository - * - Create config files - * - * @param repo_out pointer to the repo which will be created or reinitialized - * @param path the path to the repository - * @param is_bare if true, a Git repository without a working directory is created - * at the pointed path. If false, provided path will be considered as the working - * directory into which the .git directory will be created. - * - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_repository_init(git_repository **repo_out, const char *path, unsigned is_bare); - -/** - * Check if a repository's HEAD is detached - * - * A repository's HEAD is detached when it points directly to a commit - * instead of a branch. - * - * @param repo Repo to test - * @return 1 if HEAD is detached, 0 if i'ts not; error code if there - * was an error. - */ -GIT_EXTERN(int) git_repository_head_detached(git_repository *repo); - -/** - * Check if the current branch is an orphan - * - * An orphan branch is one named from HEAD but which doesn't exist in - * the refs namespace, because it doesn't have any commit to point to. - * - * @param repo Repo to test - * @return 1 if the current branch is an orphan, 0 if it's not; error - * code if therewas an error - */ -GIT_EXTERN(int) git_repository_head_orphan(git_repository *repo); - -/** - * Check if a repository is empty - * - * An empty repository has just been initialized and contains - * no commits. - * - * @param repo Repo to test - * @return 1 if the repository is empty, 0 if it isn't, error code - * if the repository is corrupted - */ -GIT_EXTERN(int) git_repository_is_empty(git_repository *repo); - -/** - * Internal path identifiers for a repository - */ -typedef enum { - GIT_REPO_PATH, - GIT_REPO_PATH_INDEX, - GIT_REPO_PATH_ODB, - GIT_REPO_PATH_WORKDIR -} git_repository_pathid; - -/** - * Get one of the paths to the repository - * - * Possible values for `id`: - * - * GIT_REPO_PATH: return the path to the repository - * GIT_REPO_PATH_INDEX: return the path to the index - * GIT_REPO_PATH_ODB: return the path to the ODB - * GIT_REPO_PATH_WORKDIR: return the path to the working - * directory - * - * @param repo a repository object - * @param id The ID of the path to return - * @return absolute path of the requested id - */ -GIT_EXTERN(const char *) git_repository_path(git_repository *repo, git_repository_pathid id); - -/** - * Check if a repository is bare - * - * @param repo Repo to test - * @return 1 if the repository is empty, 0 otherwise. - */ -GIT_EXTERN(int) git_repository_is_bare(git_repository *repo); - -/** - * Retrieve the relevant configuration for a repository - * - * By default he returned `git_config` instance contains a single - * configuration file, the `.gitconfig' file that may be found - * inside the repository. - * - * If the `user_config_path` variable is not NULL, the given config - * file will be also included in the configuration set. On most UNIX - * systems, this file may be found on `$HOME/.gitconfig`. - * - * If the `system_config_path` variable is not NULL, the given config - * file will be also included in the configuration set. On most UNIX - * systems, this file may be found on `$PREFIX/etc/gitconfig`. - * - * The resulting `git_config` instance will query the files in the following - * order: - * - * - Repository configuration file - * - User configuration file - * - System configuration file - * - * The method will fail if any of the passed config files cannot be - * found or accessed. - * - * The returned `git_config` instance is owned by the caller and must - * be manually free'd once it's no longer on use. - * - * @param out the repository's configuration - * @param repo the repository for which to get the config - * @param user_config_path Path to the user config file - * @param system_config_path Path to the system-wide config file - */ -GIT_EXTERN(int) git_repository_config(git_config **out, - git_repository *repo, - const char *user_config_path, - const char *system_config_path); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/revwalk.h b/vendor/libgit2/include/git2/revwalk.h deleted file mode 100644 index b37a16c83..000000000 --- a/vendor/libgit2/include/git2/revwalk.h +++ /dev/null @@ -1,187 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_revwalk_h__ -#define INCLUDE_git_revwalk_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" - -/** - * @file git2/revwalk.h - * @brief Git revision traversal routines - * @defgroup git_revwalk Git revision traversal routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Sort the repository contents in no particular ordering; - * this sorting is arbitrary, implementation-specific - * and subject to change at any time. - * This is the default sorting for new walkers. - */ -#define GIT_SORT_NONE (0) - -/** - * Sort the repository contents in topological order - * (parents before children); this sorting mode - * can be combined with time sorting. - */ -#define GIT_SORT_TOPOLOGICAL (1 << 0) - -/** - * Sort the repository contents by commit time; - * this sorting mode can be combined with - * topological sorting. - */ -#define GIT_SORT_TIME (1 << 1) - -/** - * Iterate through the repository contents in reverse - * order; this sorting mode can be combined with - * any of the above. - */ -#define GIT_SORT_REVERSE (1 << 2) - -/** - * Allocate a new revision walker to iterate through a repo. - * - * This revision walker uses a custom memory pool and an internal - * commit cache, so it is relatively expensive to allocate. - * - * For maximum performance, this revision walker should be - * reused for different walks. - * - * This revision walker is *not* thread safe: it may only be - * used to walk a repository on a single thread; however, - * it is possible to have several revision walkers in - * several different threads walking the same repository. - * - * @param walker pointer to the new revision walker - * @param repo the repo to walk through - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_revwalk_new(git_revwalk **walker, git_repository *repo); - -/** - * Reset the revision walker for reuse. - * - * This will clear all the pushed and hidden commits, and - * leave the walker in a blank state (just like at - * creation) ready to receive new commit pushes and - * start a new walk. - * - * The revision walk is automatically reset when a walk - * is over. - * - * @param walker handle to reset. - */ -GIT_EXTERN(void) git_revwalk_reset(git_revwalk *walker); - -/** - * Mark a commit to start traversal from. - * - * The given OID must belong to a commit on the walked - * repository. - * - * The given commit will be used as one of the roots - * when starting the revision walk. At least one commit - * must be pushed the repository before a walk can - * be started. - * - * @param walk the walker being used for the traversal. - * @param oid the oid of the commit to start from. - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_revwalk_push(git_revwalk *walk, const git_oid *oid); - - -/** - * Mark a commit (and its ancestors) uninteresting for the output. - * - * The given OID must belong to a commit on the walked - * repository. - * - * The resolved commit and all its parents will be hidden from the - * output on the revision walk. - * - * @param walk the walker being used for the traversal. - * @param oid the oid of commit that will be ignored during the traversal - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_revwalk_hide(git_revwalk *walk, const git_oid *oid); - -/** - * Get the next commit from the revision walk. - * - * The initial call to this method is *not* blocking when - * iterating through a repo with a time-sorting mode. - * - * Iterating with Topological or inverted modes makes the initial - * call blocking to preprocess the commit list, but this block should be - * mostly unnoticeable on most repositories (topological preprocessing - * times at 0.3s on the git.git repo). - * - * The revision walker is reset when the walk is over. - * - * @param oid Pointer where to store the oid of the next commit - * @param walk the walker to pop the commit from. - * @return GIT_SUCCESS if the next commit was found; - * GIT_EREVWALKOVER if there are no commits left to iterate - */ -GIT_EXTERN(int) git_revwalk_next(git_oid *oid, git_revwalk *walk); - -/** - * Change the sorting mode when iterating through the - * repository's contents. - * - * Changing the sorting mode resets the walker. - * - * @param walk the walker being used for the traversal. - * @param sort_mode combination of GIT_SORT_XXX flags - */ -GIT_EXTERN(void) git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode); - -/** - * Free a revision walker previously allocated. - * - * @param walk traversal handle to close. If NULL nothing occurs. - */ -GIT_EXTERN(void) git_revwalk_free(git_revwalk *walk); - -/** - * Return the repository on which this walker - * is operating. - * - * @param walk the revision walker - * @return the repository being walked - */ -GIT_EXTERN(git_repository *) git_revwalk_repository(git_revwalk *walk); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/signature.h b/vendor/libgit2/include/git2/signature.h deleted file mode 100644 index f5d03ac77..000000000 --- a/vendor/libgit2/include/git2/signature.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_signature_h__ -#define INCLUDE_git_signature_h__ - -#include "common.h" -#include "types.h" - -/** - * @file git2/signature.h - * @brief Git signature creation - * @defgroup git_signature Git signature creation - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Create a new action signature. The signature must be freed - * manually or using git_signature_free - * - * @param sig_out new signature, in case of error NULL - * @param name name of the person - * @param email email of the person - * @param time time when the action happened - * @param offset timezone offset in minutes for the time - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_signature_new(git_signature **sig_out, const char *name, const char *email, git_time_t time, int offset); - -/** - * Create a new action signature with a timestamp of 'now'. The - * signature must be freed manually or using git_signature_free - * - * @param sig_out new signature, in case of error NULL - * @param name name of the person - * @param email email of the person - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_signature_now(git_signature **sig_out, const char *name, const char *email); - - -/** - * Create a copy of an existing signature. - * - * All internal strings are also duplicated. - * @param sig signature to duplicated - * @return a copy of sig, NULL on out of memory - */ -GIT_EXTERN(git_signature *) git_signature_dup(const git_signature *sig); - -/** - * Free an existing signature - * - * @param sig signature to free - */ -GIT_EXTERN(void) git_signature_free(git_signature *sig); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/status.h b/vendor/libgit2/include/git2/status.h deleted file mode 100644 index 7946cc1f3..000000000 --- a/vendor/libgit2/include/git2/status.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_status_h__ -#define INCLUDE_git_status_h__ - -#include "common.h" -#include "types.h" - -/** - * @file git2/status.h - * @brief Git file status routines - * @defgroup git_status Git file status routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -#define GIT_STATUS_CURRENT 0 -/** Flags for index status */ -#define GIT_STATUS_INDEX_NEW (1 << 0) -#define GIT_STATUS_INDEX_MODIFIED (1 << 1) -#define GIT_STATUS_INDEX_DELETED (1 << 2) - -/** Flags for worktree status */ -#define GIT_STATUS_WT_NEW (1 << 3) -#define GIT_STATUS_WT_MODIFIED (1 << 4) -#define GIT_STATUS_WT_DELETED (1 << 5) - -// TODO Ignored files not handled yet -#define GIT_STATUS_IGNORED (1 << 6) - -/** - * Gather file statuses and run a callback for each one. - * - * The callback is passed the path of the file, the status and the data pointer - * passed to this function. If the callback returns something other than - * GIT_SUCCESS, this function will return that value. - * - * @param repo a repository object - * @param callback the function to call on each file - * @return GIT_SUCCESS or the return value of the callback which did not return 0; - */ -GIT_EXTERN(int) git_status_foreach(git_repository *repo, int (*callback)(const char *, unsigned int, void *), void *payload); - -/** - * Get file status for a single file - * - * @param status_flags the status value - * @param repo a repository object - * @param path the file to retrieve status for, rooted at the repo's workdir - * @return GIT_SUCCESS - */ -GIT_EXTERN(int) git_status_file(unsigned int *status_flags, git_repository *repo, const char *path); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/tag.h b/vendor/libgit2/include/git2/tag.h deleted file mode 100644 index 2b10d4525..000000000 --- a/vendor/libgit2/include/git2/tag.h +++ /dev/null @@ -1,297 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_tag_h__ -#define INCLUDE_git_tag_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "object.h" - -/** - * @file git2/tag.h - * @brief Git tag parsing routines - * @defgroup git_tag Git tag management - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Lookup a tag object from the repository. - * - * @param tag pointer to the looked up tag - * @param repo the repo to use when locating the tag. - * @param id identity of the tag to locate. - * @return 0 on success; error code otherwise - */ -GIT_INLINE(int) git_tag_lookup(git_tag **tag, git_repository *repo, const git_oid *id) -{ - return git_object_lookup((git_object **)tag, repo, id, (git_otype)GIT_OBJ_TAG); -} - -/** - * Lookup a tag object from the repository, - * given a prefix of its identifier (short id). - * - * @see git_object_lookup_prefix - * - * @param tag pointer to the looked up tag - * @param repo the repo to use when locating the tag. - * @param id identity of the tag to locate. - * @param len the length of the short identifier - * @return 0 on success; error code otherwise - */ -GIT_INLINE(int) git_tag_lookup_prefix(git_tag **tag, git_repository *repo, const git_oid *id, unsigned int len) -{ - return git_object_lookup_prefix((git_object **)tag, repo, id, len, (git_otype)GIT_OBJ_TAG); -} - -/** - * Close an open tag - * - * This is a wrapper around git_object_close() - * - * IMPORTANT: - * It *is* necessary to call this method when you stop - * using a tag. Failure to do so will cause a memory leak. - * - * @param tag the tag to close - */ - -GIT_INLINE(void) git_tag_close(git_tag *tag) -{ - git_object_close((git_object *) tag); -} - - -/** - * Get the id of a tag. - * - * @param tag a previously loaded tag. - * @return object identity for the tag. - */ -GIT_EXTERN(const git_oid *) git_tag_id(git_tag *tag); - -/** - * Get the tagged object of a tag - * - * This method performs a repository lookup for the - * given object and returns it - * - * @param target pointer where to store the target - * @param tag a previously loaded tag. - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_tag_target(git_object **target, git_tag *tag); - -/** - * Get the OID of the tagged object of a tag - * - * @param tag a previously loaded tag. - * @return pointer to the OID - */ -GIT_EXTERN(const git_oid *) git_tag_target_oid(git_tag *tag); - -/** - * Get the type of a tag's tagged object - * - * @param tag a previously loaded tag. - * @return type of the tagged object - */ -GIT_EXTERN(git_otype) git_tag_type(git_tag *tag); - -/** - * Get the name of a tag - * - * @param tag a previously loaded tag. - * @return name of the tag - */ -GIT_EXTERN(const char *) git_tag_name(git_tag *tag); - -/** - * Get the tagger (author) of a tag - * - * @param tag a previously loaded tag. - * @return reference to the tag's author - */ -GIT_EXTERN(const git_signature *) git_tag_tagger(git_tag *tag); - -/** - * Get the message of a tag - * - * @param tag a previously loaded tag. - * @return message of the tag - */ -GIT_EXTERN(const char *) git_tag_message(git_tag *tag); - - -/** - * Create a new tag in the repository from an object - * - * A new reference will also be created pointing to - * this tag object. If `force` is true and a reference - * already exists with the given name, it'll be replaced. - * - * @param oid Pointer where to store the OID of the - * newly created tag. If the tag already exists, this parameter - * will be the oid of the existing tag, and the function will - * return a GIT_EEXISTS error code. - * - * @param repo Repository where to store the tag - * - * @param tag_name Name for the tag; this name is validated - * for consistency. It should also not conflict with an - * already existing tag name - * - * @param target Object to which this tag points. This object - * must belong to the given `repo`. - * - * @param tagger Signature of the tagger for this tag, and - * of the tagging time - * - * @param message Full message for this tag - * - * @param force Overwrite existing references - * - * @return 0 on success; error code otherwise. - * A tag object is written to the ODB, and a proper reference - * is written in the /refs/tags folder, pointing to it - */ -GIT_EXTERN(int) git_tag_create( - git_oid *oid, - git_repository *repo, - const char *tag_name, - const git_object *target, - const git_signature *tagger, - const char *message, - int force); - -/** - * Create a new tag in the repository from a buffer - * - * @param oid Pointer where to store the OID of the newly created tag - * @param repo Repository where to store the tag - * @param buffer Raw tag data - * @param force Overwrite existing tags - * @return 0 on sucess; error code otherwise - */ -GIT_EXTERN(int) git_tag_create_frombuffer( - git_oid *oid, - git_repository *repo, - const char *buffer, - int force); - -/** - * Create a new lightweight tag pointing at a target object - * - * A new direct reference will be created pointing to - * this target object. If `force` is true and a reference - * already exists with the given name, it'll be replaced. - * - * @param oid Pointer where to store the OID of the provided - * target object. If the tag already exists, this parameter - * will be filled with the oid of the existing pointed object - * and the function will return a GIT_EEXISTS error code. - * - * @param repo Repository where to store the lightweight tag - * - * @param tag_name Name for the tag; this name is validated - * for consistency. It should also not conflict with an - * already existing tag name - * - * @param target Object to which this tag points. This object - * must belong to the given `repo`. - * - * @param force Overwrite existing references - * - * @return 0 on success; error code otherwise. - * A proper reference is written in the /refs/tags folder, - * pointing to the provided target object - */ -GIT_EXTERN(int) git_tag_create_lightweight( - git_oid *oid, - git_repository *repo, - const char *tag_name, - const git_object *target, - int force); - -/** - * Delete an existing tag reference. - * - * @param repo Repository where lives the tag - * - * @param tag_name Name of the tag to be deleted; - * this name is validated for consistency. - * - * @return 0 on success; error code otherwise. - */ -GIT_EXTERN(int) git_tag_delete( - git_repository *repo, - const char *tag_name); - -/** - * Fill a list with all the tags in the Repository - * - * The string array will be filled with the names of the - * matching tags; these values are owned by the user and - * should be free'd manually when no longer needed, using - * `git_strarray_free`. - * - * @param tag_names Pointer to a git_strarray structure where - * the tag names will be stored - * @param repo Repository where to find the tags - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_tag_list( - git_strarray *tag_names, - git_repository *repo); - -/** - * Fill a list with all the tags in the Repository - * which name match a defined pattern - * - * If an empty pattern is provided, all the tags - * will be returned. - * - * The string array will be filled with the names of the - * matching tags; these values are owned by the user and - * should be free'd manually when no longer needed, using - * `git_strarray_free`. - * - * @param tag_names Pointer to a git_strarray structure where - * the tag names will be stored - * @param pattern Standard fnmatch pattern - * @param repo Repository where to find the tags - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_tag_list_match( - git_strarray *tag_names, - const char *pattern, - git_repository *repo); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/thread-utils.h b/vendor/libgit2/include/git2/thread-utils.h deleted file mode 100644 index 62e6199a4..000000000 --- a/vendor/libgit2/include/git2/thread-utils.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_thread_utils_h__ -#define INCLUDE_git_thread_utils_h__ - -/* - * How TLS works is compiler+platform dependant - * Sources: http://en.wikipedia.org/wiki/Thread-Specific_Storage - * http://predef.sourceforge.net/precomp.html - */ - -#ifdef GIT_THREADS -# define GIT_HAS_TLS 1 - -/* No TLS in Cygwin */ -# if defined(__CHECKER__) || defined(__CYGWIN__) -# undef GIT_HAS_TLS -# define GIT_TLS - -/* No TLS in Mach binaries for Mac OS X */ -# elif defined(__APPLE__) && defined(__MACH__) -# undef GIT_TLS -# define GIT_TLS - -/* Normal TLS for GCC */ -# elif defined(__GNUC__) || \ - defined(__SUNPRO_C) || \ - defined(__SUNPRO_CC) || \ - defined(__xlc__) || \ - defined(__xlC__) -# define GIT_TLS __thread - -/* ICC may run on Windows or Linux */ -# elif defined(__INTEL_COMPILER) -# if defined(_WIN32) || defined(_WIN32_CE) -# define GIT_TLS __declspec(thread) -# else -# define GIT_TLS __thread -# endif - -/* Declspec for MSVC in Win32 */ -# elif defined(_WIN32) || \ - defined(_WIN32_CE) || \ - defined(__BORLANDC__) -# define GIT_TLS __declspec(thread) - -/* Other platform; no TLS */ -# else -# undef GIT_HAS_TLS -# define GIT_TLS /* nothing: tls vars are thread-global */ -# endif -#else /* Disable TLS if libgit2 is not threadsafe */ -# define GIT_TLS -#endif /* GIT_THREADS */ - -#endif /* INCLUDE_git_thread_utils_h__ */ diff --git a/vendor/libgit2/include/git2/transport.h b/vendor/libgit2/include/git2/transport.h deleted file mode 100644 index d19eb8a88..000000000 --- a/vendor/libgit2/include/git2/transport.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_transport_h__ -#define INCLUDE_git_transport_h__ - -#include "common.h" -#include "types.h" -#include "net.h" - -/** - * @file git2/transport.h - * @brief Git protocol transport abstraction - * @defgroup git_transport Git protocol transport abstraction - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Get the appropriate transport for an URL. - * @param tranport the transport for the url - * @param url the url of the repo - */ -GIT_EXTERN(int) git_transport_new(git_transport **transport, const char *url); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/tree.h b/vendor/libgit2/include/git2/tree.h deleted file mode 100644 index 5656f48f3..000000000 --- a/vendor/libgit2/include/git2/tree.h +++ /dev/null @@ -1,291 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_tree_h__ -#define INCLUDE_git_tree_h__ - -#include "common.h" -#include "types.h" -#include "oid.h" -#include "object.h" - -/** - * @file git2/tree.h - * @brief Git tree parsing, loading routines - * @defgroup git_tree Git tree parsing, loading routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Lookup a tree object from the repository. - * - * @param tree pointer to the looked up tree - * @param repo the repo to use when locating the tree. - * @param id identity of the tree to locate. - * @return 0 on success; error code otherwise - */ -GIT_INLINE(int) git_tree_lookup(git_tree **tree, git_repository *repo, const git_oid *id) -{ - return git_object_lookup((git_object **)tree, repo, id, GIT_OBJ_TREE); -} - -/** - * Lookup a tree object from the repository, - * given a prefix of its identifier (short id). - * - * @see git_object_lookup_prefix - * - * @param tree pointer to the looked up tree - * @param repo the repo to use when locating the tree. - * @param id identity of the tree to locate. - * @param len the length of the short identifier - * @return 0 on success; error code otherwise - */ -GIT_INLINE(int) git_tree_lookup_prefix(git_tree **tree, git_repository *repo, const git_oid *id, unsigned int len) -{ - return git_object_lookup_prefix((git_object **)tree, repo, id, len, GIT_OBJ_TREE); -} - -/** - * Close an open tree - * - * This is a wrapper around git_object_close() - * - * IMPORTANT: - * It *is* necessary to call this method when you stop - * using a tree. Failure to do so will cause a memory leak. - * - * @param tree the tree to close - */ - -GIT_INLINE(void) git_tree_close(git_tree *tree) -{ - git_object_close((git_object *) tree); -} - - -/** - * Get the id of a tree. - * - * @param tree a previously loaded tree. - * @return object identity for the tree. - */ -GIT_EXTERN(const git_oid *) git_tree_id(git_tree *tree); - -/** - * Get the number of entries listed in a tree - * - * @param tree a previously loaded tree. - * @return the number of entries in the tree - */ -GIT_EXTERN(unsigned int) git_tree_entrycount(git_tree *tree); - -/** - * Lookup a tree entry by its filename - * - * @param tree a previously loaded tree. - * @param filename the filename of the desired entry - * @return the tree entry; NULL if not found - */ -GIT_EXTERN(const git_tree_entry *) git_tree_entry_byname(git_tree *tree, const char *filename); - -/** - * Lookup a tree entry by its position in the tree - * - * @param tree a previously loaded tree. - * @param idx the position in the entry list - * @return the tree entry; NULL if not found - */ -GIT_EXTERN(const git_tree_entry *) git_tree_entry_byindex(git_tree *tree, unsigned int idx); - -/** - * Get the UNIX file attributes of a tree entry - * - * @param entry a tree entry - * @return attributes as an integer - */ -GIT_EXTERN(unsigned int) git_tree_entry_attributes(const git_tree_entry *entry); - -/** - * Get the filename of a tree entry - * - * @param entry a tree entry - * @return the name of the file - */ -GIT_EXTERN(const char *) git_tree_entry_name(const git_tree_entry *entry); - -/** - * Get the id of the object pointed by the entry - * - * @param entry a tree entry - * @return the oid of the object - */ -GIT_EXTERN(const git_oid *) git_tree_entry_id(const git_tree_entry *entry); - -/** - * Get the type of the object pointed by the entry - * - * @param entry a tree entry - * @return the type of the pointed object - */ -GIT_EXTERN(git_otype) git_tree_entry_type(const git_tree_entry *entry); - -/** - * Convert a tree entry to the git_object it points too. - * - * @param object pointer to the converted object - * @param repo repository where to lookup the pointed object - * @param entry a tree entry - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_tree_entry_2object(git_object **object_out, git_repository *repo, const git_tree_entry *entry); - -/** - * Write a tree to the ODB from the index file - * - * This method will scan the index and write a representation - * of its current state back to disk; it recursively creates - * tree objects for each of the subtrees stored in the index, - * but only returns the OID of the root tree. This is the OID - * that can be used e.g. to create a commit. - * - * The index instance cannot be bare, and needs to be associated - * to an existing repository. - * - * @param oid Pointer where to store the written tree - * @param index Index to write - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_tree_create_fromindex(git_oid *oid, git_index *index); - -/** - * Create a new tree builder. - * - * The tree builder can be used to create or modify - * trees in memory and write them as tree objects to the - * database. - * - * If the `source` parameter is not NULL, the tree builder - * will be initialized with the entries of the given tree. - * - * If the `source` parameter is NULL, the tree builder will - * have no entries and will have to be filled manually. - * - * @param builder_p Pointer where to store the tree builder - * @param source Source tree to initialize the builder (optional) - * @return 0 on sucess; error code otherwise - */ -GIT_EXTERN(int) git_treebuilder_create(git_treebuilder **builder_p, const git_tree *source); - -/** - * Clear all the entires in the builder - * - * @param bld Builder to clear - */ -GIT_EXTERN(void) git_treebuilder_clear(git_treebuilder *bld); - -/** - * Free a tree builder - * - * This will clear all the entries and free to builder. - * Failing to free the builder after you're done using it - * will result in a memory leak - * - * @param bld Builder to free - */ -GIT_EXTERN(void) git_treebuilder_free(git_treebuilder *bld); - -/** - * Get an entry from the builder from its filename - * - * The returned entry is owned by the builder and should - * not be freed manually. - * - * @param bld Tree builder - * @param filename Name of the entry - * @return pointer to the entry; NULL if not found - */ -GIT_EXTERN(const git_tree_entry *) git_treebuilder_get(git_treebuilder *bld, const char *filename); - -/** - * Add or update an entry to the builder - * - * Insert a new entry for `filename` in the builder with the - * given attributes. - * - * if an entry named `filename` already exists, its attributes - * will be updated with the given ones. - * - * The optional pointer `entry_out` can be used to retrieve a - * pointer to the newly created/updated entry. - * - * @param entry_out Pointer to store the entry (optional) - * @param bld Tree builder - * @param filename Filename of the entry - * @param id SHA1 oid of the entry - * @param attributes Folder attributes of the entry - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_treebuilder_insert(git_tree_entry **entry_out, git_treebuilder *bld, const char *filename, const git_oid *id, unsigned int attributes); - -/** - * Remove an entry from the builder by its filename - * - * @param bld Tree builder - * @param filename Filename of the entry to remove - */ -GIT_EXTERN(int) git_treebuilder_remove(git_treebuilder *bld, const char *filename); - -/** - * Filter the entries in the tree - * - * The `filter` callback will be called for each entry - * in the tree with a pointer to the entry and the - * provided `payload`: if the callback returns 1, the - * entry will be filtered (removed from the builder). - * - * @param bld Tree builder - * @param filter Callback to filter entries - */ -GIT_EXTERN(void) git_treebuilder_filter(git_treebuilder *bld, int (*filter)(const git_tree_entry *, void *), void *payload); - -/** - * Write the contents of the tree builder as a tree object - * - * The tree builder will be written to the given `repo`, and - * it's identifying SHA1 hash will be stored in the `oid` - * pointer. - * - * @param oid Pointer where to store the written OID - * @param repo Repository where to store the object - * @param bld Tree builder to write - * @return 0 on success; error code otherwise - */ -GIT_EXTERN(int) git_treebuilder_write(git_oid *oid, git_repository *repo, git_treebuilder *bld); - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/include/git2/types.h b/vendor/libgit2/include/git2/types.h deleted file mode 100644 index b9db4e529..000000000 --- a/vendor/libgit2/include/git2/types.h +++ /dev/null @@ -1,193 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_types_h__ -#define INCLUDE_git_types_h__ - -#include "common.h" - -/** - * @file git2/types.h - * @brief libgit2 base & compatibility types - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -/** - * Cross-platform compatibility types for off_t / time_t - * - * NOTE: This needs to be in a public header so that both the library - * implementation and client applications both agree on the same types. - * Otherwise we get undefined behavior. - * - * Use the "best" types that each platform provides. Currently we truncate - * these intermediate representations for compatibility with the git ABI, but - * if and when it changes to support 64 bit types, our code will naturally - * adapt. - * NOTE: These types should match those that are returned by our internal - * stat() functions, for all platforms. - */ -#include - -#if defined(_MSC_VER) - -typedef __int64 git_off_t; -typedef __time64_t git_time_t; - -#elif defined(__MINGW32__) - -typedef off64_t git_off_t; -typedef __time64_t git_time_t; - -#elif defined(__HAIKU__) - -typedef __haiku_std_int64 git_off_t; -typedef __haiku_std_int64 git_time_t; - -#else /* POSIX */ - -/* - * Note: Can't use off_t since if a client program includes - * before us (directly or indirectly), they'll get 32 bit off_t in their client - * app, even though /we/ define _FILE_OFFSET_BITS=64. - */ -typedef int64_t git_off_t; -typedef int64_t git_time_t; - -#endif - -/** Basic type (loose or packed) of any Git object. */ -typedef enum { - GIT_OBJ_ANY = -2, /**< Object can be any of the following */ - GIT_OBJ_BAD = -1, /**< Object is invalid. */ - GIT_OBJ__EXT1 = 0, /**< Reserved for future use. */ - GIT_OBJ_COMMIT = 1, /**< A commit object. */ - GIT_OBJ_TREE = 2, /**< A tree (directory listing) object. */ - GIT_OBJ_BLOB = 3, /**< A file revision object. */ - GIT_OBJ_TAG = 4, /**< An annotated tag object. */ - GIT_OBJ__EXT2 = 5, /**< Reserved for future use. */ - GIT_OBJ_OFS_DELTA = 6, /**< A delta, base is given by an offset. */ - GIT_OBJ_REF_DELTA = 7, /**< A delta, base is given by object id. */ -} git_otype; - -/** An open object database handle. */ -typedef struct git_odb git_odb; - -/** A custom backend in an ODB */ -typedef struct git_odb_backend git_odb_backend; - -/** An object read from the ODB */ -typedef struct git_odb_object git_odb_object; - -/** A stream to read/write from the ODB */ -typedef struct git_odb_stream git_odb_stream; - -/** - * Representation of an existing git repository, - * including all its object contents - */ -typedef struct git_repository git_repository; - -/** Representation of a generic object in a repository */ -typedef struct git_object git_object; - -/** Representation of an in-progress walk through the commits in a repo */ -typedef struct git_revwalk git_revwalk; - -/** Parsed representation of a tag object. */ -typedef struct git_tag git_tag; - -/** In-memory representation of a blob object. */ -typedef struct git_blob git_blob; - -/** Parsed representation of a commit object. */ -typedef struct git_commit git_commit; - -/** Representation of each one of the entries in a tree object. */ -typedef struct git_tree_entry git_tree_entry; - -/** Representation of a tree object. */ -typedef struct git_tree git_tree; - -/** Constructor for in-memory trees */ -typedef struct git_treebuilder git_treebuilder; - -/** Memory representation of an index file. */ -typedef struct git_index git_index; - -/** Memory representation of a set of config files */ -typedef struct git_config git_config; - -/** Interface to access a configuration file */ -typedef struct git_config_file git_config_file; - -/** Representation of a reference log entry */ -typedef struct git_reflog_entry git_reflog_entry; - -/** Representation of a reference log */ -typedef struct git_reflog git_reflog; - -/** Time in a signature */ -typedef struct git_time { - git_time_t time; /** time in seconds from epoch */ - int offset; /** timezone offset, in minutes */ -} git_time; - -/** An action signature (e.g. for committers, taggers, etc) */ -typedef struct git_signature { - char *name; /** full name of the author */ - char *email; /** email of the author */ - git_time when; /** time when the action happened */ -} git_signature; - -/** In-memory representation of a reference. */ -typedef struct git_reference git_reference; - -/** Basic type of any Git reference. */ -typedef enum { - GIT_REF_INVALID = 0, /** Invalid reference */ - GIT_REF_OID = 1, /** A reference which points at an object id */ - GIT_REF_SYMBOLIC = 2, /** A reference which points at another reference */ - GIT_REF_PACKED = 4, - GIT_REF_HAS_PEEL = 8, - GIT_REF_LISTALL = GIT_REF_OID|GIT_REF_SYMBOLIC|GIT_REF_PACKED, -} git_rtype; - - -typedef struct git_refspec git_refspec; -typedef struct git_remote git_remote; - -/** A transport to use */ -typedef struct git_transport git_transport; - -typedef int (*git_transport_cb)(git_transport **transport); - -typedef struct git_remote_head git_remote_head; -typedef struct git_headarray git_headarray; - -/** @} */ -GIT_END_DECL - -#endif diff --git a/vendor/libgit2/include/git2/zlib.h b/vendor/libgit2/include/git2/zlib.h deleted file mode 100644 index 493566340..000000000 --- a/vendor/libgit2/include/git2/zlib.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#ifndef INCLUDE_git_zlib_h__ -#define INCLUDE_git_zlib_h__ - -#include - -/** - * @file git2/zlib.h - * @brief Git data compression routines - * @defgroup git_zlib Git data compression routines - * @ingroup Git - * @{ - */ -GIT_BEGIN_DECL - -#if defined(NO_DEFLATE_BOUND) || ZLIB_VERNUM < 0x1200 -/** - * deflateBound returns an upper bound on the compressed size. - * - * This is a stub function used when zlib does not supply the - * deflateBound() implementation itself. - * - * @param stream the stream pointer. - * @param s total length of the source data (in bytes). - * @return maximum length of the compressed data. - */ -GIT_INLINE(size_t) deflateBound(z_streamp stream, size_t s) -{ - return (s + ((s + 7) >> 3) + ((s + 63) >> 6) + 11); -} -#endif - -/** @} */ -GIT_END_DECL -#endif diff --git a/vendor/libgit2/libgit2.pc.in b/vendor/libgit2/libgit2.pc.in deleted file mode 100644 index 6165ad678..000000000 --- a/vendor/libgit2/libgit2.pc.in +++ /dev/null @@ -1,9 +0,0 @@ -libdir=@CMAKE_INSTALL_PREFIX@/@INSTALL_LIB@ -includedir=@CMAKE_INSTALL_PREFIX@/@INSTALL_INC@ - -Name: libgit2 -Description: The git library, take 2 -Version: @LIBGIT2_VERSION_STRING@ -Requires: libcrypto -Libs: -L${libdir} -lgit2 -lz -lcrypto -Cflags: -I${includedir} diff --git a/vendor/libgit2/src/backends/hiredis.c b/vendor/libgit2/src/backends/hiredis.c deleted file mode 100644 index 707412bf6..000000000 --- a/vendor/libgit2/src/backends/hiredis.c +++ /dev/null @@ -1,200 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "git2/object.h" -#include "hash.h" -#include "odb.h" - -#include "git2/odb_backend.h" - -#ifdef GIT2_HIREDIS_BACKEND - -#include - -typedef struct { - git_odb_backend parent; - - redisContext *db; -} hiredis_backend; - -int hiredis_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_backend *_backend, const git_oid *oid) { - hiredis_backend *backend; - int error; - redisReply *reply; - - assert(len_p && type_p && _backend && oid); - - backend = (hiredis_backend *) _backend; - error = GIT_ERROR; - - reply = redisCommand(backend->db, "HMGET %b %s %s", oid->id, GIT_OID_RAWSZ, - "type", "size"); - - if (reply->type == REDIS_REPLY_ARRAY) { - if (reply->element[0]->type != REDIS_REPLY_NIL && - reply->element[0]->type != REDIS_REPLY_NIL) { - *type_p = (git_otype) atoi(reply->element[0]->str); - *len_p = (size_t) atoi(reply->element[1]->str); - error = GIT_SUCCESS; - } else { - error = GIT_ENOTFOUND; - } - } else { - error = GIT_ERROR; - } - - freeReplyObject(reply); - return error; -} - -int hiredis_backend__read(void **data_p, size_t *len_p, git_otype *type_p, git_odb_backend *_backend, const git_oid *oid) { - hiredis_backend *backend; - int error; - redisReply *reply; - - assert(data_p && len_p && type_p && _backend && oid); - - backend = (hiredis_backend *) _backend; - error = GIT_ERROR; - - reply = redisCommand(backend->db, "HMGET %b %s %s %s", oid->id, GIT_OID_RAWSZ, - "type", "size", "data"); - - if (reply->type == REDIS_REPLY_ARRAY) { - if (reply->element[0]->type != REDIS_REPLY_NIL && - reply->element[1]->type != REDIS_REPLY_NIL && - reply->element[2]->type != REDIS_REPLY_NIL) { - *type_p = (git_otype) atoi(reply->element[0]->str); - *len_p = (size_t) atoi(reply->element[1]->str); - *data_p = git__malloc(*len_p); - if (*data_p == NULL) { - error = GIT_ENOMEM; - } else { - memcpy(*data_p, reply->element[2]->str, *len_p); - error = GIT_SUCCESS; - } - } else { - error = GIT_ENOTFOUND; - } - } else { - error = GIT_ERROR; - } - - freeReplyObject(reply); - return error; -} - -int hiredis_backend__exists(git_odb_backend *_backend, const git_oid *oid) { - hiredis_backend *backend; - int found; - redisReply *reply; - - assert(_backend && oid); - - backend = (hiredis_backend *) _backend; - found = 0; - - reply = redisCommand(backend->db, "exists %b", oid->id, GIT_OID_RAWSZ); - if (reply->type != REDIS_REPLY_NIL && reply->type != REDIS_REPLY_ERROR) - found = 1; - - - freeReplyObject(reply); - return found; -} - -int hiredis_backend__write(git_oid *id, git_odb_backend *_backend, const void *data, size_t len, git_otype type) { - hiredis_backend *backend; - int error; - redisReply *reply; - - assert(id && _backend && data); - - backend = (hiredis_backend *) _backend; - error = GIT_ERROR; - - if ((error = git_odb_hash(id, data, len, type)) < 0) - return error; - - reply = redisCommand(backend->db, "HMSET %b " - "type %d " - "size %d " - "data %b ", id->id, GIT_OID_RAWSZ, - (int) type, len, data, len); - error = reply->type == REDIS_REPLY_ERROR ? GIT_ERROR : GIT_SUCCESS; - - freeReplyObject(reply); - return error; -} - -void hiredis_backend__free(git_odb_backend *_backend) { - hiredis_backend *backend; - assert(_backend); - backend = (hiredis_backend *) _backend; - - redisFree(backend->db); - - free(backend); -} - -int git_odb_backend_hiredis(git_odb_backend **backend_out, const char *host, int port) { - hiredis_backend *backend; - - backend = git__calloc(1, sizeof (hiredis_backend)); - if (backend == NULL) - return GIT_ENOMEM; - - - backend->db = redisConnect(host, port); - if (backend->db->err) - goto cleanup; - - backend->parent.read = &hiredis_backend__read; - backend->parent.read_header = &hiredis_backend__read_header; - backend->parent.write = &hiredis_backend__write; - backend->parent.exists = &hiredis_backend__exists; - backend->parent.free = &hiredis_backend__free; - - *backend_out = (git_odb_backend *) backend; - - return GIT_SUCCESS; -cleanup: - free(backend); - return GIT_ERROR; -} - -#else - -int git_odb_backend_hiredis(git_odb_backend ** GIT_UNUSED(backend_out), - const char *GIT_UNUSED(host), int GIT_UNUSED(port)) { - GIT_UNUSED_ARG(backend_out); - GIT_UNUSED_ARG(host); - GIT_UNUSED_ARG(port); - return GIT_ENOTIMPLEMENTED; -} - - -#endif /* HAVE_HIREDIS */ diff --git a/vendor/libgit2/src/backends/sqlite.c b/vendor/libgit2/src/backends/sqlite.c deleted file mode 100644 index a4c6d4825..000000000 --- a/vendor/libgit2/src/backends/sqlite.c +++ /dev/null @@ -1,280 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "git2/object.h" -#include "hash.h" -#include "odb.h" - -#include "git2/odb_backend.h" - -#ifdef GIT2_SQLITE_BACKEND - -#include - -#define GIT2_TABLE_NAME "git2_odb" - -typedef struct { - git_odb_backend parent; - sqlite3 *db; - sqlite3_stmt *st_read; - sqlite3_stmt *st_write; - sqlite3_stmt *st_read_header; -} sqlite_backend; - -int sqlite_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_backend *_backend, const git_oid *oid) -{ - sqlite_backend *backend; - int error; - - assert(len_p && type_p && _backend && oid); - - backend = (sqlite_backend *)_backend; - error = GIT_ERROR; - - if (sqlite3_bind_text(backend->st_read_header, 1, (char *)oid->id, 20, SQLITE_TRANSIENT) == SQLITE_OK) { - if (sqlite3_step(backend->st_read_header) == SQLITE_ROW) { - *type_p = (git_otype)sqlite3_column_int(backend->st_read_header, 0); - *len_p = (size_t)sqlite3_column_int(backend->st_read_header, 1); - assert(sqlite3_step(backend->st_read_header) == SQLITE_DONE); - error = GIT_SUCCESS; - } else { - error = GIT_ENOTFOUND; - } - } - - sqlite3_reset(backend->st_read_header); - return error; -} - - -int sqlite_backend__read(void **data_p, size_t *len_p, git_otype *type_p, git_odb_backend *_backend, const git_oid *oid) -{ - sqlite_backend *backend; - int error; - - assert(data_p && len_p && type_p && _backend && oid); - - backend = (sqlite_backend *)_backend; - error = GIT_ERROR; - - if (sqlite3_bind_text(backend->st_read, 1, (char *)oid->id, 20, SQLITE_TRANSIENT) == SQLITE_OK) { - if (sqlite3_step(backend->st_read) == SQLITE_ROW) { - *type_p = (git_otype)sqlite3_column_int(backend->st_read, 0); - *len_p = (size_t)sqlite3_column_int(backend->st_read, 1); - *data_p = git__malloc(*len_p); - - if (*data_p == NULL) { - error = GIT_ENOMEM; - } else { - memcpy(*data_p, sqlite3_column_blob(backend->st_read, 2), *len_p); - error = GIT_SUCCESS; - } - - assert(sqlite3_step(backend->st_read) == SQLITE_DONE); - } else { - error = GIT_ENOTFOUND; - } - } - - sqlite3_reset(backend->st_read); - return error; -} - -int sqlite_backend__exists(git_odb_backend *_backend, const git_oid *oid) -{ - sqlite_backend *backend; - int found; - - assert(_backend && oid); - - backend = (sqlite_backend *)_backend; - found = 0; - - if (sqlite3_bind_text(backend->st_read_header, 1, (char *)oid->id, 20, SQLITE_TRANSIENT) == SQLITE_OK) { - if (sqlite3_step(backend->st_read_header) == SQLITE_ROW) { - found = 1; - assert(sqlite3_step(backend->st_read_header) == SQLITE_DONE); - } - } - - sqlite3_reset(backend->st_read_header); - return found; -} - - -int sqlite_backend__write(git_oid *id, git_odb_backend *_backend, const void *data, size_t len, git_otype type) -{ - int error; - sqlite_backend *backend; - - assert(id && _backend && data); - - backend = (sqlite_backend *)_backend; - - if ((error = git_odb_hash(id, data, len, type)) < 0) - return error; - - error = SQLITE_ERROR; - - if (sqlite3_bind_text(backend->st_write, 1, (char *)id->id, 20, SQLITE_TRANSIENT) == SQLITE_OK && - sqlite3_bind_int(backend->st_write, 2, (int)type) == SQLITE_OK && - sqlite3_bind_int(backend->st_write, 3, len) == SQLITE_OK && - sqlite3_bind_blob(backend->st_write, 4, data, len, SQLITE_TRANSIENT) == SQLITE_OK) { - error = sqlite3_step(backend->st_write); - } - - sqlite3_reset(backend->st_write); - return (error == SQLITE_DONE) ? GIT_SUCCESS : GIT_ERROR; -} - - -void sqlite_backend__free(git_odb_backend *_backend) -{ - sqlite_backend *backend; - assert(_backend); - backend = (sqlite_backend *)_backend; - - sqlite3_finalize(backend->st_read); - sqlite3_finalize(backend->st_read_header); - sqlite3_finalize(backend->st_write); - sqlite3_close(backend->db); - - free(backend); -} - -static int create_table(sqlite3 *db) -{ - static const char *sql_creat = - "CREATE TABLE '" GIT2_TABLE_NAME "' (" - "'oid' CHARACTER(20) PRIMARY KEY NOT NULL," - "'type' INTEGER NOT NULL," - "'size' INTEGER NOT NULL," - "'data' BLOB);"; - - if (sqlite3_exec(db, sql_creat, NULL, NULL, NULL) != SQLITE_OK) - return GIT_ERROR; - - return GIT_SUCCESS; -} - -static int init_db(sqlite3 *db) -{ - static const char *sql_check = - "SELECT name FROM sqlite_master WHERE type='table' AND name='" GIT2_TABLE_NAME "';"; - - sqlite3_stmt *st_check; - int error; - - if (sqlite3_prepare_v2(db, sql_check, -1, &st_check, NULL) != SQLITE_OK) - return GIT_ERROR; - - switch (sqlite3_step(st_check)) { - case SQLITE_DONE: - /* the table was not found */ - error = create_table(db); - break; - - case SQLITE_ROW: - /* the table was found */ - error = GIT_SUCCESS; - break; - - default: - error = GIT_ERROR; - break; - } - - sqlite3_finalize(st_check); - return error; -} - -static int init_statements(sqlite_backend *backend) -{ - static const char *sql_read = - "SELECT type, size, data FROM '" GIT2_TABLE_NAME "' WHERE oid = ?;"; - - static const char *sql_read_header = - "SELECT type, size FROM '" GIT2_TABLE_NAME "' WHERE oid = ?;"; - - static const char *sql_write = - "INSERT OR IGNORE INTO '" GIT2_TABLE_NAME "' VALUES (?, ?, ?, ?);"; - - if (sqlite3_prepare_v2(backend->db, sql_read, -1, &backend->st_read, NULL) != SQLITE_OK) - return GIT_ERROR; - - if (sqlite3_prepare_v2(backend->db, sql_read_header, -1, &backend->st_read_header, NULL) != SQLITE_OK) - return GIT_ERROR; - - if (sqlite3_prepare_v2(backend->db, sql_write, -1, &backend->st_write, NULL) != SQLITE_OK) - return GIT_ERROR; - - return GIT_SUCCESS; -} - -int git_odb_backend_sqlite(git_odb_backend **backend_out, const char *sqlite_db) -{ - sqlite_backend *backend; - int error; - - backend = git__calloc(1, sizeof(sqlite_backend)); - if (backend == NULL) - return GIT_ENOMEM; - - if (sqlite3_open(sqlite_db, &backend->db) != SQLITE_OK) - goto cleanup; - - error = init_db(backend->db); - if (error < 0) - goto cleanup; - - error = init_statements(backend); - if (error < 0) - goto cleanup; - - backend->parent.read = &sqlite_backend__read; - backend->parent.read_header = &sqlite_backend__read_header; - backend->parent.write = &sqlite_backend__write; - backend->parent.exists = &sqlite_backend__exists; - backend->parent.free = &sqlite_backend__free; - - *backend_out = (git_odb_backend *)backend; - return GIT_SUCCESS; - -cleanup: - sqlite_backend__free((git_odb_backend *)backend); - return GIT_ERROR; -} - -#else - -int git_odb_backend_sqlite(git_odb_backend **GIT_UNUSED(backend_out), const char *GIT_UNUSED(sqlite_db)) -{ - GIT_UNUSED_ARG(backend_out); - GIT_UNUSED_ARG(sqlite_db); - return GIT_ENOTIMPLEMENTED; -} - -#endif /* HAVE_SQLITE3 */ diff --git a/vendor/libgit2/src/blob.c b/vendor/libgit2/src/blob.c deleted file mode 100644 index b8282e505..000000000 --- a/vendor/libgit2/src/blob.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "git2/common.h" -#include "git2/object.h" -#include "git2/repository.h" - -#include "common.h" -#include "blob.h" - -const void *git_blob_rawcontent(git_blob *blob) -{ - assert(blob); - return blob->odb_object->raw.data; -} - -int git_blob_rawsize(git_blob *blob) -{ - assert(blob); - return blob->odb_object->raw.len; -} - -void git_blob__free(git_blob *blob) -{ - git_odb_object_close(blob->odb_object); - free(blob); -} - -int git_blob__parse(git_blob *blob, git_odb_object *odb_obj) -{ - assert(blob); - git_cached_obj_incref((git_cached_obj *)odb_obj); - blob->odb_object = odb_obj; - return GIT_SUCCESS; -} - -int git_blob_create_frombuffer(git_oid *oid, git_repository *repo, const void *buffer, size_t len) -{ - int error; - git_odb_stream *stream; - - if ((error = git_odb_open_wstream(&stream, repo->db, len, GIT_OBJ_BLOB)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to create blob"); - - if ((error = stream->write(stream, buffer, len)) < GIT_SUCCESS) { - stream->free(stream); - return error; - } - - error = stream->finalize_write(oid, stream); - stream->free(stream); - - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to create blob"); - - return GIT_SUCCESS; -} - -int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *path) -{ - int error, islnk; - int fd = 0; - char full_path[GIT_PATH_MAX]; - char buffer[2048]; - git_off_t size; - git_odb_stream *stream; - struct stat st; - - if (repo->path_workdir == NULL) - return git__throw(GIT_ENOTFOUND, "Failed to create blob. (No working directory found)"); - - git_path_join(full_path, repo->path_workdir, path); - - error = p_lstat(full_path, &st); - if (error < 0) { - return git__throw(GIT_EOSERR, "Failed to stat blob. %s", strerror(errno)); - } - - islnk = S_ISLNK(st.st_mode); - size = st.st_size; - - if (!islnk) - if ((fd = p_open(full_path, O_RDONLY)) < 0) - return git__throw(GIT_ENOTFOUND, "Failed to create blob. Could not open '%s'", full_path); - - if ((error = git_odb_open_wstream(&stream, repo->db, (size_t)size, GIT_OBJ_BLOB)) < GIT_SUCCESS) { - if (!islnk) - p_close(fd); - return git__rethrow(error, "Failed to create blob"); - } - - while (size > 0) { - ssize_t read_len; - - if (!islnk) - read_len = p_read(fd, buffer, sizeof(buffer)); - else - read_len = p_readlink(full_path, buffer, sizeof(buffer)); - - if (read_len < 0) { - if (!islnk) - p_close(fd); - stream->free(stream); - return git__throw(GIT_EOSERR, "Failed to create blob. Can't read full file"); - } - - stream->write(stream, buffer, read_len); - size -= read_len; - } - - error = stream->finalize_write(oid, stream); - stream->free(stream); - if (!islnk) - p_close(fd); - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to create blob"); -} - diff --git a/vendor/libgit2/src/blob.h b/vendor/libgit2/src/blob.h deleted file mode 100644 index 4300d7e54..000000000 --- a/vendor/libgit2/src/blob.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef INCLUDE_blob_h__ -#define INCLUDE_blob_h__ - -#include "git2/blob.h" -#include "repository.h" -#include "odb.h" -#include "fileops.h" - -struct git_blob { - git_object object; - git_odb_object *odb_object; -}; - -void git_blob__free(git_blob *blob); -int git_blob__parse(git_blob *blob, git_odb_object *obj); - -#endif diff --git a/vendor/libgit2/src/block-sha1/sha1.c b/vendor/libgit2/src/block-sha1/sha1.c deleted file mode 100644 index 8c1460102..000000000 --- a/vendor/libgit2/src/block-sha1/sha1.c +++ /dev/null @@ -1,281 +0,0 @@ -/* - * SHA1 routine optimized to do word accesses rather than byte accesses, - * and to avoid unnecessary copies into the context array. - * - * This was initially based on the Mozilla SHA1 implementation, although - * none of the original Mozilla code remains. - */ - -#include "common.h" -#include "sha1.h" - -#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) - -/* - * Force usage of rol or ror by selecting the one with the smaller constant. - * It _can_ generate slightly smaller code (a constant of 1 is special), but - * perhaps more importantly it's possibly faster on any uarch that does a - * rotate with a loop. - */ - -#define SHA_ASM(op, x, n) ({ unsigned int __res; __asm__(op " %1,%0":"=r" (__res):"i" (n), "0" (x)); __res; }) -#define SHA_ROL(x,n) SHA_ASM("rol", x, n) -#define SHA_ROR(x,n) SHA_ASM("ror", x, n) - -#else - -#define SHA_ROT(X,l,r) (((X) << (l)) | ((X) >> (r))) -#define SHA_ROL(X,n) SHA_ROT(X,n,32-(n)) -#define SHA_ROR(X,n) SHA_ROT(X,32-(n),n) - -#endif - -/* - * If you have 32 registers or more, the compiler can (and should) - * try to change the array[] accesses into registers. However, on - * machines with less than ~25 registers, that won't really work, - * and at least gcc will make an unholy mess of it. - * - * So to avoid that mess which just slows things down, we force - * the stores to memory to actually happen (we might be better off - * with a 'W(t)=(val);asm("":"+m" (W(t))' there instead, as - * suggested by Artur Skawina - that will also make gcc unable to - * try to do the silly "optimize away loads" part because it won't - * see what the value will be). - * - * Ben Herrenschmidt reports that on PPC, the C version comes close - * to the optimized asm with this (ie on PPC you don't want that - * 'volatile', since there are lots of registers). - * - * On ARM we get the best code generation by forcing a full memory barrier - * between each SHA_ROUND, otherwise gcc happily get wild with spilling and - * the stack frame size simply explode and performance goes down the drain. - */ - -#if defined(__i386__) || defined(__x86_64__) - #define setW(x, val) (*(volatile unsigned int *)&W(x) = (val)) -#elif defined(__GNUC__) && defined(__arm__) - #define setW(x, val) do { W(x) = (val); __asm__("":::"memory"); } while (0) -#else - #define setW(x, val) (W(x) = (val)) -#endif - -/* - * Performance might be improved if the CPU architecture is OK with - * unaligned 32-bit loads and a fast ntohl() is available. - * Otherwise fall back to byte loads and shifts which is portable, - * and is faster on architectures with memory alignment issues. - */ - -#if defined(__i386__) || defined(__x86_64__) || \ - defined(_M_IX86) || defined(_M_X64) || \ - defined(__ppc__) || defined(__ppc64__) || \ - defined(__powerpc__) || defined(__powerpc64__) || \ - defined(__s390__) || defined(__s390x__) - -#define get_be32(p) ntohl(*(unsigned int *)(p)) -#define put_be32(p, v) do { *(unsigned int *)(p) = htonl(v); } while (0) - -#else - -#define get_be32(p) ( \ - (*((unsigned char *)(p) + 0) << 24) | \ - (*((unsigned char *)(p) + 1) << 16) | \ - (*((unsigned char *)(p) + 2) << 8) | \ - (*((unsigned char *)(p) + 3) << 0) ) -#define put_be32(p, v) do { \ - unsigned int __v = (v); \ - *((unsigned char *)(p) + 0) = __v >> 24; \ - *((unsigned char *)(p) + 1) = __v >> 16; \ - *((unsigned char *)(p) + 2) = __v >> 8; \ - *((unsigned char *)(p) + 3) = __v >> 0; } while (0) - -#endif - -/* This "rolls" over the 512-bit array */ -#define W(x) (array[(x)&15]) - -/* - * Where do we get the source from? The first 16 iterations get it from - * the input data, the next mix it from the 512-bit array. - */ -#define SHA_SRC(t) get_be32(data + t) -#define SHA_MIX(t) SHA_ROL(W(t+13) ^ W(t+8) ^ W(t+2) ^ W(t), 1) - -#define SHA_ROUND(t, input, fn, constant, A, B, C, D, E) do { \ - unsigned int TEMP = input(t); setW(t, TEMP); \ - E += TEMP + SHA_ROL(A,5) + (fn) + (constant); \ - B = SHA_ROR(B, 2); } while (0) - -#define T_0_15(t, A, B, C, D, E) SHA_ROUND(t, SHA_SRC, (((C^D)&B)^D) , 0x5a827999, A, B, C, D, E ) -#define T_16_19(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (((C^D)&B)^D) , 0x5a827999, A, B, C, D, E ) -#define T_20_39(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (B^C^D) , 0x6ed9eba1, A, B, C, D, E ) -#define T_40_59(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, ((B&C)+(D&(B^C))) , 0x8f1bbcdc, A, B, C, D, E ) -#define T_60_79(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (B^C^D) , 0xca62c1d6, A, B, C, D, E ) - -static void blk_SHA1_Block(blk_SHA_CTX *ctx, const unsigned int *data) -{ - unsigned int A,B,C,D,E; - unsigned int array[16]; - - A = ctx->H[0]; - B = ctx->H[1]; - C = ctx->H[2]; - D = ctx->H[3]; - E = ctx->H[4]; - - /* Round 1 - iterations 0-16 take their input from 'data' */ - T_0_15( 0, A, B, C, D, E); - T_0_15( 1, E, A, B, C, D); - T_0_15( 2, D, E, A, B, C); - T_0_15( 3, C, D, E, A, B); - T_0_15( 4, B, C, D, E, A); - T_0_15( 5, A, B, C, D, E); - T_0_15( 6, E, A, B, C, D); - T_0_15( 7, D, E, A, B, C); - T_0_15( 8, C, D, E, A, B); - T_0_15( 9, B, C, D, E, A); - T_0_15(10, A, B, C, D, E); - T_0_15(11, E, A, B, C, D); - T_0_15(12, D, E, A, B, C); - T_0_15(13, C, D, E, A, B); - T_0_15(14, B, C, D, E, A); - T_0_15(15, A, B, C, D, E); - - /* Round 1 - tail. Input from 512-bit mixing array */ - T_16_19(16, E, A, B, C, D); - T_16_19(17, D, E, A, B, C); - T_16_19(18, C, D, E, A, B); - T_16_19(19, B, C, D, E, A); - - /* Round 2 */ - T_20_39(20, A, B, C, D, E); - T_20_39(21, E, A, B, C, D); - T_20_39(22, D, E, A, B, C); - T_20_39(23, C, D, E, A, B); - T_20_39(24, B, C, D, E, A); - T_20_39(25, A, B, C, D, E); - T_20_39(26, E, A, B, C, D); - T_20_39(27, D, E, A, B, C); - T_20_39(28, C, D, E, A, B); - T_20_39(29, B, C, D, E, A); - T_20_39(30, A, B, C, D, E); - T_20_39(31, E, A, B, C, D); - T_20_39(32, D, E, A, B, C); - T_20_39(33, C, D, E, A, B); - T_20_39(34, B, C, D, E, A); - T_20_39(35, A, B, C, D, E); - T_20_39(36, E, A, B, C, D); - T_20_39(37, D, E, A, B, C); - T_20_39(38, C, D, E, A, B); - T_20_39(39, B, C, D, E, A); - - /* Round 3 */ - T_40_59(40, A, B, C, D, E); - T_40_59(41, E, A, B, C, D); - T_40_59(42, D, E, A, B, C); - T_40_59(43, C, D, E, A, B); - T_40_59(44, B, C, D, E, A); - T_40_59(45, A, B, C, D, E); - T_40_59(46, E, A, B, C, D); - T_40_59(47, D, E, A, B, C); - T_40_59(48, C, D, E, A, B); - T_40_59(49, B, C, D, E, A); - T_40_59(50, A, B, C, D, E); - T_40_59(51, E, A, B, C, D); - T_40_59(52, D, E, A, B, C); - T_40_59(53, C, D, E, A, B); - T_40_59(54, B, C, D, E, A); - T_40_59(55, A, B, C, D, E); - T_40_59(56, E, A, B, C, D); - T_40_59(57, D, E, A, B, C); - T_40_59(58, C, D, E, A, B); - T_40_59(59, B, C, D, E, A); - - /* Round 4 */ - T_60_79(60, A, B, C, D, E); - T_60_79(61, E, A, B, C, D); - T_60_79(62, D, E, A, B, C); - T_60_79(63, C, D, E, A, B); - T_60_79(64, B, C, D, E, A); - T_60_79(65, A, B, C, D, E); - T_60_79(66, E, A, B, C, D); - T_60_79(67, D, E, A, B, C); - T_60_79(68, C, D, E, A, B); - T_60_79(69, B, C, D, E, A); - T_60_79(70, A, B, C, D, E); - T_60_79(71, E, A, B, C, D); - T_60_79(72, D, E, A, B, C); - T_60_79(73, C, D, E, A, B); - T_60_79(74, B, C, D, E, A); - T_60_79(75, A, B, C, D, E); - T_60_79(76, E, A, B, C, D); - T_60_79(77, D, E, A, B, C); - T_60_79(78, C, D, E, A, B); - T_60_79(79, B, C, D, E, A); - - ctx->H[0] += A; - ctx->H[1] += B; - ctx->H[2] += C; - ctx->H[3] += D; - ctx->H[4] += E; -} - -void git__blk_SHA1_Init(blk_SHA_CTX *ctx) -{ - ctx->size = 0; - - /* Initialize H with the magic constants (see FIPS180 for constants) */ - ctx->H[0] = 0x67452301; - ctx->H[1] = 0xefcdab89; - ctx->H[2] = 0x98badcfe; - ctx->H[3] = 0x10325476; - ctx->H[4] = 0xc3d2e1f0; -} - -void git__blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len) -{ - unsigned int lenW = ctx->size & 63; - - ctx->size += len; - - /* Read the data into W and process blocks as they get full */ - if (lenW) { - unsigned int left = 64 - lenW; - if (len < left) - left = len; - memcpy(lenW + (char *)ctx->W, data, left); - lenW = (lenW + left) & 63; - len -= left; - data = ((const char *)data + left); - if (lenW) - return; - blk_SHA1_Block(ctx, ctx->W); - } - while (len >= 64) { - blk_SHA1_Block(ctx, data); - data = ((const char *)data + 64); - len -= 64; - } - if (len) - memcpy(ctx->W, data, len); -} - -void git__blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx) -{ - static const unsigned char pad[64] = { 0x80 }; - unsigned int padlen[2]; - int i; - - /* Pad with a binary 1 (ie 0x80), then zeroes, then length */ - padlen[0] = htonl((uint32_t)(ctx->size >> 29)); - padlen[1] = htonl((uint32_t)(ctx->size << 3)); - - i = ctx->size & 63; - git__blk_SHA1_Update(ctx, pad, 1+ (63 & (55 - i))); - git__blk_SHA1_Update(ctx, padlen, 8); - - /* Output hash */ - for (i = 0; i < 5; i++) - put_be32(hashout + i*4, ctx->H[i]); -} diff --git a/vendor/libgit2/src/block-sha1/sha1.h b/vendor/libgit2/src/block-sha1/sha1.h deleted file mode 100644 index 558d6aece..000000000 --- a/vendor/libgit2/src/block-sha1/sha1.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * SHA1 routine optimized to do word accesses rather than byte accesses, - * and to avoid unnecessary copies into the context array. - * - * This was initially based on the Mozilla SHA1 implementation, although - * none of the original Mozilla code remains. - */ - -typedef struct { - unsigned long long size; - unsigned int H[5]; - unsigned int W[16]; -} blk_SHA_CTX; - -void git__blk_SHA1_Init(blk_SHA_CTX *ctx); -void git__blk_SHA1_Update(blk_SHA_CTX *ctx, const void *dataIn, unsigned long len); -void git__blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx); - -#define SHA_CTX blk_SHA_CTX -#define SHA1_Init git__blk_SHA1_Init -#define SHA1_Update git__blk_SHA1_Update -#define SHA1_Final git__blk_SHA1_Final diff --git a/vendor/libgit2/src/bswap.h b/vendor/libgit2/src/bswap.h deleted file mode 100644 index b9211c3c8..000000000 --- a/vendor/libgit2/src/bswap.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Let's make sure we always have a sane definition for ntohl()/htonl(). - * Some libraries define those as a function call, just to perform byte - * shifting, bringing significant overhead to what should be a simple - * operation. - */ - -#include "common.h" - -/* - * Default version that the compiler ought to optimize properly with - * constant values. - */ -GIT_INLINE(uint32_t) default_swab32(uint32_t val) -{ - return (((val & 0xff000000) >> 24) | - ((val & 0x00ff0000) >> 8) | - ((val & 0x0000ff00) << 8) | - ((val & 0x000000ff) << 24)); -} - -#undef bswap32 - -GIT_INLINE(uint16_t) default_swab16(uint16_t val) -{ - return (((val & 0xff00) >> 8) | - ((val & 0x00ff) << 8)); -} - -#undef bswap16 - -#if defined(__GNUC__) && defined(__i386__) - -#define bswap32(x) ({ \ - uint32_t __res; \ - if (__builtin_constant_p(x)) { \ - __res = default_swab32(x); \ - } else { \ - __asm__("bswap %0" : "=r" (__res) : "0" ((uint32_t)(x))); \ - } \ - __res; }) - -#define bswap16(x) ({ \ - uint16_t __res; \ - if (__builtin_constant_p(x)) { \ - __res = default_swab16(x); \ - } else { \ - __asm__("xchgb %b0,%h0" : "=q" (__res) : "0" ((uint16_t)(x))); \ - } \ - __res; }) - -#elif defined(__GNUC__) && defined(__x86_64__) - -#define bswap32(x) ({ \ - uint32_t __res; \ - if (__builtin_constant_p(x)) { \ - __res = default_swab32(x); \ - } else { \ - __asm__("bswapl %0" : "=r" (__res) : "0" ((uint32_t)(x))); \ - } \ - __res; }) - -#define bswap16(x) ({ \ - uint16_t __res; \ - if (__builtin_constant_p(x)) { \ - __res = default_swab16(x); \ - } else { \ - __asm__("xchgb %b0,%h0" : "=Q" (__res) : "0" ((uint16_t)(x))); \ - } \ - __res; }) - -#elif defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_X64)) - -#include - -#define bswap32(x) _byteswap_ulong(x) -#define bswap16(x) _byteswap_ushort(x) - -#endif - -#ifdef bswap32 - -#undef ntohl -#undef htonl -#define ntohl(x) bswap32(x) -#define htonl(x) bswap32(x) - -#endif - -#ifdef bswap16 - -#undef ntohs -#undef htons -#define ntohs(x) bswap16(x) -#define htons(x) bswap16(x) - -#endif diff --git a/vendor/libgit2/src/buffer.c b/vendor/libgit2/src/buffer.c deleted file mode 100644 index 6af4c9195..000000000 --- a/vendor/libgit2/src/buffer.c +++ /dev/null @@ -1,95 +0,0 @@ -#include "buffer.h" -#include "posix.h" -#include - -#define ENSURE_SIZE(b, d) \ - if ((ssize_t)(d) >= buf->asize && git_buf_grow(b, (d)) < GIT_SUCCESS)\ - return; - -int git_buf_grow(git_buf *buf, size_t target_size) -{ - char *new_ptr; - - if (buf->asize < 0) - return GIT_ENOMEM; - - if (buf->asize == 0) - buf->asize = target_size; - - /* grow the buffer size by 1.5, until it's big enough - * to fit our target size */ - while (buf->asize < (int)target_size) - buf->asize = (buf->asize << 1) - (buf->asize >> 1); - - new_ptr = git__realloc(buf->ptr, buf->asize); - if (!new_ptr) { - buf->asize = -1; - return GIT_ENOMEM; - } - - buf->ptr = new_ptr; - return GIT_SUCCESS; -} - -int git_buf_oom(const git_buf *buf) -{ - return (buf->asize < 0); -} - -void git_buf_putc(git_buf *buf, char c) -{ - ENSURE_SIZE(buf, buf->size + 1); - buf->ptr[buf->size++] = c; -} - -void git_buf_put(git_buf *buf, const char *data, size_t len) -{ - ENSURE_SIZE(buf, buf->size + len); - memcpy(buf->ptr + buf->size, data, len); - buf->size += len; -} - -void git_buf_puts(git_buf *buf, const char *string) -{ - git_buf_put(buf, string, strlen(string)); -} - -void git_buf_printf(git_buf *buf, const char *format, ...) -{ - int len; - va_list arglist; - - ENSURE_SIZE(buf, buf->size + 1); - - while (1) { - va_start(arglist, format); - len = p_vsnprintf(buf->ptr + buf->size, buf->asize - buf->size, format, arglist); - va_end(arglist); - - if (len < 0) { - buf->asize = -1; - return; - } - - if (len + 1 <= buf->asize - buf->size) { - buf->size += len; - return; - } - - ENSURE_SIZE(buf, buf->size + len + 1); - } -} - -const char *git_buf_cstr(git_buf *buf) -{ - if (buf->size + 1 >= buf->asize && git_buf_grow(buf, buf->size + 1) < GIT_SUCCESS) - return NULL; - - buf->ptr[buf->size] = '\0'; - return buf->ptr; -} - -void git_buf_free(git_buf *buf) -{ - free(buf->ptr); -} diff --git a/vendor/libgit2/src/buffer.h b/vendor/libgit2/src/buffer.h deleted file mode 100644 index 1209340a1..000000000 --- a/vendor/libgit2/src/buffer.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef INCLUDE_buffer_h__ -#define INCLUDE_buffer_h__ - -#include "common.h" - -typedef struct { - char *ptr; - ssize_t asize, size; -} git_buf; - -#define GIT_BUF_INIT {NULL, 0, 0} - -int git_buf_grow(git_buf *buf, size_t target_size); -int git_buf_oom(const git_buf *buf); -void git_buf_putc(git_buf *buf, char c); -void git_buf_put(git_buf *buf, const char *data, size_t len); -void git_buf_puts(git_buf *buf, const char *string); -void git_buf_printf(git_buf *buf, const char *format, ...) GIT_FORMAT_PRINTF(2, 3); -const char *git_buf_cstr(git_buf *buf); -void git_buf_free(git_buf *buf); - -#define git_buf_PUTS(buf, str) git_buf_put(buf, str, sizeof(str) - 1) - -#endif diff --git a/vendor/libgit2/src/cache.c b/vendor/libgit2/src/cache.c deleted file mode 100644 index 433fc3d9c..000000000 --- a/vendor/libgit2/src/cache.c +++ /dev/null @@ -1,129 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "repository.h" -#include "commit.h" -#include "thread-utils.h" -#include "cache.h" - -int git_cache_init(git_cache *cache, size_t size, git_cached_obj_freeptr free_ptr) -{ - size_t i; - - if (size < 8) - size = 8; - - /* round up size to closest power of 2 */ - size--; - size |= size >> 1; - size |= size >> 2; - size |= size >> 4; - size |= size >> 8; - size |= size >> 16; - - cache->size_mask = size; - cache->lru_count = 0; - cache->free_obj = free_ptr; - - cache->nodes = git__malloc((size + 1) * sizeof(cache_node)); - if (cache->nodes == NULL) - return GIT_ENOMEM; - - for (i = 0; i < (size + 1); ++i) { - git_mutex_init(&cache->nodes[i].lock); - cache->nodes[i].ptr = NULL; - } - - return GIT_SUCCESS; -} - -void git_cache_free(git_cache *cache) -{ - size_t i; - - for (i = 0; i < (cache->size_mask + 1); ++i) { - if (cache->nodes[i].ptr) - git_cached_obj_decref(cache->nodes[i].ptr, cache->free_obj); - - git_mutex_free(&cache->nodes[i].lock); - } - - free(cache->nodes); -} - -void *git_cache_get(git_cache *cache, const git_oid *oid) -{ - const uint32_t *hash; - cache_node *node = NULL; - void *result = NULL; - - hash = (const uint32_t *)oid->id; - node = &cache->nodes[hash[0] & cache->size_mask]; - - git_mutex_lock(&node->lock); - { - if (node->ptr && git_cached_obj_compare(node->ptr, oid) == 0) { - git_cached_obj_incref(node->ptr); - result = node->ptr; - } - } - git_mutex_unlock(&node->lock); - - return result; -} - -void *git_cache_try_store(git_cache *cache, void *entry) -{ - const uint32_t *hash; - const git_oid *oid; - cache_node *node = NULL; - - oid = &((git_cached_obj*)entry)->oid; - hash = (const uint32_t *)oid->id; - node = &cache->nodes[hash[0] & cache->size_mask]; - - /* increase the refcount on this object, because - * the cache now owns it */ - git_cached_obj_incref(entry); - git_mutex_lock(&node->lock); - - if (node->ptr == NULL) { - node->ptr = entry; - } else if (git_cached_obj_compare(node->ptr, oid) == 0) { - git_cached_obj_decref(entry, cache->free_obj); - entry = node->ptr; - } else { - git_cached_obj_decref(node->ptr, cache->free_obj); - node->ptr = entry; - } - - /* increase the refcount again, because we are - * returning it to the user */ - git_cached_obj_incref(entry); - git_mutex_unlock(&node->lock); - - return entry; -} diff --git a/vendor/libgit2/src/cache.h b/vendor/libgit2/src/cache.h deleted file mode 100644 index 4794dea3a..000000000 --- a/vendor/libgit2/src/cache.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef INCLUDE_cache_h__ -#define INCLUDE_cache_h__ - -#include "git2/common.h" -#include "git2/oid.h" -#include "git2/odb.h" - -#include "thread-utils.h" - -#define GIT_DEFAULT_CACHE_SIZE 128 - -typedef void (*git_cached_obj_freeptr)(void *); - -typedef struct { - git_oid oid; - git_atomic refcount; -} git_cached_obj; - -typedef struct { - git_cached_obj *ptr; - git_mutex lock; -} cache_node; - -typedef struct { - cache_node *nodes; - - unsigned int lru_count; - size_t size_mask; - git_cached_obj_freeptr free_obj; -} git_cache; - - -int git_cache_init(git_cache *cache, size_t size, git_cached_obj_freeptr free_ptr); -void git_cache_free(git_cache *cache); - -void *git_cache_try_store(git_cache *cache, void *entry); -void *git_cache_get(git_cache *cache, const git_oid *oid); - - -GIT_INLINE(int) git_cached_obj_compare(git_cached_obj *obj, const git_oid *oid) -{ - return git_oid_cmp(&obj->oid, oid); -} - -GIT_INLINE(void) git_cached_obj_incref(git_cached_obj *obj) -{ - git_atomic_inc(&obj->refcount); -} - -GIT_INLINE(void) git_cached_obj_decref(git_cached_obj *obj, git_cached_obj_freeptr free_obj) -{ - if (git_atomic_dec(&obj->refcount) == 0) - free_obj(obj); -} - - - -#endif diff --git a/vendor/libgit2/src/cc-compat.h b/vendor/libgit2/src/cc-compat.h deleted file mode 100644 index cf6cccf12..000000000 --- a/vendor/libgit2/src/cc-compat.h +++ /dev/null @@ -1,73 +0,0 @@ -/* - * cc-compat.h - C compiler compat macros for internal use - */ -#ifndef INCLUDE_compat_h__ -#define INCLUDE_compat_h__ - -/* - * See if our compiler is known to support flexible array members. - */ -#ifndef GIT_FLEX_ARRAY -# if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) -# define GIT_FLEX_ARRAY /* empty */ -# elif defined(__GNUC__) -# if (__GNUC__ >= 3) -# define GIT_FLEX_ARRAY /* empty */ -# else -# define GIT_FLEX_ARRAY 0 /* older GNU extension */ -# endif -# endif - -/* Default to safer but a bit wasteful traditional style */ -# ifndef GIT_FLEX_ARRAY -# define GIT_FLEX_ARRAY 1 -# endif -#endif - -#ifdef __GNUC__ -# define GIT_TYPEOF(x) (__typeof__(x)) -#else -# define GIT_TYPEOF(x) -#endif - -#ifdef __cplusplus -# define GIT_UNUSED(x) -#else -# ifdef __GNUC__ -# define GIT_UNUSED(x) x __attribute__ ((__unused__)) -# else -# define GIT_UNUSED(x) x -# endif -#endif - -#if defined(_MSC_VER) -#define GIT_UNUSED_ARG(x) ((void)(x)); /* note trailing ; */ -#else -#define GIT_UNUSED_ARG(x) -#endif - -/* - * Does our compiler/platform support the C99 and - * header files. (C99 requires that - * includes ). - */ -#if !defined(_MSC_VER) -# define GIT_HAVE_INTTYPES_H 1 -#endif - -/* Define the printf format specifer to use for size_t output */ -#if defined(_MSC_VER) || defined(__MINGW32__) -# define PRIuZ "Iu" -#else -# define PRIuZ "zu" -#endif - -/* Micosoft Visual C/C++ */ -#if defined(_MSC_VER) -/* disable "deprecated function" warnings */ -# pragma warning ( disable : 4996 ) -/* disable "conditional expression is constant" level 4 warnings */ -# pragma warning ( disable : 4127 ) -#endif - -#endif /* INCLUDE_compat_h__ */ diff --git a/vendor/libgit2/src/commit.c b/vendor/libgit2/src/commit.c deleted file mode 100644 index dc9e5362a..000000000 --- a/vendor/libgit2/src/commit.c +++ /dev/null @@ -1,300 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "git2/common.h" -#include "git2/object.h" -#include "git2/repository.h" -#include "git2/signature.h" - -#include "common.h" -#include "odb.h" -#include "commit.h" -#include "signature.h" - -#include - -#define COMMIT_BASIC_PARSE 0x0 -#define COMMIT_FULL_PARSE 0x1 - -#define COMMIT_PRINT(commit) {\ - char oid[41]; oid[40] = 0;\ - git_oid_fmt(oid, &commit->object.id);\ - printf("Oid: %s | In degree: %d | Time: %u\n", oid, commit->in_degree, commit->commit_time);\ -} - -static void clear_parents(git_commit *commit) -{ - unsigned int i; - - for (i = 0; i < commit->parent_oids.length; ++i) { - git_oid *parent = git_vector_get(&commit->parent_oids, i); - free(parent); - } - - git_vector_clear(&commit->parent_oids); -} - -void git_commit__free(git_commit *commit) -{ - clear_parents(commit); - git_vector_free(&commit->parent_oids); - - git_signature_free(commit->author); - git_signature_free(commit->committer); - - free(commit->message); - free(commit->message_encoding); - free(commit); -} - -const git_oid *git_commit_id(git_commit *c) -{ - return git_object_id((git_object *)c); -} - -int git_commit_create_v( - git_oid *oid, - git_repository *repo, - const char *update_ref, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_tree *tree, - int parent_count, - ...) -{ - va_list ap; - int i, error; - const git_commit **parents; - - parents = git__malloc(parent_count * sizeof(git_commit *)); - - va_start(ap, parent_count); - for (i = 0; i < parent_count; ++i) - parents[i] = va_arg(ap, const git_commit *); - va_end(ap); - - error = git_commit_create( - oid, repo, update_ref, author, committer, - message_encoding, message, - tree, parent_count, parents); - - free((void *)parents); - - return error; -} - -int git_commit_create( - git_oid *oid, - git_repository *repo, - const char *update_ref, - const git_signature *author, - const git_signature *committer, - const char *message_encoding, - const char *message, - const git_tree *tree, - int parent_count, - const git_commit *parents[]) -{ - git_buf commit = GIT_BUF_INIT; - int error, i; - - if (git_object_owner((const git_object *)tree) != repo) - return git__throw(GIT_EINVALIDARGS, "The given tree does not belong to this repository"); - - git_oid__writebuf(&commit, "tree ", git_object_id((const git_object *)tree)); - - for (i = 0; i < parent_count; ++i) { - if (git_object_owner((const git_object *)parents[i]) != repo) { - error = git__throw(GIT_EINVALIDARGS, "The given parent does not belong to this repository"); - goto cleanup; - } - - git_oid__writebuf(&commit, "parent ", git_object_id((const git_object *)parents[i])); - } - - git_signature__writebuf(&commit, "author ", author); - git_signature__writebuf(&commit, "committer ", committer); - - if (message_encoding != NULL) - git_buf_printf(&commit, "encoding %s\n", message_encoding); - - git_buf_putc(&commit, '\n'); - git_buf_puts(&commit, message); - - if (git_buf_oom(&commit)) { - error = git__throw(GIT_ENOMEM, "Not enough memory to build the commit data"); - goto cleanup; - } - - error = git_odb_write(oid, git_repository_database(repo), commit.ptr, commit.size, GIT_OBJ_COMMIT); - git_buf_free(&commit); - - if (error == GIT_SUCCESS && update_ref != NULL) { - git_reference *head; - - error = git_reference_lookup(&head, repo, update_ref); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to create commit"); - - error = git_reference_resolve(&head, head); - if (error < GIT_SUCCESS) { - if (error != GIT_ENOTFOUND) - return git__rethrow(error, "Failed to create commit"); - /* - * The target of the reference was not found. This can happen - * just after a repository has been initialized (the master - * branch doesn't exist yet, as it doesn't have anything to - * point to) or after an orphan checkout, so if the target - * branch doesn't exist yet, create it and return. - */ - return git_reference_create_oid(&head, repo, git_reference_target(head), oid, 1); - } - - error = git_reference_set_oid(head, oid); - } - - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to create commit"); - - return GIT_SUCCESS; - -cleanup: - git_buf_free(&commit); - return error; -} - -int commit_parse_buffer(git_commit *commit, const void *data, size_t len) -{ - const char *buffer = data; - const char *buffer_end = (const char *)data + len; - - git_oid parent_oid; - int error; - - git_vector_init(&commit->parent_oids, 4, NULL); - - if ((error = git_oid__parse(&commit->tree_oid, &buffer, buffer_end, "tree ")) < GIT_SUCCESS) - return git__rethrow(error, "Failed to parse buffer"); - - /* - * TODO: commit grafts! - */ - - while (git_oid__parse(&parent_oid, &buffer, buffer_end, "parent ") == GIT_SUCCESS) { - git_oid *new_oid; - - new_oid = git__malloc(sizeof(git_oid)); - git_oid_cpy(new_oid, &parent_oid); - - if (git_vector_insert(&commit->parent_oids, new_oid) < GIT_SUCCESS) - return GIT_ENOMEM; - } - - commit->author = git__malloc(sizeof(git_signature)); - if ((error = git_signature__parse(commit->author, &buffer, buffer_end, "author ", '\n')) < GIT_SUCCESS) - return git__rethrow(error, "Failed to parse commit"); - - /* Always parse the committer; we need the commit time */ - commit->committer = git__malloc(sizeof(git_signature)); - if ((error = git_signature__parse(commit->committer, &buffer, buffer_end, "committer ", '\n')) < GIT_SUCCESS) - return git__rethrow(error, "Failed to parse commit"); - - if (git__prefixcmp(buffer, "encoding ") == 0) { - const char *encoding_end; - buffer += strlen("encoding "); - - encoding_end = buffer; - while (encoding_end < buffer_end && *encoding_end != '\n') - encoding_end++; - - commit->message_encoding = git__strndup(buffer, encoding_end - buffer); - if (!commit->message_encoding) - return GIT_ENOMEM; - - buffer = encoding_end; - } - - /* parse commit message */ - while (buffer < buffer_end && *buffer == '\n') - buffer++; - - if (buffer < buffer_end) { - commit->message = git__strndup(buffer, buffer_end - buffer); - if (!commit->message) - return GIT_ENOMEM; - } - - return GIT_SUCCESS; -} - -int git_commit__parse(git_commit *commit, git_odb_object *obj) -{ - assert(commit); - return commit_parse_buffer(commit, obj->raw.data, obj->raw.len); -} - -#define GIT_COMMIT_GETTER(_rvalue, _name, _return) \ - _rvalue git_commit_##_name(git_commit *commit) \ - {\ - assert(commit); \ - return _return; \ - } - -GIT_COMMIT_GETTER(const git_signature *, author, commit->author) -GIT_COMMIT_GETTER(const git_signature *, committer, commit->committer) -GIT_COMMIT_GETTER(const char *, message, commit->message) -GIT_COMMIT_GETTER(const char *, message_encoding, commit->message_encoding) -GIT_COMMIT_GETTER(git_time_t, time, commit->committer->when.time) -GIT_COMMIT_GETTER(int, time_offset, commit->committer->when.offset) -GIT_COMMIT_GETTER(unsigned int, parentcount, commit->parent_oids.length) -GIT_COMMIT_GETTER(const git_oid *, tree_oid, &commit->tree_oid); - - -int git_commit_tree(git_tree **tree_out, git_commit *commit) -{ - assert(commit); - return git_tree_lookup(tree_out, commit->object.repo, &commit->tree_oid); -} - -int git_commit_parent(git_commit **parent, git_commit *commit, unsigned int n) -{ - git_oid *parent_oid; - assert(commit); - - parent_oid = git_vector_get(&commit->parent_oids, n); - if (parent_oid == NULL) - return git__throw(GIT_ENOTFOUND, "Parent %u does not exist", n); - - return git_commit_lookup(parent, commit->object.repo, parent_oid); -} - -const git_oid *git_commit_parent_oid(git_commit *commit, unsigned int n) -{ - assert(commit); - - return git_vector_get(&commit->parent_oids, n); -} diff --git a/vendor/libgit2/src/commit.h b/vendor/libgit2/src/commit.h deleted file mode 100644 index ff2f28248..000000000 --- a/vendor/libgit2/src/commit.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef INCLUDE_commit_h__ -#define INCLUDE_commit_h__ - -#include "git2/commit.h" -#include "tree.h" -#include "repository.h" -#include "vector.h" - -#include - -struct git_commit { - git_object object; - - git_vector parent_oids; - git_oid tree_oid; - - git_signature *author; - git_signature *committer; - - char *message_encoding; - char *message; -}; - -void git_commit__free(git_commit *c); -int git_commit__parse(git_commit *commit, git_odb_object *obj); - -#endif diff --git a/vendor/libgit2/src/common.h b/vendor/libgit2/src/common.h deleted file mode 100644 index 5986a6568..000000000 --- a/vendor/libgit2/src/common.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef INCLUDE_common_h__ -#define INCLUDE_common_h__ - -#include "git2/common.h" -#include "git2/thread-utils.h" -#include "cc-compat.h" - -#ifdef GIT_HAVE_INTTYPES_H -# include -#endif -#include -#include -#include -#include -#include -#include - -#include -#include - -#ifdef GIT_WIN32 - -# include -# include -# include -# include "win32/msvc-compat.h" -# include "win32/mingw-compat.h" -# ifdef GIT_THREADS -# include "win32/pthread.h" -#endif - -# define snprintf _snprintf - -typedef SSIZE_T ssize_t; - -#else -# include - -# ifdef GIT_THREADS -# include -# endif -#endif - -#include "git2/types.h" -#include "git2/errors.h" -#include "thread-utils.h" -#include "bswap.h" - -extern void git___throw(const char *, ...) GIT_FORMAT_PRINTF(1, 2); -#define git__throw(error, ...) \ - (git___throw(__VA_ARGS__), error) - -extern void git___rethrow(const char *, ...) GIT_FORMAT_PRINTF(1, 2); -#define git__rethrow(error, ...) \ - (git___rethrow(__VA_ARGS__), error) - -#include "util.h" - -#endif /* INCLUDE_common_h__ */ diff --git a/vendor/libgit2/src/config.c b/vendor/libgit2/src/config.c deleted file mode 100644 index 771250731..000000000 --- a/vendor/libgit2/src/config.c +++ /dev/null @@ -1,354 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "fileops.h" -#include "hashtable.h" -#include "config.h" -#include "git2/config.h" -#include "vector.h" - -#include - -typedef struct { - git_config_file *file; - int priority; -} file_internal; - -void git_config_free(git_config *cfg) -{ - unsigned int i; - git_config_file *file; - file_internal *internal; - - for(i = 0; i < cfg->files.length; ++i){ - internal = git_vector_get(&cfg->files, i); - file = internal->file; - file->free(file); - free(internal); - } - - git_vector_free(&cfg->files); - free(cfg); -} - -static int config_backend_cmp(const void *a, const void *b) -{ - const file_internal *bk_a = (const file_internal *)(a); - const file_internal *bk_b = (const file_internal *)(b); - - return bk_b->priority - bk_a->priority; -} - -int git_config_new(git_config **out) -{ - git_config *cfg; - - cfg = git__malloc(sizeof(git_config)); - if (cfg == NULL) - return GIT_ENOMEM; - - memset(cfg, 0x0, sizeof(git_config)); - - if (git_vector_init(&cfg->files, 3, config_backend_cmp) < 0) { - free(cfg); - return GIT_ENOMEM; - } - - *out = cfg; - - return GIT_SUCCESS; -} - -int git_config_add_file_ondisk(git_config *cfg, const char *path, int priority) -{ - git_config_file *file = NULL; - int error; - - error = git_config_file__ondisk(&file, path); - if (error < GIT_SUCCESS) - return error; - - error = git_config_add_file(cfg, file, priority); - if (error < GIT_SUCCESS) { - /* - * free manually; the file is not owned by the config - * instance yet and will not be freed on cleanup - */ - file->free(file); - return error; - } - - return GIT_SUCCESS; -} - -int git_config_open_ondisk(git_config **cfg, const char *path) -{ - int error; - - error = git_config_new(cfg); - if (error < GIT_SUCCESS) - return error; - - error = git_config_add_file_ondisk(*cfg, path, 1); - if (error < GIT_SUCCESS) - git_config_free(*cfg); - - return error; -} - -int git_config_add_file(git_config *cfg, git_config_file *file, int priority) -{ - file_internal *internal; - int error; - - assert(cfg && file); - - if ((error = file->open(file)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to open config file"); - - internal = git__malloc(sizeof(file_internal)); - if (internal == NULL) - return GIT_ENOMEM; - - internal->file = file; - internal->priority = priority; - - if (git_vector_insert(&cfg->files, internal) < 0) { - free(internal); - return GIT_ENOMEM; - } - - git_vector_sort(&cfg->files); - internal->file->cfg = cfg; - - return GIT_SUCCESS; -} - -/* - * Loop over all the variables - */ - -int git_config_foreach(git_config *cfg, int (*fn)(const char *, const char *, void *), void *data) -{ - int ret = GIT_SUCCESS; - unsigned int i; - file_internal *internal; - git_config_file *file; - - for(i = 0; i < cfg->files.length && ret == 0; ++i) { - internal = git_vector_get(&cfg->files, i); - file = internal->file; - ret = file->foreach(file, fn, data); - } - - return ret; -} - -int git_config_delete(git_config *cfg, const char *name) -{ - return git_config_set_string(cfg, name, NULL); -} - -/************** - * Setters - **************/ - -int git_config_set_long(git_config *cfg, const char *name, long int value) -{ - char str_value[32]; /* All numbers should fit in here */ - p_snprintf(str_value, sizeof(str_value), "%ld", value); - return git_config_set_string(cfg, name, str_value); -} - -int git_config_set_int(git_config *cfg, const char *name, int value) -{ - return git_config_set_long(cfg, name, value); -} - -int git_config_set_bool(git_config *cfg, const char *name, int value) -{ - return git_config_set_string(cfg, name, value ? "true" : "false"); -} - -int git_config_set_string(git_config *cfg, const char *name, const char *value) -{ - file_internal *internal; - git_config_file *file; - - if (cfg->files.length == 0) - return git__throw(GIT_EINVALIDARGS, "Cannot set variable value; no files open in the `git_config` instance"); - - internal = git_vector_get(&cfg->files, 0); - file = internal->file; - - return file->set(file, name, value); -} - -/*********** - * Getters - ***********/ - -int git_config_get_long(git_config *cfg, const char *name, long int *out) -{ - const char *value, *num_end; - int ret; - long int num; - - ret = git_config_get_string(cfg, name, &value); - if (ret < GIT_SUCCESS) - return git__rethrow(ret, "Failed to get value for %s", name); - - ret = git__strtol32(&num, value, &num_end, 0); - if (ret < GIT_SUCCESS) - return git__rethrow(ret, "Failed to get value for %s", name); - - switch (*num_end) { - case '\0': - break; - case 'k': - case 'K': - num *= 1024; - break; - case 'm': - case 'M': - num *= 1024 * 1024; - break; - case 'g': - case 'G': - num *= 1024 * 1024 * 1024; - break; - default: - return git__throw(GIT_EINVALIDTYPE, "Failed to get value for %s. Value is of invalid type", name); - } - - *out = num; - - return GIT_SUCCESS; -} - -int git_config_get_int(git_config *cfg, const char *name, int *out) -{ - long int tmp; - int ret; - - ret = git_config_get_long(cfg, name, &tmp); - - *out = (int) tmp; - - return ret; -} - -int git_config_get_bool(git_config *cfg, const char *name, int *out) -{ - const char *value; - int error = GIT_SUCCESS; - - error = git_config_get_string(cfg, name, &value); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to get value for %s", name); - - /* A missing value means true */ - if (value == NULL) { - *out = 1; - return GIT_SUCCESS; - } - - if (!strcasecmp(value, "true") || - !strcasecmp(value, "yes") || - !strcasecmp(value, "on")) { - *out = 1; - return GIT_SUCCESS; - } - if (!strcasecmp(value, "false") || - !strcasecmp(value, "no") || - !strcasecmp(value, "off")) { - *out = 0; - return GIT_SUCCESS; - } - - /* Try to parse it as an integer */ - error = git_config_get_int(cfg, name, out); - if (error == GIT_SUCCESS) - *out = !!(*out); - - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to get value for %s", name); - return error; -} - -int git_config_get_string(git_config *cfg, const char *name, const char **out) -{ - file_internal *internal; - git_config_file *file; - int error = GIT_ENOTFOUND; - unsigned int i; - - if (cfg->files.length == 0) - return git__throw(GIT_EINVALIDARGS, "Cannot get variable value; no files open in the `git_config` instance"); - - for (i = 0; i < cfg->files.length; ++i) { - internal = git_vector_get(&cfg->files, i); - file = internal->file; - if ((error = file->get(file, name, out)) == GIT_SUCCESS) - return GIT_SUCCESS; - } - - return git__throw(error, "Config value '%s' not found", name); -} - -int git_config_find_global(char *global_config_path) -{ - const char *home; - - home = getenv("HOME"); - -#ifdef GIT_WIN32 - if (home == NULL) - home = getenv("USERPROFILE"); -#endif - - if (home == NULL) - return git__throw(GIT_EOSERR, "Failed to open global config file. Cannot locate the user's home directory"); - - git_path_join(global_config_path, home, GIT_CONFIG_FILENAME); - - if (git_futils_exists(global_config_path) < GIT_SUCCESS) - return git__throw(GIT_EOSERR, "Failed to open global config file. The file does not exist"); - - return GIT_SUCCESS; -} - -int git_config_open_global(git_config **out) -{ - int error; - char global_path[GIT_PATH_MAX]; - - if ((error = git_config_find_global(global_path)) < GIT_SUCCESS) - return error; - - return git_config_open_ondisk(out, global_path); -} - diff --git a/vendor/libgit2/src/config.h b/vendor/libgit2/src/config.h deleted file mode 100644 index e2f301bf1..000000000 --- a/vendor/libgit2/src/config.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef INCLUDE_config_h__ -#define INCLUDE_config_h__ - -#include "git2.h" -#include "git2/config.h" -#include "vector.h" -#include "repository.h" - -#define GIT_CONFIG_FILENAME ".gitconfig" -#define GIT_CONFIG_FILENAME_INREPO "config" - -struct git_config { - git_vector files; - git_repository *repo; -}; - -#endif diff --git a/vendor/libgit2/src/config_file.c b/vendor/libgit2/src/config_file.c deleted file mode 100644 index 520a806b5..000000000 --- a/vendor/libgit2/src/config_file.c +++ /dev/null @@ -1,1233 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "config.h" -#include "fileops.h" -#include "filebuf.h" -#include "git2/config.h" -#include "git2/types.h" - - -#include - -typedef struct cvar_t { - struct cvar_t *next; - char *section; - char *name; - char *value; -} cvar_t; - -typedef struct { - struct cvar_t *head; - struct cvar_t *tail; -} cvar_t_list; - -#define CVAR_LIST_HEAD(list) ((list)->head) - -#define CVAR_LIST_TAIL(list) ((list)->tail) - -#define CVAR_LIST_NEXT(var) ((var)->next) - -#define CVAR_LIST_EMPTY(list) ((list)->head == NULL) - -#define CVAR_LIST_APPEND(list, var) do {\ - if (CVAR_LIST_EMPTY(list)) {\ - CVAR_LIST_HEAD(list) = CVAR_LIST_TAIL(list) = var;\ - } else {\ - CVAR_LIST_NEXT(CVAR_LIST_TAIL(list)) = var;\ - CVAR_LIST_TAIL(list) = var;\ - }\ -} while(0) - -#define CVAR_LIST_REMOVE_HEAD(list) do {\ - CVAR_LIST_HEAD(list) = CVAR_LIST_NEXT(CVAR_LIST_HEAD(list));\ -} while(0) - -#define CVAR_LIST_REMOVE_AFTER(var) do {\ - CVAR_LIST_NEXT(var) = CVAR_LIST_NEXT(CVAR_LIST_NEXT(var));\ -} while(0) - -#define CVAR_LIST_FOREACH(list, iter)\ - for ((iter) = CVAR_LIST_HEAD(list);\ - (iter) != NULL;\ - (iter) = CVAR_LIST_NEXT(iter)) - -/* - * Inspired by the FreeBSD functions - */ -#define CVAR_LIST_FOREACH_SAFE(start, iter, tmp)\ - for ((iter) = CVAR_LIST_HEAD(vars);\ - (iter) && (((tmp) = CVAR_LIST_NEXT(iter) || 1));\ - (iter) = (tmp)) - -typedef struct { - git_config_file parent; - - cvar_t_list var_list; - - struct { - git_fbuffer buffer; - char *read_ptr; - int line_number; - int eof; - } reader; - - char *file_path; -} diskfile_backend; - -static int config_parse(diskfile_backend *cfg_file); -static int parse_variable(diskfile_backend *cfg, char **var_name, char **var_value); -static int config_write(diskfile_backend *cfg, cvar_t *var); - -static void cvar_free(cvar_t *var) -{ - if (var == NULL) - return; - - free(var->section); - free(var->name); - free(var->value); - free(var); -} - -static void cvar_list_free(cvar_t_list *list) -{ - cvar_t *cur; - - while (!CVAR_LIST_EMPTY(list)) { - cur = CVAR_LIST_HEAD(list); - CVAR_LIST_REMOVE_HEAD(list); - cvar_free(cur); - } -} - -/* - * Compare two strings according to the git section-subsection - * rules. The order of the strings is important because local is - * assumed to have the internal format (only the section name and with - * case information) and input the normalized one (only dots, no case - * information). - */ -static int cvar_match_section(const char *local, const char *input) -{ - char *first_dot; - char *local_sp = strchr(local, ' '); - int comparison_len; - - /* - * If the local section name doesn't contain a space, then we can - * just do a case-insensitive compare. - */ - if (local_sp == NULL) - return !strncasecmp(local, input, strlen(local)); - - /* - * From here onwards, there is a space diving the section and the - * subsection. Anything before the space in local is - * case-insensitive. - */ - if (strncasecmp(local, input, local_sp - local)) - return 0; - - /* - * We compare starting from the first character after the - * quotation marks, which is two characters beyond the space. For - * the input, we start one character beyond the dot. If the names - * have different lengths, then we can fail early, as we know they - * can't be the same. - * The length is given by the length between the quotation marks. - */ - - first_dot = strchr(input, '.'); - comparison_len = strlen(local_sp + 2) - 1; - - return !strncmp(local_sp + 2, first_dot + 1, comparison_len); -} - -static int cvar_match_name(const cvar_t *var, const char *str) -{ - const char *name_start; - - if (!cvar_match_section(var->section, str)) { - return 0; - } - /* Early exit if the lengths are different */ - name_start = strrchr(str, '.') + 1; - if (strlen(var->name) != strlen(name_start)) - return 0; - - return !strcasecmp(var->name, name_start); -} - -static cvar_t *cvar_list_find(cvar_t_list *list, const char *name) -{ - cvar_t *iter; - - CVAR_LIST_FOREACH (list, iter) { - if (cvar_match_name(iter, name)) - return iter; - } - - return NULL; -} - -static int cvar_normalize_name(cvar_t *var, char **output) -{ - char *section_sp = strchr(var->section, ' '); - char *quote, *name; - int len, ret; - - /* - * The final string is going to be at most one char longer than - * the input - */ - len = strlen(var->section) + strlen(var->name) + 1; - name = git__malloc(len + 1); - if (name == NULL) - return GIT_ENOMEM; - - /* If there aren't any spaces in the section, it's easy */ - if (section_sp == NULL) { - ret = p_snprintf(name, len + 1, "%s.%s", var->section, var->name); - if (ret < 0) { - free(name); - return git__throw(GIT_EOSERR, "Failed to normalize name. OS err: %s", strerror(errno)); - } - - *output = name; - return GIT_SUCCESS; - } - - /* - * If there are spaces, we replace the space by a dot, move - * section name so it overwrites the first quotation mark and - * replace the last quotation mark by a dot. We then append the - * variable name. - */ - strcpy(name, var->section); - section_sp = strchr(name, ' '); - *section_sp = '.'; - /* Remove first quote */ - quote = strchr(name, '"'); - memmove(quote, quote+1, strlen(quote+1)); - /* Remove second quote */ - quote = strchr(name, '"'); - *quote = '.'; - strcpy(quote+1, var->name); - - *output = name; - return GIT_SUCCESS; -} - -static char *interiorize_section(const char *orig) -{ - char *dot, *last_dot, *section, *ret; - int len; - - dot = strchr(orig, '.'); - last_dot = strrchr(orig, '.'); - len = last_dot - orig; - - /* No subsection, this is easy */ - if (last_dot == dot) - return git__strndup(orig, dot - orig); - - section = git__malloc(len + 4); - if (section == NULL) - return NULL; - - memset(section, 0x0, len + 4); - ret = section; - len = dot - orig; - memcpy(section, orig, len); - section += len; - len = strlen(" \""); - memcpy(section, " \"", len); - section += len; - len = last_dot - dot - 1; - memcpy(section, dot + 1, len); - section += len; - *section = '"'; - - return ret; -} - -static int config_open(git_config_file *cfg) -{ - int error; - diskfile_backend *b = (diskfile_backend *)cfg; - - error = git_futils_readbuffer(&b->reader.buffer, b->file_path); - if(error < GIT_SUCCESS) - goto cleanup; - - error = config_parse(b); - if (error < GIT_SUCCESS) - goto cleanup; - - git_futils_freebuffer(&b->reader.buffer); - - return error; - - cleanup: - cvar_list_free(&b->var_list); - git_futils_freebuffer(&b->reader.buffer); - - return git__rethrow(error, "Failed to open config"); -} - -static void backend_free(git_config_file *_backend) -{ - diskfile_backend *backend = (diskfile_backend *)_backend; - - if (backend == NULL) - return; - - free(backend->file_path); - cvar_list_free(&backend->var_list); - - free(backend); -} - -static int file_foreach(git_config_file *backend, int (*fn)(const char *, const char *, void *), void *data) -{ - int ret = GIT_SUCCESS; - cvar_t *var; - diskfile_backend *b = (diskfile_backend *)backend; - - CVAR_LIST_FOREACH(&b->var_list, var) { - char *normalized = NULL; - - ret = cvar_normalize_name(var, &normalized); - if (ret < GIT_SUCCESS) - return ret; - - ret = fn(normalized, var->value, data); - free(normalized); - if (ret) - break; - } - - return ret; -} - -static int config_set(git_config_file *cfg, const char *name, const char *value) -{ - cvar_t *var = NULL; - cvar_t *existing = NULL; - int error = GIT_SUCCESS; - const char *last_dot; - diskfile_backend *b = (diskfile_backend *)cfg; - - /* - * If it already exists, we just need to update its value. - */ - existing = cvar_list_find(&b->var_list, name); - if (existing != NULL) { - char *tmp = value ? git__strdup(value) : NULL; - if (tmp == NULL && value != NULL) - return GIT_ENOMEM; - - free(existing->value); - existing->value = tmp; - - return config_write(b, existing); - } - - /* - * Otherwise, create it and stick it at the end of the queue. If - * value is NULL, we return an error, because you can't delete a - * variable that doesn't exist. - */ - - if (value == NULL) - return git__throw(GIT_ENOTFOUND, "Can't delete non-exitent variable"); - - last_dot = strrchr(name, '.'); - if (last_dot == NULL) { - return git__throw(GIT_EINVALIDTYPE, "Variables without section aren't allowed"); - } - - var = git__malloc(sizeof(cvar_t)); - if (var == NULL) - return GIT_ENOMEM; - - memset(var, 0x0, sizeof(cvar_t)); - - var->section = interiorize_section(name); - if (var->section == NULL) { - error = GIT_ENOMEM; - goto out; - } - - var->name = git__strdup(last_dot + 1); - if (var->name == NULL) { - error = GIT_ENOMEM; - goto out; - } - - var->value = value ? git__strdup(value) : NULL; - if (var->value == NULL && value != NULL) { - error = GIT_ENOMEM; - goto out; - } - - CVAR_LIST_APPEND(&b->var_list, var); - error = config_write(b, var); - - out: - if (error < GIT_SUCCESS) - cvar_free(var); - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to set config value"); -} - -/* - * Internal function that actually gets the value in string form - */ -static int config_get(git_config_file *cfg, const char *name, const char **out) -{ - cvar_t *var; - int error = GIT_SUCCESS; - diskfile_backend *b = (diskfile_backend *)cfg; - - var = cvar_list_find(&b->var_list, name); - - if (var == NULL) - return git__throw(GIT_ENOTFOUND, "Variable '%s' not found", name); - - *out = var->value; - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to get config value for %s", name); -} - -int git_config_file__ondisk(git_config_file **out, const char *path) -{ - diskfile_backend *backend; - - backend = git__malloc(sizeof(diskfile_backend)); - if (backend == NULL) - return GIT_ENOMEM; - - memset(backend, 0x0, sizeof(diskfile_backend)); - - backend->file_path = git__strdup(path); - if (backend->file_path == NULL) { - free(backend); - return GIT_ENOMEM; - } - - backend->parent.open = config_open; - backend->parent.get = config_get; - backend->parent.set = config_set; - backend->parent.foreach = file_foreach; - backend->parent.free = backend_free; - - *out = (git_config_file *)backend; - - return GIT_SUCCESS; -} - -static int cfg_getchar_raw(diskfile_backend *cfg) -{ - int c; - - c = *cfg->reader.read_ptr++; - - /* - Win 32 line breaks: if we find a \r\n sequence, - return only the \n as a newline - */ - if (c == '\r' && *cfg->reader.read_ptr == '\n') { - cfg->reader.read_ptr++; - c = '\n'; - } - - if (c == '\n') - cfg->reader.line_number++; - - if (c == 0) { - cfg->reader.eof = 1; - c = '\n'; - } - - return c; -} - -#define SKIP_WHITESPACE (1 << 1) -#define SKIP_COMMENTS (1 << 2) - -static int cfg_getchar(diskfile_backend *cfg_file, int flags) -{ - const int skip_whitespace = (flags & SKIP_WHITESPACE); - const int skip_comments = (flags & SKIP_COMMENTS); - int c; - - assert(cfg_file->reader.read_ptr); - - do c = cfg_getchar_raw(cfg_file); - while (skip_whitespace && isspace(c)); - - if (skip_comments && (c == '#' || c == ';')) { - do c = cfg_getchar_raw(cfg_file); - while (c != '\n'); - } - - return c; -} - -/* - * Read the next char, but don't move the reading pointer. - */ -static int cfg_peek(diskfile_backend *cfg, int flags) -{ - void *old_read_ptr; - int old_lineno, old_eof; - int ret; - - assert(cfg->reader.read_ptr); - - old_read_ptr = cfg->reader.read_ptr; - old_lineno = cfg->reader.line_number; - old_eof = cfg->reader.eof; - - ret = cfg_getchar(cfg, flags); - - cfg->reader.read_ptr = old_read_ptr; - cfg->reader.line_number = old_lineno; - cfg->reader.eof = old_eof; - - return ret; -} - -/* - * Read and consume a line, returning it in newly-allocated memory. - */ -static char *cfg_readline(diskfile_backend *cfg) -{ - char *line = NULL; - char *line_src, *line_end; - int line_len; - - line_src = cfg->reader.read_ptr; - - /* Skip empty empty lines */ - while (isspace(*line_src)) - ++line_src; - - line_end = strchr(line_src, '\n'); - - /* no newline at EOF */ - if (line_end == NULL) - line_end = strchr(line_src, 0); - - line_len = line_end - line_src; - - line = git__malloc(line_len + 1); - if (line == NULL) - return NULL; - - memcpy(line, line_src, line_len); - - line[line_len] = '\0'; - - while (--line_len >= 0 && isspace(line[line_len])) - line[line_len] = '\0'; - - if (*line_end == '\n') - line_end++; - - if (*line_end == '\0') - cfg->reader.eof = 1; - - cfg->reader.line_number++; - cfg->reader.read_ptr = line_end; - - return line; -} - -/* - * Consume a line, without storing it anywhere - */ -void cfg_consume_line(diskfile_backend *cfg) -{ - char *line_start, *line_end; - - line_start = cfg->reader.read_ptr; - line_end = strchr(line_start, '\n'); - /* No newline at EOF */ - if(line_end == NULL){ - line_end = strchr(line_start, '\0'); - } - - if (*line_end == '\n') - line_end++; - - if (*line_end == '\0') - cfg->reader.eof = 1; - - cfg->reader.line_number++; - cfg->reader.read_ptr = line_end; -} - -GIT_INLINE(int) config_keychar(int c) -{ - return isalnum(c) || c == '-'; -} - -static int parse_section_header_ext(const char *line, const char *base_name, char **section_name) -{ - int buf_len, total_len, pos, rpos; - int c, ret; - char *subsection, *first_quote, *last_quote; - int error = GIT_SUCCESS; - int quote_marks; - /* - * base_name is what came before the space. We should be at the - * first quotation mark, except for now, line isn't being kept in - * sync so we only really use it to calculate the length. - */ - - first_quote = strchr(line, '"'); - last_quote = strrchr(line, '"'); - - if (last_quote - first_quote == 0) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse ext header. There is no final quotation mark"); - - buf_len = last_quote - first_quote + 2; - - subsection = git__malloc(buf_len + 2); - if (subsection == NULL) - return GIT_ENOMEM; - - pos = 0; - rpos = 0; - quote_marks = 0; - - line = first_quote; - c = line[rpos++]; - - /* - * At the end of each iteration, whatever is stored in c will be - * added to the string. In case of error, jump to out - */ - do { - if (quote_marks == 2) { - error = git__throw(GIT_EOBJCORRUPTED, "Falied to parse ext header. Text after closing quote"); - goto out; - - } - - switch (c) { - case '"': - ++quote_marks; - break; - case '\\': - c = line[rpos++]; - switch (c) { - case '"': - case '\\': - break; - default: - error = git__throw(GIT_EOBJCORRUPTED, "Failed to parse ext header. Unsupported escape char \\%c", c); - goto out; - } - break; - default: - break; - } - - subsection[pos++] = (char) c; - } while ((c = line[rpos++]) != ']'); - - subsection[pos] = '\0'; - - total_len = strlen(base_name) + strlen(subsection) + 2; - *section_name = git__malloc(total_len); - if (*section_name == NULL) { - error = GIT_ENOMEM; - goto out; - } - - ret = p_snprintf(*section_name, total_len, "%s %s", base_name, subsection); - if (ret < 0) { - error = git__throw(GIT_EOSERR, "Failed to parse ext header. OS error: %s", strerror(errno)); - goto out; - } - - git__strntolower(*section_name, strchr(*section_name, ' ') - *section_name); - - out: - free(subsection); - - return error; -} - -static int parse_section_header(diskfile_backend *cfg, char **section_out) -{ - char *name, *name_end; - int name_length, c, pos; - int error = GIT_SUCCESS; - char *line; - - line = cfg_readline(cfg); - if (line == NULL) - return GIT_ENOMEM; - - /* find the end of the variable's name */ - name_end = strchr(line, ']'); - if (name_end == NULL) { - free(line); - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse header. Can't find header name end"); - } - - name = (char *)git__malloc((size_t)(name_end - line) + 1); - if (name == NULL) { - free(line); - return GIT_ENOMEM; - } - - name_length = 0; - pos = 0; - - /* Make sure we were given a section header */ - c = line[pos++]; - if (c != '[') { - error = git__throw(GIT_ERROR, "Failed to parse header. Didn't get section header. This is a bug"); - goto error; - } - - c = line[pos++]; - - do { - if (isspace(c)){ - name[name_length] = '\0'; - error = parse_section_header_ext(line, name, section_out); - free(line); - free(name); - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to parse header"); - } - - if (!config_keychar(c) && c != '.') { - error = git__throw(GIT_EOBJCORRUPTED, "Failed to parse header. Wrong format on header"); - goto error; - } - - name[name_length++] = (char) tolower(c); - - } while ((c = line[pos++]) != ']'); - - if (line[pos - 1] != ']') { - error = git__throw(GIT_EOBJCORRUPTED, "Failed to parse header. Config file ended unexpectedly"); - goto error; - } - - name[name_length] = 0; - free(line); - git__strtolower(name); - *section_out = name; - return GIT_SUCCESS; - -error: - free(line); - free(name); - return error; -} - -static int skip_bom(diskfile_backend *cfg) -{ - static const char *utf8_bom = "\xef\xbb\xbf"; - - if (memcmp(cfg->reader.read_ptr, utf8_bom, sizeof(utf8_bom)) == 0) - cfg->reader.read_ptr += sizeof(utf8_bom); - - /* TODO: the reference implementation does pretty stupid - shit with the BoM - */ - - return GIT_SUCCESS; -} - -/* - (* basic types *) - digit = "0".."9" - integer = digit { digit } - alphabet = "a".."z" + "A" .. "Z" - - section_char = alphabet | "." | "-" - extension_char = (* any character except newline *) - any_char = (* any character *) - variable_char = "alphabet" | "-" - - - (* actual grammar *) - config = { section } - - section = header { definition } - - header = "[" section [subsection | subsection_ext] "]" - - subsection = "." section - subsection_ext = "\"" extension "\"" - - section = section_char { section_char } - extension = extension_char { extension_char } - - definition = variable_name ["=" variable_value] "\n" - - variable_name = variable_char { variable_char } - variable_value = string | boolean | integer - - string = quoted_string | plain_string - quoted_string = "\"" plain_string "\"" - plain_string = { any_char } - - boolean = boolean_true | boolean_false - boolean_true = "yes" | "1" | "true" | "on" - boolean_false = "no" | "0" | "false" | "off" -*/ - -static void strip_comments(char *line) -{ - int quote_count = 0; - char *ptr; - - for (ptr = line; *ptr; ++ptr) { - if (ptr[0] == '"' && ptr > line && ptr[-1] != '\\') - quote_count++; - - if ((ptr[0] == ';' || ptr[0] == '#') && (quote_count % 2) == 0) { - ptr[0] = '\0'; - break; - } - } - - if (isspace(ptr[-1])) { - /* TODO skip whitespace */ - } -} - -static int config_parse(diskfile_backend *cfg_file) -{ - int error = GIT_SUCCESS, c; - char *current_section = NULL; - char *var_name; - char *var_value; - cvar_t *var; - - /* Initialize the reading position */ - cfg_file->reader.read_ptr = cfg_file->reader.buffer.data; - cfg_file->reader.eof = 0; - - /* If the file is empty, there's nothing for us to do */ - if (*cfg_file->reader.read_ptr == '\0') - return GIT_SUCCESS; - - skip_bom(cfg_file); - - while (error == GIT_SUCCESS && !cfg_file->reader.eof) { - - c = cfg_peek(cfg_file, SKIP_WHITESPACE); - - switch (c) { - case '\0': /* We've arrived at the end of the file */ - break; - - case '[': /* section header, new section begins */ - free(current_section); - current_section = NULL; - error = parse_section_header(cfg_file, ¤t_section); - break; - - case ';': - case '#': - cfg_consume_line(cfg_file); - break; - - default: /* assume variable declaration */ - error = parse_variable(cfg_file, &var_name, &var_value); - - if (error < GIT_SUCCESS) - break; - - var = malloc(sizeof(cvar_t)); - if (var == NULL) { - error = GIT_ENOMEM; - break; - } - - memset(var, 0x0, sizeof(cvar_t)); - - var->section = git__strdup(current_section); - if (var->section == NULL) { - error = GIT_ENOMEM; - free(var); - break; - } - - var->name = var_name; - var->value = var_value; - git__strtolower(var->name); - - CVAR_LIST_APPEND(&cfg_file->var_list, var); - - break; - } - } - - free(current_section); - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to parse config"); -} - -static int write_section(git_filebuf *file, cvar_t *var) -{ - int error; - - error = git_filebuf_printf(file, "[%s]\n", var->section); - if (error < GIT_SUCCESS) - return error; - - error = git_filebuf_printf(file, " %s = %s\n", var->name, var->value); - return error; -} - -/* - * This is pretty much the parsing, except we write out anything we don't have - */ -static int config_write(diskfile_backend *cfg, cvar_t *var) -{ - int error = GIT_SUCCESS, c; - int section_matches = 0, last_section_matched = 0; - char *current_section = NULL; - char *var_name, *var_value, *data_start; - git_filebuf file; - const char *pre_end = NULL, *post_start = NULL; - - /* We need to read in our own config file */ - error = git_futils_readbuffer(&cfg->reader.buffer, cfg->file_path); - if (error < GIT_SUCCESS) { - return git__rethrow(error, "Failed to read existing config file %s", cfg->file_path); - } - - /* Initialise the reading position */ - cfg->reader.read_ptr = cfg->reader.buffer.data; - cfg->reader.eof = 0; - data_start = cfg->reader.read_ptr; - - /* Lock the file */ - error = git_filebuf_open(&file, cfg->file_path, 0); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to lock config file"); - - skip_bom(cfg); - - while (error == GIT_SUCCESS && !cfg->reader.eof) { - c = cfg_peek(cfg, SKIP_WHITESPACE); - - switch (c) { - case '\0': /* We've arrived at the end of the file */ - break; - - case '[': /* section header, new section begins */ - /* - * We set both positions to the current one in case we - * need to add a variable to the end of a section. In that - * case, we want both variables to point just before the - * new section. If we actually want to replace it, the - * default case will take care of updating them. - */ - pre_end = post_start = cfg->reader.read_ptr; - if (current_section) - free(current_section); - error = parse_section_header(cfg, ¤t_section); - if (error < GIT_SUCCESS) - break; - - /* Keep track of when it stops matching */ - last_section_matched = section_matches; - section_matches = !strcmp(current_section, var->section); - break; - - case ';': - case '#': - cfg_consume_line(cfg); - break; - - default: - /* - * If the section doesn't match, but the last section did, - * it means we need to add a variable (so skip the line - * otherwise). If both the section and name match, we need - * to overwrite the variable (so skip the line - * otherwise). pre_end needs to be updated each time so we - * don't loose that information, but we only need to - * update post_start if we're going to use it in this - * iteration. - */ - if (!section_matches) { - if (!last_section_matched) { - cfg_consume_line(cfg); - break; - } - } else { - int cmp = -1; - - pre_end = cfg->reader.read_ptr; - if ((error = parse_variable(cfg, &var_name, &var_value)) == GIT_SUCCESS) - cmp = strcasecmp(var->name, var_name); - - free(var_name); - free(var_value); - - if (cmp != 0) - break; - - post_start = cfg->reader.read_ptr; - } - - /* - * We've found the variable we wanted to change, so - * write anything up to it - */ - error = git_filebuf_write(&file, data_start, pre_end - data_start); - if (error < GIT_SUCCESS) { - git__rethrow(error, "Failed to write the first part of the file"); - break; - } - - /* - * Then replace the variable. If the value is NULL, it - * means we want to delete it, so pretend everything went - * fine - */ - if (var->value == NULL) - error = GIT_SUCCESS; - else - error = git_filebuf_printf(&file, "\t%s = %s\n", var->name, var->value); - if (error < GIT_SUCCESS) { - git__rethrow(error, "Failed to overwrite the variable"); - break; - } - - /* And then the write out rest of the file */ - error = git_filebuf_write(&file, post_start, - cfg->reader.buffer.len - (post_start - data_start)); - - if (error < GIT_SUCCESS) { - git__rethrow(error, "Failed to write the rest of the file"); - break; - } - - goto cleanup; - } - } - - /* - * Being here can mean that - * - * 1) our section is the last one in the file and we're - * adding a variable - * - * 2) we didn't find a section for us so we need to create it - * ourselves. - * - * Either way we need to write out the whole file. - */ - - error = git_filebuf_write(&file, cfg->reader.buffer.data, cfg->reader.buffer.len); - if (error < GIT_SUCCESS) { - git__rethrow(error, "Failed to write original config content"); - goto cleanup; - } - - /* And now if we just need to add a variable */ - if (section_matches) { - error = git_filebuf_printf(&file, "\t%s = %s\n", var->name, var->value); - goto cleanup; - } - - /* Or maybe we need to write out a whole section */ - error = write_section(&file, var); - if (error < GIT_SUCCESS) - git__rethrow(error, "Failed to write new section"); - - cleanup: - free(current_section); - - if (error < GIT_SUCCESS) - git_filebuf_cleanup(&file); - else - error = git_filebuf_commit(&file); - - git_futils_freebuffer(&cfg->reader.buffer); - return error; -} - -static int is_multiline_var(const char *str) -{ - char *end = strrchr(str, '\0') - 1; - - while (isspace(*end)) - --end; - - return *end == '\\'; -} - -static int parse_multiline_variable(diskfile_backend *cfg, const char *first, char **out) -{ - char *line = NULL, *end; - int error = GIT_SUCCESS, len, ret; - char *buf; - - /* Check that the next line exists */ - line = cfg_readline(cfg); - if (line == NULL) - return GIT_ENOMEM; - - /* We've reached the end of the file, there is input missing */ - if (line[0] == '\0') { - error = git__throw(GIT_EOBJCORRUPTED, "Failed to parse multiline var. File ended unexpectedly"); - goto out; - } - - strip_comments(line); - - /* If it was just a comment, pretend it didn't exist */ - if (line[0] == '\0') { - error = parse_multiline_variable(cfg, first, out); - goto out; - } - - /* Find the continuation character '\' and strip the whitespace */ - end = strrchr(first, '\\'); - while (isspace(end[-1])) - --end; - - *end = '\0'; /* Terminate the string here */ - - len = strlen(first) + strlen(line) + 2; - buf = git__malloc(len); - if (buf == NULL) { - error = GIT_ENOMEM; - goto out; - } - - ret = p_snprintf(buf, len, "%s %s", first, line); - if (ret < 0) { - error = git__throw(GIT_EOSERR, "Failed to parse multiline var. Failed to put together two lines. OS err: %s", strerror(errno)); - free(buf); - goto out; - } - - /* - * If we need to continue reading the next line, pretend - * everything we've read up to now was in one line and call - * ourselves. - */ - if (is_multiline_var(buf)) { - char *final_val; - error = parse_multiline_variable(cfg, buf, &final_val); - free(buf); - buf = final_val; - } - - *out = buf; - - out: - free(line); - return error; -} - -static int parse_variable(diskfile_backend *cfg, char **var_name, char **var_value) -{ - char *tmp; - int error = GIT_SUCCESS; - const char *var_end = NULL; - const char *value_start = NULL; - char *line; - - line = cfg_readline(cfg); - if (line == NULL) - return GIT_ENOMEM; - - strip_comments(line); - - var_end = strchr(line, '='); - - if (var_end == NULL) - var_end = strchr(line, '\0'); - else - value_start = var_end + 1; - - if (isspace(var_end[-1])) { - do var_end--; - while (isspace(var_end[0])); - } - - tmp = git__strndup(line, var_end - line + 1); - if (tmp == NULL) { - error = GIT_ENOMEM; - goto out; - } - - *var_name = tmp; - - /* - * Now, let's try to parse the value - */ - if (value_start != NULL) { - - while (isspace(value_start[0])) - value_start++; - - if (value_start[0] == '\0') - goto out; - - if (is_multiline_var(value_start)) { - error = parse_multiline_variable(cfg, value_start, var_value); - if (error < GIT_SUCCESS) - free(*var_name); - goto out; - } - - tmp = strdup(value_start); - if (tmp == NULL) { - free(*var_name); - error = GIT_ENOMEM; - goto out; - } - - *var_value = tmp; - } else { - /* If there is no value, boolean true is assumed */ - *var_value = NULL; - } - - out: - free(line); - return error; -} diff --git a/vendor/libgit2/src/delta-apply.c b/vendor/libgit2/src/delta-apply.c deleted file mode 100644 index a6b711436..000000000 --- a/vendor/libgit2/src/delta-apply.c +++ /dev/null @@ -1,109 +0,0 @@ -#include "common.h" -#include "git2/odb.h" -#include "delta-apply.h" - -/* - * This file was heavily cribbed from BinaryDelta.java in JGit, which - * itself was heavily cribbed from patch-delta.c in the - * GIT project. The original delta patching code was written by - * Nicolas Pitre . - */ - -static int hdr_sz( - size_t *size, - const unsigned char **delta, - const unsigned char *end) -{ - const unsigned char *d = *delta; - size_t r = 0; - unsigned int c, shift = 0; - - do { - if (d == end) - return -1; - c = *d++; - r |= (c & 0x7f) << shift; - shift += 7; - } while (c & 0x80); - *delta = d; - *size = r; - return 0; -} - -int git__delta_apply( - git_rawobj *out, - const unsigned char *base, - size_t base_len, - const unsigned char *delta, - size_t delta_len) -{ - const unsigned char *delta_end = delta + delta_len; - size_t base_sz, res_sz; - unsigned char *res_dp; - - /* Check that the base size matches the data we were given; - * if not we would underflow while accessing data from the - * base object, resulting in data corruption or segfault. - */ - if ((hdr_sz(&base_sz, &delta, delta_end) < 0) || (base_sz != base_len)) - return git__throw(GIT_ERROR, "Failed to apply delta. Base size does not match given data"); - - if (hdr_sz(&res_sz, &delta, delta_end) < 0) - return git__throw(GIT_ERROR, "Failed to apply delta. Base size does not match given data"); - - if ((res_dp = git__malloc(res_sz + 1)) == NULL) - return GIT_ENOMEM; - res_dp[res_sz] = '\0'; - out->data = res_dp; - out->len = res_sz; - - while (delta < delta_end) { - unsigned char cmd = *delta++; - if (cmd & 0x80) { - /* cmd is a copy instruction; copy from the base. - */ - size_t off = 0, len = 0; - - if (cmd & 0x01) off = *delta++; - if (cmd & 0x02) off |= *delta++ << 8; - if (cmd & 0x04) off |= *delta++ << 16; - if (cmd & 0x08) off |= *delta++ << 24; - - if (cmd & 0x10) len = *delta++; - if (cmd & 0x20) len |= *delta++ << 8; - if (cmd & 0x40) len |= *delta++ << 16; - if (!len) len = 0x10000; - - if (base_len < off + len || res_sz < len) - goto fail; - memcpy(res_dp, base + off, len); - res_dp += len; - res_sz -= len; - - } else if (cmd) { - /* cmd is a literal insert instruction; copy from - * the delta stream itself. - */ - if (delta_end - delta < cmd || res_sz < cmd) - goto fail; - memcpy(res_dp, delta, cmd); - delta += cmd; - res_dp += cmd; - res_sz -= cmd; - - } else { - /* cmd == 0 is reserved for future encodings. - */ - goto fail; - } - } - - if (delta != delta_end || res_sz) - goto fail; - return GIT_SUCCESS; - -fail: - free(out->data); - out->data = NULL; - return git__throw(GIT_ERROR, "Failed to apply delta"); -} diff --git a/vendor/libgit2/src/delta-apply.h b/vendor/libgit2/src/delta-apply.h deleted file mode 100644 index 36c5cc60d..000000000 --- a/vendor/libgit2/src/delta-apply.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef INCLUDE_delta_apply_h__ -#define INCLUDE_delta_apply_h__ - -#include "odb.h" - -/** - * Apply a git binary delta to recover the original content. - * - * @param out the output buffer to receive the original data. - * Only out->data and out->len are populated, as this is - * the only information available in the delta. - * @param base the base to copy from during copy instructions. - * @param base_len number of bytes available at base. - * @param delta the delta to execute copy/insert instructions from. - * @param delta_len total number of bytes in the delta. - * @return - * - GIT_SUCCESS on a successful delta unpack. - * - GIT_ERROR if the delta is corrupt or doesn't match the base. - */ -extern int git__delta_apply( - git_rawobj *out, - const unsigned char *base, - size_t base_len, - const unsigned char *delta, - size_t delta_len); - -#endif diff --git a/vendor/libgit2/src/dir.h b/vendor/libgit2/src/dir.h deleted file mode 100644 index c01c3fae7..000000000 --- a/vendor/libgit2/src/dir.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef INCLUDE_dir_h__ -#define INCLUDE_dir_h__ - -#include "common.h" - -#ifndef GIT_WIN32 -# include -#endif - -#ifdef GIT_WIN32 - -struct git__dirent { - int d_ino; - char d_name[261]; -}; - -typedef struct { - HANDLE h; - WIN32_FIND_DATA f; - struct git__dirent entry; - char *dir; - int first; -} git__DIR; - -extern git__DIR *git__opendir(const char *); -extern struct git__dirent *git__readdir(git__DIR *); -extern void git__rewinddir(git__DIR *); -extern int git__closedir(git__DIR *); - -# ifndef GIT__WIN32_NO_WRAP_DIR -# define dirent git__dirent -# define DIR git__DIR -# define opendir git__opendir -# define readdir git__readdir -# define rewinddir git__rewinddir -# define closedir git__closedir -# endif - -#endif - -#endif /* INCLUDE_dir_h__ */ diff --git a/vendor/libgit2/src/errors.c b/vendor/libgit2/src/errors.c deleted file mode 100644 index 5031245de..000000000 --- a/vendor/libgit2/src/errors.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "common.h" -#include "git2/thread-utils.h" /* for GIT_TLS */ -#include "thread-utils.h" /* for GIT_TLS */ - -#include - -static GIT_TLS char g_last_error[1024]; - -static struct { - int num; - const char *str; -} error_codes[] = { - {GIT_ERROR, "Unspecified error"}, - {GIT_ENOTOID, "Input was not a properly formatted Git object id."}, - {GIT_ENOTFOUND, "Object does not exist in the scope searched."}, - {GIT_ENOMEM, "Not enough space available."}, - {GIT_EOSERR, "Consult the OS error information."}, - {GIT_EOBJTYPE, "The specified object is of invalid type"}, - {GIT_EOBJCORRUPTED, "The specified object has its data corrupted"}, - {GIT_ENOTAREPO, "The specified repository is invalid"}, - {GIT_EINVALIDTYPE, "The object or config variable type is invalid or doesn't match"}, - {GIT_EMISSINGOBJDATA, "The object cannot be written that because it's missing internal data"}, - {GIT_EPACKCORRUPTED, "The packfile for the ODB is corrupted"}, - {GIT_EFLOCKFAIL, "Failed to adquire or release a file lock"}, - {GIT_EZLIB, "The Z library failed to inflate/deflate an object's data"}, - {GIT_EBUSY, "The queried object is currently busy"}, - {GIT_EINVALIDPATH, "The path is invalid"}, - {GIT_EBAREINDEX, "The index file is not backed up by an existing repository"}, - {GIT_EINVALIDREFNAME, "The name of the reference is not valid"}, - {GIT_EREFCORRUPTED, "The specified reference has its data corrupted"}, - {GIT_ETOONESTEDSYMREF, "The specified symbolic reference is too deeply nested"}, - {GIT_EPACKEDREFSCORRUPTED, "The pack-refs file is either corrupted of its format is not currently supported"}, - {GIT_EINVALIDPATH, "The path is invalid" }, - {GIT_EREVWALKOVER, "The revision walker is empty; there are no more commits left to iterate"}, - {GIT_EINVALIDREFSTATE, "The state of the reference is not valid"}, - {GIT_ENOTIMPLEMENTED, "This feature has not been implemented yet"}, - {GIT_EEXISTS, "A reference with this name already exists"}, - {GIT_EOVERFLOW, "The given integer literal is too large to be parsed"}, - {GIT_ENOTNUM, "The given literal is not a valid number"}, - {GIT_EAMBIGUOUSOIDPREFIX, "The given oid prefix is ambiguous"}, -}; - -const char *git_strerror(int num) -{ - size_t i; - - if (num == GIT_EOSERR) - return strerror(errno); - for (i = 0; i < ARRAY_SIZE(error_codes); i++) - if (num == error_codes[i].num) - return error_codes[i].str; - - return "Unknown error"; -} - -void git___rethrow(const char *msg, ...) -{ - char new_error[1024]; - char *old_error = NULL; - - va_list va; - - va_start(va, msg); - vsnprintf(new_error, sizeof(new_error), msg, va); - va_end(va); - - old_error = strdup(g_last_error); - snprintf(g_last_error, sizeof(g_last_error), "%s \n - %s", new_error, old_error); - free(old_error); -} - -void git___throw(const char *msg, ...) -{ - va_list va; - - va_start(va, msg); - vsnprintf(g_last_error, sizeof(g_last_error), msg, va); - va_end(va); -} - -const char *git_lasterror(void) -{ - if (!g_last_error[0]) - return NULL; - - return g_last_error; -} - -void git_clearerror(void) -{ - g_last_error[0] = '\0'; -} diff --git a/vendor/libgit2/src/fetch.c b/vendor/libgit2/src/fetch.c deleted file mode 100644 index 74c93da8d..000000000 --- a/vendor/libgit2/src/fetch.c +++ /dev/null @@ -1,136 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "git2/remote.h" -#include "git2/oid.h" -#include "git2/refs.h" -#include "git2/revwalk.h" - -#include "common.h" -#include "transport.h" -#include "remote.h" -#include "refspec.h" -#include "fetch.h" - -static int filter_wants(git_remote *remote) -{ - git_vector list; - git_headarray refs; - git_transport *t = remote->transport; - git_repository *repo = remote->repo; - const git_refspec *spec; - int error; - unsigned int i; - - error = git_vector_init(&list, 16, NULL); - if (error < GIT_SUCCESS) - return error; - - error = t->ls(t, &refs); - if (error < GIT_SUCCESS) { - error = git__rethrow(error, "Failed to get remote ref list"); - goto cleanup; - } - - spec = git_remote_fetchspec(remote); - if (spec == NULL) { - error = git__throw(GIT_ERROR, "The remote has no fetchspec"); - goto cleanup; - } - - for (i = 0; i < refs.len; ++i) { - git_remote_head *head = refs.heads[i]; - - /* If it doesn't match the refpec, we don't want it */ - error = git_refspec_src_match(spec, head->name); - if (error == GIT_ENOMATCH) - continue; - if (error < GIT_SUCCESS) { - error = git__rethrow(error, "Error matching remote ref name"); - goto cleanup; - } - - /* If we have the object, mark it so we don't ask for it */ - if (git_odb_exists(repo->db, &head->oid)) - head->local = 1; - else - remote->need_pack = 1; - - error = git_vector_insert(&list, head); - if (error < GIT_SUCCESS) - goto cleanup; - } - - remote->refs.len = list.length; - remote->refs.heads = (git_remote_head **) list.contents; - - return GIT_SUCCESS; - -cleanup: - git_vector_free(&list); - return error; -} - -/* - * In this first version, we push all our refs in and start sending - * them out. When we get an ACK we hide that commit and continue - * traversing until we're done - */ -int git_fetch_negotiate(git_remote *remote) -{ - int error; - git_headarray *list = &remote->refs; - git_transport *t = remote->transport; - - error = filter_wants(remote); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to filter the reference list for wants"); - - /* Don't try to negotiate when we don't want anything */ - if (list->len == 0) - return GIT_SUCCESS; - if (!remote->need_pack) - return GIT_SUCCESS; - - /* - * Now we have everything set up so we can start tell the server - * what we want and what we have. - */ - error = t->send_wants(t, list); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to send want list"); - - return t->negotiate_fetch(t, remote->repo, &remote->refs); -} - -int git_fetch_download_pack(char **out, git_remote *remote) -{ - if(!remote->need_pack) { - *out = NULL; - return GIT_SUCCESS; - } - - return remote->transport->download_pack(out, remote->transport, remote->repo); -} diff --git a/vendor/libgit2/src/fetch.h b/vendor/libgit2/src/fetch.h deleted file mode 100644 index ad4451ffe..000000000 --- a/vendor/libgit2/src/fetch.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef INCLUDE_fetch_h__ -#define INCLUDE_fetch_h__ - -int git_fetch_negotiate(git_remote *remote); -int git_fetch_download_pack(char **out, git_remote *remote); - -#endif diff --git a/vendor/libgit2/src/filebuf.c b/vendor/libgit2/src/filebuf.c deleted file mode 100644 index 6d398a7db..000000000 --- a/vendor/libgit2/src/filebuf.c +++ /dev/null @@ -1,396 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include - -#include "common.h" -#include "filebuf.h" -#include "fileops.h" - -static const size_t WRITE_BUFFER_SIZE = (4096 * 2); - -static int lock_file(git_filebuf *file, int flags) -{ - if (git_futils_exists(file->path_lock) == 0) { - if (flags & GIT_FILEBUF_FORCE) - p_unlink(file->path_lock); - else - return git__throw(GIT_EOSERR, "Failed to lock file"); - } - - /* create path to the file buffer is required */ - if (flags & GIT_FILEBUF_FORCE) { - file->fd = git_futils_creat_locked_withpath(file->path_lock, 0644); - } else { - file->fd = git_futils_creat_locked(file->path_lock, 0644); - } - - if (file->fd < 0) - return git__throw(GIT_EOSERR, "Failed to create lock"); - - if ((flags & GIT_FILEBUF_APPEND) && git_futils_exists(file->path_original) == 0) { - git_file source; - char buffer[2048]; - size_t read_bytes; - - source = p_open(file->path_original, O_RDONLY); - if (source < 0) - return git__throw(GIT_EOSERR, "Failed to lock file. Could not open %s", file->path_original); - - while ((read_bytes = p_read(source, buffer, 2048)) > 0) { - p_write(file->fd, buffer, read_bytes); - if (file->digest) - git_hash_update(file->digest, buffer, read_bytes); - } - - p_close(source); - } - - return GIT_SUCCESS; -} - -void git_filebuf_cleanup(git_filebuf *file) -{ - if (file->fd >= 0) - p_close(file->fd); - - if (file->fd >= 0 && file->path_lock && git_futils_exists(file->path_lock) == GIT_SUCCESS) - p_unlink(file->path_lock); - - if (file->digest) - git_hash_free_ctx(file->digest); - - free(file->buffer); - free(file->z_buf); - - deflateEnd(&file->zs); - - free(file->path_original); - free(file->path_lock); -} - -GIT_INLINE(int) flush_buffer(git_filebuf *file) -{ - int result = file->write(file, file->buffer, file->buf_pos); - file->buf_pos = 0; - return result; -} - -static int write_normal(git_filebuf *file, void *source, size_t len) -{ - int result = 0; - - if (len > 0) { - result = p_write(file->fd, (void *)source, len); - if (file->digest) - git_hash_update(file->digest, source, len); - } - - return result; -} - -static int write_deflate(git_filebuf *file, void *source, size_t len) -{ - int result = Z_OK; - z_stream *zs = &file->zs; - - if (len > 0 || file->flush_mode == Z_FINISH) { - zs->next_in = (void *)source; - zs->avail_in = len; - - do { - int have; - - zs->next_out = file->z_buf; - zs->avail_out = file->buf_size; - - result = deflate(zs, file->flush_mode); - assert(result != Z_STREAM_ERROR); - - have = file->buf_size - zs->avail_out; - - if (p_write(file->fd, file->z_buf, have) < GIT_SUCCESS) - return git__throw(GIT_EOSERR, "Failed to write to file"); - - } while (zs->avail_out == 0); - - assert(zs->avail_in == 0); - - if (file->digest) - git_hash_update(file->digest, source, len); - } - - return GIT_SUCCESS; -} - -int git_filebuf_open(git_filebuf *file, const char *path, int flags) -{ - int error; - size_t path_len; - - assert(file && path); - - memset(file, 0x0, sizeof(git_filebuf)); - - file->buf_size = WRITE_BUFFER_SIZE; - file->buf_pos = 0; - file->fd = -1; - - /* Allocate the main cache buffer */ - file->buffer = git__malloc(file->buf_size); - if (file->buffer == NULL){ - error = GIT_ENOMEM; - goto cleanup; - } - - /* If we are hashing on-write, allocate a new hash context */ - if (flags & GIT_FILEBUF_HASH_CONTENTS) { - if ((file->digest = git_hash_new_ctx()) == NULL) { - error = GIT_ENOMEM; - goto cleanup; - } - } - - /* If we are deflating on-write, */ - if (flags & GIT_FILEBUF_DEFLATE_CONTENTS) { - - /* Initialize the ZLib stream */ - if (deflateInit(&file->zs, Z_BEST_SPEED) != Z_OK) { - error = git__throw(GIT_EZLIB, "Failed to initialize zlib"); - goto cleanup; - } - - /* Allocate the Zlib cache buffer */ - file->z_buf = git__malloc(file->buf_size); - if (file->z_buf == NULL){ - error = GIT_ENOMEM; - goto cleanup; - } - - /* Never flush */ - file->flush_mode = Z_NO_FLUSH; - file->write = &write_deflate; - } else { - file->write = &write_normal; - } - - /* If we are writing to a temp file */ - if (flags & GIT_FILEBUF_TEMPORARY) { - char tmp_path[GIT_PATH_MAX]; - - /* Open the file as temporary for locking */ - file->fd = git_futils_mktmp(tmp_path, path); - if (file->fd < 0) { - error = GIT_EOSERR; - goto cleanup; - } - - /* No original path */ - file->path_original = NULL; - file->path_lock = git__strdup(tmp_path); - - if (file->path_lock == NULL) { - error = GIT_ENOMEM; - goto cleanup; - } - } else { - path_len = strlen(path); - - /* Save the original path of the file */ - file->path_original = git__strdup(path); - if (file->path_original == NULL) { - error = GIT_ENOMEM; - goto cleanup; - } - - /* create the locking path by appending ".lock" to the original */ - file->path_lock = git__malloc(path_len + GIT_FILELOCK_EXTLENGTH); - if (file->path_lock == NULL) { - error = GIT_ENOMEM; - goto cleanup; - } - - memcpy(file->path_lock, file->path_original, path_len); - memcpy(file->path_lock + path_len, GIT_FILELOCK_EXTENSION, GIT_FILELOCK_EXTLENGTH); - - /* open the file for locking */ - if ((error = lock_file(file, flags)) < GIT_SUCCESS) - goto cleanup; - } - - return GIT_SUCCESS; - -cleanup: - git_filebuf_cleanup(file); - return git__rethrow(error, "Failed to open file buffer for '%s'", path); -} - -int git_filebuf_hash(git_oid *oid, git_filebuf *file) -{ - int error; - - assert(oid && file && file->digest); - - if ((error = flush_buffer(file)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to get hash for file"); - - git_hash_final(oid, file->digest); - git_hash_free_ctx(file->digest); - file->digest = NULL; - - return GIT_SUCCESS; -} - -int git_filebuf_commit_at(git_filebuf *file, const char *path) -{ - free(file->path_original); - file->path_original = git__strdup(path); - if (file->path_original == NULL) - return GIT_ENOMEM; - - return git_filebuf_commit(file); -} - -int git_filebuf_commit(git_filebuf *file) -{ - int error; - - /* temporary files cannot be committed */ - assert(file && file->path_original); - - file->flush_mode = Z_FINISH; - if ((error = flush_buffer(file)) < GIT_SUCCESS) - goto cleanup; - - p_close(file->fd); - file->fd = -1; - - error = git_futils_mv_atomic(file->path_lock, file->path_original); - -cleanup: - git_filebuf_cleanup(file); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to commit locked file from buffer"); - return GIT_SUCCESS; -} - -GIT_INLINE(void) add_to_cache(git_filebuf *file, const void *buf, size_t len) -{ - memcpy(file->buffer + file->buf_pos, buf, len); - file->buf_pos += len; -} - -int git_filebuf_write(git_filebuf *file, const void *buff, size_t len) -{ - int error; - const unsigned char *buf = buff; - - for (;;) { - size_t space_left = file->buf_size - file->buf_pos; - - /* cache if it's small */ - if (space_left > len) { - add_to_cache(file, buf, len); - return GIT_SUCCESS; - } - - add_to_cache(file, buf, space_left); - - if ((error = flush_buffer(file)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to write to buffer"); - - len -= space_left; - buf += space_left; - } -} - -int git_filebuf_reserve(git_filebuf *file, void **buffer, size_t len) -{ - int error; - size_t space_left = file->buf_size - file->buf_pos; - - *buffer = NULL; - - if (len > file->buf_size) - return GIT_ENOMEM; - - if (space_left <= len) { - if ((error = flush_buffer(file)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to reserve buffer"); - } - - *buffer = (file->buffer + file->buf_pos); - file->buf_pos += len; - - return GIT_SUCCESS; -} - -int git_filebuf_printf(git_filebuf *file, const char *format, ...) -{ - va_list arglist; - size_t space_left; - int len, error; - char *tmp_buffer; - - space_left = file->buf_size - file->buf_pos; - - do { - va_start(arglist, format); - len = p_vsnprintf((char *)file->buffer + file->buf_pos, space_left, format, arglist); - va_end(arglist); - - if (len < 0) - return git__throw(GIT_EOSERR, "Failed to format string"); - - if ((size_t)len + 1 <= space_left) { - file->buf_pos += len; - return GIT_SUCCESS; - } - - if ((error = flush_buffer(file)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to output to buffer"); - - space_left = file->buf_size - file->buf_pos; - - } while ((size_t)len + 1 <= space_left); - - tmp_buffer = git__malloc(len + 1); - if (!tmp_buffer) - return GIT_ENOMEM; - - va_start(arglist, format); - len = p_vsnprintf(tmp_buffer, len + 1, format, arglist); - va_end(arglist); - - if (len < 0) { - free(tmp_buffer); - return git__throw(GIT_EOSERR, "Failed to format string"); - } - - error = git_filebuf_write(file, tmp_buffer, len); - free(tmp_buffer); - - return error; -} - diff --git a/vendor/libgit2/src/filebuf.h b/vendor/libgit2/src/filebuf.h deleted file mode 100644 index 9154cabcd..000000000 --- a/vendor/libgit2/src/filebuf.h +++ /dev/null @@ -1,51 +0,0 @@ -#ifndef INCLUDE_filebuf_h__ -#define INCLUDE_filebuf_h__ - -#include "fileops.h" -#include "hash.h" -#include "git2/zlib.h" - -#ifdef GIT_THREADS -# define GIT_FILEBUF_THREADS -#endif - -#define GIT_FILEBUF_HASH_CONTENTS (1 << 0) -#define GIT_FILEBUF_APPEND (1 << 2) -#define GIT_FILEBUF_FORCE (1 << 3) -#define GIT_FILEBUF_TEMPORARY (1 << 4) -#define GIT_FILEBUF_DEFLATE_CONTENTS (1 << 5) - -#define GIT_FILELOCK_EXTENSION ".lock\0" -#define GIT_FILELOCK_EXTLENGTH 6 - -struct git_filebuf { - char *path_original; - char *path_lock; - - int (*write)(struct git_filebuf *file, void *source, size_t len); - - git_hash_ctx *digest; - - unsigned char *buffer; - unsigned char *z_buf; - - z_stream zs; - int flush_mode; - - size_t buf_size, buf_pos; - git_file fd; -}; - -typedef struct git_filebuf git_filebuf; - -int git_filebuf_write(git_filebuf *lock, const void *buff, size_t len); -int git_filebuf_reserve(git_filebuf *file, void **buff, size_t len); -int git_filebuf_printf(git_filebuf *file, const char *format, ...) GIT_FORMAT_PRINTF(2, 3); - -int git_filebuf_open(git_filebuf *lock, const char *path, int flags); -int git_filebuf_commit(git_filebuf *lock); -int git_filebuf_commit_at(git_filebuf *lock, const char *path); -void git_filebuf_cleanup(git_filebuf *lock); -int git_filebuf_hash(git_oid *oid, git_filebuf *file); - -#endif diff --git a/vendor/libgit2/src/fileops.c b/vendor/libgit2/src/fileops.c deleted file mode 100644 index d7413a138..000000000 --- a/vendor/libgit2/src/fileops.c +++ /dev/null @@ -1,376 +0,0 @@ -#include "common.h" -#include "fileops.h" -#include - -int git_futils_mv_atomic(const char *from, const char *to) -{ -#ifdef GIT_WIN32 - /* - * Win32 POSIX compilance my ass. If the destination - * file exists, the `rename` call fails. This is as - * close as it gets with the Win32 API. - */ - return MoveFileEx(from, to, MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED) ? GIT_SUCCESS : GIT_EOSERR; -#else - /* Don't even try this on Win32 */ - if (!link(from, to)) { - p_unlink(from); - return GIT_SUCCESS; - } - - if (!rename(from, to)) - return GIT_SUCCESS; - - return GIT_ERROR; -#endif -} - -int git_futils_mkpath2file(const char *file_path) -{ - const int mode = 0755; /* or 0777 ? */ - int error = GIT_SUCCESS; - char target_folder_path[GIT_PATH_MAX]; - - error = git_path_dirname_r(target_folder_path, sizeof(target_folder_path), file_path); - if (error < GIT_SUCCESS) - return git__throw(GIT_EINVALIDPATH, "Failed to recursively build `%s` tree structure. Unable to parse parent folder name", file_path); - - /* Does the containing folder exist? */ - if (git_futils_isdir(target_folder_path)) { - git_path_join(target_folder_path, target_folder_path, ""); /* Ensure there's a trailing slash */ - - /* Let's create the tree structure */ - error = git_futils_mkdir_r(target_folder_path, mode); - if (error < GIT_SUCCESS) - return error; /* The callee already takes care of setting the correct error message. */ - } - - return GIT_SUCCESS; -} - -int git_futils_mktmp(char *path_out, const char *filename) -{ - int fd; - - strcpy(path_out, filename); - strcat(path_out, "_git2_XXXXXX"); - - if ((fd = p_mkstemp(path_out)) < 0) - return git__throw(GIT_EOSERR, "Failed to create temporary file %s", path_out); - - return fd; -} - -int git_futils_creat_withpath(const char *path, int mode) -{ - if (git_futils_mkpath2file(path) < GIT_SUCCESS) - return git__throw(GIT_EOSERR, "Failed to create file %s", path); - - return p_creat(path, mode); -} - -int git_futils_creat_locked(const char *path, int mode) -{ - int fd = open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY | O_EXCL, mode); - return fd >= 0 ? fd : git__throw(GIT_EOSERR, "Failed to create locked file. Could not open %s", path); -} - -int git_futils_creat_locked_withpath(const char *path, int mode) -{ - if (git_futils_mkpath2file(path) < GIT_SUCCESS) - return git__throw(GIT_EOSERR, "Failed to create locked file %s", path); - - return git_futils_creat_locked(path, mode); -} - -int git_futils_isdir(const char *path) -{ -#ifdef GIT_WIN32 - DWORD attr = GetFileAttributes(path); - if (attr == INVALID_FILE_ATTRIBUTES) - return GIT_ERROR; - - return (attr & FILE_ATTRIBUTE_DIRECTORY) ? GIT_SUCCESS : GIT_ERROR; - -#else - struct stat st; - if (p_stat(path, &st) < GIT_SUCCESS) - return GIT_ERROR; - - return S_ISDIR(st.st_mode) ? GIT_SUCCESS : GIT_ERROR; -#endif -} - -int git_futils_isfile(const char *path) -{ - struct stat st; - int stat_error; - - assert(path); - stat_error = p_stat(path, &st); - - if (stat_error < GIT_SUCCESS) - return -1; - - if (!S_ISREG(st.st_mode)) - return -1; - - return 0; -} - -int git_futils_exists(const char *path) -{ - assert(path); - return access(path, F_OK); -} - -git_off_t git_futils_filesize(git_file fd) -{ - struct stat sb; - if (p_fstat(fd, &sb)) - return GIT_ERROR; - - return sb.st_size; -} - -int git_futils_readbuffer_updated(git_fbuffer *obj, const char *path, time_t *mtime, int *updated) -{ - git_file fd; - size_t len; - struct stat st; - unsigned char *buff; - - assert(obj && path && *path); - - if (updated != NULL) - *updated = 0; - - if (p_stat(path, &st) < 0) - return git__throw(GIT_ENOTFOUND, "Failed to stat file %s", path); - - if (S_ISDIR(st.st_mode)) - return git__throw(GIT_ERROR, "Can't read a dir into a buffer"); - - /* - * If we were given a time, we only want to read the file if it - * has been modified. - */ - if (mtime != NULL && *mtime >= st.st_mtime) - return GIT_SUCCESS; - - if (mtime != NULL) - *mtime = st.st_mtime; - if (!git__is_sizet(st.st_size+1)) - return git__throw(GIT_ERROR, "Failed to read file `%s`. An error occured while calculating its size", path); - - len = (size_t) st.st_size; - - if ((fd = p_open(path, O_RDONLY)) < 0) - return git__throw(GIT_EOSERR, "Failed to open %s for reading", path); - - if ((buff = git__malloc(len + 1)) == NULL) { - p_close(fd); - return GIT_ENOMEM; - } - - if (p_read(fd, buff, len) < 0) { - p_close(fd); - free(buff); - return git__throw(GIT_ERROR, "Failed to read file `%s`", path); - } - buff[len] = '\0'; - - p_close(fd); - - if (mtime != NULL) - *mtime = st.st_mtime; - if (updated != NULL) - *updated = 1; - - obj->data = buff; - obj->len = len; - - return GIT_SUCCESS; -} - -int git_futils_readbuffer(git_fbuffer *obj, const char *path) -{ - return git_futils_readbuffer_updated(obj, path, NULL, NULL); -} - -void git_futils_freebuffer(git_fbuffer *obj) -{ - assert(obj); - free(obj->data); - obj->data = NULL; -} - - -int git_futils_mv_withpath(const char *from, const char *to) -{ - if (git_futils_mkpath2file(to) < GIT_SUCCESS) - return GIT_EOSERR; /* The callee already takes care of setting the correct error message. */ - - return git_futils_mv_atomic(from, to); /* The callee already takes care of setting the correct error message. */ -} - -int git_futils_mmap_ro(git_map *out, git_file fd, git_off_t begin, size_t len) -{ - return p_mmap(out, len, GIT_PROT_READ, GIT_MAP_SHARED, fd, begin); -} - -void git_futils_mmap_free(git_map *out) -{ - p_munmap(out); -} - -/* Taken from git.git */ -GIT_INLINE(int) is_dot_or_dotdot(const char *name) -{ - return (name[0] == '.' && - (name[1] == '\0' || - (name[1] == '.' && name[2] == '\0'))); -} - -int git_futils_direach( - char *path, - size_t path_sz, - int (*fn)(void *, char *), - void *arg) -{ - size_t wd_len = strlen(path); - DIR *dir; - struct dirent *de; - - if (!wd_len || path_sz < wd_len + 2) - return git__throw(GIT_EINVALIDARGS, "Failed to process `%s` tree structure. Path is either empty or buffer size is too short", path); - - while (path[wd_len - 1] == '/') - wd_len--; - path[wd_len++] = '/'; - path[wd_len] = '\0'; - - dir = opendir(path); - if (!dir) - return git__throw(GIT_EOSERR, "Failed to process `%s` tree structure. An error occured while opening the directory", path); - - while ((de = readdir(dir)) != NULL) { - size_t de_len; - int result; - - if (is_dot_or_dotdot(de->d_name)) - continue; - - de_len = strlen(de->d_name); - if (path_sz < wd_len + de_len + 1) { - closedir(dir); - return git__throw(GIT_ERROR, "Failed to process `%s` tree structure. Buffer size is too short", path); - } - - strcpy(path + wd_len, de->d_name); - result = fn(arg, path); - if (result < GIT_SUCCESS) { - closedir(dir); - return result; /* The callee is reponsible for setting the correct error message */ - } - if (result > 0) { - closedir(dir); - return result; - } - } - - closedir(dir); - return GIT_SUCCESS; -} - -int git_futils_mkdir_r(const char *path, int mode) -{ - int error, root_path_offset; - char *pp, *sp; - char *path_copy = git__strdup(path); - - if (path_copy == NULL) - return GIT_ENOMEM; - - error = GIT_SUCCESS; - pp = path_copy; - - root_path_offset = git_path_root(pp); - if (root_path_offset > 0) - pp += root_path_offset; /* On Windows, will skip the drive name (eg. C: or D:) */ - - while (error == GIT_SUCCESS && (sp = strchr(pp, '/')) != NULL) { - if (sp != pp && git_futils_isdir(path_copy) < GIT_SUCCESS) { - *sp = 0; - error = p_mkdir(path_copy, mode); - - /* Do not choke while trying to recreate an existing directory */ - if (errno == EEXIST) - error = GIT_SUCCESS; - - *sp = '/'; - } - - pp = sp + 1; - } - - if (*pp != '\0' && error == GIT_SUCCESS) { - error = p_mkdir(path, mode); - if (errno == EEXIST) - error = GIT_SUCCESS; - } - - free(path_copy); - - if (error < GIT_SUCCESS) - return git__throw(error, "Failed to recursively create `%s` tree structure", path); - - return GIT_SUCCESS; -} - -static int _rmdir_recurs_foreach(void *opaque, char *path) -{ - int error = GIT_SUCCESS; - int force = *(int *)opaque; - - if (git_futils_isdir(path) == GIT_SUCCESS) { - size_t root_size = strlen(path); - - if ((error = git_futils_direach(path, GIT_PATH_MAX, _rmdir_recurs_foreach, opaque)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to remove directory `%s`", path); - - path[root_size] = '\0'; - return p_rmdir(path); - - } else if (force) { - return p_unlink(path); - } - - return git__rethrow(error, "Failed to remove directory. `%s` is not empty", path); -} - -int git_futils_rmdir_r(const char *path, int force) -{ - char p[GIT_PATH_MAX]; - strncpy(p, path, GIT_PATH_MAX); - return _rmdir_recurs_foreach(&force, p); -} - -int git_futils_cmp_path(const char *name1, int len1, int isdir1, - const char *name2, int len2, int isdir2) -{ - int len = len1 < len2 ? len1 : len2; - int cmp; - - cmp = memcmp(name1, name2, len); - if (cmp) - return cmp; - if (len1 < len2) - return ((!isdir1 && !isdir2) ? -1 : - (isdir1 ? '/' - name2[len1] : name2[len1] - '/')); - if (len1 > len2) - return ((!isdir1 && !isdir2) ? 1 : - (isdir2 ? name1[len2] - '/' : '/' - name1[len2])); - return 0; -} - diff --git a/vendor/libgit2/src/fileops.h b/vendor/libgit2/src/fileops.h deleted file mode 100644 index 84c35e41b..000000000 --- a/vendor/libgit2/src/fileops.h +++ /dev/null @@ -1,155 +0,0 @@ -/* - * fileops.h - OS agnostic disk io operations - * - * This header describes the strictly internal part of the api - */ -#ifndef INCLUDE_fileops_h__ -#define INCLUDE_fileops_h__ - -#include "common.h" -#include "map.h" -#include "dir.h" -#include "posix.h" -#include "path.h" - -/** - * Filebuffer methods - * - * Read whole files into an in-memory buffer for processing - */ -#define GIT_FBUFFER_INIT {NULL, 0} - -typedef struct { /* file io buffer */ - void *data; /* data bytes */ - size_t len; /* data length */ -} git_fbuffer; - -extern int git_futils_readbuffer(git_fbuffer *obj, const char *path); -extern int git_futils_readbuffer_updated(git_fbuffer *obj, const char *path, time_t *mtime, int *updated); -extern void git_futils_freebuffer(git_fbuffer *obj); - -/** - * File utils - * - * These are custom filesystem-related helper methods. They are - * rather high level, and wrap the underlying POSIX methods - * - * All these methods return GIT_SUCCESS on success, - * or an error code on failure and an error message is set. - */ - -/** - * Check if a file exists and can be accessed. - */ -extern int git_futils_exists(const char *path); - -/** - * Create and open a file, while also - * creating all the folders in its path - */ -extern int git_futils_creat_withpath(const char *path, int mode); - -/** - * Create an open a process-locked file - */ -extern int git_futils_creat_locked(const char *path, int mode); - -/** - * Create an open a process-locked file, while - * also creating all the folders in its path - */ -extern int git_futils_creat_locked_withpath(const char *path, int mode); - -/** - * Check if the given path points to a directory - */ -extern int git_futils_isdir(const char *path); - -/** - * Check if the given path points to a regular file - */ -extern int git_futils_isfile(const char *path); - -/** - * Create a path recursively - */ -extern int git_futils_mkdir_r(const char *path, int mode); - -/** - * Create all the folders required to contain - * the full path of a file - */ -extern int git_futils_mkpath2file(const char *path); - -extern int git_futils_rmdir_r(const char *path, int force); - -/** - * Create and open a temporary file with a `_git2_` suffix - */ -extern int git_futils_mktmp(char *path_out, const char *filename); - -/** - * Atomically rename a file on the filesystem - */ -extern int git_futils_mv_atomic(const char *from, const char *to); - -/** - * Move a file on the filesystem, create the - * destination path if it doesn't exist - */ -extern int git_futils_mv_withpath(const char *from, const char *to); - - -/** - * Get the filesize in bytes of a file - */ -extern git_off_t git_futils_filesize(git_file fd); - -/** - * Read-only map all or part of a file into memory. - * When possible this function should favor a virtual memory - * style mapping over some form of malloc()+read(), as the - * data access will be random and is not likely to touch the - * majority of the region requested. - * - * @param out buffer to populate with the mapping information. - * @param fd open descriptor to configure the mapping from. - * @param begin first byte to map, this should be page aligned. - * @param end number of bytes to map. - * @return - * - GIT_SUCCESS on success; - * - GIT_EOSERR on an unspecified OS related error. - */ -extern int git_futils_mmap_ro( - git_map *out, - git_file fd, - git_off_t begin, - size_t len); - -/** - * Release the memory associated with a previous memory mapping. - * @param map the mapping description previously configured. - */ -extern void git_futils_mmap_free(git_map *map); - -/** - * Walk each directory entry, except '.' and '..', calling fn(state). - * - * @param pathbuf buffer the function reads the initial directory - * path from, and updates with each successive entry's name. - * @param pathmax maximum allocation of pathbuf. - * @param fn function to invoke with each entry. The first arg is - * the input state and the second arg is pathbuf. The function - * may modify the pathbuf, but only by appending new text. - * @param state to pass to fn as the first arg. - */ -extern int git_futils_direach( - char *pathbuf, - size_t pathmax, - int (*fn)(void *, char *), - void *state); - -extern int git_futils_cmp_path(const char *name1, int len1, int isdir1, - const char *name2, int len2, int isdir2); - -#endif /* INCLUDE_fileops_h__ */ diff --git a/vendor/libgit2/src/hash.c b/vendor/libgit2/src/hash.c deleted file mode 100644 index b8b311bcb..000000000 --- a/vendor/libgit2/src/hash.c +++ /dev/null @@ -1,92 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "hash.h" - -#if defined(PPC_SHA1) -# include "ppc/sha1.h" -#else -# include "sha1.h" -#endif - -struct git_hash_ctx { - SHA_CTX c; -}; - -git_hash_ctx *git_hash_new_ctx(void) -{ - git_hash_ctx *ctx = git__malloc(sizeof(*ctx)); - - if (!ctx) - return NULL; - - SHA1_Init(&ctx->c); - - return ctx; -} - -void git_hash_free_ctx(git_hash_ctx *ctx) -{ - free(ctx); -} - -void git_hash_init(git_hash_ctx *ctx) -{ - assert(ctx); - SHA1_Init(&ctx->c); -} - -void git_hash_update(git_hash_ctx *ctx, const void *data, size_t len) -{ - assert(ctx); - SHA1_Update(&ctx->c, data, len); -} - -void git_hash_final(git_oid *out, git_hash_ctx *ctx) -{ - assert(ctx); - SHA1_Final(out->id, &ctx->c); -} - -void git_hash_buf(git_oid *out, const void *data, size_t len) -{ - SHA_CTX c; - - SHA1_Init(&c); - SHA1_Update(&c, data, len); - SHA1_Final(out->id, &c); -} - -void git_hash_vec(git_oid *out, git_buf_vec *vec, size_t n) -{ - SHA_CTX c; - size_t i; - - SHA1_Init(&c); - for (i = 0; i < n; i++) - SHA1_Update(&c, vec[i].data, vec[i].len); - SHA1_Final(out->id, &c); -} diff --git a/vendor/libgit2/src/hash.h b/vendor/libgit2/src/hash.h deleted file mode 100644 index 2b769a4c9..000000000 --- a/vendor/libgit2/src/hash.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * hash.h - */ -#ifndef INCLUDE_hash_h__ -#define INCLUDE_hash_h__ - -#include "git2/oid.h" - -typedef struct git_hash_ctx git_hash_ctx; - -typedef struct { - void *data; - size_t len; -} git_buf_vec; - -git_hash_ctx *git_hash_new_ctx(void); -void git_hash_free_ctx(git_hash_ctx *ctx); - -void git_hash_init(git_hash_ctx *c); -void git_hash_update(git_hash_ctx *c, const void *data, size_t len); -void git_hash_final(git_oid *out, git_hash_ctx *c); - -void git_hash_buf(git_oid *out, const void *data, size_t len); -void git_hash_vec(git_oid *out, git_buf_vec *vec, size_t n); - -#endif /* INCLUDE_hash_h__ */ diff --git a/vendor/libgit2/src/hashtable.c b/vendor/libgit2/src/hashtable.c deleted file mode 100644 index 86e5a113a..000000000 --- a/vendor/libgit2/src/hashtable.c +++ /dev/null @@ -1,261 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "repository.h" -#include "commit.h" - -#define MAX_LOOPS 5 -static const double max_load_factor = 0.65; - -static int resize_to(git_hashtable *self, size_t new_size); -static int set_size(git_hashtable *self, size_t new_size); -static git_hashtable_node *node_with_hash(git_hashtable *self, const void *key, int hash_id); -static void node_swap_with(git_hashtable_node *self, git_hashtable_node *other); -static int node_insert(git_hashtable *self, git_hashtable_node *new_node); -static int insert_nodes(git_hashtable *self, git_hashtable_node *old_nodes, size_t old_size); - -static int resize_to(git_hashtable *self, size_t new_size) -{ - git_hashtable_node *old_nodes = self->nodes; - size_t old_size = self->size; - - self->is_resizing = 1; - - do { - self->size = new_size; - self->size_mask = new_size - 1; - self->key_count = 0; - self->nodes = git__calloc(1, sizeof(git_hashtable_node) * self->size); - - if (self->nodes == NULL) - return GIT_ENOMEM; - - if (insert_nodes(self, old_nodes, old_size) == 0) - self->is_resizing = 0; - else { - new_size *= 2; - free(self->nodes); - } - } while(self->is_resizing); - - free(old_nodes); - return GIT_SUCCESS; -} - -static int set_size(git_hashtable *self, size_t new_size) -{ - self->nodes = realloc(self->nodes, new_size * sizeof(git_hashtable_node)); - if (self->nodes == NULL) - return GIT_ENOMEM; - - if (new_size > self->size) { - memset(&self->nodes[self->size], 0x0, (new_size - self->size) * sizeof(git_hashtable_node)); - } - - self->size = new_size; - self->size_mask = new_size - 1; - return GIT_SUCCESS; -} - -static git_hashtable_node *node_with_hash(git_hashtable *self, const void *key, int hash_id) -{ - size_t pos = self->hash(key, hash_id) & self->size_mask; - return git_hashtable_node_at(self->nodes, pos); -} - -static void node_swap_with(git_hashtable_node *self, git_hashtable_node *other) -{ - git_hashtable_node tmp = *self; - *self = *other; - *other = tmp; -} - -static int node_insert(git_hashtable *self, git_hashtable_node *new_node) -{ - int iteration, hash_id; - - for (iteration = 0; iteration < MAX_LOOPS; iteration++) { - for (hash_id = 0; hash_id < GIT_HASHTABLE_HASHES; ++hash_id) { - git_hashtable_node *node; - node = node_with_hash(self, new_node->key, hash_id); - node_swap_with(new_node, node); - if(new_node->key == 0x0){ - self->key_count++; - return GIT_SUCCESS; - } - } - } - - if (self->is_resizing) - return git__throw(GIT_EBUSY, "Failed to insert node. Hashtable is currently resizing"); - - resize_to(self, self->size * 2); - git_hashtable_insert(self, new_node->key, new_node->value); - return GIT_SUCCESS; -} - -static int insert_nodes(git_hashtable *self, git_hashtable_node *old_nodes, size_t old_size) -{ - size_t i; - - for (i = 0; i < old_size; ++i) { - git_hashtable_node *node = git_hashtable_node_at(old_nodes, i); - if (node->key && git_hashtable_insert(self, node->key, node->value) < GIT_SUCCESS) - return GIT_ENOMEM; - } - - return GIT_SUCCESS; -} - -git_hashtable *git_hashtable_alloc(size_t min_size, - git_hash_ptr hash, - git_hash_keyeq_ptr key_eq) -{ - git_hashtable *table; - - assert(hash && key_eq); - - if ((table = git__malloc(sizeof(git_hashtable))) == NULL) - return NULL; - - memset(table, 0x0, sizeof(git_hashtable)); - - if (min_size < 8) - min_size = 8; - - /* round up size to closest power of 2 */ - min_size--; - min_size |= min_size >> 1; - min_size |= min_size >> 2; - min_size |= min_size >> 4; - min_size |= min_size >> 8; - min_size |= min_size >> 16; - - table->hash = hash; - table->key_equal = key_eq; - - set_size(table, min_size + 1); - - return table; -} - -void git_hashtable_clear(git_hashtable *self) -{ - assert(self); - - memset(self->nodes, 0x0, sizeof(git_hashtable_node) * self->size); - self->key_count = 0; -} - -void git_hashtable_free(git_hashtable *self) -{ - assert(self); - - free(self->nodes); - free(self); -} - - -int git_hashtable_insert2(git_hashtable *self, const void *key, void *value, void **old_value) -{ - int hash_id; - git_hashtable_node *node; - - assert(self && self->nodes); - - *old_value = NULL; - - for (hash_id = 0; hash_id < GIT_HASHTABLE_HASHES; ++hash_id) { - node = node_with_hash(self, key, hash_id); - - if (!node->key) { - node->key = key; - node->value = value; - self->key_count++; - return GIT_SUCCESS; - } - - if (key == node->key || self->key_equal(key, node->key) == 0) { - *old_value = node->value; - node->key = key; - node->value = value; - return GIT_SUCCESS; - } - } - - /* no space in table; must do cuckoo dance */ - { - git_hashtable_node x; - x.key = key; - x.value = value; - return node_insert(self, &x); - } -} - -void *git_hashtable_lookup(git_hashtable *self, const void *key) -{ - int hash_id; - git_hashtable_node *node; - - assert(self && self->nodes); - - for (hash_id = 0; hash_id < GIT_HASHTABLE_HASHES; ++hash_id) { - node = node_with_hash(self, key, hash_id); - if (node->key && self->key_equal(key, node->key) == 0) - return node->value; - } - - return NULL; -} - -int git_hashtable_remove(git_hashtable *self, const void *key) -{ - int hash_id; - git_hashtable_node *node; - - assert(self && self->nodes); - - for (hash_id = 0; hash_id < GIT_HASHTABLE_HASHES; ++hash_id) { - node = node_with_hash(self, key, hash_id); - if (node->key && self->key_equal(key, node->key) == 0) { - node->key = NULL; - node->value = NULL; - self->key_count--; - return GIT_SUCCESS; - } - } - - return git__throw(GIT_ENOTFOUND, "Entry not found in hash table"); -} - -int git_hashtable_merge(git_hashtable *self, git_hashtable *other) -{ - if (resize_to(self, (self->size + other->size) * 2) < GIT_SUCCESS) - return GIT_ENOMEM; - - return insert_nodes(self, other->nodes, other->key_count); -} - diff --git a/vendor/libgit2/src/hashtable.h b/vendor/libgit2/src/hashtable.h deleted file mode 100644 index be21be2b1..000000000 --- a/vendor/libgit2/src/hashtable.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef INCLUDE_hashtable_h__ -#define INCLUDE_hashtable_h__ - -#include "git2/common.h" -#include "git2/oid.h" -#include "git2/odb.h" -#include "common.h" - -#define GIT_HASHTABLE_HASHES 3 - -typedef uint32_t (*git_hash_ptr)(const void *, int hash_id); -typedef int (*git_hash_keyeq_ptr)(const void *key_a, const void *key_b); - -struct git_hashtable_node { - const void *key; - void *value; -}; - -struct git_hashtable { - struct git_hashtable_node *nodes; - - size_t size_mask; - size_t size; - size_t key_count; - - int is_resizing; - - git_hash_ptr hash; - git_hash_keyeq_ptr key_equal; -}; - -typedef struct git_hashtable_node git_hashtable_node; -typedef struct git_hashtable git_hashtable; - -git_hashtable *git_hashtable_alloc(size_t min_size, - git_hash_ptr hash, - git_hash_keyeq_ptr key_eq); -void *git_hashtable_lookup(git_hashtable *h, const void *key); -int git_hashtable_remove(git_hashtable *table, const void *key); -void git_hashtable_free(git_hashtable *h); -void git_hashtable_clear(git_hashtable *h); -int git_hashtable_merge(git_hashtable *self, git_hashtable *other); - -int git_hashtable_insert2(git_hashtable *h, const void *key, void *value, void **old_value); - -GIT_INLINE(int) git_hashtable_insert(git_hashtable *h, const void *key, void *value) -{ - void *_unused; - return git_hashtable_insert2(h, key, value, &_unused); -} - -#define git_hashtable_node_at(nodes, pos) ((git_hashtable_node *)(&nodes[pos])) - -#define GIT_HASHTABLE_FOREACH(self, pkey, pvalue, code) {\ - git_hashtable *_self = (self);\ - git_hashtable_node *_nodes = _self->nodes;\ - unsigned int _i, _size = _self->size;\ - for (_i = 0; _i < _size; _i ++) {\ - git_hashtable_node *_node = git_hashtable_node_at(_nodes, _i);\ - if (_node->key)\ - {\ - pkey = _node->key;\ - pvalue = _node->value;\ - code;\ - }\ - }\ -} - -#define GIT_HASHTABLE_FOREACH_DELETE() {\ - _node->key = NULL; _node->value = NULL; _self->key_count--;\ -} - - -#endif diff --git a/vendor/libgit2/src/index.c b/vendor/libgit2/src/index.c deleted file mode 100644 index bbe9efa49..000000000 --- a/vendor/libgit2/src/index.c +++ /dev/null @@ -1,1060 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include - -#include "common.h" -#include "repository.h" -#include "index.h" -#include "hash.h" -#include "git2/odb.h" -#include "git2/blob.h" - -#define entry_size(type,len) ((offsetof(type, path) + (len) + 8) & ~7) -#define short_entry_size(len) entry_size(struct entry_short, len) -#define long_entry_size(len) entry_size(struct entry_long, len) - -#define minimal_entry_size (offsetof(struct entry_short, path)) - -static const size_t INDEX_FOOTER_SIZE = GIT_OID_RAWSZ; -static const size_t INDEX_HEADER_SIZE = 12; - -static const unsigned int INDEX_VERSION_NUMBER = 2; -static const unsigned int INDEX_VERSION_NUMBER_EXT = 3; - -static const unsigned int INDEX_HEADER_SIG = 0x44495243; -static const char INDEX_EXT_TREECACHE_SIG[] = {'T', 'R', 'E', 'E'}; -static const char INDEX_EXT_UNMERGED_SIG[] = {'R', 'E', 'U', 'C'}; - -struct index_header { - uint32_t signature; - uint32_t version; - uint32_t entry_count; -}; - -struct index_extension { - char signature[4]; - uint32_t extension_size; -}; - -struct entry_time { - uint32_t seconds; - uint32_t nanoseconds; -}; - -struct entry_short { - struct entry_time ctime; - struct entry_time mtime; - uint32_t dev; - uint32_t ino; - uint32_t mode; - uint32_t uid; - uint32_t gid; - uint32_t file_size; - git_oid oid; - uint16_t flags; - char path[1]; /* arbitrary length */ -}; - -struct entry_long { - struct entry_time ctime; - struct entry_time mtime; - uint32_t dev; - uint32_t ino; - uint32_t mode; - uint32_t uid; - uint32_t gid; - uint32_t file_size; - git_oid oid; - uint16_t flags; - uint16_t flags_extended; - char path[1]; /* arbitrary length */ -}; - -/* local declarations */ -static size_t read_extension(git_index *index, const char *buffer, size_t buffer_size); -static size_t read_entry(git_index_entry *dest, const void *buffer, size_t buffer_size); -static int read_header(struct index_header *dest, const void *buffer); - -static int read_tree(git_index *index, const char *buffer, size_t buffer_size); -static int read_tree_internal(git_index_tree **, const char **, const char *, git_index_tree *); - -static int parse_index(git_index *index, const char *buffer, size_t buffer_size); -static int is_index_extended(git_index *index); -static int write_index(git_index *index, git_filebuf *file); - -static int index_srch(const void *key, const void *array_member) -{ - const git_index_entry *entry = array_member; - - return strcmp(key, entry->path); -} - -static int index_cmp(const void *a, const void *b) -{ - const git_index_entry *entry_a = a; - const git_index_entry *entry_b = b; - - return strcmp(entry_a->path, entry_b->path); -} - -static int unmerged_srch(const void *key, const void *array_member) -{ - const git_index_entry_unmerged *entry = array_member; - - return strcmp(key, entry->path); -} - -static int unmerged_cmp(const void *a, const void *b) -{ - const git_index_entry_unmerged *info_a = a; - const git_index_entry_unmerged *info_b = b; - - return strcmp(info_a->path, info_b->path); -} - -static unsigned int index_create_mode(unsigned int mode) -{ - if (S_ISLNK(mode)) - return S_IFLNK; - if (S_ISDIR(mode) || (mode & S_IFMT) == (S_IFLNK | S_IFDIR)) - return (S_IFLNK | S_IFDIR); - return S_IFREG | ((mode & 0100) ? 0755 : 0644); -} - -static int index_initialize(git_index **index_out, git_repository *owner, const char *index_path) -{ - git_index *index; - - assert(index_out && index_path); - - index = git__malloc(sizeof(git_index)); - if (index == NULL) - return GIT_ENOMEM; - - memset(index, 0x0, sizeof(git_index)); - - index->index_file_path = git__strdup(index_path); - if (index->index_file_path == NULL) { - free(index); - return GIT_ENOMEM; - } - - index->repository = owner; - - git_vector_init(&index->entries, 32, index_cmp); - - /* Check if index file is stored on disk already */ - if (git_futils_exists(index->index_file_path) == 0) - index->on_disk = 1; - - *index_out = index; - return git_index_read(index); -} - -int git_index_open(git_index **index_out, const char *index_path) -{ - return index_initialize(index_out, NULL, index_path); -} - -/* - * Moved from `repository.c` - */ -int git_repository_index(git_index **index_out, git_repository *repo) -{ - if (repo->is_bare) - return git__throw(GIT_EBAREINDEX, "Failed to open index. Repository is bare"); - - return index_initialize(index_out, repo, repo->path_index); -} - -void git_index_free(git_index *index) -{ - if (index == NULL) - return; - - git_index_clear(index); - git_vector_free(&index->entries); - git_vector_free(&index->unmerged); - - free(index->index_file_path); - free(index); -} - -static void free_tree(git_index_tree *tree) -{ - unsigned int i; - - if (tree == NULL) - return; - - for (i = 0; i < tree->children_count; ++i) - free_tree(tree->children[i]); - - free(tree->name); - free(tree->children); - free(tree); -} - -void git_index_clear(git_index *index) -{ - unsigned int i; - - assert(index); - - for (i = 0; i < index->entries.length; ++i) { - git_index_entry *e; - e = git_vector_get(&index->entries, i); - free(e->path); - free(e); - } - - for (i = 0; i < index->unmerged.length; ++i) { - git_index_entry_unmerged *e; - e = git_vector_get(&index->unmerged, i); - free(e->path); - free(e); - } - - git_vector_clear(&index->entries); - git_vector_clear(&index->unmerged); - index->last_modified = 0; - - free_tree(index->tree); - index->tree = NULL; -} - -int git_index_read(git_index *index) -{ - int error = GIT_SUCCESS, updated; - git_fbuffer buffer = GIT_FBUFFER_INIT; - time_t mtime; - - assert(index->index_file_path); - - if (!index->on_disk || git_futils_exists(index->index_file_path) < 0) { - git_index_clear(index); - index->on_disk = 0; - return GIT_SUCCESS; - } - - /* We don't want to update the mtime if we fail to parse the index */ - mtime = index->last_modified; - error = git_futils_readbuffer_updated(&buffer, index->index_file_path, &mtime, &updated); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to read index"); - - if (updated) { - git_index_clear(index); - error = parse_index(index, buffer.data, buffer.len); - - if (error == GIT_SUCCESS) - index->last_modified = mtime; - - git_futils_freebuffer(&buffer); - } - - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to parse index"); - return error; -} - -int git_index_write(git_index *index) -{ - git_filebuf file; - struct stat indexst; - int error; - - git_vector_sort(&index->entries); - - if ((error = git_filebuf_open(&file, index->index_file_path, GIT_FILEBUF_HASH_CONTENTS)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to write index"); - - if ((error = write_index(index, &file)) < GIT_SUCCESS) { - git_filebuf_cleanup(&file); - return git__rethrow(error, "Failed to write index"); - } - - if ((error = git_filebuf_commit(&file)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to write index"); - - if (p_stat(index->index_file_path, &indexst) == 0) { - index->last_modified = indexst.st_mtime; - index->on_disk = 1; - } - - return GIT_SUCCESS; -} - -unsigned int git_index_entrycount(git_index *index) -{ - assert(index); - return index->entries.length; -} - -unsigned int git_index_entrycount_unmerged(git_index *index) -{ - assert(index); - return index->unmerged.length; -} - -git_index_entry *git_index_get(git_index *index, unsigned int n) -{ - git_vector_sort(&index->entries); - return git_vector_get(&index->entries, n); -} - -static int index_entry_init(git_index_entry **entry_out, git_index *index, const char *rel_path, int stage) -{ - git_index_entry *entry; - char full_path[GIT_PATH_MAX]; - struct stat st; - git_oid oid; - int error; - - if (index->repository == NULL) - return git__throw(GIT_EBAREINDEX, "Failed to initialize entry. Repository is bare"); - - git_path_join(full_path, index->repository->path_workdir, rel_path); - - if (p_lstat(full_path, &st) < 0) - return git__throw(GIT_ENOTFOUND, "Failed to initialize entry. '%s' cannot be opened", full_path); - - if (stage < 0 || stage > 3) - return git__throw(GIT_ERROR, "Failed to initialize entry. Invalid stage %i", stage); - - /* write the blob to disk and get the oid */ - if ((error = git_blob_create_fromfile(&oid, index->repository, rel_path)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to initialize index entry"); - - entry = git__malloc(sizeof(git_index_entry)); - if (!entry) - return GIT_ENOMEM; - memset(entry, 0x0, sizeof(git_index_entry)); - - entry->ctime.seconds = (git_time_t)st.st_ctime; - entry->mtime.seconds = (git_time_t)st.st_mtime; - /* entry.mtime.nanoseconds = st.st_mtimensec; */ - /* entry.ctime.nanoseconds = st.st_ctimensec; */ - entry->dev= st.st_rdev; - entry->ino = st.st_ino; - entry->mode = index_create_mode(st.st_mode); - entry->uid = st.st_uid; - entry->gid = st.st_gid; - entry->file_size = st.st_size; - entry->oid = oid; - - entry->flags |= (stage << GIT_IDXENTRY_STAGESHIFT); - entry->path = git__strdup(rel_path); - if (entry->path == NULL) { - free(entry); - return GIT_ENOMEM; - } - - *entry_out = entry; - return GIT_SUCCESS; -} - -static git_index_entry *index_entry_dup(const git_index_entry *source_entry) -{ - git_index_entry *entry; - - entry = git__malloc(sizeof(git_index_entry)); - if (!entry) - return NULL; - - memcpy(entry, source_entry, sizeof(git_index_entry)); - - /* duplicate the path string so we own it */ - entry->path = git__strdup(entry->path); - if (!entry->path) - return NULL; - - return entry; -} - -static void index_entry_free(git_index_entry *entry) -{ - if (!entry) - return; - free(entry->path); - free(entry); -} - -static int index_insert(git_index *index, git_index_entry *entry, int replace) -{ - size_t path_length; - int position; - git_index_entry **entry_array; - - assert(index && entry); - - if (entry->path == NULL) - return git__throw(GIT_EMISSINGOBJDATA, "Failed to insert into index. Entry has no path"); - - /* make sure that the path length flag is correct */ - path_length = strlen(entry->path); - - entry->flags &= ~GIT_IDXENTRY_NAMEMASK; - - if (path_length < GIT_IDXENTRY_NAMEMASK) - entry->flags |= path_length & GIT_IDXENTRY_NAMEMASK; - else - entry->flags |= GIT_IDXENTRY_NAMEMASK;; - - /* - * replacing is not requested: just insert entry at the end; - * the index is no longer sorted - */ - if (!replace) { - if (git_vector_insert(&index->entries, entry) < GIT_SUCCESS) - return GIT_ENOMEM; - - return GIT_SUCCESS; - } - - /* look if an entry with this path already exists */ - position = git_index_find(index, entry->path); - - /* - * if no entry exists add the entry at the end; - * the index is no longer sorted - */ - if (position == GIT_ENOTFOUND) { - if (git_vector_insert(&index->entries, entry) < GIT_SUCCESS) - return GIT_ENOMEM; - - return GIT_SUCCESS; - } - - /* exists, replace it */ - entry_array = (git_index_entry **) index->entries.contents; - free(entry_array[position]->path); - free(entry_array[position]); - entry_array[position] = entry; - - return GIT_SUCCESS; -} - -static int index_add(git_index *index, const char *path, int stage, int replace) -{ - git_index_entry *entry = NULL; - int ret; - - ret = index_entry_init(&entry, index, path, stage); - if (ret) - goto err; - - ret = index_insert(index, entry, replace); - if (ret) - goto err; - - return ret; -err: - index_entry_free(entry); - return git__rethrow(ret, "Failed to append to index"); -} - -int git_index_add(git_index *index, const char *path, int stage) -{ - return index_add(index, path, stage, 1); -} - -int git_index_append(git_index *index, const char *path, int stage) -{ - return index_add(index, path, stage, 0); -} - -static int index_add2(git_index *index, const git_index_entry *source_entry, - int replace) -{ - git_index_entry *entry = NULL; - int ret; - - entry = index_entry_dup(source_entry); - if (entry == NULL) { - ret = GIT_ENOMEM; - goto err; - } - - ret = index_insert(index, entry, replace); - if (ret) - goto err; - - return ret; -err: - index_entry_free(entry); - return git__rethrow(ret, "Failed to append to index"); -} - -int git_index_add2(git_index *index, const git_index_entry *source_entry) -{ - return index_add2(index, source_entry, 1); -} - -int git_index_append2(git_index *index, const git_index_entry *source_entry) -{ - return index_add2(index, source_entry, 1); -} - -int git_index_remove(git_index *index, int position) -{ - git_vector_sort(&index->entries); - return git_vector_remove(&index->entries, (unsigned int)position); -} - -int git_index_find(git_index *index, const char *path) -{ - return git_vector_bsearch2(&index->entries, index_srch, path); -} - -void git_index_uniq(git_index *index) -{ - git_vector_uniq(&index->entries); -} - -const git_index_entry_unmerged *git_index_get_unmerged_bypath(git_index *index, const char *path) -{ - int pos; - assert(index && path); - - if (!index->unmerged.length) - return NULL; - - if ((pos = git_vector_bsearch2(&index->unmerged, unmerged_srch, path)) < GIT_SUCCESS) - return NULL; - - return git_vector_get(&index->unmerged, pos); -} - -const git_index_entry_unmerged *git_index_get_unmerged_byindex(git_index *index, unsigned int n) -{ - assert(index); - return git_vector_get(&index->unmerged, n); -} - - -static int read_tree_internal(git_index_tree **out, - const char **buffer_in, const char *buffer_end, git_index_tree *parent) -{ - git_index_tree *tree; - const char *name_start, *buffer; - long count; - int error = GIT_SUCCESS; - - if ((tree = git__malloc(sizeof(git_index_tree))) == NULL) - return GIT_ENOMEM; - - memset(tree, 0x0, sizeof(git_index_tree)); - tree->parent = parent; - - buffer = name_start = *buffer_in; - - if ((buffer = memchr(buffer, '\0', buffer_end - buffer)) == NULL) { - error = GIT_EOBJCORRUPTED; - goto cleanup; - } - - /* NUL-terminated tree name */ - tree->name = git__strdup(name_start); - if (tree->name == NULL) { - error = GIT_ENOMEM; - goto cleanup; - } - - if (++buffer >= buffer_end) { - error = GIT_EOBJCORRUPTED; - goto cleanup; - } - - /* Blank-terminated ASCII decimal number of entries in this tree */ - if (git__strtol32(&count, buffer, &buffer, 10) < GIT_SUCCESS || count < -1) { - error = GIT_EOBJCORRUPTED; - goto cleanup; - } - - /* Invalidated TREE. Free the tree but report success */ - if (count == -1) { - /* FIXME: return buffer_end or the end position for - * this single tree entry */ - *buffer_in = buffer_end; - *out = NULL; - free_tree(tree); /* Needs to be done manually */ - return GIT_SUCCESS; - } - - tree->entries = count; - - if (*buffer != ' ' || ++buffer >= buffer_end) { - error = GIT_EOBJCORRUPTED; - goto cleanup; - } - - /* Number of children of the tree, newline-terminated */ - if (git__strtol32(&count, buffer, &buffer, 10) < GIT_SUCCESS || - count < 0) { - error = GIT_EOBJCORRUPTED; - goto cleanup; - } - - tree->children_count = count; - - if (*buffer != '\n' || ++buffer >= buffer_end) { - error = GIT_EOBJCORRUPTED; - goto cleanup; - } - - /* 160-bit SHA-1 for this tree and it's children */ - if (buffer + GIT_OID_RAWSZ > buffer_end) { - error = GIT_EOBJCORRUPTED; - goto cleanup; - } - - git_oid_fromraw(&tree->oid, (const unsigned char *)buffer); - buffer += GIT_OID_RAWSZ; - - /* Parse children: */ - if (tree->children_count > 0) { - unsigned int i; - int err; - - tree->children = git__malloc(tree->children_count * sizeof(git_index_tree *)); - if (tree->children == NULL) - goto cleanup; - - for (i = 0; i < tree->children_count; ++i) { - err = read_tree_internal(&tree->children[i], &buffer, buffer_end, tree); - - if (err < GIT_SUCCESS) - goto cleanup; - } - } - - *buffer_in = buffer; - *out = tree; - return GIT_SUCCESS; - - cleanup: - free_tree(tree); - return error; -} - -static int read_tree(git_index *index, const char *buffer, size_t buffer_size) -{ - const char *buffer_end = buffer + buffer_size; - int error; - - error = read_tree_internal(&index->tree, &buffer, buffer_end, NULL); - - if (buffer < buffer_end) - return GIT_EOBJCORRUPTED; - - return error; -} - -static int read_unmerged(git_index *index, const char *buffer, size_t size) -{ - const char *endptr; - size_t len; - int i; - - git_vector_init(&index->unmerged, 16, unmerged_cmp); - - while (size) { - git_index_entry_unmerged *lost; - - len = strlen(buffer) + 1; - if (size <= len) - return git__throw(GIT_ERROR, "Failed to read unmerged entries"); - - if ((lost = git__malloc(sizeof(git_index_entry_unmerged))) == NULL) - return GIT_ENOMEM; - - if (git_vector_insert(&index->unmerged, lost) < GIT_SUCCESS) - return git__throw(GIT_ERROR, "Failed to read unmerged entries"); - - lost->path = git__strdup(buffer); - if (!lost->path) - return GIT_ENOMEM; - - size -= len; - buffer += len; - - for (i = 0; i < 3; i++) { - long tmp; - - if (git__strtol32(&tmp, buffer, &endptr, 8) < GIT_SUCCESS || - !endptr || endptr == buffer || *endptr || (unsigned)tmp > UINT_MAX) - return GIT_ERROR; - - lost->mode[i] = tmp; - - len = (endptr + 1) - buffer; - if (size <= len) - return git__throw(GIT_ERROR, "Failed to read unmerged entries"); - - size -= len; - buffer += len; - } - - for (i = 0; i < 3; i++) { - if (!lost->mode[i]) - continue; - if (size < 20) - return git__throw(GIT_ERROR, "Failed to read unmerged entries"); - git_oid_fromraw(&lost->oid[i], (const unsigned char *) buffer); - size -= 20; - buffer += 20; - } - } - - return GIT_SUCCESS; -} - -static size_t read_entry(git_index_entry *dest, const void *buffer, size_t buffer_size) -{ - size_t path_length, entry_size; - uint16_t flags_raw; - const char *path_ptr; - const struct entry_short *source = buffer; - - if (INDEX_FOOTER_SIZE + minimal_entry_size > buffer_size) - return 0; - - memset(dest, 0x0, sizeof(git_index_entry)); - - dest->ctime.seconds = (git_time_t)ntohl(source->ctime.seconds); - dest->ctime.nanoseconds = ntohl(source->ctime.nanoseconds); - dest->mtime.seconds = (git_time_t)ntohl(source->mtime.seconds); - dest->mtime.nanoseconds = ntohl(source->mtime.nanoseconds); - dest->dev = ntohl(source->dev); - dest->ino = ntohl(source->ino); - dest->mode = ntohl(source->mode); - dest->uid = ntohl(source->uid); - dest->gid = ntohl(source->gid); - dest->file_size = ntohl(source->file_size); - git_oid_cpy(&dest->oid, &source->oid); - dest->flags = ntohs(source->flags); - - if (dest->flags & GIT_IDXENTRY_EXTENDED) { - const struct entry_long *source_l = (const struct entry_long *)source; - path_ptr = source_l->path; - - flags_raw = ntohs(source_l->flags_extended); - memcpy(&dest->flags_extended, &flags_raw, 2); - } else - path_ptr = source->path; - - path_length = dest->flags & GIT_IDXENTRY_NAMEMASK; - - /* if this is a very long string, we must find its - * real length without overflowing */ - if (path_length == 0xFFF) { - const char *path_end; - - path_end = memchr(path_ptr, '\0', buffer_size); - if (path_end == NULL) - return 0; - - path_length = path_end - path_ptr; - } - - if (dest->flags & GIT_IDXENTRY_EXTENDED) - entry_size = long_entry_size(path_length); - else - entry_size = short_entry_size(path_length); - - if (INDEX_FOOTER_SIZE + entry_size > buffer_size) - return 0; - - dest->path = git__strdup(path_ptr); - assert(dest->path); - - return entry_size; -} - -static int read_header(struct index_header *dest, const void *buffer) -{ - const struct index_header *source = buffer; - - dest->signature = ntohl(source->signature); - if (dest->signature != INDEX_HEADER_SIG) - return GIT_EOBJCORRUPTED; - - dest->version = ntohl(source->version); - if (dest->version != INDEX_VERSION_NUMBER_EXT && - dest->version != INDEX_VERSION_NUMBER) - return GIT_EOBJCORRUPTED; - - dest->entry_count = ntohl(source->entry_count); - return GIT_SUCCESS; -} - -static size_t read_extension(git_index *index, const char *buffer, size_t buffer_size) -{ - const struct index_extension *source; - struct index_extension dest; - size_t total_size; - - source = (const struct index_extension *)(buffer); - - memcpy(dest.signature, source->signature, 4); - dest.extension_size = ntohl(source->extension_size); - - total_size = dest.extension_size + sizeof(struct index_extension); - - if (buffer_size - total_size < INDEX_FOOTER_SIZE) - return 0; - - /* optional extension */ - if (dest.signature[0] >= 'A' && dest.signature[0] <= 'Z') { - /* tree cache */ - if (memcmp(dest.signature, INDEX_EXT_TREECACHE_SIG, 4) == 0) { - if (read_tree(index, buffer + 8, dest.extension_size) < GIT_SUCCESS) - return 0; - } else if (memcmp(dest.signature, INDEX_EXT_UNMERGED_SIG, 4) == 0) { - if (read_unmerged(index, buffer + 8, dest.extension_size) < GIT_SUCCESS) - return 0; - } - /* else, unsupported extension. We cannot parse this, but we can skip - * it by returning `total_size */ - } else { - /* we cannot handle non-ignorable extensions; - * in fact they aren't even defined in the standard */ - return 0; - } - - return total_size; -} - -static int parse_index(git_index *index, const char *buffer, size_t buffer_size) -{ - unsigned int i; - struct index_header header; - git_oid checksum_calculated, checksum_expected; - -#define seek_forward(_increase) { \ - if (_increase >= buffer_size) \ - return git__throw(GIT_EOBJCORRUPTED, "Failed to seek forward. Buffer size exceeded"); \ - buffer += _increase; \ - buffer_size -= _increase;\ -} - - if (buffer_size < INDEX_HEADER_SIZE + INDEX_FOOTER_SIZE) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse index. Buffer too small"); - - /* Precalculate the SHA1 of the files's contents -- we'll match it to - * the provided SHA1 in the footer */ - git_hash_buf(&checksum_calculated, buffer, buffer_size - INDEX_FOOTER_SIZE); - - /* Parse header */ - if (read_header(&header, buffer) < GIT_SUCCESS) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse index. Header is corrupted"); - - seek_forward(INDEX_HEADER_SIZE); - - git_vector_clear(&index->entries); - - /* Parse all the entries */ - for (i = 0; i < header.entry_count && buffer_size > INDEX_FOOTER_SIZE; ++i) { - size_t entry_size; - git_index_entry *entry; - - entry = git__malloc(sizeof(git_index_entry)); - if (entry == NULL) - return GIT_ENOMEM; - - entry_size = read_entry(entry, buffer, buffer_size); - - /* 0 bytes read means an object corruption */ - if (entry_size == 0) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse index. Entry size is zero"); - - if (git_vector_insert(&index->entries, entry) < GIT_SUCCESS) - return GIT_ENOMEM; - - seek_forward(entry_size); - } - - if (i != header.entry_count) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse index. Header entries changed while parsing"); - - /* There's still space for some extensions! */ - while (buffer_size > INDEX_FOOTER_SIZE) { - size_t extension_size; - - extension_size = read_extension(index, buffer, buffer_size); - - /* see if we have read any bytes from the extension */ - if (extension_size == 0) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse index. Extension size is zero"); - - seek_forward(extension_size); - } - - if (buffer_size != INDEX_FOOTER_SIZE) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse index. Buffer size does not match index footer size"); - - /* 160-bit SHA-1 over the content of the index file before this checksum. */ - git_oid_fromraw(&checksum_expected, (const unsigned char *)buffer); - - if (git_oid_cmp(&checksum_calculated, &checksum_expected) != 0) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse index. Calculated checksum does not match expected checksum"); - -#undef seek_forward - - /* force sorting in the vector: the entries are - * assured to be sorted on the index */ - index->entries.sorted = 1; - return GIT_SUCCESS; -} - -static int is_index_extended(git_index *index) -{ - unsigned int i, extended; - - extended = 0; - - for (i = 0; i < index->entries.length; ++i) { - git_index_entry *entry; - entry = git_vector_get(&index->entries, i); - entry->flags &= ~GIT_IDXENTRY_EXTENDED; - if (entry->flags_extended & GIT_IDXENTRY_EXTENDED_FLAGS) { - extended++; - entry->flags |= GIT_IDXENTRY_EXTENDED; - } - } - return extended; -} - -static int write_disk_entry(git_filebuf *file, git_index_entry *entry) -{ - struct entry_short *ondisk; - size_t path_len, disk_size; - char *path; - - path_len = strlen(entry->path); - - if (entry->flags & GIT_IDXENTRY_EXTENDED) - disk_size = long_entry_size(path_len); - else - disk_size = short_entry_size(path_len); - - if (git_filebuf_reserve(file, (void **)&ondisk, disk_size) < GIT_SUCCESS) - return GIT_ENOMEM; - - memset(ondisk, 0x0, disk_size); - - /** - * Yes, we have to truncate. - * - * The on-disk format for Index entries clearly defines - * the time and size fields to be 4 bytes each -- so even if - * we store these values with 8 bytes on-memory, they must - * be truncated to 4 bytes before writing to disk. - * - * In 2038 I will be either too dead or too rich to care about this - */ - ondisk->ctime.seconds = htonl((uint32_t)entry->ctime.seconds); - ondisk->mtime.seconds = htonl((uint32_t)entry->mtime.seconds); - ondisk->ctime.nanoseconds = htonl(entry->ctime.nanoseconds); - ondisk->mtime.nanoseconds = htonl(entry->mtime.nanoseconds); - ondisk->dev = htonl(entry->dev); - ondisk->ino = htonl(entry->ino); - ondisk->mode = htonl(entry->mode); - ondisk->uid = htonl(entry->uid); - ondisk->gid = htonl(entry->gid); - ondisk->file_size = htonl((uint32_t)entry->file_size); - - git_oid_cpy(&ondisk->oid, &entry->oid); - - ondisk->flags = htons(entry->flags); - - if (entry->flags & GIT_IDXENTRY_EXTENDED) { - struct entry_long *ondisk_ext; - ondisk_ext = (struct entry_long *)ondisk; - ondisk_ext->flags_extended = htons(entry->flags_extended); - path = ondisk_ext->path; - } - else - path = ondisk->path; - - memcpy(path, entry->path, path_len); - - return GIT_SUCCESS; -} - -static int write_entries(git_index *index, git_filebuf *file) -{ - unsigned int i; - - for (i = 0; i < index->entries.length; ++i) { - git_index_entry *entry; - entry = git_vector_get(&index->entries, i); - if (write_disk_entry(file, entry) < GIT_SUCCESS) - return GIT_ENOMEM; - } - - return GIT_SUCCESS; -} - -static int write_index(git_index *index, git_filebuf *file) -{ - int error = GIT_SUCCESS; - git_oid hash_final; - - struct index_header header; - - int is_extended; - - assert(index && file); - - is_extended = is_index_extended(index); - - header.signature = htonl(INDEX_HEADER_SIG); - header.version = htonl(is_extended ? INDEX_VERSION_NUMBER_EXT : INDEX_VERSION_NUMBER); - header.entry_count = htonl(index->entries.length); - - git_filebuf_write(file, &header, sizeof(struct index_header)); - - error = write_entries(index, file); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to write index"); - - /* TODO: write extensions (tree cache) */ - - /* get out the hash for all the contents we've appended to the file */ - git_filebuf_hash(&hash_final, file); - - /* write it at the end of the file */ - git_filebuf_write(file, hash_final.id, GIT_OID_RAWSZ); - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to write index"); -} - -int git_index_entry_stage(const git_index_entry *entry) -{ - return (entry->flags & GIT_IDXENTRY_STAGEMASK) >> GIT_IDXENTRY_STAGESHIFT; -} diff --git a/vendor/libgit2/src/index.h b/vendor/libgit2/src/index.h deleted file mode 100644 index f2402fd71..000000000 --- a/vendor/libgit2/src/index.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef INCLUDE_index_h__ -#define INCLUDE_index_h__ - -#include "fileops.h" -#include "filebuf.h" -#include "vector.h" -#include "git2/odb.h" -#include "git2/index.h" - -struct git_index_tree { - char *name; - - struct git_index_tree *parent; - struct git_index_tree **children; - size_t children_count; - - size_t entries; - git_oid oid; -}; - -typedef struct git_index_tree git_index_tree; - -struct git_index { - git_repository *repository; - char *index_file_path; - - time_t last_modified; - git_vector entries; - - unsigned int on_disk:1; - git_index_tree *tree; - - git_vector unmerged; -}; - -#endif diff --git a/vendor/libgit2/src/indexer.c b/vendor/libgit2/src/indexer.c deleted file mode 100644 index 3934250e2..000000000 --- a/vendor/libgit2/src/indexer.c +++ /dev/null @@ -1,415 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "git2/indexer.h" -#include "git2/object.h" -#include "git2/zlib.h" -#include "git2/oid.h" - -#include "common.h" -#include "pack.h" -#include "mwindow.h" -#include "posix.h" -#include "pack.h" -#include "filebuf.h" -#include "sha1.h" - -#define UINT31_MAX (0x7FFFFFFF) - -struct entry { - git_oid oid; - uint32_t crc; - uint32_t offset; - uint64_t offset_long; -}; - -struct git_indexer { - struct git_pack_file *pack; - struct stat st; - struct git_pack_header hdr; - size_t nr_objects; - git_vector objects; - git_filebuf file; - unsigned int fanout[256]; - git_oid hash; -}; - -const git_oid *git_indexer_hash(git_indexer *idx) -{ - return &idx->hash; -} - -static int parse_header(git_indexer *idx) -{ - int error; - - /* Verify we recognize this pack file format. */ - if ((error = p_read(idx->pack->mwf.fd, &idx->hdr, sizeof(idx->hdr))) < GIT_SUCCESS) - return git__rethrow(error, "Failed to read in pack header"); - - if (idx->hdr.hdr_signature != ntohl(PACK_SIGNATURE)) - return git__throw(GIT_EOBJCORRUPTED, "Wrong pack signature"); - - if (!pack_version_ok(idx->hdr.hdr_version)) - return git__throw(GIT_EOBJCORRUPTED, "Wrong pack version"); - - - return GIT_SUCCESS; -} - -static int objects_cmp(const void *a, const void *b) -{ - const struct entry *entrya = a; - const struct entry *entryb = b; - - return git_oid_cmp(&entrya->oid, &entryb->oid); -} - -static int cache_cmp(const void *a, const void *b) -{ - const struct git_pack_entry *ea = a; - const struct git_pack_entry *eb = b; - - return git_oid_cmp(&ea->sha1, &eb->sha1); -} - - -int git_indexer_new(git_indexer **out, const char *packname) -{ - git_indexer *idx; - unsigned int namelen; - int ret, error; - - assert(out && packname); - - if (git_path_root(packname) < 0) - return git__throw(GIT_EINVALIDPATH, "Path is not absolute"); - - idx = git__malloc(sizeof(git_indexer)); - if (idx == NULL) - return GIT_ENOMEM; - - memset(idx, 0x0, sizeof(*idx)); - - namelen = strlen(packname); - idx->pack = git__malloc(sizeof(struct git_pack_file) + namelen + 1); - if (idx->pack == NULL) { - error = GIT_ENOMEM; - goto cleanup; - } - - memset(idx->pack, 0x0, sizeof(struct git_pack_file)); - memcpy(idx->pack->pack_name, packname, namelen + 1); - - ret = p_stat(packname, &idx->st); - if (ret < 0) { - if (errno == ENOENT) - error = git__throw(GIT_ENOTFOUND, "Failed to stat packfile. File not found"); - else - error = git__throw(GIT_EOSERR, "Failed to stat packfile."); - - goto cleanup; - } - - ret = p_open(idx->pack->pack_name, O_RDONLY); - if (ret < 0) { - error = git__throw(GIT_EOSERR, "Failed to open packfile"); - goto cleanup; - } - - idx->pack->mwf.fd = ret; - idx->pack->mwf.size = (git_off_t)idx->st.st_size; - - error = parse_header(idx); - if (error < GIT_SUCCESS) { - error = git__rethrow(error, "Failed to parse packfile header"); - goto cleanup; - } - - idx->nr_objects = ntohl(idx->hdr.hdr_entries); - - error = git_vector_init(&idx->pack->cache, idx->nr_objects, cache_cmp); - if (error < GIT_SUCCESS) - goto cleanup; - - idx->pack->has_cache = 1; - error = git_vector_init(&idx->objects, idx->nr_objects, objects_cmp); - if (error < GIT_SUCCESS) - goto cleanup; - - *out = idx; - - return GIT_SUCCESS; - -cleanup: - git_indexer_free(idx); - - return error; -} - -static void index_path(char *path, git_indexer *idx) -{ - char *ptr; - const char prefix[] = "pack-", suffix[] = ".idx\0"; - - ptr = strrchr(path, '/') + 1; - - memcpy(ptr, prefix, strlen(prefix)); - ptr += strlen(prefix); - git_oid_fmt(ptr, &idx->hash); - ptr += GIT_OID_HEXSZ; - memcpy(ptr, suffix, strlen(suffix)); -} - -int git_indexer_write(git_indexer *idx) -{ - git_mwindow *w = NULL; - int error, namelen; - unsigned int i, long_offsets = 0, left; - struct git_pack_idx_header hdr; - char filename[GIT_PATH_MAX]; - struct entry *entry; - void *packfile_hash; - git_oid file_hash; - SHA_CTX ctx; - - git_vector_sort(&idx->objects); - - namelen = strlen(idx->pack->pack_name); - memcpy(filename, idx->pack->pack_name, namelen); - memcpy(filename + namelen - strlen("pack"), "idx", strlen("idx") + 1); - - error = git_filebuf_open(&idx->file, filename, GIT_FILEBUF_HASH_CONTENTS); - - /* Write out the header */ - hdr.idx_signature = htonl(PACK_IDX_SIGNATURE); - hdr.idx_version = htonl(2); - error = git_filebuf_write(&idx->file, &hdr, sizeof(hdr)); - - /* Write out the fanout table */ - for (i = 0; i < 256; ++i) { - uint32_t n = htonl(idx->fanout[i]); - error = git_filebuf_write(&idx->file, &n, sizeof(n)); - if (error < GIT_SUCCESS) - goto cleanup; - } - - /* Write out the object names (SHA-1 hashes) */ - SHA1_Init(&ctx); - git_vector_foreach(&idx->objects, i, entry) { - error = git_filebuf_write(&idx->file, &entry->oid, sizeof(git_oid)); - SHA1_Update(&ctx, &entry->oid, GIT_OID_RAWSZ); - if (error < GIT_SUCCESS) - goto cleanup; - } - SHA1_Final(idx->hash.id, &ctx); - - /* Write out the CRC32 values */ - git_vector_foreach(&idx->objects, i, entry) { - error = git_filebuf_write(&idx->file, &entry->crc, sizeof(uint32_t)); - if (error < GIT_SUCCESS) - goto cleanup; - } - - /* Write out the offsets */ - git_vector_foreach(&idx->objects, i, entry) { - uint32_t n; - - if (entry->offset == UINT32_MAX) - n = htonl(0x80000000 | long_offsets++); - else - n = htonl(entry->offset); - - error = git_filebuf_write(&idx->file, &n, sizeof(uint32_t)); - if (error < GIT_SUCCESS) - goto cleanup; - } - - /* Write out the long offsets */ - git_vector_foreach(&idx->objects, i, entry) { - uint32_t split[2]; - - if (entry->offset != UINT32_MAX) - continue; - - split[0] = htonl(entry->offset_long >> 32); - split[1] = htonl(entry->offset_long & 0xffffffff); - - error = git_filebuf_write(&idx->file, &split, sizeof(uint32_t) * 2); - if (error < GIT_SUCCESS) - goto cleanup; - } - - /* Write out the packfile trailer */ - - packfile_hash = git_mwindow_open(&idx->pack->mwf, &w, idx->st.st_size - GIT_OID_RAWSZ, GIT_OID_RAWSZ, &left); - git_mwindow_close(&w); - if (packfile_hash == NULL) { - error = git__rethrow(GIT_ENOMEM, "Failed to open window to packfile hash"); - goto cleanup; - } - - memcpy(&file_hash, packfile_hash, GIT_OID_RAWSZ); - - git_mwindow_close(&w); - - error = git_filebuf_write(&idx->file, &file_hash, sizeof(git_oid)); - - /* Write out the index sha */ - error = git_filebuf_hash(&file_hash, &idx->file); - if (error < GIT_SUCCESS) - goto cleanup; - - error = git_filebuf_write(&idx->file, &file_hash, sizeof(git_oid)); - if (error < GIT_SUCCESS) - goto cleanup; - - /* Figure out what the final name should be */ - index_path(filename, idx); - /* Commit file */ - error = git_filebuf_commit_at(&idx->file, filename); - -cleanup: - git_mwindow_free_all(&idx->pack->mwf); - if (error < GIT_SUCCESS) - git_filebuf_cleanup(&idx->file); - - return error; -} - -int git_indexer_run(git_indexer *idx, git_indexer_stats *stats) -{ - git_mwindow_file *mwf; - off_t off = sizeof(struct git_pack_header); - int error; - struct entry *entry; - unsigned int left, processed; - - assert(idx && stats); - - mwf = &idx->pack->mwf; - error = git_mwindow_file_register(mwf); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to register mwindow file"); - - stats->total = idx->nr_objects; - stats->processed = processed = 0; - - while (processed < idx->nr_objects) { - git_rawobj obj; - git_oid oid; - struct git_pack_entry *pentry; - git_mwindow *w = NULL; - int i; - off_t entry_start = off; - void *packed; - size_t entry_size; - - entry = git__malloc(sizeof(struct entry)); - memset(entry, 0x0, sizeof(struct entry)); - - if (off > UINT31_MAX) { - entry->offset = UINT32_MAX; - entry->offset_long = off; - } else { - entry->offset = off; - } - - error = git_packfile_unpack(&obj, idx->pack, &off); - if (error < GIT_SUCCESS) { - error = git__rethrow(error, "Failed to unpack object"); - goto cleanup; - } - - /* FIXME: Parse the object instead of hashing it */ - error = git_odb__hash_obj(&oid, &obj); - if (error < GIT_SUCCESS) { - error = git__rethrow(error, "Failed to hash object"); - goto cleanup; - } - - pentry = git__malloc(sizeof(struct git_pack_entry)); - if (pentry == NULL) { - error = GIT_ENOMEM; - goto cleanup; - } - git_oid_cpy(&pentry->sha1, &oid); - pentry->offset = entry_start; - error = git_vector_insert(&idx->pack->cache, pentry); - if (error < GIT_SUCCESS) - goto cleanup; - - git_oid_cpy(&entry->oid, &oid); - entry->crc = crc32(0L, Z_NULL, 0); - - entry_size = off - entry_start; - packed = git_mwindow_open(mwf, &w, entry_start, entry_size, &left); - if (packed == NULL) { - error = git__rethrow(error, "Failed to open window to read packed data"); - goto cleanup; - } - entry->crc = htonl(crc32(entry->crc, packed, entry_size)); - git_mwindow_close(&w); - - /* Add the object to the list */ - error = git_vector_insert(&idx->objects, entry); - if (error < GIT_SUCCESS) { - error = git__rethrow(error, "Failed to add entry to list"); - goto cleanup; - } - - for (i = oid.id[0]; i < 256; ++i) { - idx->fanout[i]++; - } - - free(obj.data); - - stats->processed = ++processed; - } - -cleanup: - git_mwindow_free_all(mwf); - - return error; - -} - -void git_indexer_free(git_indexer *idx) -{ - unsigned int i; - struct entry *e; - struct git_pack_entry *pe; - - p_close(idx->pack->mwf.fd); - git_vector_foreach(&idx->objects, i, e) - free(e); - git_vector_free(&idx->objects); - git_vector_foreach(&idx->pack->cache, i, pe) - free(pe); - git_vector_free(&idx->pack->cache); - free(idx->pack); - free(idx); -} - diff --git a/vendor/libgit2/src/map.h b/vendor/libgit2/src/map.h deleted file mode 100644 index 1dfbeeb4b..000000000 --- a/vendor/libgit2/src/map.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef INCLUDE_map_h__ -#define INCLUDE_map_h__ - -#include "common.h" - - -/* p_mmap() prot values */ -#define GIT_PROT_NONE 0x0 -#define GIT_PROT_READ 0x1 -#define GIT_PROT_WRITE 0x2 -#define GIT_PROT_EXEC 0x4 - -/* git__mmmap() flags values */ -#define GIT_MAP_FILE 0 -#define GIT_MAP_SHARED 1 -#define GIT_MAP_PRIVATE 2 -#define GIT_MAP_TYPE 0xf -#define GIT_MAP_FIXED 0x10 - -typedef struct { /* memory mapped buffer */ - void *data; /* data bytes */ - size_t len; /* data length */ -#ifdef GIT_WIN32 - HANDLE fmh; /* file mapping handle */ -#endif -} git_map; - -extern int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset); -extern int p_munmap(git_map *map); - -#endif /* INCLUDE_map_h__ */ diff --git a/vendor/libgit2/src/mingw-compat.h b/vendor/libgit2/src/mingw-compat.h deleted file mode 100644 index b7919c2e8..000000000 --- a/vendor/libgit2/src/mingw-compat.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef INCLUDE_mingw_compat__ -#define INCLUDE_mingw_compat__ - -#if defined(__MINGW32__) - -/* use a 64-bit file offset type */ -# define lseek _lseeki64 -# define stat _stati64 -# define fstat _fstati64 - -#endif - -#endif /* INCLUDE_mingw_compat__ */ diff --git a/vendor/libgit2/src/msvc-compat.h b/vendor/libgit2/src/msvc-compat.h deleted file mode 100644 index d4c031d2d..000000000 --- a/vendor/libgit2/src/msvc-compat.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef INCLUDE_msvc_compat__ -#define INCLUDE_msvc_compat__ - -#if defined(_MSC_VER) - -/* access() mode parameter #defines */ -# define F_OK 0 /* existence check */ -# define W_OK 2 /* write mode check */ -# define R_OK 4 /* read mode check */ - -# define lseek _lseeki64 -# define stat _stat64 -# define fstat _fstat64 - -/* stat: file mode type testing macros */ -# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) -# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) -# define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO) - -#if (_MSC_VER >= 1600) -# include -#else -/* add some missing typedef's */ -typedef signed char int8_t; -typedef unsigned char uint8_t; - -typedef short int16_t; -typedef unsigned short uint16_t; - -typedef long int32_t; -typedef unsigned long uint32_t; - -typedef long long int64_t; -typedef unsigned long long uint64_t; - -typedef long long intmax_t; -typedef unsigned long long uintmax_t; -#endif - -#endif - -#endif /* INCLUDE_msvc_compat__ */ diff --git a/vendor/libgit2/src/mwindow.c b/vendor/libgit2/src/mwindow.c deleted file mode 100644 index 585d75c12..000000000 --- a/vendor/libgit2/src/mwindow.c +++ /dev/null @@ -1,275 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "mwindow.h" -#include "vector.h" -#include "fileops.h" -#include "map.h" - -#define DEFAULT_WINDOW_SIZE \ - (sizeof(void*) >= 8 \ - ? 1 * 1024 * 1024 * 1024 \ - : 32 * 1024 * 1024) - -#define DEFAULT_MAPPED_LIMIT \ - ((1024L * 1024L) * (sizeof(void*) >= 8 ? 8192 : 256)) - -/* - * We need this because each process is only allowed a specific amount - * of memory. Making it writable should generate one instance per - * process, but we still need to set a couple of variables. - */ - -static git_mwindow_ctl ctl = { - 0, - 0, - DEFAULT_WINDOW_SIZE, - DEFAULT_MAPPED_LIMIT, - 0, - 0, - 0, - 0, - {0, 0, 0, 0, 0} -}; - -/* - * Free all the windows in a sequence, typically because we're done - * with the file - */ -void git_mwindow_free_all(git_mwindow_file *mwf) -{ - unsigned int i; - /* - * Remove these windows from the global list - */ - for (i = 0; i < ctl.windowfiles.length; ++i){ - if (git_vector_get(&ctl.windowfiles, i) == mwf) { - git_vector_remove(&ctl.windowfiles, i); - break; - } - } - - if (ctl.windowfiles.length == 0) { - git_vector_free(&ctl.windowfiles); - ctl.windowfiles.contents = NULL; - } - - while (mwf->windows) { - git_mwindow *w = mwf->windows; - assert(w->inuse_cnt == 0); - - ctl.mapped -= w->window_map.len; - ctl.open_windows--; - - git_futils_mmap_free(&w->window_map); - - mwf->windows = w->next; - free(w); - } -} - -/* - * Check if a window 'win' contains the address 'offset' - */ -int git_mwindow_contains(git_mwindow *win, git_off_t offset) -{ - git_off_t win_off = win->offset; - return win_off <= offset - && offset <= (git_off_t)(win_off + win->window_map.len); -} - -/* - * Find the least-recently-used window in a file - */ -void git_mwindow_scan_lru( - git_mwindow_file *mwf, - git_mwindow **lru_w, - git_mwindow **lru_l) -{ - git_mwindow *w, *w_l; - - for (w_l = NULL, w = mwf->windows; w; w = w->next) { - if (!w->inuse_cnt) { - /* - * If the current one is more recent than the last one, - * store it in the output parameter. If lru_w is NULL, - * it's the first loop, so store it as well. - */ - if (!*lru_w || w->last_used < (*lru_w)->last_used) { - *lru_w = w; - *lru_l = w_l; - } - } - w_l = w; - } -} - -/* - * Close the least recently used window. You should check to see if - * the file descriptors need closing from time to time. - */ -int git_mwindow_close_lru(git_mwindow_file *mwf) -{ - unsigned int i; - git_mwindow *lru_w = NULL, *lru_l = NULL; - - /* FIMXE: Does this give us any advantage? */ - if(mwf->windows) - git_mwindow_scan_lru(mwf, &lru_w, &lru_l); - - for (i = 0; i < ctl.windowfiles.length; ++i) { - git_mwindow_scan_lru(git_vector_get(&ctl.windowfiles, i), &lru_w, &lru_l); - } - - if (lru_w) { - git_mwindow_close(&lru_w); - ctl.mapped -= lru_w->window_map.len; - git_futils_mmap_free(&lru_w->window_map); - - if (lru_l) - lru_l->next = lru_w->next; - else - mwf->windows = lru_w->next; - - free(lru_w); - ctl.open_windows--; - - return GIT_SUCCESS; - } - - return git__throw(GIT_ERROR, "Failed to close memory window. Couln't find LRU"); -} - -static git_mwindow *new_window(git_mwindow_file *mwf, git_file fd, git_off_t size, git_off_t offset) -{ - size_t walign = ctl.window_size / 2; - git_off_t len; - git_mwindow *w; - - w = git__malloc(sizeof(*w)); - if (w == NULL) - return w; - - memset(w, 0x0, sizeof(*w)); - w->offset = (offset / walign) * walign; - - len = size - w->offset; - if (len > (git_off_t)ctl.window_size) - len = (git_off_t)ctl.window_size; - - ctl.mapped += (size_t)len; - - while(ctl.mapped_limit < ctl.mapped && - git_mwindow_close_lru(mwf) == GIT_SUCCESS) {} - - /* FIXME: Shouldn't we error out if there's an error in closing lru? */ - - if (git_futils_mmap_ro(&w->window_map, fd, w->offset, (size_t)len) < GIT_SUCCESS) - goto cleanup; - - ctl.mmap_calls++; - ctl.open_windows++; - - if (ctl.mapped > ctl.peak_mapped) - ctl.peak_mapped = ctl.mapped; - - if (ctl.open_windows > ctl.peak_open_windows) - ctl.peak_open_windows = ctl.open_windows; - - return w; - -cleanup: - free(w); - return NULL; -} - -/* - * Open a new window, closing the least recenty used until we have - * enough space. Don't forget to add it to your list - */ -unsigned char *git_mwindow_open(git_mwindow_file *mwf, git_mwindow **cursor, - git_off_t offset, int extra, unsigned int *left) -{ - git_mwindow *w = *cursor; - - if (!w || !git_mwindow_contains(w, offset + extra)) { - if (w) { - w->inuse_cnt--; - } - - for (w = mwf->windows; w; w = w->next) { - if (git_mwindow_contains(w, offset + extra)) - break; - } - - /* - * If there isn't a suitable window, we need to create a new - * one. - */ - if (!w) { - w = new_window(mwf, mwf->fd, mwf->size, offset); - if (w == NULL) - return NULL; - w->next = mwf->windows; - mwf->windows = w; - } - } - - /* If we changed w, store it in the cursor */ - if (w != *cursor) { - w->last_used = ctl.used_ctr++; - w->inuse_cnt++; - *cursor = w; - } - - offset -= w->offset; - assert(git__is_sizet(offset)); - - if (left) - *left = (unsigned int)(w->window_map.len - offset); - - return (unsigned char *) w->window_map.data + offset; -} - -int git_mwindow_file_register(git_mwindow_file *mwf) -{ - int error; - - if (ctl.windowfiles.length == 0 && - (error = git_vector_init(&ctl.windowfiles, 8, NULL)) < GIT_SUCCESS) - return error; - - return git_vector_insert(&ctl.windowfiles, mwf); -} - -void git_mwindow_close(git_mwindow **window) -{ - git_mwindow *w = *window; - if (w) { - w->inuse_cnt--; - *window = NULL; - } -} diff --git a/vendor/libgit2/src/mwindow.h b/vendor/libgit2/src/mwindow.h deleted file mode 100644 index 1d4a58453..000000000 --- a/vendor/libgit2/src/mwindow.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDE_mwindow__ -#define INCLUDE_mwindow__ - -#include "map.h" -#include "vector.h" -#include "fileops.h" - -typedef struct git_mwindow { - struct git_mwindow *next; - git_map window_map; - git_off_t offset; - unsigned int last_used; - unsigned int inuse_cnt; -} git_mwindow; - -typedef struct git_mwindow_file { - git_mwindow *windows; - int fd; - git_off_t size; -} git_mwindow_file; - -typedef struct git_mwindow_ctl { - size_t mapped; - unsigned int open_windows; - size_t window_size; /* needs default value */ - size_t mapped_limit; /* needs default value */ - unsigned int mmap_calls; - unsigned int peak_open_windows; - size_t peak_mapped; - size_t used_ctr; - git_vector windowfiles; -} git_mwindow_ctl; - -int git_mwindow_contains(git_mwindow *win, git_off_t offset); -void git_mwindow_free_all(git_mwindow_file *mwf); -unsigned char *git_mwindow_open(git_mwindow_file *mwf, git_mwindow **cursor, git_off_t offset, int extra, unsigned int *left); -void git_mwindow_scan_lru(git_mwindow_file *mwf, git_mwindow **lru_w, git_mwindow **lru_l); -int git_mwindow_file_register(git_mwindow_file *mwf); -void git_mwindow_close(git_mwindow **w_cursor); - -#endif diff --git a/vendor/libgit2/src/netops.c b/vendor/libgit2/src/netops.c deleted file mode 100644 index b5251925e..000000000 --- a/vendor/libgit2/src/netops.c +++ /dev/null @@ -1,163 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef _WIN32 -# include -# include -# include -# include -#else -# define _WIN32_WINNT 0x0501 -# include -# include -# pragma comment(lib, "Ws2_32.lib") -#endif - -#include "git2/errors.h" - -#include "common.h" -#include "netops.h" - -void gitno_buffer_setup(gitno_buffer *buf, char *data, unsigned int len, int fd) -{ - memset(buf, 0x0, sizeof(gitno_buffer)); - memset(data, 0x0, len); - buf->data = data; - buf->len = len - 1; - buf->offset = 0; - buf->fd = fd; -} - -int gitno_recv(gitno_buffer *buf) -{ - int ret; - - ret = recv(buf->fd, buf->data + buf->offset, buf->len - buf->offset, 0); - if (ret < 0) - return git__throw(GIT_EOSERR, "Failed to receive data: %s", strerror(errno)); - if (ret == 0) /* Orderly shutdown, so exit */ - return GIT_SUCCESS; - - buf->offset += ret; - - return ret; -} - -/* Consume up to ptr and move the rest of the buffer to the beginning */ -void gitno_consume(gitno_buffer *buf, const char *ptr) -{ - size_t consumed; - - assert(ptr - buf->data >= 0); - assert(ptr - buf->data <= (int) buf->len); - - consumed = ptr - buf->data; - - memmove(buf->data, ptr, buf->offset - consumed); - memset(buf->data + buf->offset, 0x0, buf->len - buf->offset); - buf->offset -= consumed; -} - -/* Consume const bytes and move the rest of the buffer to the beginning */ -void gitno_consume_n(gitno_buffer *buf, size_t cons) -{ - memmove(buf->data, buf->data + cons, buf->len - buf->offset); - memset(buf->data + cons, 0x0, buf->len - buf->offset); - buf->offset -= cons; -} - -int gitno_connect(const char *host, const char *port) -{ - struct addrinfo *info, *p; - struct addrinfo hints; - int ret, error = GIT_SUCCESS; - int s; - - memset(&hints, 0x0, sizeof(struct addrinfo)); - hints.ai_family = AF_UNSPEC; - hints.ai_socktype = SOCK_STREAM; - - ret = getaddrinfo(host, port, &hints, &info); - if (ret != 0) { - error = GIT_EOSERR; - goto cleanup; - } - - for (p = info; p != NULL; p = p->ai_next) { - s = socket(p->ai_family, p->ai_socktype, p->ai_protocol); - if (s < 0) { - error = GIT_EOSERR; - goto cleanup; - } - - ret = connect(s, p->ai_addr, p->ai_addrlen); - /* If we can't connect, try the next one */ - if (ret < 0) { - continue; - } - - /* Return the socket */ - error = s; - goto cleanup; - } - - /* Oops, we couldn't connect to any address */ - error = GIT_EOSERR; - -cleanup: - freeaddrinfo(info); - return error; -} - -int gitno_send(int s, const char *msg, size_t len, int flags) -{ - int ret; - size_t off = 0; - - while (off < len) { - ret = send(s, msg + off, len - off, flags); - if (ret < 0) - return GIT_EOSERR; - - off += ret; - } - - return off; -} - -int gitno_select_in(gitno_buffer *buf, long int sec, long int usec) -{ - fd_set fds; - struct timeval tv; - - tv.tv_sec = sec; - tv.tv_usec = usec; - - FD_ZERO(&fds); - FD_SET(buf->fd, &fds); - - /* The select(2) interface is silly */ - return select(buf->fd + 1, &fds, NULL, NULL, &tv); -} diff --git a/vendor/libgit2/src/netops.h b/vendor/libgit2/src/netops.h deleted file mode 100644 index c259ed2d6..000000000 --- a/vendor/libgit2/src/netops.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * netops.h - convencience functions for networking - */ -#ifndef INCLUDE_netops_h__ -#define INCLUDE_netops_h__ - -#ifndef GIT_WIN32 -typedef int GIT_SOCKET; -#else -typedef unsigned int GIT_SOCKET; -#endif - -typedef struct gitno_buffer { - char *data; - size_t len; - size_t offset; - GIT_SOCKET fd; -} gitno_buffer; - -void gitno_buffer_setup(gitno_buffer *buf, char *data, unsigned int len, int fd); -int gitno_recv(gitno_buffer *buf); -void gitno_consume(gitno_buffer *buf, const char *ptr); -void gitno_consume_n(gitno_buffer *buf, size_t cons); - -int gitno_connect(const char *host, const char *port); -int gitno_send(int s, const char *msg, size_t len, int flags); -int gitno_select_in(gitno_buffer *buf, long int sec, long int usec); - -#endif diff --git a/vendor/libgit2/src/object.c b/vendor/libgit2/src/object.c deleted file mode 100644 index 8b07197f1..000000000 --- a/vendor/libgit2/src/object.c +++ /dev/null @@ -1,302 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include - -#include "git2/object.h" - -#include "common.h" -#include "repository.h" - -#include "commit.h" -#include "tree.h" -#include "blob.h" -#include "tag.h" - -static const int OBJECT_BASE_SIZE = 4096; - -static struct { - const char *str; /* type name string */ - int loose; /* valid loose object type flag */ - size_t size; /* size in bytes of the object structure */ -} git_objects_table[] = { - /* 0 = GIT_OBJ__EXT1 */ - { "", 0, 0}, - - /* 1 = GIT_OBJ_COMMIT */ - { "commit", 1, sizeof(struct git_commit)}, - - /* 2 = GIT_OBJ_TREE */ - { "tree", 1, sizeof(struct git_tree) }, - - /* 3 = GIT_OBJ_BLOB */ - { "blob", 1, sizeof(struct git_blob) }, - - /* 4 = GIT_OBJ_TAG */ - { "tag", 1, sizeof(struct git_tag) }, - - /* 5 = GIT_OBJ__EXT2 */ - { "", 0, 0 }, - - /* 6 = GIT_OBJ_OFS_DELTA */ - { "OFS_DELTA", 0, 0 }, - - /* 7 = GIT_OBJ_REF_DELTA */ - { "REF_DELTA", 0, 0 } -}; - -static int create_object(git_object **object_out, git_otype type) -{ - git_object *object = NULL; - - assert(object_out); - - *object_out = NULL; - - switch (type) { - case GIT_OBJ_COMMIT: - case GIT_OBJ_TAG: - case GIT_OBJ_BLOB: - case GIT_OBJ_TREE: - object = git__malloc(git_object__size(type)); - if (object == NULL) - return GIT_ENOMEM; - memset(object, 0x0, git_object__size(type)); - break; - - default: - return git__throw(GIT_EINVALIDTYPE, "The given type is invalid"); - } - - object->type = type; - - *object_out = object; - return GIT_SUCCESS; -} - -int git_object_lookup_prefix(git_object **object_out, git_repository *repo, const git_oid *id, unsigned int len, git_otype type) -{ - git_object *object = NULL; - git_odb_object *odb_obj; - int error = GIT_SUCCESS; - - assert(repo && object_out && id); - - if (len < GIT_OID_MINPREFIXLEN) - return git__throw(GIT_EAMBIGUOUSOIDPREFIX, - "Failed to lookup object. Prefix length is lower than %d.", GIT_OID_MINPREFIXLEN); - - if (len > GIT_OID_HEXSZ) - len = GIT_OID_HEXSZ; - - if (len == GIT_OID_HEXSZ) { - /* We want to match the full id : we can first look up in the cache, - * since there is no need to check for non ambiguousity - */ - object = git_cache_get(&repo->objects, id); - if (object != NULL) { - if (type != GIT_OBJ_ANY && type != object->type) - { - git_object_close(object); - return git__throw(GIT_EINVALIDTYPE, "Failed to lookup object. The given type does not match the type on the ODB"); - } - - *object_out = object; - return GIT_SUCCESS; - } - - /* Object was not found in the cache, let's explore the backends. - * We could just use git_odb_read_unique_short_oid, - * it is the same cost for packed and loose object backends, - * but it may be much more costly for sqlite and hiredis. - */ - error = git_odb_read(&odb_obj, repo->db, id); - } else { - git_oid short_oid; - - /* We copy the first len*4 bits from id and fill the remaining with 0s */ - memcpy(short_oid.id, id->id, (len + 1) / 2); - if (len % 2) - short_oid.id[len / 2] &= 0xF0; - memset(short_oid.id + (len + 1) / 2, 0, (GIT_OID_HEXSZ - len) / 2); - - /* If len < GIT_OID_HEXSZ (a strict short oid was given), we have - * 2 options : - * - We always search in the cache first. If we find that short oid is - * ambiguous, we can stop. But in all the other cases, we must then - * explore all the backends (to find an object if there was match, - * or to check that oid is not ambiguous if we have found 1 match in - * the cache) - * - We never explore the cache, go right to exploring the backends - * We chose the latter : we explore directly the backends. - */ - error = git_odb_read_prefix(&odb_obj, repo->db, &short_oid, len); - } - - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to lookup object"); - - if (type != GIT_OBJ_ANY && type != odb_obj->raw.type) { - git_odb_object_close(odb_obj); - return git__throw(GIT_EINVALIDTYPE, "Failed to lookup object. The given type does not match the type on the ODB"); - } - - type = odb_obj->raw.type; - - if ((error = create_object(&object, type)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to lookup object"); - - /* Initialize parent object */ - git_oid_cpy(&object->cached.oid, &odb_obj->cached.oid); - object->repo = repo; - - switch (type) { - case GIT_OBJ_COMMIT: - error = git_commit__parse((git_commit *)object, odb_obj); - break; - - case GIT_OBJ_TREE: - error = git_tree__parse((git_tree *)object, odb_obj); - break; - - case GIT_OBJ_TAG: - error = git_tag__parse((git_tag *)object, odb_obj); - break; - - case GIT_OBJ_BLOB: - error = git_blob__parse((git_blob *)object, odb_obj); - break; - - default: - break; - } - - git_odb_object_close(odb_obj); - - if (error < GIT_SUCCESS) { - git_object__free(object); - return git__rethrow(error, "Failed to lookup object"); - } - - *object_out = git_cache_try_store(&repo->objects, object); - return GIT_SUCCESS; -} - -int git_object_lookup(git_object **object_out, git_repository *repo, const git_oid *id, git_otype type) { - return git_object_lookup_prefix(object_out, repo, id, GIT_OID_HEXSZ, type); -} - -void git_object__free(void *_obj) -{ - git_object *object = (git_object *)_obj; - - assert(object); - - switch (object->type) { - case GIT_OBJ_COMMIT: - git_commit__free((git_commit *)object); - break; - - case GIT_OBJ_TREE: - git_tree__free((git_tree *)object); - break; - - case GIT_OBJ_TAG: - git_tag__free((git_tag *)object); - break; - - case GIT_OBJ_BLOB: - git_blob__free((git_blob *)object); - break; - - default: - free(object); - break; - } -} - -void git_object_close(git_object *object) -{ - if (object == NULL) - return; - - git_cached_obj_decref((git_cached_obj *)object, git_object__free); -} - -const git_oid *git_object_id(const git_object *obj) -{ - assert(obj); - return &obj->cached.oid; -} - -git_otype git_object_type(const git_object *obj) -{ - assert(obj); - return obj->type; -} - -git_repository *git_object_owner(const git_object *obj) -{ - assert(obj); - return obj->repo; -} - -const char *git_object_type2string(git_otype type) -{ - if (type < 0 || ((size_t) type) >= ARRAY_SIZE(git_objects_table)) - return ""; - - return git_objects_table[type].str; -} - -git_otype git_object_string2type(const char *str) -{ - size_t i; - - if (!str || !*str) - return GIT_OBJ_BAD; - - for (i = 0; i < ARRAY_SIZE(git_objects_table); i++) - if (!strcmp(str, git_objects_table[i].str)) - return (git_otype)i; - - return GIT_OBJ_BAD; -} - -int git_object_typeisloose(git_otype type) -{ - if (type < 0 || ((size_t) type) >= ARRAY_SIZE(git_objects_table)) - return 0; - - return git_objects_table[type].loose; -} - -size_t git_object__size(git_otype type) -{ - if (type < 0 || ((size_t) type) >= ARRAY_SIZE(git_objects_table)) - return 0; - - return git_objects_table[type].size; -} - diff --git a/vendor/libgit2/src/odb.c b/vendor/libgit2/src/odb.c deleted file mode 100644 index ec81cdacb..000000000 --- a/vendor/libgit2/src/odb.c +++ /dev/null @@ -1,684 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "git2/zlib.h" -#include "git2/object.h" -#include "fileops.h" -#include "hash.h" -#include "odb.h" -#include "delta-apply.h" - -#include "git2/odb_backend.h" - -#define GIT_ALTERNATES_FILE "info/alternates" - -/* TODO: is this correct? */ -#define GIT_LOOSE_PRIORITY 2 -#define GIT_PACKED_PRIORITY 1 - -typedef struct -{ - git_odb_backend *backend; - int priority; - int is_alternate; -} backend_internal; - -static int format_object_header(char *hdr, size_t n, size_t obj_len, git_otype obj_type) -{ - const char *type_str = git_object_type2string(obj_type); - int len = p_snprintf(hdr, n, "%s %"PRIuZ, type_str, obj_len); - - if (len < 0 || ((size_t) len) >= n) - return git__throw(GIT_ERROR, "Cannot format object header. Length is out of bounds"); - - return len+1; -} - -int git_odb__hash_obj(git_oid *id, git_rawobj *obj) -{ - git_buf_vec vec[2]; - char header[64]; - int hdrlen; - - assert(id && obj); - - if (!git_object_typeisloose(obj->type)) - return git__throw(GIT_ERROR, "Failed to hash object. Wrong object type"); - - if (!obj->data && obj->len != 0) - return git__throw(GIT_ERROR, "Failed to hash object. No data given"); - - if ((hdrlen = format_object_header(header, sizeof(header), obj->len, obj->type)) < 0) - return git__rethrow(hdrlen, "Failed to hash object"); - - vec[0].data = header; - vec[0].len = hdrlen; - vec[1].data = obj->data; - vec[1].len = obj->len; - - git_hash_vec(id, vec, 2); - - return GIT_SUCCESS; -} - - -static git_odb_object *new_odb_object(const git_oid *oid, git_rawobj *source) -{ - git_odb_object *object = git__malloc(sizeof(git_odb_object)); - memset(object, 0x0, sizeof(git_odb_object)); - - git_oid_cpy(&object->cached.oid, oid); - memcpy(&object->raw, source, sizeof(git_rawobj)); - - return object; -} - -static void free_odb_object(void *o) -{ - git_odb_object *object = (git_odb_object *)o; - - if (object != NULL) { - free(object->raw.data); - free(object); - } -} - -const git_oid *git_odb_object_id(git_odb_object *object) -{ - return &object->cached.oid; -} - -const void *git_odb_object_data(git_odb_object *object) -{ - return object->raw.data; -} - -size_t git_odb_object_size(git_odb_object *object) -{ - return object->raw.len; -} - -git_otype git_odb_object_type(git_odb_object *object) -{ - return object->raw.type; -} - -void git_odb_object_close(git_odb_object *object) -{ - git_cached_obj_decref((git_cached_obj *)object, &free_odb_object); -} - -int git_odb_hashfile(git_oid *out, const char *path, git_otype type) -{ - int fd, hdr_len; - char hdr[64], buffer[2048]; - git_off_t size; - git_hash_ctx *ctx; - - if ((fd = p_open(path, O_RDONLY)) < 0) - return git__throw(GIT_ENOTFOUND, "Could not open '%s'", path); - - if ((size = git_futils_filesize(fd)) < 0 || !git__is_sizet(size)) { - p_close(fd); - return git__throw(GIT_EOSERR, "'%s' appears to be corrupted", path); - } - - hdr_len = format_object_header(hdr, sizeof(hdr), (size_t)size, type); - if (hdr_len < 0) - return git__throw(GIT_ERROR, "Failed to format blob header. Length is out of bounds"); - - ctx = git_hash_new_ctx(); - - git_hash_update(ctx, hdr, hdr_len); - - while (size > 0) { - ssize_t read_len; - - read_len = read(fd, buffer, sizeof(buffer)); - - if (read_len < 0) { - p_close(fd); - git_hash_free_ctx(ctx); - return git__throw(GIT_EOSERR, "Can't read full file '%s'", path); - } - - git_hash_update(ctx, buffer, read_len); - size -= read_len; - } - - p_close(fd); - - git_hash_final(out, ctx); - git_hash_free_ctx(ctx); - - return GIT_SUCCESS; -} - -int git_odb_hash(git_oid *id, const void *data, size_t len, git_otype type) -{ - git_rawobj raw; - - assert(id); - - raw.data = (void *)data; - raw.len = len; - raw.type = type; - - return git_odb__hash_obj(id, &raw); -} - -/** - * FAKE WSTREAM - */ - -typedef struct { - git_odb_stream stream; - char *buffer; - size_t size, written; - git_otype type; -} fake_wstream; - -static int fake_wstream__fwrite(git_oid *oid, git_odb_stream *_stream) -{ - fake_wstream *stream = (fake_wstream *)_stream; - return _stream->backend->write(oid, _stream->backend, stream->buffer, stream->size, stream->type); -} - -static int fake_wstream__write(git_odb_stream *_stream, const char *data, size_t len) -{ - fake_wstream *stream = (fake_wstream *)_stream; - - if (stream->written + len > stream->size) - return GIT_ENOMEM; - - memcpy(stream->buffer + stream->written, data, len); - stream->written += len; - return GIT_SUCCESS; -} - -static void fake_wstream__free(git_odb_stream *_stream) -{ - fake_wstream *stream = (fake_wstream *)_stream; - - free(stream->buffer); - free(stream); -} - -static int init_fake_wstream(git_odb_stream **stream_p, git_odb_backend *backend, size_t size, git_otype type) -{ - fake_wstream *stream; - - stream = git__calloc(1, sizeof(fake_wstream)); - if (stream == NULL) - return GIT_ENOMEM; - - stream->size = size; - stream->type = type; - stream->buffer = git__malloc(size); - if (stream->buffer == NULL) { - free(stream); - return GIT_ENOMEM; - } - - stream->stream.backend = backend; - stream->stream.read = NULL; /* read only */ - stream->stream.write = &fake_wstream__write; - stream->stream.finalize_write = &fake_wstream__fwrite; - stream->stream.free = &fake_wstream__free; - stream->stream.mode = GIT_STREAM_WRONLY; - - *stream_p = (git_odb_stream *)stream; - return GIT_SUCCESS; -} - -/*********************************************************** - * - * OBJECT DATABASE PUBLIC API - * - * Public calls for the ODB functionality - * - ***********************************************************/ - -static int backend_sort_cmp(const void *a, const void *b) -{ - const backend_internal *backend_a = (const backend_internal *)(a); - const backend_internal *backend_b = (const backend_internal *)(b); - - if (backend_a->is_alternate == backend_b->is_alternate) - return (backend_b->priority - backend_a->priority); - - return backend_a->is_alternate ? 1 : -1; -} - -int git_odb_new(git_odb **out) -{ - int error; - - git_odb *db = git__calloc(1, sizeof(*db)); - if (!db) - return GIT_ENOMEM; - - error = git_cache_init(&db->cache, GIT_DEFAULT_CACHE_SIZE, &free_odb_object); - if (error < GIT_SUCCESS) { - free(db); - return git__rethrow(error, "Failed to create object database"); - } - - if ((error = git_vector_init(&db->backends, 4, backend_sort_cmp)) < GIT_SUCCESS) { - free(db); - return git__rethrow(error, "Failed to create object database"); - } - - *out = db; - return GIT_SUCCESS; -} - -static int add_backend_internal(git_odb *odb, git_odb_backend *backend, int priority, int is_alternate) -{ - backend_internal *internal; - - assert(odb && backend); - - if (backend->odb != NULL && backend->odb != odb) - return git__throw(GIT_EBUSY, "The backend is already owned by another ODB"); - - internal = git__malloc(sizeof(backend_internal)); - if (internal == NULL) - return GIT_ENOMEM; - - internal->backend = backend; - internal->priority = priority; - internal->is_alternate = is_alternate; - - if (git_vector_insert(&odb->backends, internal) < 0) { - free(internal); - return GIT_ENOMEM; - } - - git_vector_sort(&odb->backends); - internal->backend->odb = odb; - return GIT_SUCCESS; -} - -int git_odb_add_backend(git_odb *odb, git_odb_backend *backend, int priority) -{ - return add_backend_internal(odb, backend, priority, 0); -} - -int git_odb_add_alternate(git_odb *odb, git_odb_backend *backend, int priority) -{ - return add_backend_internal(odb, backend, priority, 1); -} - -static int add_default_backends(git_odb *db, const char *objects_dir, int as_alternates) -{ - git_odb_backend *loose, *packed; - int error; - - /* add the loose object backend */ - error = git_odb_backend_loose(&loose, objects_dir); - if (error < GIT_SUCCESS) - return error; - - error = add_backend_internal(db, loose, GIT_LOOSE_PRIORITY, as_alternates); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to add backend"); - - /* add the packed file backend */ - error = git_odb_backend_pack(&packed, objects_dir); - if (error < GIT_SUCCESS) - return error; - - error = add_backend_internal(db, packed, GIT_PACKED_PRIORITY, as_alternates); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to add backend"); - - return GIT_SUCCESS; -} - -static int load_alternates(git_odb *odb, const char *objects_dir) -{ - char alternates_path[GIT_PATH_MAX]; - char *buffer, *alternate; - - git_fbuffer alternates_buf = GIT_FBUFFER_INIT; - int error; - - git_path_join(alternates_path, objects_dir, GIT_ALTERNATES_FILE); - - if (git_futils_exists(alternates_path) < GIT_SUCCESS) - return GIT_SUCCESS; - - if (git_futils_readbuffer(&alternates_buf, alternates_path) < GIT_SUCCESS) - return git__throw(GIT_EOSERR, "Failed to add backend. Can't read alternates"); - - buffer = (char *)alternates_buf.data; - error = GIT_SUCCESS; - - /* add each alternate as a new backend; one alternate per line */ - while ((alternate = git__strtok(&buffer, "\r\n")) != NULL) { - char full_path[GIT_PATH_MAX]; - - if (*alternate == '\0' || *alternate == '#') - continue; - - /* relative path: build based on the current `objects` folder */ - if (*alternate == '.') { - git_path_join(full_path, objects_dir, alternate); - alternate = full_path; - } - - if ((error = add_default_backends(odb, alternate, 1)) < GIT_SUCCESS) - break; - } - - git_futils_freebuffer(&alternates_buf); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to load alternates"); - return error; -} - -int git_odb_open(git_odb **out, const char *objects_dir) -{ - git_odb *db; - int error; - - assert(out && objects_dir); - - *out = NULL; - - if ((error = git_odb_new(&db)) < 0) - return git__rethrow(error, "Failed to open ODB"); - - if ((error = add_default_backends(db, objects_dir, 0)) < GIT_SUCCESS) - goto cleanup; - - if ((error = load_alternates(db, objects_dir)) < GIT_SUCCESS) - goto cleanup; - - *out = db; - return GIT_SUCCESS; - -cleanup: - git_odb_close(db); - return error; /* error already set - pass through */ -} - -void git_odb_close(git_odb *db) -{ - unsigned int i; - - if (db == NULL) - return; - - for (i = 0; i < db->backends.length; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *backend = internal->backend; - - if (backend->free) backend->free(backend); - else free(backend); - - free(internal); - } - - git_vector_free(&db->backends); - git_cache_free(&db->cache); - free(db); -} - -int git_odb_exists(git_odb *db, const git_oid *id) -{ - git_odb_object *object; - unsigned int i; - int found = 0; - - assert(db && id); - - if ((object = git_cache_get(&db->cache, id)) != NULL) { - git_odb_object_close(object); - return 1; - } - - for (i = 0; i < db->backends.length && !found; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - if (b->exists != NULL) - found = b->exists(b, id); - } - - return found; -} - -int git_odb_read_header(size_t *len_p, git_otype *type_p, git_odb *db, const git_oid *id) -{ - unsigned int i; - int error = GIT_ENOTFOUND; - git_odb_object *object; - - assert(db && id); - - if ((object = git_cache_get(&db->cache, id)) != NULL) { - *len_p = object->raw.len; - *type_p = object->raw.type; - git_odb_object_close(object); - return GIT_SUCCESS; - } - - for (i = 0; i < db->backends.length && error < 0; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - if (b->read_header != NULL) - error = b->read_header(len_p, type_p, b, id); - } - - if (error == GIT_EPASSTHROUGH) - return GIT_SUCCESS; - - /* - * no backend could read only the header. - * try reading the whole object and freeing the contents - */ - if (error < 0) { - if ((error = git_odb_read(&object, db, id)) < GIT_SUCCESS) - return error; /* error already set - pass through */ - - *len_p = object->raw.len; - *type_p = object->raw.type; - git_odb_object_close(object); - } - - return GIT_SUCCESS; -} - -int git_odb_read(git_odb_object **out, git_odb *db, const git_oid *id) -{ - unsigned int i; - int error = GIT_ENOTFOUND; - git_rawobj raw; - - assert(out && db && id); - - *out = git_cache_get(&db->cache, id); - if (*out != NULL) - return GIT_SUCCESS; - - for (i = 0; i < db->backends.length && error < 0; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - if (b->read != NULL) - error = b->read(&raw.data, &raw.len, &raw.type, b, id); - } - - if (error == GIT_EPASSTHROUGH || error == GIT_SUCCESS) { - *out = git_cache_try_store(&db->cache, new_odb_object(id, &raw)); - return GIT_SUCCESS; - } - - return git__rethrow(error, "Failed to read object"); -} - -int git_odb_read_prefix(git_odb_object **out, git_odb *db, const git_oid *short_id, unsigned int len) -{ - unsigned int i; - int error = GIT_ENOTFOUND; - git_oid full_oid; - git_rawobj raw; - int found = 0; - - assert(out && db); - - if (len < GIT_OID_MINPREFIXLEN) - return git__throw(GIT_EAMBIGUOUSOIDPREFIX, "Failed to lookup object. Prefix length is lower than %d.", GIT_OID_MINPREFIXLEN); - - if (len > GIT_OID_HEXSZ) - len = GIT_OID_HEXSZ; - - if (len == GIT_OID_HEXSZ) { - *out = git_cache_get(&db->cache, short_id); - if (*out != NULL) - return GIT_SUCCESS; - } - - for (i = 0; i < db->backends.length && found < 2; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - if (b->read != NULL) { - error = b->read_prefix(&full_oid, &raw.data, &raw.len, &raw.type, b, short_id, len); - switch (error) { - case GIT_SUCCESS: - found++; - break; - case GIT_ENOTFOUND: - case GIT_EPASSTHROUGH: - break; - case GIT_EAMBIGUOUSOIDPREFIX: - return git__rethrow(error, "Failed to read object. Ambiguous sha1 prefix"); - default: - return git__rethrow(error, "Failed to read object"); - } - } - } - - if (found == 1) { - *out = git_cache_try_store(&db->cache, new_odb_object(&full_oid, &raw)); - } else if (found > 1) { - return git__throw(GIT_EAMBIGUOUSOIDPREFIX, "Failed to read object. Ambiguous sha1 prefix"); - } else { - return git__throw(GIT_ENOTFOUND, "Failed to read object. Object not found"); - } - - return GIT_SUCCESS; -} - -int git_odb_write(git_oid *oid, git_odb *db, const void *data, size_t len, git_otype type) -{ - unsigned int i; - int error = GIT_ERROR; - git_odb_stream *stream; - - assert(oid && db); - - for (i = 0; i < db->backends.length && error < 0; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - /* we don't write in alternates! */ - if (internal->is_alternate) - continue; - - if (b->write != NULL) - error = b->write(oid, b, data, len, type); - } - - if (error == GIT_EPASSTHROUGH || error == GIT_SUCCESS) - return GIT_SUCCESS; - - /* if no backends were able to write the object directly, we try a streaming - * write to the backends; just write the whole object into the stream in one - * push */ - - if ((error = git_odb_open_wstream(&stream, db, len, type)) == GIT_SUCCESS) { - stream->write(stream, data, len); - error = stream->finalize_write(oid, stream); - stream->free(stream); - return GIT_SUCCESS; - } - - return git__rethrow(error, "Failed to write object"); -} - -int git_odb_open_wstream(git_odb_stream **stream, git_odb *db, size_t size, git_otype type) -{ - unsigned int i; - int error = GIT_ERROR; - - assert(stream && db); - - for (i = 0; i < db->backends.length && error < 0; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - /* we don't write in alternates! */ - if (internal->is_alternate) - continue; - - if (b->writestream != NULL) - error = b->writestream(stream, b, size, type); - else if (b->write != NULL) - error = init_fake_wstream(stream, b, size, type); - } - - if (error == GIT_EPASSTHROUGH || error == GIT_SUCCESS) - return GIT_SUCCESS; - - return git__rethrow(error, "Failed to open write stream"); -} - -int git_odb_open_rstream(git_odb_stream **stream, git_odb *db, const git_oid *oid) -{ - unsigned int i; - int error = GIT_ERROR; - - assert(stream && db); - - for (i = 0; i < db->backends.length && error < 0; ++i) { - backend_internal *internal = git_vector_get(&db->backends, i); - git_odb_backend *b = internal->backend; - - if (b->readstream != NULL) - error = b->readstream(stream, b, oid); - } - - if (error == GIT_EPASSTHROUGH || error == GIT_SUCCESS) - return GIT_SUCCESS; - - return git__rethrow(error, "Failed to open read stream"); -} - diff --git a/vendor/libgit2/src/odb.h b/vendor/libgit2/src/odb.h deleted file mode 100644 index 1d4f07dcc..000000000 --- a/vendor/libgit2/src/odb.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef INCLUDE_odb_h__ -#define INCLUDE_odb_h__ - -#include "git2/odb.h" -#include "git2/oid.h" -#include "git2/types.h" - -#include "vector.h" -#include "cache.h" - -/* DO NOT EXPORT */ -typedef struct { - void *data; /**< Raw, decompressed object data. */ - size_t len; /**< Total number of bytes in data. */ - git_otype type; /**< Type of this object. */ -} git_rawobj; - -/* EXPORT */ -struct git_odb_object { - git_cached_obj cached; - git_rawobj raw; -}; - -/* EXPORT */ -struct git_odb { - void *_internal; - git_vector backends; - git_cache cache; -}; - -int git_odb__hash_obj(git_oid *id, git_rawobj *obj); - -#endif diff --git a/vendor/libgit2/src/odb_loose.c b/vendor/libgit2/src/odb_loose.c deleted file mode 100644 index a3a4e5b56..000000000 --- a/vendor/libgit2/src/odb_loose.c +++ /dev/null @@ -1,855 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "git2/zlib.h" -#include "git2/object.h" -#include "git2/oid.h" -#include "fileops.h" -#include "hash.h" -#include "odb.h" -#include "delta-apply.h" -#include "filebuf.h" - -#include "git2/odb_backend.h" -#include "git2/types.h" - -typedef struct { /* object header data */ - git_otype type; /* object type */ - size_t size; /* object size */ -} obj_hdr; - -typedef struct { - git_odb_stream stream; - git_filebuf fbuf; - int finished; -} loose_writestream; - -typedef struct loose_backend { - git_odb_backend parent; - - int object_zlib_level; /** loose object zlib compression level. */ - int fsync_object_files; /** loose object file fsync flag. */ - char *objects_dir; -} loose_backend; - -/* State structure for exploring directories, - * in order to locate objects matching a short oid. - */ -typedef struct { - size_t dir_len; - unsigned char short_oid[GIT_OID_HEXSZ]; /* hex formatted oid to match */ - unsigned int short_oid_len; - int found; /* number of matching - * objects already found */ - unsigned char res_oid[GIT_OID_HEXSZ]; /* hex formatted oid of - * the object found */ -} loose_locate_object_state; - - - -/*********************************************************** - * - * MISCELANEOUS HELPER FUNCTIONS - * - ***********************************************************/ - -static size_t object_file_name(char *name, size_t n, char *dir, const git_oid *id) -{ - size_t len = strlen(dir); - - /* check length: 43 = 40 hex sha1 chars + 2 * '/' + '\0' */ - if (len+43 > n) - return len+43; - - /* the object dir: eg $GIT_DIR/objects */ - strcpy(name, dir); - if (name[len-1] != '/') - name[len++] = '/'; - - /* loose object filename: aa/aaa... (41 bytes) */ - git_oid_pathfmt(&name[len], id); - name[len+41] = '\0'; - - return 0; -} - - -static size_t get_binary_object_header(obj_hdr *hdr, git_fbuffer *obj) -{ - unsigned char c; - unsigned char *data = obj->data; - size_t shift, size, used = 0; - - if (obj->len == 0) - return 0; - - c = data[used++]; - hdr->type = (c >> 4) & 7; - - size = c & 15; - shift = 4; - while (c & 0x80) { - if (obj->len <= used) - return 0; - if (sizeof(size_t) * 8 <= shift) - return 0; - c = data[used++]; - size += (c & 0x7f) << shift; - shift += 7; - } - hdr->size = size; - - return used; -} - -static size_t get_object_header(obj_hdr *hdr, unsigned char *data) -{ - char c, typename[10]; - size_t size, used = 0; - - /* - * type name string followed by space. - */ - while ((c = data[used]) != ' ') { - typename[used++] = c; - if (used >= sizeof(typename)) - return 0; - } - typename[used] = 0; - if (used == 0) - return 0; - hdr->type = git_object_string2type(typename); - used++; /* consume the space */ - - /* - * length follows immediately in decimal (without - * leading zeros). - */ - size = data[used++] - '0'; - if (size > 9) - return 0; - if (size) { - while ((c = data[used]) != '\0') { - size_t d = c - '0'; - if (d > 9) - break; - used++; - size = size * 10 + d; - } - } - hdr->size = size; - - /* - * the length must be followed by a zero byte - */ - if (data[used++] != '\0') - return 0; - - return used; -} - - - -/*********************************************************** - * - * ZLIB RELATED FUNCTIONS - * - ***********************************************************/ - -static void init_stream(z_stream *s, void *out, size_t len) -{ - memset(s, 0, sizeof(*s)); - s->next_out = out; - s->avail_out = len; -} - -static void set_stream_input(z_stream *s, void *in, size_t len) -{ - s->next_in = in; - s->avail_in = len; -} - -static void set_stream_output(z_stream *s, void *out, size_t len) -{ - s->next_out = out; - s->avail_out = len; -} - - -static int start_inflate(z_stream *s, git_fbuffer *obj, void *out, size_t len) -{ - int status; - - init_stream(s, out, len); - set_stream_input(s, obj->data, obj->len); - - if ((status = inflateInit(s)) < Z_OK) - return status; - - return inflate(s, 0); -} - -static int finish_inflate(z_stream *s) -{ - int status = Z_OK; - - while (status == Z_OK) - status = inflate(s, Z_FINISH); - - inflateEnd(s); - - if ((status != Z_STREAM_END) || (s->avail_in != 0)) - return git__throw(GIT_ERROR, "Failed to finish inflation. Stream aborted prematurely"); - - return GIT_SUCCESS; -} - -static int is_zlib_compressed_data(unsigned char *data) -{ - unsigned int w; - - w = ((unsigned int)(data[0]) << 8) + data[1]; - return data[0] == 0x78 && !(w % 31); -} - -static int inflate_buffer(void *in, size_t inlen, void *out, size_t outlen) -{ - z_stream zs; - int status = Z_OK; - - memset(&zs, 0x0, sizeof(zs)); - - zs.next_out = out; - zs.avail_out = outlen; - - zs.next_in = in; - zs.avail_in = inlen; - - if (inflateInit(&zs) < Z_OK) - return git__throw(GIT_ERROR, "Failed to inflate buffer"); - - while (status == Z_OK) - status = inflate(&zs, Z_FINISH); - - inflateEnd(&zs); - - if ((status != Z_STREAM_END) /*|| (zs.avail_in != 0) */) - return git__throw(GIT_ERROR, "Failed to inflate buffer. Stream aborted prematurely"); - - if (zs.total_out != outlen) - return git__throw(GIT_ERROR, "Failed to inflate buffer. Stream aborted prematurely"); - - return GIT_SUCCESS; -} - -static void *inflate_tail(z_stream *s, void *hb, size_t used, obj_hdr *hdr) -{ - unsigned char *buf, *head = hb; - size_t tail; - - /* - * allocate a buffer to hold the inflated data and copy the - * initial sequence of inflated data from the tail of the - * head buffer, if any. - */ - if ((buf = git__malloc(hdr->size + 1)) == NULL) { - inflateEnd(s); - return NULL; - } - tail = s->total_out - used; - if (used > 0 && tail > 0) { - if (tail > hdr->size) - tail = hdr->size; - memcpy(buf, head + used, tail); - } - used = tail; - - /* - * inflate the remainder of the object data, if any - */ - if (hdr->size < used) - inflateEnd(s); - else { - set_stream_output(s, buf + used, hdr->size - used); - if (finish_inflate(s)) { - free(buf); - return NULL; - } - } - - return buf; -} - -/* - * At one point, there was a loose object format that was intended to - * mimic the format used in pack-files. This was to allow easy copying - * of loose object data into packs. This format is no longer used, but - * we must still read it. - */ -static int inflate_packlike_loose_disk_obj(git_rawobj *out, git_fbuffer *obj) -{ - unsigned char *in, *buf; - obj_hdr hdr; - size_t len, used; - - /* - * read the object header, which is an (uncompressed) - * binary encoding of the object type and size. - */ - if ((used = get_binary_object_header(&hdr, obj)) == 0) - return git__throw(GIT_ERROR, "Failed to inflate loose object. Object has no header"); - - if (!git_object_typeisloose(hdr.type)) - return git__throw(GIT_ERROR, "Failed to inflate loose object. Wrong object type"); - - /* - * allocate a buffer and inflate the data into it - */ - buf = git__malloc(hdr.size + 1); - if (!buf) - return GIT_ENOMEM; - - in = ((unsigned char *)obj->data) + used; - len = obj->len - used; - if (inflate_buffer(in, len, buf, hdr.size)) { - free(buf); - return git__throw(GIT_ERROR, "Failed to inflate loose object. Could not inflate buffer"); - } - buf[hdr.size] = '\0'; - - out->data = buf; - out->len = hdr.size; - out->type = hdr.type; - - return GIT_SUCCESS; -} - -static int inflate_disk_obj(git_rawobj *out, git_fbuffer *obj) -{ - unsigned char head[64], *buf; - z_stream zs; - obj_hdr hdr; - size_t used; - - /* - * check for a pack-like loose object - */ - if (!is_zlib_compressed_data(obj->data)) - return inflate_packlike_loose_disk_obj(out, obj); - - /* - * inflate the initial part of the io buffer in order - * to parse the object header (type and size). - */ - if (start_inflate(&zs, obj, head, sizeof(head)) < Z_OK) - return git__throw(GIT_ERROR, "Failed to inflate disk object. Could not inflate buffer"); - - if ((used = get_object_header(&hdr, head)) == 0) - return git__throw(GIT_ERROR, "Failed to inflate disk object. Object has no header"); - - if (!git_object_typeisloose(hdr.type)) - return git__throw(GIT_ERROR, "Failed to inflate disk object. Wrong object type"); - - /* - * allocate a buffer and inflate the object data into it - * (including the initial sequence in the head buffer). - */ - if ((buf = inflate_tail(&zs, head, used, &hdr)) == NULL) - return GIT_ENOMEM; - buf[hdr.size] = '\0'; - - out->data = buf; - out->len = hdr.size; - out->type = hdr.type; - - return GIT_SUCCESS; -} - - - - - - -/*********************************************************** - * - * ODB OBJECT READING & WRITING - * - * Backend for the public API; read headers and full objects - * from the ODB. Write raw data to the ODB. - * - ***********************************************************/ - -static int read_loose(git_rawobj *out, const char *loc) -{ - int error; - git_fbuffer obj = GIT_FBUFFER_INIT; - - assert(out && loc); - - out->data = NULL; - out->len = 0; - out->type = GIT_OBJ_BAD; - - if (git_futils_readbuffer(&obj, loc) < 0) - return git__throw(GIT_ENOTFOUND, "Failed to read loose object. File not found"); - - error = inflate_disk_obj(out, &obj); - git_futils_freebuffer(&obj); - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to read loose object"); -} - -static int read_header_loose(git_rawobj *out, const char *loc) -{ - int error = GIT_SUCCESS, z_return = Z_ERRNO, read_bytes; - git_file fd; - z_stream zs; - obj_hdr header_obj; - unsigned char raw_buffer[16], inflated_buffer[64]; - - assert(out && loc); - - out->data = NULL; - - if ((fd = p_open(loc, O_RDONLY)) < 0) - return git__throw(GIT_ENOTFOUND, "Failed to read loose object header. File not found"); - - init_stream(&zs, inflated_buffer, sizeof(inflated_buffer)); - - if (inflateInit(&zs) < Z_OK) { - error = GIT_EZLIB; - goto cleanup; - } - - do { - if ((read_bytes = read(fd, raw_buffer, sizeof(raw_buffer))) > 0) { - set_stream_input(&zs, raw_buffer, read_bytes); - z_return = inflate(&zs, 0); - } else { - z_return = Z_STREAM_END; - break; - } - } while (z_return == Z_OK); - - if ((z_return != Z_STREAM_END && z_return != Z_BUF_ERROR) - || get_object_header(&header_obj, inflated_buffer) == 0 - || git_object_typeisloose(header_obj.type) == 0) { - error = GIT_EOBJCORRUPTED; - goto cleanup; - } - - out->len = header_obj.size; - out->type = header_obj.type; - -cleanup: - finish_inflate(&zs); - p_close(fd); - - if (error < GIT_SUCCESS) - return git__throw(error, "Failed to read loose object header. Header is corrupted"); - - return GIT_SUCCESS; -} - -static int locate_object(char *object_location, loose_backend *backend, const git_oid *oid) -{ - object_file_name(object_location, GIT_PATH_MAX, backend->objects_dir, oid); - return git_futils_exists(object_location); -} - -/* Explore an entry of a directory and see if it matches a short oid */ -int fn_locate_object_short_oid(void *state, char *pathbuf) { - loose_locate_object_state *sstate = (loose_locate_object_state *)state; - - size_t pathbuf_len = strlen(pathbuf); - if (pathbuf_len - sstate->dir_len != GIT_OID_HEXSZ - 2) { - /* Entry cannot be an object. Continue to next entry */ - return GIT_SUCCESS; - } - - if (!git_futils_exists(pathbuf) && git_futils_isdir(pathbuf)) { - /* We are already in the directory matching the 2 first hex characters, - * compare the first ncmp characters of the oids */ - if (!memcmp(sstate->short_oid + 2, - (unsigned char *)pathbuf + sstate->dir_len, - sstate->short_oid_len - 2)) { - - if (!sstate->found) { - sstate->res_oid[0] = sstate->short_oid[0]; - sstate->res_oid[1] = sstate->short_oid[1]; - memcpy(sstate->res_oid+2, pathbuf+sstate->dir_len, GIT_OID_HEXSZ-2); - } - sstate->found++; - } - } - if (sstate->found > 1) - return git__throw(GIT_EAMBIGUOUSOIDPREFIX, "Ambiguous sha1 prefix within loose objects"); - - return GIT_SUCCESS; -} - -/* Locate an object matching a given short oid */ -static int locate_object_short_oid(char *object_location, git_oid *res_oid, loose_backend *backend, const git_oid *short_oid, unsigned int len) -{ - char *objects_dir = backend->objects_dir; - size_t dir_len = strlen(objects_dir); - loose_locate_object_state state; - int error; - - if (dir_len+43 > GIT_PATH_MAX) - return git__throw(GIT_ERROR, "Failed to locate object from short oid. Object path too long"); - - strcpy(object_location, objects_dir); - - /* Add a separator if not already there */ - if (object_location[dir_len-1] != '/') - object_location[dir_len++] = '/'; - - /* Convert raw oid to hex formatted oid */ - git_oid_fmt((char *)state.short_oid, short_oid); - /* Explore OBJ_DIR/xx/ where xx is the beginning of hex formatted short oid */ - sprintf(object_location+dir_len, "%.2s/", state.short_oid); - - /* Check that directory exists */ - if (git_futils_exists(object_location) || git_futils_isdir(object_location)) - return git__throw(GIT_ENOTFOUND, "Failed to locate object from short oid. Object not found"); - - state.dir_len = dir_len+3; - state.short_oid_len = len; - state.found = 0; - /* Explore directory to find a unique object matching short_oid */ - error = git_futils_direach(object_location, GIT_PATH_MAX, fn_locate_object_short_oid, &state); - if (error) { - return git__rethrow(error, "Failed to locate object from short oid"); - } - if (!state.found) { - return git__throw(GIT_ENOTFOUND, "Failed to locate object from short oid. Object not found"); - } - - /* Convert obtained hex formatted oid to raw */ - error = git_oid_fromstr(res_oid, (char *)state.res_oid); - if (error) { - return git__rethrow(error, "Failed to locate object from short oid"); - } - - /* Update the location according to the oid obtained */ - git_oid_pathfmt(object_location+dir_len, res_oid); - - return GIT_SUCCESS; -} - - - - - - - - - -/*********************************************************** - * - * LOOSE BACKEND PUBLIC API - * - * Implement the git_odb_backend API calls - * - ***********************************************************/ - -int loose_backend__read_header(size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid) -{ - char object_path[GIT_PATH_MAX]; - git_rawobj raw; - int error; - - assert(backend && oid); - - raw.len = 0; - raw.type = GIT_OBJ_BAD; - - if (locate_object(object_path, (loose_backend *)backend, oid) < 0) - return git__throw(GIT_ENOTFOUND, "Failed to read loose backend header. Object not found"); - - if ((error = read_header_loose(&raw, object_path)) < GIT_SUCCESS) - return error; - - *len_p = raw.len; - *type_p = raw.type; - return GIT_SUCCESS; -} - -int loose_backend__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid) -{ - char object_path[GIT_PATH_MAX]; - git_rawobj raw; - int error; - - assert(backend && oid); - - if (locate_object(object_path, (loose_backend *)backend, oid) < 0) - return git__throw(GIT_ENOTFOUND, "Failed to read loose backend. Object not found"); - - if ((error = read_loose(&raw, object_path)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to read loose backend"); - - *buffer_p = raw.data; - *len_p = raw.len; - *type_p = raw.type; - - return GIT_SUCCESS; -} - -int loose_backend__read_prefix( - git_oid *out_oid, - void **buffer_p, - size_t *len_p, - git_otype *type_p, - git_odb_backend *backend, - const git_oid *short_oid, - unsigned int len) -{ - if (len < GIT_OID_MINPREFIXLEN) - return git__throw(GIT_EAMBIGUOUSOIDPREFIX, "Failed to read loose backend. Prefix length is lower than %d.", GIT_OID_MINPREFIXLEN); - - if (len >= GIT_OID_HEXSZ) { - /* We can fall back to regular read method */ - int error = loose_backend__read(buffer_p, len_p, type_p, backend, short_oid); - if (error == GIT_SUCCESS) - git_oid_cpy(out_oid, short_oid); - - return error; - } else { - char object_path[GIT_PATH_MAX]; - git_rawobj raw; - int error; - - assert(backend && short_oid); - - if ((error = locate_object_short_oid(object_path, out_oid, (loose_backend *)backend, short_oid, len)) < 0) { - return git__rethrow(error, "Failed to read loose backend"); - } - - if ((error = read_loose(&raw, object_path)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to read loose backend"); - - *buffer_p = raw.data; - *len_p = raw.len; - *type_p = raw.type; - } - - return GIT_SUCCESS; -} - -int loose_backend__exists(git_odb_backend *backend, const git_oid *oid) -{ - char object_path[GIT_PATH_MAX]; - - assert(backend && oid); - - return locate_object(object_path, (loose_backend *)backend, oid) == GIT_SUCCESS; -} - -int loose_backend__stream_fwrite(git_oid *oid, git_odb_stream *_stream) -{ - loose_writestream *stream = (loose_writestream *)_stream; - loose_backend *backend = (loose_backend *)_stream->backend; - - int error; - char final_path[GIT_PATH_MAX]; - - if ((error = git_filebuf_hash(oid, &stream->fbuf)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to write loose backend"); - - if (object_file_name(final_path, sizeof(final_path), backend->objects_dir, oid)) - return GIT_ENOMEM; - - if ((error = git_futils_mkpath2file(final_path)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to write loose backend"); - - stream->finished = 1; - return git_filebuf_commit_at(&stream->fbuf, final_path); -} - -int loose_backend__stream_write(git_odb_stream *_stream, const char *data, size_t len) -{ - loose_writestream *stream = (loose_writestream *)_stream; - return git_filebuf_write(&stream->fbuf, data, len); -} - -void loose_backend__stream_free(git_odb_stream *_stream) -{ - loose_writestream *stream = (loose_writestream *)_stream; - - if (!stream->finished) - git_filebuf_cleanup(&stream->fbuf); - - free(stream); -} - -static int format_object_header(char *hdr, size_t n, size_t obj_len, git_otype obj_type) -{ - const char *type_str = git_object_type2string(obj_type); - int len = snprintf(hdr, n, "%s %"PRIuZ, type_str, obj_len); - - assert(len > 0); /* otherwise snprintf() is broken */ - assert(((size_t) len) < n); /* otherwise the caller is broken! */ - - if (len < 0 || ((size_t) len) >= n) - return git__throw(GIT_ERROR, "Failed to format object header. Length is out of bounds"); - return len+1; -} - -int loose_backend__stream(git_odb_stream **stream_out, git_odb_backend *_backend, size_t length, git_otype type) -{ - loose_backend *backend; - loose_writestream *stream; - - char hdr[64], tmp_path[GIT_PATH_MAX]; - int hdrlen; - int error; - - assert(_backend); - - backend = (loose_backend *)_backend; - *stream_out = NULL; - - hdrlen = format_object_header(hdr, sizeof(hdr), length, type); - if (hdrlen < GIT_SUCCESS) - return git__throw(GIT_EOBJCORRUPTED, "Failed to create loose backend stream. Object is corrupted"); - - stream = git__calloc(1, sizeof(loose_writestream)); - if (stream == NULL) - return GIT_ENOMEM; - - stream->stream.backend = _backend; - stream->stream.read = NULL; /* read only */ - stream->stream.write = &loose_backend__stream_write; - stream->stream.finalize_write = &loose_backend__stream_fwrite; - stream->stream.free = &loose_backend__stream_free; - stream->stream.mode = GIT_STREAM_WRONLY; - - git_path_join(tmp_path, backend->objects_dir, "tmp_object"); - - error = git_filebuf_open(&stream->fbuf, tmp_path, - GIT_FILEBUF_HASH_CONTENTS | - GIT_FILEBUF_DEFLATE_CONTENTS | - GIT_FILEBUF_TEMPORARY); - - if (error < GIT_SUCCESS) { - free(stream); - return git__rethrow(error, "Failed to create loose backend stream"); - } - - error = stream->stream.write((git_odb_stream *)stream, hdr, hdrlen); - if (error < GIT_SUCCESS) { - git_filebuf_cleanup(&stream->fbuf); - free(stream); - return git__rethrow(error, "Failed to create loose backend stream"); - } - - *stream_out = (git_odb_stream *)stream; - return GIT_SUCCESS; -} - -int loose_backend__write(git_oid *oid, git_odb_backend *_backend, const void *data, size_t len, git_otype type) -{ - int error, header_len; - char final_path[GIT_PATH_MAX], header[64]; - git_filebuf fbuf; - loose_backend *backend; - - backend = (loose_backend *)_backend; - - /* prepare the header for the file */ - { - header_len = format_object_header(header, sizeof(header), len, type); - if (header_len < GIT_SUCCESS) - return GIT_EOBJCORRUPTED; - } - - git_path_join(final_path, backend->objects_dir, "tmp_object"); - - error = git_filebuf_open(&fbuf, final_path, - GIT_FILEBUF_HASH_CONTENTS | - GIT_FILEBUF_DEFLATE_CONTENTS | - GIT_FILEBUF_TEMPORARY); - - if (error < GIT_SUCCESS) - return error; - - git_filebuf_write(&fbuf, header, header_len); - git_filebuf_write(&fbuf, data, len); - git_filebuf_hash(oid, &fbuf); - - if ((error = object_file_name(final_path, sizeof(final_path), backend->objects_dir, oid)) < GIT_SUCCESS) - goto cleanup; - - if ((error = git_futils_mkpath2file(final_path)) < GIT_SUCCESS) - goto cleanup; - - return git_filebuf_commit_at(&fbuf, final_path); - -cleanup: - git_filebuf_cleanup(&fbuf); - return error; -} - -void loose_backend__free(git_odb_backend *_backend) -{ - loose_backend *backend; - assert(_backend); - backend = (loose_backend *)_backend; - - free(backend->objects_dir); - free(backend); -} - -int git_odb_backend_loose(git_odb_backend **backend_out, const char *objects_dir) -{ - loose_backend *backend; - - backend = git__calloc(1, sizeof(loose_backend)); - if (backend == NULL) - return GIT_ENOMEM; - - backend->objects_dir = git__strdup(objects_dir); - if (backend->objects_dir == NULL) { - free(backend); - return GIT_ENOMEM; - } - - backend->object_zlib_level = Z_BEST_SPEED; - backend->fsync_object_files = 0; - - backend->parent.read = &loose_backend__read; - backend->parent.write = &loose_backend__write; - backend->parent.read_prefix = &loose_backend__read_prefix; - backend->parent.read_header = &loose_backend__read_header; - backend->parent.writestream = &loose_backend__stream; - backend->parent.exists = &loose_backend__exists; - backend->parent.free = &loose_backend__free; - - *backend_out = (git_odb_backend *)backend; - return GIT_SUCCESS; -} diff --git a/vendor/libgit2/src/odb_pack.c b/vendor/libgit2/src/odb_pack.c deleted file mode 100644 index 5b2be58e1..000000000 --- a/vendor/libgit2/src/odb_pack.c +++ /dev/null @@ -1,500 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "git2/zlib.h" -#include "git2/repository.h" -#include "git2/oid.h" -#include "fileops.h" -#include "hash.h" -#include "odb.h" -#include "delta-apply.h" -#include "sha1_lookup.h" -#include "mwindow.h" -#include "pack.h" - -#include "git2/odb_backend.h" - -struct pack_backend { - git_odb_backend parent; - git_vector packs; - struct git_pack_file *last_found; - char *pack_folder; - time_t pack_folder_mtime; -}; - -/** - * The wonderful tale of a Packed Object lookup query - * =================================================== - * A riveting and epic story of epicness and ASCII - * art, presented by yours truly, - * Sir Vicent of Marti - * - * - * Chapter 1: Once upon a time... - * Initialization of the Pack Backend - * -------------------------------------------------- - * - * # git_odb_backend_pack - * | Creates the pack backend structure, initializes the - * | callback pointers to our default read() and exist() methods, - * | and tries to preload all the known packfiles in the ODB. - * | - * |-# packfile_load_all - * | Tries to find the `pack` folder, if it exists. ODBs without - * | a pack folder are ignored altogether. If there's a `pack` folder - * | we run a `dirent` callback through every file in the pack folder - * | to find our packfiles. The packfiles are then sorted according - * | to a sorting callback. - * | - * |-# packfile_load__cb - * | | This callback is called from `dirent` with every single file - * | | inside the pack folder. We find the packs by actually locating - * | | their index (ends in ".idx"). From that index, we verify that - * | | the corresponding packfile exists and is valid, and if so, we - * | | add it to the pack list. - * | | - * | |-# packfile_check - * | Make sure that there's a packfile to back this index, and store - * | some very basic information regarding the packfile itself, - * | such as the full path, the size, and the modification time. - * | We don't actually open the packfile to check for internal consistency. - * | - * |-# packfile_sort__cb - * Sort all the preloaded packs according to some specific criteria: - * we prioritize the "newer" packs because it's more likely they - * contain the objects we are looking for, and we prioritize local - * packs over remote ones. - * - * - * - * Chapter 2: To be, or not to be... - * A standard packed `exist` query for an OID - * -------------------------------------------------- - * - * # pack_backend__exists - * | Check if the given SHA1 oid exists in any of the packs - * | that have been loaded for our ODB. - * | - * |-# pack_entry_find - * | Iterate through all the packs that have been preloaded - * | (starting by the pack where the latest object was found) - * | to try to find the OID in one of them. - * | - * |-# pack_entry_find1 - * | Check the index of an individual pack to see if the SHA1 - * | OID can be found. If we can find the offset to that SHA1 - * | inside of the index, that means the object is contained - * | inside of the packfile and we can stop searching. - * | Before returning, we verify that the packfile behing the - * | index we are searching still exists on disk. - * | - * |-# pack_entry_find_offset - * | | Mmap the actual index file to disk if it hasn't been opened - * | | yet, and run a binary search through it to find the OID. - * | | See for specifics - * | | on the Packfile Index format and how do we find entries in it. - * | | - * | |-# pack_index_open - * | | Guess the name of the index based on the full path to the - * | | packfile, open it and verify its contents. Only if the index - * | | has not been opened already. - * | | - * | |-# pack_index_check - * | Mmap the index file and do a quick run through the header - * | to guess the index version (right now we support v1 and v2), - * | and to verify that the size of the index makes sense. - * | - * |-# packfile_open - * See `packfile_open` in Chapter 3 - * - * - * - * Chapter 3: The neverending story... - * A standard packed `lookup` query for an OID - * -------------------------------------------------- - * TODO - * - */ - - -/*********************************************************** - * - * FORWARD DECLARATIONS - * - ***********************************************************/ - -static void pack_window_free_all(struct pack_backend *backend, struct git_pack_file *p); -static int pack_window_contains(git_mwindow *win, off_t offset); - -static int packfile_sort__cb(const void *a_, const void *b_); - -static int packfile_load__cb(void *_data, char *path); -static int packfile_refresh_all(struct pack_backend *backend); - -static int pack_entry_find(struct git_pack_entry *e, - struct pack_backend *backend, const git_oid *oid); - -/* Can find the offset of an object given - * a prefix of an identifier. - * Throws GIT_EAMBIGUOUSOIDPREFIX if short oid - * is ambiguous. - * This method assumes that len is between - * GIT_OID_MINPREFIXLEN and GIT_OID_HEXSZ. - */ -static int pack_entry_find_prefix(struct git_pack_entry *e, - struct pack_backend *backend, - const git_oid *short_oid, - unsigned int len); - - - -/*********************************************************** - * - * PACK WINDOW MANAGEMENT - * - ***********************************************************/ - -GIT_INLINE(void) pack_window_free_all(struct pack_backend *GIT_UNUSED(backend), struct git_pack_file *p) -{ - GIT_UNUSED_ARG(backend); - git_mwindow_free_all(&p->mwf); -} - -GIT_INLINE(int) pack_window_contains(git_mwindow *win, off_t offset) -{ - /* We must promise at least 20 bytes (one hash) after the - * offset is available from this window, otherwise the offset - * is not actually in this window and a different window (which - * has that one hash excess) must be used. This is to support - * the object header and delta base parsing routines below. - */ - return git_mwindow_contains(win, offset + 20); -} - -static int packfile_sort__cb(const void *a_, const void *b_) -{ - const struct git_pack_file *a = a_; - const struct git_pack_file *b = b_; - int st; - - /* - * Local packs tend to contain objects specific to our - * variant of the project than remote ones. In addition, - * remote ones could be on a network mounted filesystem. - * Favor local ones for these reasons. - */ - st = a->pack_local - b->pack_local; - if (st) - return -st; - - /* - * Younger packs tend to contain more recent objects, - * and more recent objects tend to get accessed more - * often. - */ - if (a->mtime < b->mtime) - return 1; - else if (a->mtime == b->mtime) - return 0; - - return -1; -} - - - -static int packfile_load__cb(void *_data, char *path) -{ - struct pack_backend *backend = (struct pack_backend *)_data; - struct git_pack_file *pack; - int error; - size_t i; - - if (git__suffixcmp(path, ".idx") != 0) - return GIT_SUCCESS; /* not an index */ - - for (i = 0; i < backend->packs.length; ++i) { - struct git_pack_file *p = git_vector_get(&backend->packs, i); - if (memcmp(p->pack_name, path, strlen(path) - strlen(".idx")) == 0) - return GIT_SUCCESS; - } - - error = git_packfile_check(&pack, path); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to load packfile"); - - if (git_vector_insert(&backend->packs, pack) < GIT_SUCCESS) { - free(pack); - return GIT_ENOMEM; - } - - return GIT_SUCCESS; -} - -static int packfile_refresh_all(struct pack_backend *backend) -{ - int error; - struct stat st; - - if (backend->pack_folder == NULL) - return GIT_SUCCESS; - - if (p_stat(backend->pack_folder, &st) < 0 || !S_ISDIR(st.st_mode)) - return git__throw(GIT_ENOTFOUND, "Failed to refresh packfiles. Backend not found"); - - if (st.st_mtime != backend->pack_folder_mtime) { - char path[GIT_PATH_MAX]; - strcpy(path, backend->pack_folder); - - /* reload all packs */ - error = git_futils_direach(path, GIT_PATH_MAX, packfile_load__cb, (void *)backend); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to refresh packfiles"); - - git_vector_sort(&backend->packs); - backend->pack_folder_mtime = st.st_mtime; - } - - return GIT_SUCCESS; -} - -static int pack_entry_find(struct git_pack_entry *e, struct pack_backend *backend, const git_oid *oid) -{ - int error; - size_t i; - - if ((error = packfile_refresh_all(backend)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to find pack entry"); - - if (backend->last_found && - git_pack_entry_find(e, backend->last_found, oid, GIT_OID_HEXSZ) == GIT_SUCCESS) - return GIT_SUCCESS; - - for (i = 0; i < backend->packs.length; ++i) { - struct git_pack_file *p; - - p = git_vector_get(&backend->packs, i); - if (p == backend->last_found) - continue; - - if (git_pack_entry_find(e, p, oid, GIT_OID_HEXSZ) == GIT_SUCCESS) { - backend->last_found = p; - return GIT_SUCCESS; - } - } - - return git__throw(GIT_ENOTFOUND, "Failed to find pack entry"); -} - -static int pack_entry_find_prefix( - struct git_pack_entry *e, - struct pack_backend *backend, - const git_oid *short_oid, - unsigned int len) -{ - int error; - size_t i; - unsigned found = 0; - - if ((error = packfile_refresh_all(backend)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to find pack entry"); - - if (backend->last_found) { - error = git_pack_entry_find(e, backend->last_found, short_oid, len); - if (error == GIT_EAMBIGUOUSOIDPREFIX) { - return git__rethrow(error, "Failed to find pack entry. Ambiguous sha1 prefix"); - } else if (error == GIT_SUCCESS) { - found = 1; - } - } - - for (i = 0; i < backend->packs.length; ++i) { - struct git_pack_file *p; - - p = git_vector_get(&backend->packs, i); - if (p == backend->last_found) - continue; - - error = git_pack_entry_find(e, p, short_oid, len); - if (error == GIT_EAMBIGUOUSOIDPREFIX) { - return git__rethrow(error, "Failed to find pack entry. Ambiguous sha1 prefix"); - } else if (error == GIT_SUCCESS) { - found++; - if (found > 1) - break; - backend->last_found = p; - } - } - - if (!found) { - return git__rethrow(GIT_ENOTFOUND, "Failed to find pack entry"); - } else if (found > 1) { - return git__rethrow(GIT_EAMBIGUOUSOIDPREFIX, "Failed to find pack entry. Ambiguous sha1 prefix"); - } else { - return GIT_SUCCESS; - } - -} - - -/*********************************************************** - * - * PACKED BACKEND PUBLIC API - * - * Implement the git_odb_backend API calls - * - ***********************************************************/ - -/* -int pack_backend__read_header(git_rawobj *obj, git_odb_backend *backend, const git_oid *oid) -{ - pack_location location; - - assert(obj && backend && oid); - - if (locate_packfile(&location, (struct pack_backend *)backend, oid) < 0) - return GIT_ENOTFOUND; - - return read_header_packed(obj, &location); -} -*/ - -int pack_backend__read(void **buffer_p, size_t *len_p, git_otype *type_p, git_odb_backend *backend, const git_oid *oid) -{ - struct git_pack_entry e; - git_rawobj raw; - int error; - - if ((error = pack_entry_find(&e, (struct pack_backend *)backend, oid)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to read pack backend"); - - if ((error = git_packfile_unpack(&raw, e.p, &e.offset)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to read pack backend"); - - *buffer_p = raw.data; - *len_p = raw.len; - *type_p = raw.type; - - return GIT_SUCCESS; -} - -int pack_backend__read_prefix( - git_oid *out_oid, - void **buffer_p, - size_t *len_p, - git_otype *type_p, - git_odb_backend *backend, - const git_oid *short_oid, - unsigned int len) -{ - if (len < GIT_OID_MINPREFIXLEN) - return git__throw(GIT_EAMBIGUOUSOIDPREFIX, "Failed to read pack backend. Prefix length is lower than %d.", GIT_OID_MINPREFIXLEN); - - if (len >= GIT_OID_HEXSZ) { - /* We can fall back to regular read method */ - int error = pack_backend__read(buffer_p, len_p, type_p, backend, short_oid); - if (error == GIT_SUCCESS) - git_oid_cpy(out_oid, short_oid); - - return error; - } else { - struct git_pack_entry e; - git_rawobj raw; - int error; - - if ((error = pack_entry_find_prefix(&e, (struct pack_backend *)backend, short_oid, len)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to read pack backend"); - - if ((error = git_packfile_unpack(&raw, e.p, &e.offset)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to read pack backend"); - - *buffer_p = raw.data; - *len_p = raw.len; - *type_p = raw.type; - git_oid_cpy(out_oid, &e.sha1); - } - - return GIT_SUCCESS; -} - -int pack_backend__exists(git_odb_backend *backend, const git_oid *oid) -{ - struct git_pack_entry e; - return pack_entry_find(&e, (struct pack_backend *)backend, oid) == GIT_SUCCESS; -} - -void pack_backend__free(git_odb_backend *_backend) -{ - struct pack_backend *backend; - size_t i; - - assert(_backend); - - backend = (struct pack_backend *)_backend; - - for (i = 0; i < backend->packs.length; ++i) { - struct git_pack_file *p = git_vector_get(&backend->packs, i); - packfile_free(p); - } - - git_vector_free(&backend->packs); - free(backend->pack_folder); - free(backend); -} - -int git_odb_backend_pack(git_odb_backend **backend_out, const char *objects_dir) -{ - struct pack_backend *backend; - char path[GIT_PATH_MAX]; - - backend = git__calloc(1, sizeof(struct pack_backend)); - if (backend == NULL) - return GIT_ENOMEM; - - if (git_vector_init(&backend->packs, 8, packfile_sort__cb) < GIT_SUCCESS) { - free(backend); - return GIT_ENOMEM; - } - - git_path_join(path, objects_dir, "pack"); - if (git_futils_isdir(path) == GIT_SUCCESS) { - backend->pack_folder = git__strdup(path); - backend->pack_folder_mtime = 0; - - if (backend->pack_folder == NULL) { - free(backend); - return GIT_ENOMEM; - } - } - - backend->parent.read = &pack_backend__read; - backend->parent.read_prefix = &pack_backend__read_prefix; - backend->parent.read_header = NULL; - backend->parent.exists = &pack_backend__exists; - backend->parent.free = &pack_backend__free; - - *backend_out = (git_odb_backend *)backend; - return GIT_SUCCESS; -} diff --git a/vendor/libgit2/src/oid.c b/vendor/libgit2/src/oid.c deleted file mode 100644 index f12ba30b9..000000000 --- a/vendor/libgit2/src/oid.c +++ /dev/null @@ -1,386 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "git2/oid.h" -#include "repository.h" -#include -#include - -static signed char from_hex[] = { --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 00 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 10 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 20 */ - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, /* 30 */ --1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 40 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 50 */ --1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 60 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 70 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 80 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* 90 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* a0 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* b0 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* c0 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* d0 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* e0 */ --1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, /* f0 */ -}; -static char to_hex[] = "0123456789abcdef"; - -int git_oid_fromstrn(git_oid *out, const char *str, size_t length) -{ - size_t p; - - if (length > GIT_OID_HEXSZ) - length = GIT_OID_HEXSZ; - - if (length % 2) - length--; - - for (p = 0; p < length; p += 2) { - int v = (from_hex[(unsigned char)str[p + 0]] << 4) - | from_hex[(unsigned char)str[p + 1]]; - - if (v < 0) - return git__throw(GIT_ENOTOID, "Failed to generate sha1. Given string is not a valid sha1 hash"); - - out->id[p / 2] = (unsigned char)v; - } - - for (; p < GIT_OID_HEXSZ; p += 2) - out->id[p / 2] = 0x0; - - return GIT_SUCCESS; -} - -int git_oid_fromstr(git_oid *out, const char *str) -{ - return git_oid_fromstrn(out, str, GIT_OID_HEXSZ); -} - -GIT_INLINE(char) *fmt_one(char *str, unsigned int val) -{ - *str++ = to_hex[val >> 4]; - *str++ = to_hex[val & 0xf]; - return str; -} - -void git_oid_fmt(char *str, const git_oid *oid) -{ - size_t i; - - for (i = 0; i < sizeof(oid->id); i++) - str = fmt_one(str, oid->id[i]); -} - -void git_oid_pathfmt(char *str, const git_oid *oid) -{ - size_t i; - - str = fmt_one(str, oid->id[0]); - *str++ = '/'; - for (i = 1; i < sizeof(oid->id); i++) - str = fmt_one(str, oid->id[i]); -} - -char *git_oid_allocfmt(const git_oid *oid) -{ - char *str = git__malloc(GIT_OID_HEXSZ + 1); - if (!str) - return NULL; - git_oid_fmt(str, oid); - str[GIT_OID_HEXSZ] = '\0'; - return str; -} - -char *git_oid_to_string(char *out, size_t n, const git_oid *oid) -{ - char str[GIT_OID_HEXSZ]; - - if (!out || n == 0 || !oid) - return ""; - - n--; /* allow room for terminating NUL */ - - if (n > 0) { - git_oid_fmt(str, oid); - if (n > GIT_OID_HEXSZ) - n = GIT_OID_HEXSZ; - memcpy(out, str, n); - } - - out[n] = '\0'; - - return out; -} - -int git_oid__parse(git_oid *oid, const char **buffer_out, - const char *buffer_end, const char *header) -{ - const size_t sha_len = GIT_OID_HEXSZ; - const size_t header_len = strlen(header); - - const char *buffer = *buffer_out; - - if (buffer + (header_len + sha_len + 1) > buffer_end) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse OID. Buffer too small"); - - if (memcmp(buffer, header, header_len) != 0) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse OID. Buffer and header do not match"); - - if (buffer[header_len + sha_len] != '\n') - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse OID. Buffer not terminated correctly"); - - if (git_oid_fromstr(oid, buffer + header_len) < GIT_SUCCESS) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse OID. Failed to generate sha1"); - - *buffer_out = buffer + (header_len + sha_len + 1); - - return GIT_SUCCESS; -} - -void git_oid__writebuf(git_buf *buf, const char *header, const git_oid *oid) -{ - char hex_oid[GIT_OID_HEXSZ]; - - git_oid_fmt(hex_oid, oid); - git_buf_puts(buf, header); - git_buf_put(buf, hex_oid, GIT_OID_HEXSZ); - git_buf_putc(buf, '\n'); -} - -void git_oid_fromraw(git_oid *out, const unsigned char *raw) -{ - memcpy(out->id, raw, sizeof(out->id)); -} - -void git_oid_cpy(git_oid *out, const git_oid *src) -{ - memcpy(out->id, src->id, sizeof(out->id)); -} - -int git_oid_cmp(const git_oid *a, const git_oid *b) -{ - return memcmp(a->id, b->id, sizeof(a->id)); -} - -int git_oid_ncmp(const git_oid *oid_a, const git_oid *oid_b, unsigned int len) -{ - const unsigned char *a = oid_a->id; - const unsigned char *b = oid_b->id; - - do { - if (*a != *b) - return 1; - a++; - b++; - len -= 2; - } while (len > 1); - - if (len) - if ((*a ^ *b) & 0xf0) - return 1; - - return 0; -} - -typedef short node_index; - -typedef union { - const char *tail; - node_index children[16]; -} trie_node; - -struct git_oid_shorten { - trie_node *nodes; - size_t node_count, size; - int min_length, full; -}; - -static int resize_trie(git_oid_shorten *self, size_t new_size) -{ - self->nodes = realloc(self->nodes, new_size * sizeof(trie_node)); - if (self->nodes == NULL) - return GIT_ENOMEM; - - if (new_size > self->size) { - memset(&self->nodes[self->size], 0x0, (new_size - self->size) * sizeof(trie_node)); - } - - self->size = new_size; - return GIT_SUCCESS; -} - -static trie_node *push_leaf(git_oid_shorten *os, node_index idx, int push_at, const char *oid) -{ - trie_node *node, *leaf; - node_index idx_leaf; - - if (os->node_count >= os->size) { - if (resize_trie(os, os->size * 2) < GIT_SUCCESS) - return NULL; - } - - idx_leaf = (node_index)os->node_count++; - - if (os->node_count == SHRT_MAX) - os->full = 1; - - node = &os->nodes[idx]; - node->children[push_at] = -idx_leaf; - - leaf = &os->nodes[idx_leaf]; - leaf->tail = oid; - - return node; -} - -git_oid_shorten *git_oid_shorten_new(size_t min_length) -{ - git_oid_shorten *os; - - os = git__malloc(sizeof(git_oid_shorten)); - if (os == NULL) - return NULL; - - memset(os, 0x0, sizeof(git_oid_shorten)); - - if (resize_trie(os, 16) < GIT_SUCCESS) { - free(os); - return NULL; - } - - os->node_count = 1; - os->min_length = min_length; - - return os; -} - -void git_oid_shorten_free(git_oid_shorten *os) -{ - free(os->nodes); - free(os); -} - - -/* - * What wizardry is this? - * - * This is just a memory-optimized trie: basically a very fancy - * 16-ary tree, which is used to store the prefixes of the OID - * strings. - * - * Read more: http://en.wikipedia.org/wiki/Trie - * - * Magic that happens in this method: - * - * - Each node in the trie is an union, so it can work both as - * a normal node, or as a leaf. - * - * - Each normal node points to 16 children (one for each possible - * character in the oid). This is *not* stored in an array of - * pointers, because in a 64-bit arch this would be sucking - * 16*sizeof(void*) = 128 bytes of memory per node, which is fucking - * insane. What we do is store Node Indexes, and use these indexes - * to look up each node in the om->index array. These indexes are - * signed shorts, so this limits the amount of unique OIDs that - * fit in the structure to about 20000 (assuming a more or less uniform - * distribution). - * - * - All the nodes in om->index array are stored contiguously in - * memory, and each of them is 32 bytes, so we fit 2x nodes per - * cache line. Convenient for speed. - * - * - To differentiate the leafs from the normal nodes, we store all - * the indexes towards a leaf as a negative index (indexes to normal - * nodes are positives). When we find that one of the children for - * a node has a negative value, that means it's going to be a leaf. - * This reduces the amount of indexes we have by two, but also reduces - * the size of each node by 1-4 bytes (the amount we would need to - * add a `is_leaf` field): this is good because it allows the nodes - * to fit cleanly in cache lines. - * - * - Once we reach an empty children, instead of continuing to insert - * new nodes for each remaining character of the OID, we store a pointer - * to the tail in the leaf; if the leaf is reached again, we turn it - * into a normal node and use the tail to create a new leaf. - * - * This is a pretty good balance between performance and memory usage. - */ -int git_oid_shorten_add(git_oid_shorten *os, const char *text_oid) -{ - int i, is_leaf; - node_index idx; - - if (os->full) - return GIT_ENOMEM; - - if (text_oid == NULL) - return os->min_length; - - idx = 0; - is_leaf = 0; - - for (i = 0; i < GIT_OID_HEXSZ; ++i) { - int c = from_hex[(int)text_oid[i]]; - trie_node *node; - - if (c == -1) - return git__throw(GIT_ENOTOID, "Failed to shorten OID. Invalid hex value"); - - node = &os->nodes[idx]; - - if (is_leaf) { - const char *tail; - - tail = node->tail; - node->tail = NULL; - - node = push_leaf(os, idx, from_hex[(int)tail[0]], &tail[1]); - if (node == NULL) - return GIT_ENOMEM; - } - - if (node->children[c] == 0) { - if (push_leaf(os, idx, c, &text_oid[i + 1]) == NULL) - return GIT_ENOMEM; - break; - } - - idx = node->children[c]; - is_leaf = 0; - - if (idx < 0) { - node->children[c] = idx = -idx; - is_leaf = 1; - } - } - - if (++i > os->min_length) - os->min_length = i; - - return os->min_length; -} - diff --git a/vendor/libgit2/src/pack.c b/vendor/libgit2/src/pack.c deleted file mode 100644 index d882516be..000000000 --- a/vendor/libgit2/src/pack.c +++ /dev/null @@ -1,804 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "mwindow.h" -#include "odb.h" -#include "pack.h" -#include "delta-apply.h" -#include "sha1_lookup.h" - -#include "git2/oid.h" -#include "git2/zlib.h" - -static int packfile_open(struct git_pack_file *p); -static off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n); -int packfile_unpack_compressed( - git_rawobj *obj, - struct git_pack_file *p, - git_mwindow **w_curs, - off_t *curpos, - size_t size, - git_otype type); - -/* Can find the offset of an object given - * a prefix of an identifier. - * Throws GIT_EAMBIGUOUSOIDPREFIX if short oid - * is ambiguous within the pack. - * This method assumes that len is between - * GIT_OID_MINPREFIXLEN and GIT_OID_HEXSZ. - */ -static int pack_entry_find_offset( - off_t *offset_out, - git_oid *found_oid, - struct git_pack_file *p, - const git_oid *short_oid, - unsigned int len); - -/*********************************************************** - * - * PACK INDEX METHODS - * - ***********************************************************/ - -static void pack_index_free(struct git_pack_file *p) -{ - if (p->index_map.data) { - git_futils_mmap_free(&p->index_map); - p->index_map.data = NULL; - } -} - -static int pack_index_check(const char *path, struct git_pack_file *p) -{ - struct git_pack_idx_header *hdr; - uint32_t version, nr, i, *index; - - void *idx_map; - size_t idx_size; - - struct stat st; - - /* TODO: properly open the file without access time */ - git_file fd = p_open(path, O_RDONLY /*| O_NOATIME */); - - int error; - - if (fd < 0) - return git__throw(GIT_EOSERR, "Failed to check index. File missing or corrupted"); - - if (p_fstat(fd, &st) < GIT_SUCCESS) { - p_close(fd); - return git__throw(GIT_EOSERR, "Failed to check index. File appears to be corrupted"); - } - - if (!git__is_sizet(st.st_size)) - return GIT_ENOMEM; - - idx_size = (size_t)st.st_size; - - if (idx_size < 4 * 256 + 20 + 20) { - p_close(fd); - return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Object is corrupted"); - } - - error = git_futils_mmap_ro(&p->index_map, fd, 0, idx_size); - p_close(fd); - - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to check index"); - - hdr = idx_map = p->index_map.data; - - if (hdr->idx_signature == htonl(PACK_IDX_SIGNATURE)) { - version = ntohl(hdr->idx_version); - - if (version < 2 || version > 2) { - git_futils_mmap_free(&p->index_map); - return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Unsupported index version"); - } - - } else - version = 1; - - nr = 0; - index = idx_map; - - if (version > 1) - index += 2; /* skip index header */ - - for (i = 0; i < 256; i++) { - uint32_t n = ntohl(index[i]); - if (n < nr) { - git_futils_mmap_free(&p->index_map); - return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Index is non-monotonic"); - } - nr = n; - } - - if (version == 1) { - /* - * Total size: - * - 256 index entries 4 bytes each - * - 24-byte entries * nr (20-byte sha1 + 4-byte offset) - * - 20-byte SHA1 of the packfile - * - 20-byte SHA1 file checksum - */ - if (idx_size != 4*256 + nr * 24 + 20 + 20) { - git_futils_mmap_free(&p->index_map); - return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Object is corrupted"); - } - } else if (version == 2) { - /* - * Minimum size: - * - 8 bytes of header - * - 256 index entries 4 bytes each - * - 20-byte sha1 entry * nr - * - 4-byte crc entry * nr - * - 4-byte offset entry * nr - * - 20-byte SHA1 of the packfile - * - 20-byte SHA1 file checksum - * And after the 4-byte offset table might be a - * variable sized table containing 8-byte entries - * for offsets larger than 2^31. - */ - unsigned long min_size = 8 + 4*256 + nr*(20 + 4 + 4) + 20 + 20; - unsigned long max_size = min_size; - - if (nr) - max_size += (nr - 1)*8; - - if (idx_size < min_size || idx_size > max_size) { - git_futils_mmap_free(&p->index_map); - return git__throw(GIT_EOBJCORRUPTED, "Failed to check index. Wrong index size"); - } - - /* Make sure that off_t is big enough to access the whole pack... - * Is this an issue in libgit2? It shouldn't. */ - if (idx_size != min_size && (sizeof(off_t) <= 4)) { - git_futils_mmap_free(&p->index_map); - return git__throw(GIT_EOSERR, "Failed to check index. off_t not big enough to access the whole pack"); - } - } - - p->index_version = version; - p->num_objects = nr; - return GIT_SUCCESS; -} - -static int pack_index_open(struct git_pack_file *p) -{ - char *idx_name; - int error; - - if (p->index_map.data) - return GIT_SUCCESS; - - idx_name = git__strdup(p->pack_name); - strcpy(idx_name + strlen(idx_name) - strlen(".pack"), ".idx"); - - error = pack_index_check(idx_name, p); - free(idx_name); - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to open index"); -} - -static unsigned char *pack_window_open( - struct git_pack_file *p, - git_mwindow **w_cursor, - off_t offset, - unsigned int *left) -{ - if (p->mwf.fd == -1 && packfile_open(p) < GIT_SUCCESS) - return NULL; - - /* Since packfiles end in a hash of their content and it's - * pointless to ask for an offset into the middle of that - * hash, and the pack_window_contains function above wouldn't match - * don't allow an offset too close to the end of the file. - */ - if (offset > (p->mwf.size - 20)) - return NULL; - - return git_mwindow_open(&p->mwf, w_cursor, offset, 20, left); - } - -static unsigned long packfile_unpack_header1( - size_t *sizep, - git_otype *type, - const unsigned char *buf, - unsigned long len) -{ - unsigned shift; - unsigned long size, c; - unsigned long used = 0; - - c = buf[used++]; - *type = (c >> 4) & 7; - size = c & 15; - shift = 4; - while (c & 0x80) { - if (len <= used || bitsizeof(long) <= shift) - return 0; - - c = buf[used++]; - size += (c & 0x7f) << shift; - shift += 7; - } - - *sizep = (size_t)size; - return used; -} - -int git_packfile_unpack_header( - size_t *size_p, - git_otype *type_p, - git_mwindow_file *mwf, - git_mwindow **w_curs, - off_t *curpos) -{ - unsigned char *base; - unsigned int left; - unsigned long used; - - /* pack_window_open() assures us we have [base, base + 20) available - * as a range that we can look at at. (Its actually the hash - * size that is assured.) With our object header encoding - * the maximum deflated object size is 2^137, which is just - * insane, so we know won't exceed what we have been given. - */ -// base = pack_window_open(p, w_curs, *curpos, &left); - base = git_mwindow_open(mwf, w_curs, *curpos, 20, &left); - if (base == NULL) - return GIT_ENOMEM; - - used = packfile_unpack_header1(size_p, type_p, base, left); - - if (used == 0) - return git__throw(GIT_EOBJCORRUPTED, "Header length is zero"); - - *curpos += used; - return GIT_SUCCESS; -} - -static int packfile_unpack_delta( - git_rawobj *obj, - struct git_pack_file *p, - git_mwindow **w_curs, - off_t *curpos, - size_t delta_size, - git_otype delta_type, - off_t obj_offset) -{ - off_t base_offset; - git_rawobj base, delta; - int error; - - base_offset = get_delta_base(p, w_curs, curpos, delta_type, obj_offset); - if (base_offset == 0) - return git__throw(GIT_EOBJCORRUPTED, "Delta offset is zero"); - if (base_offset < 0) - return git__rethrow(base_offset, "Failed to get delta base"); - - git_mwindow_close(w_curs); - error = git_packfile_unpack(&base, p, &base_offset); - - /* - * TODO: git.git tries to load the base from other packfiles - * or loose objects. - * - * We'll need to do this in order to support thin packs. - */ - if (error < GIT_SUCCESS) - return git__rethrow(error, "Corrupted delta"); - - error = packfile_unpack_compressed(&delta, p, w_curs, curpos, delta_size, delta_type); - if (error < GIT_SUCCESS) { - free(base.data); - return git__rethrow(error, "Corrupted delta"); - } - - obj->type = base.type; - error = git__delta_apply(obj, - base.data, base.len, - delta.data, delta.len); - - free(base.data); - free(delta.data); - - /* TODO: we might want to cache this shit. eventually */ - //add_delta_base_cache(p, base_offset, base, base_size, *type); - return error; /* error set by git__delta_apply */ -} - -int git_packfile_unpack( - git_rawobj *obj, - struct git_pack_file *p, - off_t *obj_offset) -{ - git_mwindow *w_curs = NULL; - off_t curpos = *obj_offset; - int error; - - size_t size = 0; - git_otype type; - - /* - * TODO: optionally check the CRC on the packfile - */ - - obj->data = NULL; - obj->len = 0; - obj->type = GIT_OBJ_BAD; - - error = git_packfile_unpack_header(&size, &type, &p->mwf, &w_curs, &curpos); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to unpack packfile"); - - switch (type) { - case GIT_OBJ_OFS_DELTA: - case GIT_OBJ_REF_DELTA: - error = packfile_unpack_delta( - obj, p, &w_curs, &curpos, - size, type, *obj_offset); - break; - - case GIT_OBJ_COMMIT: - case GIT_OBJ_TREE: - case GIT_OBJ_BLOB: - case GIT_OBJ_TAG: - error = packfile_unpack_compressed( - obj, p, &w_curs, &curpos, - size, type); - break; - - default: - error = GIT_EOBJCORRUPTED; - break; - } - - git_mwindow_close(&w_curs); - - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to unpack object"); - - *obj_offset = curpos; - return GIT_SUCCESS; -} - -int packfile_unpack_compressed( - git_rawobj *obj, - struct git_pack_file *p, - git_mwindow **w_curs, - off_t *curpos, - size_t size, - git_otype type) -{ - int st; - z_stream stream; - unsigned char *buffer, *in; - - buffer = git__malloc(size + 1); - memset(buffer, 0x0, size + 1); - - memset(&stream, 0, sizeof(stream)); - stream.next_out = buffer; - stream.avail_out = size + 1; - - st = inflateInit(&stream); - if (st != Z_OK) { - free(buffer); - return git__throw(GIT_EZLIB, "Error in zlib"); - } - - do { - in = pack_window_open(p, w_curs, *curpos, &stream.avail_in); - stream.next_in = in; - st = inflate(&stream, Z_FINISH); - - if (!stream.avail_out) - break; /* the payload is larger than it should be */ - - *curpos += stream.next_in - in; - } while (st == Z_OK || st == Z_BUF_ERROR); - - inflateEnd(&stream); - - if ((st != Z_STREAM_END) || stream.total_out != size) { - free(buffer); - return git__throw(GIT_EZLIB, "Error in zlib"); - } - - obj->type = type; - obj->len = size; - obj->data = buffer; - return GIT_SUCCESS; -} - -/* - * curpos is where the data starts, delta_obj_offset is the where the - * header starts - */ -off_t get_delta_base( - struct git_pack_file *p, - git_mwindow **w_curs, - off_t *curpos, - git_otype type, - off_t delta_obj_offset) -{ - unsigned char *base_info = pack_window_open(p, w_curs, *curpos, NULL); - off_t base_offset; - git_oid unused; - - /* pack_window_open() assured us we have [base_info, base_info + 20) - * as a range that we can look at without walking off the - * end of the mapped window. Its actually the hash size - * that is assured. An OFS_DELTA longer than the hash size - * is stupid, as then a REF_DELTA would be smaller to store. - */ - if (type == GIT_OBJ_OFS_DELTA) { - unsigned used = 0; - unsigned char c = base_info[used++]; - base_offset = c & 127; - while (c & 128) { - base_offset += 1; - if (!base_offset || MSB(base_offset, 7)) - return 0; /* overflow */ - c = base_info[used++]; - base_offset = (base_offset << 7) + (c & 127); - } - base_offset = delta_obj_offset - base_offset; - if (base_offset <= 0 || base_offset >= delta_obj_offset) - return 0; /* out of bound */ - *curpos += used; - } else if (type == GIT_OBJ_REF_DELTA) { - /* If we have the cooperative cache, search in it first */ - if (p->has_cache) { - int pos; - struct git_pack_entry key; - - git_oid_fromraw(&key.sha1, base_info); - pos = git_vector_bsearch(&p->cache, &key); - if (pos >= 0) { - *curpos += 20; - return ((struct git_pack_entry *)git_vector_get(&p->cache, pos))->offset; - } - } - /* The base entry _must_ be in the same pack */ - if (pack_entry_find_offset(&base_offset, &unused, p, (git_oid *)base_info, GIT_OID_HEXSZ) < GIT_SUCCESS) - return git__rethrow(GIT_EPACKCORRUPTED, "Base entry delta is not in the same pack"); - *curpos += 20; - } else - return 0; - - return base_offset; -} - -/*********************************************************** - * - * PACKFILE METHODS - * - ***********************************************************/ - -static struct git_pack_file *packfile_alloc(int extra) -{ - struct git_pack_file *p = git__malloc(sizeof(*p) + extra); - memset(p, 0, sizeof(*p)); - p->mwf.fd = -1; - return p; -} - - -void packfile_free(struct git_pack_file *p) -{ - assert(p); - - /* clear_delta_base_cache(); */ - git_mwindow_free_all(&p->mwf); - - if (p->mwf.fd != -1) - p_close(p->mwf.fd); - - pack_index_free(p); - - free(p->bad_object_sha1); - free(p); -} - -static int packfile_open(struct git_pack_file *p) -{ - struct stat st; - struct git_pack_header hdr; - git_oid sha1; - unsigned char *idx_sha1; - - if (!p->index_map.data && pack_index_open(p) < GIT_SUCCESS) - return git__throw(GIT_ENOTFOUND, "Failed to open packfile. File not found"); - - /* TODO: open with noatime */ - p->mwf.fd = p_open(p->pack_name, O_RDONLY); - if (p->mwf.fd < 0 || p_fstat(p->mwf.fd, &st) < GIT_SUCCESS) - return git__throw(GIT_EOSERR, "Failed to open packfile. File appears to be corrupted"); - - if (git_mwindow_file_register(&p->mwf) < GIT_SUCCESS) { - p_close(p->mwf.fd); - return git__throw(GIT_ERROR, "Failed to register packfile windows"); - } - - /* If we created the struct before we had the pack we lack size. */ - if (!p->mwf.size) { - if (!S_ISREG(st.st_mode)) - goto cleanup; - p->mwf.size = (off_t)st.st_size; - } else if (p->mwf.size != st.st_size) - goto cleanup; - -#if 0 - /* We leave these file descriptors open with sliding mmap; - * there is no point keeping them open across exec(), though. - */ - fd_flag = fcntl(p->mwf.fd, F_GETFD, 0); - if (fd_flag < 0) - return error("cannot determine file descriptor flags"); - - fd_flag |= FD_CLOEXEC; - if (fcntl(p->pack_fd, F_SETFD, fd_flag) == -1) - return GIT_EOSERR; -#endif - - /* Verify we recognize this pack file format. */ - if (p_read(p->mwf.fd, &hdr, sizeof(hdr)) < GIT_SUCCESS) - goto cleanup; - - if (hdr.hdr_signature != htonl(PACK_SIGNATURE)) - goto cleanup; - - if (!pack_version_ok(hdr.hdr_version)) - goto cleanup; - - /* Verify the pack matches its index. */ - if (p->num_objects != ntohl(hdr.hdr_entries)) - goto cleanup; - - if (p_lseek(p->mwf.fd, p->mwf.size - GIT_OID_RAWSZ, SEEK_SET) == -1) - goto cleanup; - - if (p_read(p->mwf.fd, sha1.id, GIT_OID_RAWSZ) < GIT_SUCCESS) - goto cleanup; - - idx_sha1 = ((unsigned char *)p->index_map.data) + p->index_map.len - 40; - - if (git_oid_cmp(&sha1, (git_oid *)idx_sha1) != 0) - goto cleanup; - - return GIT_SUCCESS; - -cleanup: - p_close(p->mwf.fd); - p->mwf.fd = -1; - return git__throw(GIT_EPACKCORRUPTED, "Failed to open packfile. Pack is corrupted"); -} - -int git_packfile_check(struct git_pack_file **pack_out, const char *path) -{ - struct stat st; - struct git_pack_file *p; - size_t path_len; - - *pack_out = NULL; - path_len = strlen(path); - p = packfile_alloc(path_len + 2); - - /* - * Make sure a corresponding .pack file exists and that - * the index looks sane. - */ - path_len -= strlen(".idx"); - if (path_len < 1) { - free(p); - return git__throw(GIT_ENOTFOUND, "Failed to check packfile. Wrong path name"); - } - - memcpy(p->pack_name, path, path_len); - - strcpy(p->pack_name + path_len, ".keep"); - if (git_futils_exists(p->pack_name) == GIT_SUCCESS) - p->pack_keep = 1; - - strcpy(p->pack_name + path_len, ".pack"); - if (p_stat(p->pack_name, &st) < GIT_SUCCESS || !S_ISREG(st.st_mode)) { - free(p); - return git__throw(GIT_ENOTFOUND, "Failed to check packfile. File not found"); - } - - /* ok, it looks sane as far as we can check without - * actually mapping the pack file. - */ - p->mwf.size = (off_t)st.st_size; - p->pack_local = 1; - p->mtime = (git_time_t)st.st_mtime; - - /* see if we can parse the sha1 oid in the packfile name */ - if (path_len < 40 || - git_oid_fromstr(&p->sha1, path + path_len - GIT_OID_HEXSZ) < GIT_SUCCESS) - memset(&p->sha1, 0x0, GIT_OID_RAWSZ); - - *pack_out = p; - return GIT_SUCCESS; -} - -/*********************************************************** - * - * PACKFILE ENTRY SEARCH INTERNALS - * - ***********************************************************/ - -static off_t nth_packed_object_offset(const struct git_pack_file *p, uint32_t n) -{ - const unsigned char *index = p->index_map.data; - index += 4 * 256; - if (p->index_version == 1) { - return ntohl(*((uint32_t *)(index + 24 * n))); - } else { - uint32_t off; - index += 8 + p->num_objects * (20 + 4); - off = ntohl(*((uint32_t *)(index + 4 * n))); - if (!(off & 0x80000000)) - return off; - index += p->num_objects * 4 + (off & 0x7fffffff) * 8; - return (((uint64_t)ntohl(*((uint32_t *)(index + 0)))) << 32) | - ntohl(*((uint32_t *)(index + 4))); - } -} - -static int pack_entry_find_offset( - off_t *offset_out, - git_oid *found_oid, - struct git_pack_file *p, - const git_oid *short_oid, - unsigned int len) -{ - const uint32_t *level1_ofs = p->index_map.data; - const unsigned char *index = p->index_map.data; - unsigned hi, lo, stride; - int pos, found = 0; - const unsigned char *current = 0; - - *offset_out = 0; - - if (index == NULL) { - int error; - - if ((error = pack_index_open(p)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to find offset for pack entry"); - - assert(p->index_map.data); - - index = p->index_map.data; - level1_ofs = p->index_map.data; - } - - if (p->index_version > 1) { - level1_ofs += 2; - index += 8; - } - - index += 4 * 256; - hi = ntohl(level1_ofs[(int)short_oid->id[0]]); - lo = ((short_oid->id[0] == 0x0) ? 0 : ntohl(level1_ofs[(int)short_oid->id[0] - 1])); - - if (p->index_version > 1) { - stride = 20; - } else { - stride = 24; - index += 4; - } - -#ifdef INDEX_DEBUG_LOOKUP - printf("%02x%02x%02x... lo %u hi %u nr %d\n", - short_oid->id[0], short_oid->id[1], short_oid->id[2], lo, hi, p->num_objects); -#endif - - /* Use git.git lookup code */ - pos = sha1_entry_pos(index, stride, 0, lo, hi, p->num_objects, short_oid->id); - - if (pos >= 0) { - /* An object matching exactly the oid was found */ - found = 1; - current = index + pos * stride; - } else { - /* No object was found */ - /* pos refers to the object with the "closest" oid to short_oid */ - pos = - 1 - pos; - if (pos < (int)p->num_objects) { - current = index + pos * stride; - - if (!git_oid_ncmp(short_oid, (const git_oid *)current, len)) { - found = 1; - } - } - } - - if (found && pos + 1 < (int)p->num_objects) { - /* Check for ambiguousity */ - const unsigned char *next = current + stride; - - if (!git_oid_ncmp(short_oid, (const git_oid *)next, len)) { - found = 2; - } - } - - if (!found) { - return git__throw(GIT_ENOTFOUND, "Failed to find offset for pack entry. Entry not found"); - } else if (found > 1) { - return git__throw(GIT_EAMBIGUOUSOIDPREFIX, "Failed to find offset for pack entry. Ambiguous sha1 prefix within pack"); - } else { - *offset_out = nth_packed_object_offset(p, pos); - git_oid_fromraw(found_oid, current); - -#ifdef INDEX_DEBUG_LOOKUP - unsigned char hex_sha1[GIT_OID_HEXSZ + 1]; - git_oid_fmt(hex_sha1, found_oid); - hex_sha1[GIT_OID_HEXSZ] = '\0'; - printf("found lo=%d %s\n", lo, hex_sha1); -#endif - return GIT_SUCCESS; - } -} - -int git_pack_entry_find( - struct git_pack_entry *e, - struct git_pack_file *p, - const git_oid *short_oid, - unsigned int len) -{ - off_t offset; - git_oid found_oid; - int error; - - assert(p); - - if (len == GIT_OID_HEXSZ && p->num_bad_objects) { - unsigned i; - for (i = 0; i < p->num_bad_objects; i++) - if (git_oid_cmp(short_oid, &p->bad_object_sha1[i]) == 0) - return git__throw(GIT_ERROR, "Failed to find pack entry. Bad object found"); - } - - error = pack_entry_find_offset(&offset, &found_oid, p, short_oid, len); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to find pack entry. Couldn't find offset"); - - /* we found a unique entry in the index; - * make sure the packfile backing the index - * still exists on disk */ - if (p->mwf.fd == -1 && packfile_open(p) < GIT_SUCCESS) - return git__throw(GIT_EOSERR, "Failed to find pack entry. Packfile doesn't exist on disk"); - - e->offset = offset; - e->p = p; - - git_oid_cpy(&e->sha1, &found_oid); - return GIT_SUCCESS; -} diff --git a/vendor/libgit2/src/pack.h b/vendor/libgit2/src/pack.h deleted file mode 100644 index 164086fdf..000000000 --- a/vendor/libgit2/src/pack.h +++ /dev/null @@ -1,115 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDE_pack_h__ -#define INCLUDE_pack_h__ - -#include "git2/oid.h" - -#include "common.h" -#include "map.h" -#include "mwindow.h" -#include "odb.h" - -#define PACK_SIGNATURE 0x5041434b /* "PACK" */ -#define PACK_VERSION 2 -#define pack_version_ok(v) ((v) == htonl(2) || (v) == htonl(3)) -struct git_pack_header { - uint32_t hdr_signature; - uint32_t hdr_version; - uint32_t hdr_entries; -}; - -/* - * The first four bytes of index formats later than version 1 should - * start with this signature, as all older git binaries would find this - * value illegal and abort reading the file. - * - * This is the case because the number of objects in a packfile - * cannot exceed 1,431,660,000 as every object would need at least - * 3 bytes of data and the overall packfile cannot exceed 4 GiB with - * version 1 of the index file due to the offsets limited to 32 bits. - * Clearly the signature exceeds this maximum. - * - * Very old git binaries will also compare the first 4 bytes to the - * next 4 bytes in the index and abort with a "non-monotonic index" - * error if the second 4 byte word is smaller than the first 4 - * byte word. This would be true in the proposed future index - * format as idx_signature would be greater than idx_version. - */ - -#define PACK_IDX_SIGNATURE 0xff744f63 /* "\377tOc" */ - -struct git_pack_idx_header { - uint32_t idx_signature; - uint32_t idx_version; -}; - -struct git_pack_file { - git_mwindow_file mwf; - git_map index_map; - - uint32_t num_objects; - uint32_t num_bad_objects; - git_oid *bad_object_sha1; /* array of git_oid */ - - int index_version; - git_time_t mtime; - unsigned pack_local:1, pack_keep:1, has_cache:1; - git_oid sha1; - git_vector cache; - - /* something like ".git/objects/pack/xxxxx.pack" */ - char pack_name[GIT_FLEX_ARRAY]; /* more */ -}; - -struct git_pack_entry { - off_t offset; - git_oid sha1; - struct git_pack_file *p; -}; - -int git_packfile_unpack_header( - size_t *size_p, - git_otype *type_p, - git_mwindow_file *mwf, - git_mwindow **w_curs, - off_t *curpos); - -int git_packfile_unpack(git_rawobj *obj, struct git_pack_file *p, off_t *obj_offset); - -off_t get_delta_base(struct git_pack_file *p, git_mwindow **w_curs, - off_t *curpos, git_otype type, - off_t delta_obj_offset); - -void packfile_free(struct git_pack_file *p); -int git_packfile_check(struct git_pack_file **pack_out, const char *path); -int git_pack_entry_find( - struct git_pack_entry *e, - struct git_pack_file *p, - const git_oid *short_oid, - unsigned int len); - -#endif diff --git a/vendor/libgit2/src/path.c b/vendor/libgit2/src/path.c deleted file mode 100644 index 374694432..000000000 --- a/vendor/libgit2/src/path.c +++ /dev/null @@ -1,264 +0,0 @@ -#include "common.h" -#include "path.h" -#include "posix.h" - -#include -#include -#include - -/* - * Based on the Android implementation, BSD licensed. - * Check http://android.git.kernel.org/ - */ -int git_path_basename_r(char *buffer, size_t bufflen, const char *path) -{ - const char *endp, *startp; - int len, result; - - /* Empty or NULL string gets treated as "." */ - if (path == NULL || *path == '\0') { - startp = "."; - len = 1; - goto Exit; - } - - /* Strip trailing slashes */ - endp = path + strlen(path) - 1; - while (endp > path && *endp == '/') - endp--; - - /* All slashes becomes "/" */ - if (endp == path && *endp == '/') { - startp = "/"; - len = 1; - goto Exit; - } - - /* Find the start of the base */ - startp = endp; - while (startp > path && *(startp - 1) != '/') - startp--; - - len = endp - startp +1; - -Exit: - result = len; - if (buffer == NULL) { - return result; - } - if (len > (int)bufflen-1) { - len = (int)bufflen-1; - result = GIT_ENOMEM; - } - - if (len >= 0) { - memmove(buffer, startp, len); - buffer[len] = 0; - } - return result; -} - -/* - * Based on the Android implementation, BSD licensed. - * Check http://android.git.kernel.org/ - */ -int git_path_dirname_r(char *buffer, size_t bufflen, const char *path) -{ - const char *endp; - int result, len; - - /* Empty or NULL string gets treated as "." */ - if (path == NULL || *path == '\0') { - path = "."; - len = 1; - goto Exit; - } - - /* Strip trailing slashes */ - endp = path + strlen(path) - 1; - while (endp > path && *endp == '/') - endp--; - - /* Find the start of the dir */ - while (endp > path && *endp != '/') - endp--; - - /* Either the dir is "/" or there are no slashes */ - if (endp == path) { - path = (*endp == '/') ? "/" : "."; - len = 1; - goto Exit; - } - - do { - endp--; - } while (endp > path && *endp == '/'); - - len = endp - path +1; - -#ifdef GIT_WIN32 - /* Mimic unix behavior where '/.git' returns '/': 'C:/.git' will return - 'C:/' here */ - - if (len == 2 && isalpha(path[0]) && path[1] == ':') { - len = 3; - goto Exit; - } -#endif - -Exit: - result = len; - if (len+1 > GIT_PATH_MAX) { - return GIT_ENOMEM; - } - if (buffer == NULL) - return result; - - if (len > (int)bufflen-1) { - len = (int)bufflen-1; - result = GIT_ENOMEM; - } - - if (len >= 0) { - memmove(buffer, path, len); - buffer[len] = 0; - } - return result; -} - - -char *git_path_dirname(const char *path) -{ - char *dname = NULL; - int len; - - len = (path ? strlen(path) : 0) + 2; - dname = (char *)git__malloc(len); - if (dname == NULL) - return NULL; - - if (git_path_dirname_r(dname, len, path) < GIT_SUCCESS) { - free(dname); - return NULL; - } - - return dname; -} - -char *git_path_basename(const char *path) -{ - char *bname = NULL; - int len; - - len = (path ? strlen(path) : 0) + 2; - bname = (char *)git__malloc(len); - if (bname == NULL) - return NULL; - - if (git_path_basename_r(bname, len, path) < GIT_SUCCESS) { - free(bname); - return NULL; - } - - return bname; -} - - -const char *git_path_topdir(const char *path) -{ - size_t len; - int i; - - assert(path); - len = strlen(path); - - if (!len || path[len - 1] != '/') - return NULL; - - for (i = len - 2; i >= 0; --i) - if (path[i] == '/') - break; - - return &path[i + 1]; -} - -void git_path_join_n(char *buffer_out, int count, ...) -{ - va_list ap; - int i; - char *buffer_start = buffer_out; - - va_start(ap, count); - for (i = 0; i < count; ++i) { - const char *path; - int len; - - path = va_arg(ap, const char *); - - assert((i == 0) || path != buffer_start); - - if (i > 0 && *path == '/' && buffer_out > buffer_start && buffer_out[-1] == '/') - path++; - - if (!*path) - continue; - - len = strlen(path); - memmove(buffer_out, path, len); - buffer_out = buffer_out + len; - - if (i < count - 1 && buffer_out[-1] != '/') - *buffer_out++ = '/'; - } - va_end(ap); - - *buffer_out = '\0'; -} - -int git_path_root(const char *path) -{ - int offset = 0; - -#ifdef GIT_WIN32 - /* Does the root of the path look like a windows drive ? */ - if (isalpha(path[0]) && (path[1] == ':')) - offset += 2; -#endif - - if (*(path + offset) == '/') - return offset; - - return -1; /* Not a real error. Rather a signal than the path is not rooted */ -} - -int git_path_prettify(char *path_out, const char *path, const char *base) -{ - char *result; - - if (base == NULL || git_path_root(path) >= 0) { - result = p_realpath(path, path_out); - } else { - char aux_path[GIT_PATH_MAX]; - git_path_join(aux_path, base, path); - result = p_realpath(aux_path, path_out); - } - - return result ? GIT_SUCCESS : GIT_EOSERR; -} - -int git_path_prettify_dir(char *path_out, const char *path, const char *base) -{ - size_t end; - - if (git_path_prettify(path_out, path, base) < GIT_SUCCESS) - return GIT_EOSERR; - - end = strlen(path_out); - - if (end && path_out[end - 1] != '/') { - path_out[end] = '/'; - path_out[end + 1] = '\0'; - } - - return GIT_SUCCESS; -} diff --git a/vendor/libgit2/src/path.h b/vendor/libgit2/src/path.h deleted file mode 100644 index 36e22a768..000000000 --- a/vendor/libgit2/src/path.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * posix.h - Path management methods - */ -#ifndef INCLUDE_path_h__ -#define INCLUDE_path_h__ - -#include "common.h" - -/* - * The dirname() function shall take a pointer to a character string - * that contains a pathname, and return a pointer to a string that is a - * pathname of the parent directory of that file. Trailing '/' characters - * in the path are not counted as part of the path. - * - * If path does not contain a '/', then dirname() shall return a pointer to - * the string ".". If path is a null pointer or points to an empty string, - * dirname() shall return a pointer to the string "." . - * - * The `git_path_dirname` implementation is thread safe. The returned - * string must be manually free'd. - * - * The `git_path_dirname_r` implementation expects a string allocated - * by the user with big enough size. - */ -extern char *git_path_dirname(const char *path); -extern int git_path_dirname_r(char *buffer, size_t bufflen, const char *path); - -/* - * This function returns the basename of the file, which is the last - * part of its full name given by fname, with the drive letter and - * leading directories stripped off. For example, the basename of - * c:/foo/bar/file.ext is file.ext, and the basename of a:foo is foo. - * - * Trailing slashes and backslashes are significant: the basename of - * c:/foo/bar/ is an empty string after the rightmost slash. - * - * The `git_path_basename` implementation is thread safe. The returned - * string must be manually free'd. - * - * The `git_path_basename_r` implementation expects a string allocated - * by the user with big enough size. - */ -extern char *git_path_basename(const char *path); -extern int git_path_basename_r(char *buffer, size_t bufflen, const char *path); - -extern const char *git_path_topdir(const char *path); - -/** - * Join two paths together. Takes care of properly fixing the - * middle slashes and everything - * - * The paths are joined together into buffer_out; this is expected - * to be an user allocated buffer of `GIT_PATH_MAX` size - */ -extern void git_path_join_n(char *buffer_out, int npath, ...); - -GIT_INLINE(void) git_path_join(char *buffer_out, const char *path_a, const char *path_b) -{ - git_path_join_n(buffer_out, 2, path_a, path_b); -} - -int git_path_root(const char *path); - -int git_path_prettify(char *path_out, const char *path, const char *base); -int git_path_prettify_dir(char *path_out, const char *path, const char *base); - -#ifdef GIT_WIN32 -GIT_INLINE(void) git_path_mkposix(char *path) -{ - while (*path) { - if (*path == '\\') - *path = '/'; - - path++; - } -} -#else -# define git_path_mkposix(p) /* blank */ -#endif - -#endif diff --git a/vendor/libgit2/src/pkt.c b/vendor/libgit2/src/pkt.c deleted file mode 100644 index 4eac0411f..000000000 --- a/vendor/libgit2/src/pkt.c +++ /dev/null @@ -1,362 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" - -#include "git2/types.h" -#include "git2/errors.h" -#include "git2/refs.h" -#include "git2/revwalk.h" - -#include "pkt.h" -#include "util.h" -#include "netops.h" -#include "posix.h" - -#include - -#define PKT_LEN_SIZE 4 - -static int flush_pkt(git_pkt **out) -{ - git_pkt *pkt; - - pkt = git__malloc(sizeof(git_pkt)); - if (pkt == NULL) - return GIT_ENOMEM; - - pkt->type = GIT_PKT_FLUSH; - *out = pkt; - - return GIT_SUCCESS; -} - -/* the rest of the line will be useful for multi_ack */ -static int ack_pkt(git_pkt **out, const char *GIT_UNUSED(line), size_t GIT_UNUSED(len)) -{ - git_pkt *pkt; - GIT_UNUSED_ARG(line); - GIT_UNUSED_ARG(len); - - pkt = git__malloc(sizeof(git_pkt)); - if (pkt == NULL) - return GIT_ENOMEM; - - pkt->type = GIT_PKT_ACK; - *out = pkt; - - return GIT_SUCCESS; -} - -static int nak_pkt(git_pkt **out) -{ - git_pkt *pkt; - - pkt = git__malloc(sizeof(git_pkt)); - if (pkt == NULL) - return GIT_ENOMEM; - - pkt->type = GIT_PKT_NAK; - *out = pkt; - - return GIT_SUCCESS; -} - -static int pack_pkt(git_pkt **out) -{ - git_pkt *pkt; - - pkt = git__malloc(sizeof(git_pkt)); - if (pkt == NULL) - return GIT_ENOMEM; - - pkt->type = GIT_PKT_PACK; - *out = pkt; - - return GIT_SUCCESS; -} - -/* - * Parse an other-ref line. - */ -static int ref_pkt(git_pkt **out, const char *line, size_t len) -{ - git_pkt_ref *pkt; - int error, has_caps = 0; - - pkt = git__malloc(sizeof(git_pkt_ref)); - if (pkt == NULL) - return GIT_ENOMEM; - - memset(pkt, 0x0, sizeof(git_pkt_ref)); - pkt->type = GIT_PKT_REF; - error = git_oid_fromstr(&pkt->head.oid, line); - if (error < GIT_SUCCESS) { - error = git__throw(error, "Failed to parse reference ID"); - goto out; - } - - /* Check for a bit of consistency */ - if (line[GIT_OID_HEXSZ] != ' ') { - error = git__throw(GIT_EOBJCORRUPTED, "Failed to parse ref. No SP"); - goto out; - } - - /* Jump from the name */ - line += GIT_OID_HEXSZ + 1; - len -= (GIT_OID_HEXSZ + 1); - - if (strlen(line) < len) - has_caps = 1; - - if (line[len - 1] == '\n') - --len; - - pkt->head.name = git__malloc(len + 1); - if (pkt->head.name == NULL) { - error = GIT_ENOMEM; - goto out; - } - memcpy(pkt->head.name, line, len); - pkt->head.name[len] = '\0'; - - if (has_caps) { - pkt->capabilities = strchr(pkt->head.name, '\0') + 1; - } - -out: - if (error < GIT_SUCCESS) - free(pkt); - else - *out = (git_pkt *)pkt; - - return error; -} - -static ssize_t parse_len(const char *line) -{ - char num[PKT_LEN_SIZE + 1]; - int i, error; - long len; - const char *num_end; - - memcpy(num, line, PKT_LEN_SIZE); - num[PKT_LEN_SIZE] = '\0'; - - for (i = 0; i < PKT_LEN_SIZE; ++i) { - if (!isxdigit(num[i])) - return GIT_ENOTNUM; - } - - error = git__strtol32(&len, num, &num_end, 16); - if (error < GIT_SUCCESS) { - return error; - } - - return (unsigned int) len; -} - -/* - * As per the documentation, the syntax is: - * - * pkt-line = data-pkt / flush-pkt - * data-pkt = pkt-len pkt-payload - * pkt-len = 4*(HEXDIG) - * pkt-payload = (pkt-len -4)*(OCTET) - * flush-pkt = "0000" - * - * Which means that the first four bytes are the length of the line, - * in ASCII hexadecimal (including itself) - */ - -int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t bufflen) -{ - int error = GIT_SUCCESS; - size_t len; - - /* Not even enough for the length */ - if (bufflen > 0 && bufflen < PKT_LEN_SIZE) - return GIT_ESHORTBUFFER; - - error = parse_len(line); - if (error < GIT_SUCCESS) { - /* - * If we fail to parse the length, it might be because the - * server is trying to send us the packfile already. - */ - if (bufflen >= 4 && !git__prefixcmp(line, "PACK")) { - *out = line; - return pack_pkt(head); - } - - return git__throw(error, "Failed to parse pkt length"); - } - - len = error; - - /* - * If we were given a buffer length, then make sure there is - * enough in the buffer to satisfy this line - */ - if (bufflen > 0 && bufflen < len) - return GIT_ESHORTBUFFER; - - line += PKT_LEN_SIZE; - /* - * TODO: How do we deal with empty lines? Try again? with the next - * line? - */ - if (len == PKT_LEN_SIZE) { - *out = line; - return GIT_SUCCESS; - } - - if (len == 0) { /* Flush pkt */ - *out = line; - return flush_pkt(head); - } - - len -= PKT_LEN_SIZE; /* the encoded length includes its own size */ - - /* Assming the minimal size is actually 4 */ - if (!git__prefixcmp(line, "ACK")) - error = ack_pkt(head, line, len); - else if (!git__prefixcmp(line, "NAK")) - error = nak_pkt(head); - else - error = ref_pkt(head, line, len); - - *out = line + len; - - return error; -} - -void git_pkt_free(git_pkt *pkt) -{ - if(pkt->type == GIT_PKT_REF) { - git_pkt_ref *p = (git_pkt_ref *) pkt; - free(p->head.name); - } - - free(pkt); -} - -int git_pkt_send_flush(int s) -{ - char flush[] = "0000"; - - return gitno_send(s, flush, strlen(flush), 0); -} - -static int send_want_with_caps(git_remote_head *head, git_transport_caps *caps, int fd) -{ - char capstr[20]; /* Longer than we need */ - char oid[GIT_OID_HEXSZ +1] = {0}, *cmd; - int error, len; - - if (caps->ofs_delta) - strcpy(capstr, GIT_CAP_OFS_DELTA); - - len = strlen("XXXXwant ") + GIT_OID_HEXSZ + 1 /* NUL */ + strlen(capstr) + 1 /* LF */; - cmd = git__malloc(len + 1); - if (cmd == NULL) - return GIT_ENOMEM; - - git_oid_fmt(oid, &head->oid); - memset(cmd, 0x0, len + 1); - p_snprintf(cmd, len + 1, "%04xwant %s%c%s\n", len, oid, 0, capstr); - error = gitno_send(fd, cmd, len, 0); - free(cmd); - return error; -} - -/* - * All "want" packets have the same length and format, so what we do - * is overwrite the OID each time. - */ -#define WANT_PREFIX "0032want " - -int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd) -{ - unsigned int i = 0; - int error = GIT_SUCCESS; - char buf[sizeof(WANT_PREFIX) + GIT_OID_HEXSZ + 1]; - git_remote_head *head; - - memcpy(buf, WANT_PREFIX, strlen(WANT_PREFIX)); - buf[sizeof(buf) - 2] = '\n'; - buf[sizeof(buf) - 1] = '\0'; - - /* If there are common caps, find the first one */ - if (caps->common) { - for (; i < refs->len; ++i) { - head = refs->heads[i]; - if (head->local) - continue; - else - break; - } - - error = send_want_with_caps(refs->heads[i], caps, fd); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to send want pkt with caps"); - /* Increase it here so it's correct whether we run this or not */ - i++; - } - - /* Continue from where we left off */ - for (; i < refs->len; ++i) { - head = refs->heads[i]; - if (head->local) - continue; - - git_oid_fmt(buf + strlen(WANT_PREFIX), &head->oid); - error = gitno_send(fd, buf, strlen(buf), 0); - return git__rethrow(error, "Failed to send want pkt"); - } - - return git_pkt_send_flush(fd); -} - -/* - * TODO: this should be a more generic function, maybe to be used by - * git_pkt_send_wants, as it's not performance-critical - */ -#define HAVE_PREFIX "0032have " - -int git_pkt_send_have(git_oid *oid, int fd) -{ - char buf[] = "0032have 0000000000000000000000000000000000000000\n"; - - git_oid_fmt(buf + strlen(HAVE_PREFIX), oid); - return gitno_send(fd, buf, strlen(buf), 0); -} - -int git_pkt_send_done(int fd) -{ - char buf[] = "0009done\n"; - - return gitno_send(fd, buf, strlen(buf), 0); -} diff --git a/vendor/libgit2/src/pkt.h b/vendor/libgit2/src/pkt.h deleted file mode 100644 index 1c6a20659..000000000 --- a/vendor/libgit2/src/pkt.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDE_pkt_h__ -#define INCLUDE_pkt_h__ - -#include "common.h" -#include "transport.h" -#include "git2/net.h" - -enum git_pkt_type { - GIT_PKT_CMD, - GIT_PKT_FLUSH, - GIT_PKT_REF, - GIT_PKT_HAVE, - GIT_PKT_ACK, - GIT_PKT_NAK, - GIT_PKT_PACK, -}; - -/* Used for multi-ack */ -enum git_ack_status { - GIT_ACK_NONE, - GIT_ACK_CONTINUE, - GIT_ACK_COMMON, - GIT_ACK_READY -}; - -/* This would be a flush pkt */ -typedef struct { - enum git_pkt_type type; -} git_pkt; - -struct git_pkt_cmd { - enum git_pkt_type type; - char *cmd; - char *path; - char *host; -}; - -/* This is a pkt-line with some info in it */ -typedef struct { - enum git_pkt_type type; - git_remote_head head; - char *capabilities; -} git_pkt_ref; - -/* Useful later */ -typedef struct { - enum git_pkt_type type; - git_oid oid; - enum git_ack_status status; -} git_pkt_ack; - -int git_pkt_parse_line(git_pkt **head, const char *line, const char **out, size_t len); -int git_pkt_send_flush(int s); -int git_pkt_send_done(int s); -int git_pkt_send_wants(git_headarray *refs, git_transport_caps *caps, int fd); -int git_pkt_send_have(git_oid *oid, int fd); -void git_pkt_free(git_pkt *pkt); - -#endif diff --git a/vendor/libgit2/src/posix.c b/vendor/libgit2/src/posix.c deleted file mode 100644 index 4bb8c3246..000000000 --- a/vendor/libgit2/src/posix.c +++ /dev/null @@ -1,74 +0,0 @@ -#include "common.h" -#include "posix.h" -#include "path.h" -#include -#include - -int p_open(const char *path, int flags) -{ - return open(path, flags | O_BINARY); -} - -int p_creat(const char *path, int mode) -{ - return open(path, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, mode); -} - -int p_read(git_file fd, void *buf, size_t cnt) -{ - char *b = buf; - while (cnt) { - ssize_t r = read(fd, b, cnt); - if (r < 0) { - if (errno == EINTR || errno == EAGAIN) - continue; - return GIT_EOSERR; - } - if (!r) - break; - cnt -= r; - b += r; - } - return (int)(b - (char *)buf); -} - -int p_write(git_file fd, const void *buf, size_t cnt) -{ - const char *b = buf; - while (cnt) { - ssize_t r = write(fd, b, cnt); - if (r < 0) { - if (errno == EINTR || errno == EAGAIN) - continue; - return GIT_EOSERR; - } - if (!r) { - errno = EPIPE; - return GIT_EOSERR; - } - cnt -= r; - b += r; - } - return GIT_SUCCESS; -} - -int p_getcwd(char *buffer_out, size_t size) -{ - char *cwd_buffer; - - assert(buffer_out && size > 0); - -#ifdef GIT_WIN32 - cwd_buffer = _getcwd(buffer_out, size); -#else - cwd_buffer = getcwd(buffer_out, size); -#endif - - if (cwd_buffer == NULL) - return git__throw(GIT_EOSERR, "Failed to retrieve current working directory"); - - git_path_mkposix(buffer_out); - - git_path_join(buffer_out, buffer_out, ""); //Ensure the path ends with a trailing slash - return GIT_SUCCESS; -} diff --git a/vendor/libgit2/src/posix.h b/vendor/libgit2/src/posix.h deleted file mode 100644 index f1424f8d3..000000000 --- a/vendor/libgit2/src/posix.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * posix.h - OS agnostic POSIX calls - */ -#ifndef INCLUDE_posix_h__ -#define INCLUDE_posix_h__ - -#include "common.h" -#include -#include - -#define S_IFGITLINK 0160000 -#define S_ISGITLINK(m) (((m) & S_IFMT) == S_IFGITLINK) - -#if !defined(O_BINARY) -#define O_BINARY 0 -#endif - -typedef int git_file; - -/** - * Standard POSIX Methods - * - * All the methods starting with the `p_` prefix are - * direct ports of the standard POSIX methods. - * - * Some of the methods are slightly wrapped to provide - * saner defaults. Some of these methods are emulated - * in Windows platforns. - * - * Use your manpages to check the docs on these. - * Straightforward - */ -extern int p_open(const char *path, int flags); -extern int p_creat(const char *path, int mode); -extern int p_read(git_file fd, void *buf, size_t cnt); -extern int p_write(git_file fd, const void *buf, size_t cnt); -extern int p_getcwd(char *buffer_out, size_t size); - -#define p_lseek(f,n,w) lseek(f, n, w) -#define p_stat(p,b) stat(p, b) -#define p_fstat(f,b) fstat(f, b) -#define p_chdir(p) chdir(p) -#define p_rmdir(p) rmdir(p) -#define p_chmod(p,m) chmod(p, m) -#define p_close(fd) close(fd) - -/** - * Platform-dependent methods - */ -#ifdef GIT_WIN32 -# include "win32/posix.h" -#else -# include "unix/posix.h" -#endif - -#endif diff --git a/vendor/libgit2/src/ppc/sha1.c b/vendor/libgit2/src/ppc/sha1.c deleted file mode 100644 index ec6a1926d..000000000 --- a/vendor/libgit2/src/ppc/sha1.c +++ /dev/null @@ -1,72 +0,0 @@ -/* - * SHA-1 implementation. - * - * Copyright (C) 2005 Paul Mackerras - * - * This version assumes we are running on a big-endian machine. - * It calls an external sha1_core() to process blocks of 64 bytes. - */ -#include -#include -#include "sha1.h" - -extern void ppc_sha1_core(uint32_t *hash, const unsigned char *p, - unsigned int nblocks); - -int ppc_SHA1_Init(ppc_SHA_CTX *c) -{ - c->hash[0] = 0x67452301; - c->hash[1] = 0xEFCDAB89; - c->hash[2] = 0x98BADCFE; - c->hash[3] = 0x10325476; - c->hash[4] = 0xC3D2E1F0; - c->len = 0; - c->cnt = 0; - return 0; -} - -int ppc_SHA1_Update(ppc_SHA_CTX *c, const void *ptr, unsigned long n) -{ - unsigned long nb; - const unsigned char *p = ptr; - - c->len += (uint64_t) n << 3; - while (n != 0) { - if (c->cnt || n < 64) { - nb = 64 - c->cnt; - if (nb > n) - nb = n; - memcpy(&c->buf.b[c->cnt], p, nb); - if ((c->cnt += nb) == 64) { - ppc_sha1_core(c->hash, c->buf.b, 1); - c->cnt = 0; - } - } else { - nb = n >> 6; - ppc_sha1_core(c->hash, p, nb); - nb <<= 6; - } - n -= nb; - p += nb; - } - return 0; -} - -int ppc_SHA1_Final(unsigned char *hash, ppc_SHA_CTX *c) -{ - unsigned int cnt = c->cnt; - - c->buf.b[cnt++] = 0x80; - if (cnt > 56) { - if (cnt < 64) - memset(&c->buf.b[cnt], 0, 64 - cnt); - ppc_sha1_core(c->hash, c->buf.b, 1); - cnt = 0; - } - if (cnt < 56) - memset(&c->buf.b[cnt], 0, 56 - cnt); - c->buf.l[7] = c->len; - ppc_sha1_core(c->hash, c->buf.b, 1); - memcpy(hash, c->hash, 20); - return 0; -} diff --git a/vendor/libgit2/src/ppc/sha1.h b/vendor/libgit2/src/ppc/sha1.h deleted file mode 100644 index 70957110c..000000000 --- a/vendor/libgit2/src/ppc/sha1.h +++ /dev/null @@ -1,25 +0,0 @@ -/* - * SHA-1 implementation. - * - * Copyright (C) 2005 Paul Mackerras - */ -#include - -typedef struct { - uint32_t hash[5]; - uint32_t cnt; - uint64_t len; - union { - unsigned char b[64]; - uint64_t l[8]; - } buf; -} ppc_SHA_CTX; - -int ppc_SHA1_Init(ppc_SHA_CTX *c); -int ppc_SHA1_Update(ppc_SHA_CTX *c, const void *p, unsigned long n); -int ppc_SHA1_Final(unsigned char *hash, ppc_SHA_CTX *c); - -#define SHA_CTX ppc_SHA_CTX -#define SHA1_Init ppc_SHA1_Init -#define SHA1_Update ppc_SHA1_Update -#define SHA1_Final ppc_SHA1_Final diff --git a/vendor/libgit2/src/ppc/sha1ppc.S b/vendor/libgit2/src/ppc/sha1ppc.S deleted file mode 100644 index 1711eef6e..000000000 --- a/vendor/libgit2/src/ppc/sha1ppc.S +++ /dev/null @@ -1,224 +0,0 @@ -/* - * SHA-1 implementation for PowerPC. - * - * Copyright (C) 2005 Paul Mackerras - */ - -/* - * PowerPC calling convention: - * %r0 - volatile temp - * %r1 - stack pointer. - * %r2 - reserved - * %r3-%r12 - Incoming arguments & return values; volatile. - * %r13-%r31 - Callee-save registers - * %lr - Return address, volatile - * %ctr - volatile - * - * Register usage in this routine: - * %r0 - temp - * %r3 - argument (pointer to 5 words of SHA state) - * %r4 - argument (pointer to data to hash) - * %r5 - Constant K in SHA round (initially number of blocks to hash) - * %r6-%r10 - Working copies of SHA variables A..E (actually E..A order) - * %r11-%r26 - Data being hashed W[]. - * %r27-%r31 - Previous copies of A..E, for final add back. - * %ctr - loop count - */ - - -/* - * We roll the registers for A, B, C, D, E around on each - * iteration; E on iteration t is D on iteration t+1, and so on. - * We use registers 6 - 10 for this. (Registers 27 - 31 hold - * the previous values.) - */ -#define RA(t) (((t)+4)%5+6) -#define RB(t) (((t)+3)%5+6) -#define RC(t) (((t)+2)%5+6) -#define RD(t) (((t)+1)%5+6) -#define RE(t) (((t)+0)%5+6) - -/* We use registers 11 - 26 for the W values */ -#define W(t) ((t)%16+11) - -/* Register 5 is used for the constant k */ - -/* - * The basic SHA-1 round function is: - * E += ROTL(A,5) + F(B,C,D) + W[i] + K; B = ROTL(B,30) - * Then the variables are renamed: (A,B,C,D,E) = (E,A,B,C,D). - * - * Every 20 rounds, the function F() and the constant K changes: - * - 20 rounds of f0(b,c,d) = "bit wise b ? c : d" = (^b & d) + (b & c) - * - 20 rounds of f1(b,c,d) = b^c^d = (b^d)^c - * - 20 rounds of f2(b,c,d) = majority(b,c,d) = (b&d) + ((b^d)&c) - * - 20 more rounds of f1(b,c,d) - * - * These are all scheduled for near-optimal performance on a G4. - * The G4 is a 3-issue out-of-order machine with 3 ALUs, but it can only - * *consider* starting the oldest 3 instructions per cycle. So to get - * maximum performance out of it, you have to treat it as an in-order - * machine. Which means interleaving the computation round t with the - * computation of W[t+4]. - * - * The first 16 rounds use W values loaded directly from memory, while the - * remaining 64 use values computed from those first 16. We preload - * 4 values before starting, so there are three kinds of rounds: - * - The first 12 (all f0) also load the W values from memory. - * - The next 64 compute W(i+4) in parallel. 8*f0, 20*f1, 20*f2, 16*f1. - * - The last 4 (all f1) do not do anything with W. - * - * Therefore, we have 6 different round functions: - * STEPD0_LOAD(t,s) - Perform round t and load W(s). s < 16 - * STEPD0_UPDATE(t,s) - Perform round t and compute W(s). s >= 16. - * STEPD1_UPDATE(t,s) - * STEPD2_UPDATE(t,s) - * STEPD1(t) - Perform round t with no load or update. - * - * The G5 is more fully out-of-order, and can find the parallelism - * by itself. The big limit is that it has a 2-cycle ALU latency, so - * even though it's 2-way, the code has to be scheduled as if it's - * 4-way, which can be a limit. To help it, we try to schedule the - * read of RA(t) as late as possible so it doesn't stall waiting for - * the previous round's RE(t-1), and we try to rotate RB(t) as early - * as possible while reading RC(t) (= RB(t-1)) as late as possible. - */ - -/* the initial loads. */ -#define LOADW(s) \ - lwz W(s),(s)*4(%r4) - -/* - * Perform a step with F0, and load W(s). Uses W(s) as a temporary - * before loading it. - * This is actually 10 instructions, which is an awkward fit. - * It can execute grouped as listed, or delayed one instruction. - * (If delayed two instructions, there is a stall before the start of the - * second line.) Thus, two iterations take 7 cycles, 3.5 cycles per round. - */ -#define STEPD0_LOAD(t,s) \ -add RE(t),RE(t),W(t); andc %r0,RD(t),RB(t); and W(s),RC(t),RB(t); \ -add RE(t),RE(t),%r0; rotlwi %r0,RA(t),5; rotlwi RB(t),RB(t),30; \ -add RE(t),RE(t),W(s); add %r0,%r0,%r5; lwz W(s),(s)*4(%r4); \ -add RE(t),RE(t),%r0 - -/* - * This is likewise awkward, 13 instructions. However, it can also - * execute starting with 2 out of 3 possible moduli, so it does 2 rounds - * in 9 cycles, 4.5 cycles/round. - */ -#define STEPD0_UPDATE(t,s,loadk...) \ -add RE(t),RE(t),W(t); andc %r0,RD(t),RB(t); xor W(s),W((s)-16),W((s)-3); \ -add RE(t),RE(t),%r0; and %r0,RC(t),RB(t); xor W(s),W(s),W((s)-8); \ -add RE(t),RE(t),%r0; rotlwi %r0,RA(t),5; xor W(s),W(s),W((s)-14); \ -add RE(t),RE(t),%r5; loadk; rotlwi RB(t),RB(t),30; rotlwi W(s),W(s),1; \ -add RE(t),RE(t),%r0 - -/* Nicely optimal. Conveniently, also the most common. */ -#define STEPD1_UPDATE(t,s,loadk...) \ -add RE(t),RE(t),W(t); xor %r0,RD(t),RB(t); xor W(s),W((s)-16),W((s)-3); \ -add RE(t),RE(t),%r5; loadk; xor %r0,%r0,RC(t); xor W(s),W(s),W((s)-8); \ -add RE(t),RE(t),%r0; rotlwi %r0,RA(t),5; xor W(s),W(s),W((s)-14); \ -add RE(t),RE(t),%r0; rotlwi RB(t),RB(t),30; rotlwi W(s),W(s),1 - -/* - * The naked version, no UPDATE, for the last 4 rounds. 3 cycles per. - * We could use W(s) as a temp register, but we don't need it. - */ -#define STEPD1(t) \ - add RE(t),RE(t),W(t); xor %r0,RD(t),RB(t); \ -rotlwi RB(t),RB(t),30; add RE(t),RE(t),%r5; xor %r0,%r0,RC(t); \ -add RE(t),RE(t),%r0; rotlwi %r0,RA(t),5; /* spare slot */ \ -add RE(t),RE(t),%r0 - -/* - * 14 instructions, 5 cycles per. The majority function is a bit - * awkward to compute. This can execute with a 1-instruction delay, - * but it causes a 2-instruction delay, which triggers a stall. - */ -#define STEPD2_UPDATE(t,s,loadk...) \ -add RE(t),RE(t),W(t); and %r0,RD(t),RB(t); xor W(s),W((s)-16),W((s)-3); \ -add RE(t),RE(t),%r0; xor %r0,RD(t),RB(t); xor W(s),W(s),W((s)-8); \ -add RE(t),RE(t),%r5; loadk; and %r0,%r0,RC(t); xor W(s),W(s),W((s)-14); \ -add RE(t),RE(t),%r0; rotlwi %r0,RA(t),5; rotlwi W(s),W(s),1; \ -add RE(t),RE(t),%r0; rotlwi RB(t),RB(t),30 - -#define STEP0_LOAD4(t,s) \ - STEPD0_LOAD(t,s); \ - STEPD0_LOAD((t+1),(s)+1); \ - STEPD0_LOAD((t)+2,(s)+2); \ - STEPD0_LOAD((t)+3,(s)+3) - -#define STEPUP4(fn, t, s, loadk...) \ - STEP##fn##_UPDATE(t,s,); \ - STEP##fn##_UPDATE((t)+1,(s)+1,); \ - STEP##fn##_UPDATE((t)+2,(s)+2,); \ - STEP##fn##_UPDATE((t)+3,(s)+3,loadk) - -#define STEPUP20(fn, t, s, loadk...) \ - STEPUP4(fn, t, s,); \ - STEPUP4(fn, (t)+4, (s)+4,); \ - STEPUP4(fn, (t)+8, (s)+8,); \ - STEPUP4(fn, (t)+12, (s)+12,); \ - STEPUP4(fn, (t)+16, (s)+16, loadk) - - .globl ppc_sha1_core -ppc_sha1_core: - stwu %r1,-80(%r1) - stmw %r13,4(%r1) - - /* Load up A - E */ - lmw %r27,0(%r3) - - mtctr %r5 - -1: - LOADW(0) - lis %r5,0x5a82 - mr RE(0),%r31 - LOADW(1) - mr RD(0),%r30 - mr RC(0),%r29 - LOADW(2) - ori %r5,%r5,0x7999 /* K0-19 */ - mr RB(0),%r28 - LOADW(3) - mr RA(0),%r27 - - STEP0_LOAD4(0, 4) - STEP0_LOAD4(4, 8) - STEP0_LOAD4(8, 12) - STEPUP4(D0, 12, 16,) - STEPUP4(D0, 16, 20, lis %r5,0x6ed9) - - ori %r5,%r5,0xeba1 /* K20-39 */ - STEPUP20(D1, 20, 24, lis %r5,0x8f1b) - - ori %r5,%r5,0xbcdc /* K40-59 */ - STEPUP20(D2, 40, 44, lis %r5,0xca62) - - ori %r5,%r5,0xc1d6 /* K60-79 */ - STEPUP4(D1, 60, 64,) - STEPUP4(D1, 64, 68,) - STEPUP4(D1, 68, 72,) - STEPUP4(D1, 72, 76,) - addi %r4,%r4,64 - STEPD1(76) - STEPD1(77) - STEPD1(78) - STEPD1(79) - - /* Add results to original values */ - add %r31,%r31,RE(0) - add %r30,%r30,RD(0) - add %r29,%r29,RC(0) - add %r28,%r28,RB(0) - add %r27,%r27,RA(0) - - bdnz 1b - - /* Save final hash, restore registers, and return */ - stmw %r27,0(%r3) - lmw %r13,4(%r1) - addi %r1,%r1,80 - blr diff --git a/vendor/libgit2/src/pqueue.c b/vendor/libgit2/src/pqueue.c deleted file mode 100644 index 9883a35d8..000000000 --- a/vendor/libgit2/src/pqueue.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - * BORING COPYRIGHT NOTICE: - * - * This file is a heavily modified version of the priority queue found - * in the Apache project and the libpqueue library. - * - * https://github.com/vy/libpqueue - * - * These are the original authors: - * - * Copyright 2010 Volkan Yazıcı - * Copyright 2006-2010 The Apache Software Foundation - * - * This file is licensed under the Apache 2.0 license, which - * supposedly makes it compatible with the GPLv2 that libgit2 uses. - * - * Check the Apache license at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * So much licensing trouble for a binary heap. Oh well. - */ - -#include "common.h" -#include "pqueue.h" - -#define left(i) ((i) << 1) -#define right(i) (((i) << 1) + 1) -#define parent(i) ((i) >> 1) - -int git_pqueue_init(git_pqueue *q, size_t n, git_pqueue_cmp cmppri) -{ - assert(q); - - /* Need to allocate n+1 elements since element 0 isn't used. */ - if ((q->d = malloc((n + 1) * sizeof(void *))) == NULL) - return GIT_ENOMEM; - - q->size = 1; - q->avail = q->step = (n + 1); /* see comment above about n+1 */ - q->cmppri = cmppri; - - return GIT_SUCCESS; -} - - -void git_pqueue_free(git_pqueue *q) -{ - free(q->d); - q->d = NULL; -} - -void git_pqueue_clear(git_pqueue *q) -{ - q->size = 1; -} - -size_t git_pqueue_size(git_pqueue *q) -{ - /* queue element 0 exists but doesn't count since it isn't used. */ - return (q->size - 1); -} - - -static void bubble_up(git_pqueue *q, size_t i) -{ - size_t parent_node; - void *moving_node = q->d[i]; - - for (parent_node = parent(i); - ((i > 1) && q->cmppri(q->d[parent_node], moving_node)); - i = parent_node, parent_node = parent(i)) { - q->d[i] = q->d[parent_node]; - } - - q->d[i] = moving_node; -} - - -static size_t maxchild(git_pqueue *q, size_t i) -{ - size_t child_node = left(i); - - if (child_node >= q->size) - return 0; - - if ((child_node + 1) < q->size && - q->cmppri(q->d[child_node], q->d[child_node + 1])) - child_node++; /* use right child instead of left */ - - return child_node; -} - - -static void percolate_down(git_pqueue *q, size_t i) -{ - size_t child_node; - void *moving_node = q->d[i]; - - while ((child_node = maxchild(q, i)) != 0 && - q->cmppri(moving_node, q->d[child_node])) { - q->d[i] = q->d[child_node]; - i = child_node; - } - - q->d[i] = moving_node; -} - - -int git_pqueue_insert(git_pqueue *q, void *d) -{ - void *tmp; - size_t i; - size_t newsize; - - if (!q) return 1; - - /* allocate more memory if necessary */ - if (q->size >= q->avail) { - newsize = q->size + q->step; - if ((tmp = realloc(q->d, sizeof(void *) * newsize)) == NULL) - return GIT_ENOMEM; - - q->d = tmp; - q->avail = newsize; - } - - /* insert item */ - i = q->size++; - q->d[i] = d; - bubble_up(q, i); - - return GIT_SUCCESS; -} - - -void *git_pqueue_pop(git_pqueue *q) -{ - void *head; - - if (!q || q->size == 1) - return NULL; - - head = q->d[1]; - q->d[1] = q->d[--q->size]; - percolate_down(q, 1); - - return head; -} - - -void *git_pqueue_peek(git_pqueue *q) -{ - if (!q || q->size == 1) - return NULL; - return q->d[1]; -} diff --git a/vendor/libgit2/src/pqueue.h b/vendor/libgit2/src/pqueue.h deleted file mode 100644 index ef8362c33..000000000 --- a/vendor/libgit2/src/pqueue.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - * BORING COPYRIGHT NOTICE: - * - * This file is a heavily modified version of the priority queue found - * in the Apache project and the libpqueue library. - * - * https://github.com/vy/libpqueue - * - * These are the original authors: - * - * Copyright 2010 Volkan Yazıcı - * Copyright 2006-2010 The Apache Software Foundation - * - * This file is licensed under the Apache 2.0 license, which - * supposedly makes it compatible with the GPLv2 that libgit2 uses. - * - * Check the Apache license at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * So much licensing trouble for a binary heap. Oh well. - */ - -#ifndef INCLUDE_pqueue_h__ -#define INCLUDE_pqueue_h__ - -/** callback functions to get/set/compare the priority of an element */ -typedef int (*git_pqueue_cmp)(void *a, void *b); - -/** the priority queue handle */ -typedef struct { - size_t size, avail, step; - git_pqueue_cmp cmppri; - void **d; -} git_pqueue; - - -/** - * initialize the queue - * - * @param n the initial estimate of the number of queue items for which memory - * should be preallocated - * @param cmppri the callback function to compare two nodes of the queue - * - * @Return the handle or NULL for insufficent memory - */ -int git_pqueue_init(git_pqueue *q, size_t n, git_pqueue_cmp cmppri); - - -/** - * free all memory used by the queue - * @param q the queue - */ -void git_pqueue_free(git_pqueue *q); - -/** - * clear all the elements in the queue - * @param q the queue - */ -void git_pqueue_clear(git_pqueue *q); - -/** - * return the size of the queue. - * @param q the queue - */ -size_t git_pqueue_size(git_pqueue *q); - - -/** - * insert an item into the queue. - * @param q the queue - * @param d the item - * @return 0 on success - */ -int git_pqueue_insert(git_pqueue *q, void *d); - - -/** - * pop the highest-ranking item from the queue. - * @param p the queue - * @param d where to copy the entry to - * @return NULL on error, otherwise the entry - */ -void *git_pqueue_pop(git_pqueue *q); - - -/** - * access highest-ranking item without removing it. - * @param q the queue - * @param d the entry - * @return NULL on error, otherwise the entry - */ -void *git_pqueue_peek(git_pqueue *q); - -#endif /* PQUEUE_H */ -/** @} */ - diff --git a/vendor/libgit2/src/reflog.c b/vendor/libgit2/src/reflog.c deleted file mode 100644 index d28e5cba1..000000000 --- a/vendor/libgit2/src/reflog.c +++ /dev/null @@ -1,296 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "reflog.h" -#include "repository.h" -#include "filebuf.h" -#include "signature.h" - -static int reflog_init(git_reflog **reflog, git_reference *ref) -{ - git_reflog *log; - - *reflog = NULL; - - log = git__malloc(sizeof(git_reflog)); - if (log == NULL) - return GIT_ENOMEM; - - memset(log, 0x0, sizeof(git_reflog)); - - log->ref_name = git__strdup(ref->name); - - if (git_vector_init(&log->entries, 0, NULL) < 0) { - free(log->ref_name); - free(log); - return GIT_ENOMEM; - } - - *reflog = log; - - return GIT_SUCCESS; -} - -static int reflog_write(const char *log_path, const char *oid_old, - const char *oid_new, const git_signature *committer, - const char *msg) -{ - int error; - git_buf log = GIT_BUF_INIT; - git_filebuf fbuf; - - assert(log_path && oid_old && oid_new && committer); - - git_buf_puts(&log, oid_old); - git_buf_putc(&log, ' '); - - git_buf_puts(&log, oid_new); - - git_signature__writebuf(&log, " ", committer); - log.size--; /* drop LF */ - - if (msg) { - if (strchr(msg, '\n')) { - git_buf_free(&log); - return git__throw(GIT_ERROR, "Reflog message cannot contain newline"); - } - - git_buf_putc(&log, '\t'); - git_buf_puts(&log, msg); - } - - git_buf_putc(&log, '\n'); - - if ((error = git_filebuf_open(&fbuf, log_path, GIT_FILEBUF_APPEND)) < GIT_SUCCESS) { - git_buf_free(&log); - return git__throw(GIT_ERROR, "Failed to write reflog. Cannot open reflog `%s`", log_path); - } - - git_filebuf_write(&fbuf, log.ptr, log.size); - error = git_filebuf_commit(&fbuf); - - git_buf_free(&log); - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to write reflog"); -} - -static int reflog_parse(git_reflog *log, const char *buf, size_t buf_size) -{ - int error = GIT_SUCCESS; - const char *ptr; - git_reflog_entry *entry; - -#define seek_forward(_increase) { \ - if (_increase >= buf_size) { \ - if (entry->committer) \ - free(entry->committer); \ - free(entry); \ - return git__throw(GIT_ERROR, "Failed to seek forward. Buffer size exceeded"); \ - } \ - buf += _increase; \ - buf_size -= _increase; \ -} - - while (buf_size > GIT_REFLOG_SIZE_MIN) { - entry = git__malloc(sizeof(git_reflog_entry)); - if (entry == NULL) - return GIT_ENOMEM; - entry->committer = NULL; - - if (git_oid_fromstrn(&entry->oid_old, buf, GIT_OID_HEXSZ) < GIT_SUCCESS) { - free(entry); - return GIT_ERROR; - } - seek_forward(GIT_OID_HEXSZ + 1); - - if (git_oid_fromstrn(&entry->oid_cur, buf, GIT_OID_HEXSZ) < GIT_SUCCESS) { - free(entry); - return GIT_ERROR; - } - seek_forward(GIT_OID_HEXSZ + 1); - - ptr = buf; - - /* Seek forward to the end of the signature. */ - while (*buf && *buf != '\t' && *buf != '\n') - seek_forward(1); - - entry->committer = git__malloc(sizeof(git_signature)); - if (entry->committer == NULL) { - free(entry); - return GIT_ENOMEM; - } - - if ((error = git_signature__parse(entry->committer, &ptr, buf + 1, NULL, *buf)) < GIT_SUCCESS) { - free(entry->committer); - free(entry); - return git__rethrow(error, "Failed to parse reflog. Could not parse signature"); - } - - if (*buf == '\t') { - /* We got a message. Read everything till we reach LF. */ - seek_forward(1); - ptr = buf; - - while (*buf && *buf != '\n') - seek_forward(1); - - entry->msg = git__strndup(ptr, buf - ptr); - } else - entry->msg = NULL; - - while (*buf && *buf == '\n' && buf_size > 1) - seek_forward(1); - - if ((error = git_vector_insert(&log->entries, entry)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to parse reflog. Could not add new entry"); - } - -#undef seek_forward - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to parse reflog"); -} - -void git_reflog_free(git_reflog *reflog) -{ - unsigned int i; - git_reflog_entry *entry; - - for (i=0; i < reflog->entries.length; i++) { - entry = git_vector_get(&reflog->entries, i); - - git_signature_free(entry->committer); - - free(entry->msg); - free(entry); - } - - git_vector_free(&reflog->entries); - free(reflog->ref_name); - free(reflog); -} - -int git_reflog_read(git_reflog **reflog, git_reference *ref) -{ - int error; - char log_path[GIT_PATH_MAX]; - git_fbuffer log_file = GIT_FBUFFER_INIT; - git_reflog *log = NULL; - - *reflog = NULL; - - if ((error = reflog_init(&log, ref)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to read reflog. Cannot init reflog"); - - git_path_join_n(log_path, 3, ref->owner->path_repository, GIT_REFLOG_DIR, ref->name); - - if ((error = git_futils_readbuffer(&log_file, log_path)) < GIT_SUCCESS) { - git_reflog_free(log); - return git__rethrow(error, "Failed to read reflog. Cannot read file `%s`", log_path); - } - - error = reflog_parse(log, log_file.data, log_file.len); - - git_futils_freebuffer(&log_file); - - if (error == GIT_SUCCESS) - *reflog = log; - else - git_reflog_free(log); - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to read reflog"); -} - -int git_reflog_write(git_reference *ref, const git_oid *oid_old, - const git_signature *committer, const char *msg) -{ - int error; - char old[GIT_OID_HEXSZ+1]; - char new[GIT_OID_HEXSZ+1]; - char log_path[GIT_PATH_MAX]; - git_reference *r; - const git_oid *oid; - - if ((error = git_reference_resolve(&r, ref)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to write reflog. Cannot resolve reference `%s`", ref->name); - - oid = git_reference_oid(r); - if (oid == NULL) - return git__throw(GIT_ERROR, "Failed to write reflog. Cannot resolve reference `%s`", r->name); - - git_oid_to_string(new, GIT_OID_HEXSZ+1, oid); - - git_path_join_n(log_path, 3, ref->owner->path_repository, GIT_REFLOG_DIR, ref->name); - - if (git_futils_exists(log_path)) { - if ((error = git_futils_mkpath2file(log_path)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to write reflog. Cannot create reflog directory"); - } else if (git_futils_isfile(log_path)) { - return git__throw(GIT_ERROR, "Failed to write reflog. `%s` is directory", log_path); - } else if (oid_old == NULL) - return git__throw(GIT_ERROR, "Failed to write reflog. Old OID cannot be NULL for existing reference"); - - if (oid_old) - git_oid_to_string(old, GIT_OID_HEXSZ+1, oid_old); - else - p_snprintf(old, GIT_OID_HEXSZ+1, "%0*d", GIT_OID_HEXSZ, 0); - - return reflog_write(log_path, old, new, committer, msg); -} - -unsigned int git_reflog_entrycount(git_reflog *reflog) -{ - assert(reflog); - return reflog->entries.length; -} - -const git_reflog_entry * git_reflog_entry_byindex(git_reflog *reflog, unsigned int idx) -{ - assert(reflog); - return git_vector_get(&reflog->entries, idx); -} - -const git_oid * git_reflog_entry_oidold(const git_reflog_entry *entry) -{ - assert(entry); - return &entry->oid_old; -} - -const git_oid * git_reflog_entry_oidnew(const git_reflog_entry *entry) -{ - assert(entry); - return &entry->oid_cur; -} - -git_signature * git_reflog_entry_committer(const git_reflog_entry *entry) -{ - assert(entry); - return entry->committer; -} - -char * git_reflog_entry_msg(const git_reflog_entry *entry) -{ - assert(entry); - return entry->msg; -} diff --git a/vendor/libgit2/src/reflog.h b/vendor/libgit2/src/reflog.h deleted file mode 100644 index b6daf2a76..000000000 --- a/vendor/libgit2/src/reflog.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef INCLUDE_reflog_h__ -#define INCLUDE_reflog_h__ - -#include "common.h" -#include "git2/reflog.h" -#include "vector.h" - -#define GIT_REFLOG_DIR "logs/" - -#define GIT_REFLOG_SIZE_MIN (2*GIT_OID_HEXSZ+2+17) - -struct git_reflog_entry { - git_oid oid_old; - git_oid oid_cur; - - git_signature *committer; - - char *msg; -}; - -struct git_reflog { - char *ref_name; - git_vector entries; -}; - -#endif /* INCLUDE_reflog_h__ */ diff --git a/vendor/libgit2/src/refs.c b/vendor/libgit2/src/refs.c deleted file mode 100644 index 77521bc63..000000000 --- a/vendor/libgit2/src/refs.c +++ /dev/null @@ -1,1753 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "refs.h" -#include "hash.h" -#include "repository.h" -#include "fileops.h" - -#include -#include - -#define MAX_NESTING_LEVEL 5 - -typedef struct { - git_reference ref; - git_oid oid; - git_oid peel_target; -} reference_oid; - -typedef struct { - git_reference ref; - char *target; -} reference_symbolic; - -static const int default_table_size = 32; - -static uint32_t reftable_hash(const void *key, int hash_id) -{ - static uint32_t hash_seeds[GIT_HASHTABLE_HASHES] = { - 2147483647, - 0x5d20bb23, - 0x7daaab3c - }; - - return git__hash(key, strlen((const char *)key), hash_seeds[hash_id]); -} - -static void reference_free(git_reference *reference); -static int reference_create(git_reference **ref_out, git_repository *repo, const char *name, git_rtype type); -static int reference_read(git_fbuffer *file_content, time_t *mtime, const char *repo_path, const char *ref_name, int *updated); - -/* loose refs */ -static int loose_parse_symbolic(git_reference *ref, git_fbuffer *file_content); -static int loose_parse_oid(git_reference *ref, git_fbuffer *file_content); -static int loose_lookup(git_reference **ref_out, git_repository *repo, const char *name, int skip_symbolic); -static int loose_write(git_reference *ref); -static int loose_update(git_reference *ref); - -/* packed refs */ -static int packed_parse_peel(reference_oid *tag_ref, const char **buffer_out, const char *buffer_end); -static int packed_parse_oid(reference_oid **ref_out, git_repository *repo, const char **buffer_out, const char *buffer_end); -static int packed_load(git_repository *repo); -static int packed_loadloose(git_repository *repository); -static int packed_write_ref(reference_oid *ref, git_filebuf *file); -static int packed_find_peel(reference_oid *ref); -static int packed_remove_loose(git_repository *repo, git_vector *packing_list); -static int packed_sort(const void *a, const void *b); -static int packed_write(git_repository *repo); - -/* internal helpers */ -static int reference_available(git_repository *repo, const char *ref, const char *old_ref); - -/* name normalization */ -static int check_valid_ref_char(char ch); -static int normalize_name(char *buffer_out, size_t out_size, const char *name, int is_oid_ref); - -/***************************************** - * Internal methods - Constructor/destructor - *****************************************/ -static void reference_free(git_reference *reference) -{ - if (reference == NULL) - return; - - if (reference->name) - free(reference->name); - - if (reference->type == GIT_REF_SYMBOLIC) - free(((reference_symbolic *)reference)->target); - - free(reference); -} - -static int reference_create( - git_reference **ref_out, - git_repository *repo, - const char *name, - git_rtype type) -{ - char normalized[GIT_REFNAME_MAX]; - int error = GIT_SUCCESS, size; - git_reference *reference = NULL; - - assert(ref_out && repo && name); - - if (type == GIT_REF_SYMBOLIC) - size = sizeof(reference_symbolic); - else if (type == GIT_REF_OID) - size = sizeof(reference_oid); - else - return git__throw(GIT_EINVALIDARGS, - "Invalid reference type. Use either GIT_REF_OID or GIT_REF_SYMBOLIC as type specifier"); - - reference = git__malloc(size); - if (reference == NULL) - return GIT_ENOMEM; - - memset(reference, 0x0, size); - reference->owner = repo; - reference->type = type; - - error = normalize_name(normalized, sizeof(normalized), name, (type & GIT_REF_OID)); - if (error < GIT_SUCCESS) - goto cleanup; - - reference->name = git__strdup(normalized); - if (reference->name == NULL) { - error = GIT_ENOMEM; - goto cleanup; - } - - *ref_out = reference; - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to create reference"); - -cleanup: - reference_free(reference); - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to create reference"); -} - -static int reference_read(git_fbuffer *file_content, time_t *mtime, const char *repo_path, const char *ref_name, int *updated) -{ - char path[GIT_PATH_MAX]; - - assert(file_content && repo_path && ref_name); - - /* Determine the full path of the file */ - git_path_join(path, repo_path, ref_name); - - return git_futils_readbuffer_updated(file_content, path, mtime, updated); -} - - - - -/***************************************** - * Internal methods - Loose references - *****************************************/ -static int loose_update(git_reference *ref) -{ - int error, updated; - git_fbuffer ref_file = GIT_FBUFFER_INIT; - - if (ref->type & GIT_REF_PACKED) - return packed_load(ref->owner); - -/* error = reference_read(NULL, &ref_time, ref->owner->path_repository, ref->name); - if (error < GIT_SUCCESS) - goto cleanup; - - if (ref_time == ref->mtime) - return GIT_SUCCESS; -*/ - error = reference_read(&ref_file, &ref->mtime, ref->owner->path_repository, ref->name, &updated); - if (error < GIT_SUCCESS) - goto cleanup; - - if (!updated) - goto cleanup; - - if (ref->type == GIT_REF_SYMBOLIC) - error = loose_parse_symbolic(ref, &ref_file); - else if (ref->type == GIT_REF_OID) - error = loose_parse_oid(ref, &ref_file); - else - error = git__throw(GIT_EOBJCORRUPTED, - "Invalid reference type (%d) for loose reference", ref->type); - - -cleanup: - git_futils_freebuffer(&ref_file); - if (error != GIT_SUCCESS) { - reference_free(ref); - git_hashtable_remove(ref->owner->references.loose_cache, ref->name); - } - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to update loose reference"); -} - -static int loose_parse_symbolic(git_reference *ref, git_fbuffer *file_content) -{ - const unsigned int header_len = strlen(GIT_SYMREF); - const char *refname_start; - char *eol; - reference_symbolic *ref_sym; - - refname_start = (const char *)file_content->data; - ref_sym = (reference_symbolic *)ref; - - if (file_content->len < (header_len + 1)) - return git__throw(GIT_EOBJCORRUPTED, - "Failed to parse loose reference. Object too short"); - - /* - * Assume we have already checked for the header - * before calling this function - */ - - refname_start += header_len; - - free(ref_sym->target); - ref_sym->target = git__strdup(refname_start); - if (ref_sym->target == NULL) - return GIT_ENOMEM; - - /* remove newline at the end of file */ - eol = strchr(ref_sym->target, '\n'); - if (eol == NULL) - return git__throw(GIT_EOBJCORRUPTED, - "Failed to parse loose reference. Missing EOL"); - - *eol = '\0'; - if (eol[-1] == '\r') - eol[-1] = '\0'; - - return GIT_SUCCESS; -} - -static int loose_parse_oid(git_reference *ref, git_fbuffer *file_content) -{ - int error; - reference_oid *ref_oid; - char *buffer; - - buffer = (char *)file_content->data; - ref_oid = (reference_oid *)ref; - - /* File format: 40 chars (OID) + newline */ - if (file_content->len < GIT_OID_HEXSZ + 1) - return git__throw(GIT_EOBJCORRUPTED, - "Failed to parse loose reference. Reference too short"); - - if ((error = git_oid_fromstr(&ref_oid->oid, buffer)) < GIT_SUCCESS) - return git__rethrow(GIT_EOBJCORRUPTED, "Failed to parse loose reference."); - - buffer = buffer + GIT_OID_HEXSZ; - if (*buffer == '\r') - buffer++; - - if (*buffer != '\n') - return git__throw(GIT_EOBJCORRUPTED, - "Failed to parse loose reference. Missing EOL"); - - return GIT_SUCCESS; -} - - -static git_rtype loose_guess_rtype(const char *full_path) -{ - git_fbuffer ref_file = GIT_FBUFFER_INIT; - git_rtype type; - - type = GIT_REF_INVALID; - - if (git_futils_readbuffer(&ref_file, full_path) == GIT_SUCCESS) { - if (git__prefixcmp((const char *)(ref_file.data), GIT_SYMREF) == 0) - type = GIT_REF_SYMBOLIC; - else - type = GIT_REF_OID; - } - - git_futils_freebuffer(&ref_file); - return type; -} - -static int loose_lookup( - git_reference **ref_out, - git_repository *repo, - const char *name, - int skip_symbolic) -{ - int error = GIT_SUCCESS; - git_fbuffer ref_file = GIT_FBUFFER_INIT; - git_reference *ref = NULL; - time_t ref_time = 0; - - *ref_out = NULL; - - error = reference_read(&ref_file, &ref_time, repo->path_repository, name, NULL); - if (error < GIT_SUCCESS) - goto cleanup; - - if (git__prefixcmp((const char *)(ref_file.data), GIT_SYMREF) == 0) { - if (skip_symbolic) - return GIT_SUCCESS; - - error = reference_create(&ref, repo, name, GIT_REF_SYMBOLIC); - if (error < GIT_SUCCESS) - goto cleanup; - - error = loose_parse_symbolic(ref, &ref_file); - } else { - error = reference_create(&ref, repo, name, GIT_REF_OID); - if (error < GIT_SUCCESS) - goto cleanup; - - error = loose_parse_oid(ref, &ref_file); - } - - if (error < GIT_SUCCESS) - goto cleanup; - - ref->mtime = ref_time; - *ref_out = ref; - git_futils_freebuffer(&ref_file); - return GIT_SUCCESS; - -cleanup: - git_futils_freebuffer(&ref_file); - reference_free(ref); - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to lookup loose reference"); -} - -static int loose_write(git_reference *ref) -{ - git_filebuf file; - char ref_path[GIT_PATH_MAX]; - int error; - struct stat st; - - git_path_join(ref_path, ref->owner->path_repository, ref->name); - - if ((error = git_filebuf_open(&file, ref_path, GIT_FILEBUF_FORCE)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to write loose reference"); - - if (ref->type & GIT_REF_OID) { - reference_oid *ref_oid = (reference_oid *)ref; - char oid[GIT_OID_HEXSZ + 1]; - - memset(oid, 0x0, sizeof(oid)); - - git_oid_fmt(oid, &ref_oid->oid); - error = git_filebuf_printf(&file, "%s\n", oid); - if (error < GIT_SUCCESS) - goto unlock; - - } else if (ref->type & GIT_REF_SYMBOLIC) { /* GIT_REF_SYMBOLIC */ - reference_symbolic *ref_sym = (reference_symbolic *)ref; - - error = git_filebuf_printf(&file, GIT_SYMREF "%s\n", ref_sym->target); - } else { - error = git__throw(GIT_EOBJCORRUPTED, "Failed to write reference. Invalid reference type"); - goto unlock; - } - - error = git_filebuf_commit(&file); - - if (p_stat(ref_path, &st) == GIT_SUCCESS) - ref->mtime = st.st_mtime; - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to write loose reference"); - -unlock: - git_filebuf_cleanup(&file); - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to write loose reference"); -} - - - - - - -/***************************************** - * Internal methods - Packed references - *****************************************/ - -static int packed_parse_peel( - reference_oid *tag_ref, - const char **buffer_out, - const char *buffer_end) -{ - const char *buffer = *buffer_out + 1; - - assert(buffer[-1] == '^'); - - /* Ensure it's not the first entry of the file */ - if (tag_ref == NULL) - return git__throw(GIT_EPACKEDREFSCORRUPTED, "Failed to parse packed reference. Reference is the first entry of the file"); - - /* Ensure reference is a tag */ - if (git__prefixcmp(tag_ref->ref.name, GIT_REFS_TAGS_DIR) != 0) - return git__throw(GIT_EPACKEDREFSCORRUPTED, "Failed to parse packed reference. Reference is not a tag"); - - if (buffer + GIT_OID_HEXSZ >= buffer_end) - return git__throw(GIT_EPACKEDREFSCORRUPTED, "Failed to parse packed reference. Buffer too small"); - - /* Is this a valid object id? */ - if (git_oid_fromstr(&tag_ref->peel_target, buffer) < GIT_SUCCESS) - return git__throw(GIT_EPACKEDREFSCORRUPTED, "Failed to parse packed reference. Not a valid object ID"); - - buffer = buffer + GIT_OID_HEXSZ; - if (*buffer == '\r') - buffer++; - - if (*buffer != '\n') - return git__throw(GIT_EPACKEDREFSCORRUPTED, "Failed to parse packed reference. Buffer not terminated correctly"); - - *buffer_out = buffer + 1; - tag_ref->ref.type |= GIT_REF_HAS_PEEL; - - return GIT_SUCCESS; -} - -static int packed_parse_oid( - reference_oid **ref_out, - git_repository *repo, - const char **buffer_out, - const char *buffer_end) -{ - reference_oid *ref = NULL; - - const char *buffer = *buffer_out; - const char *refname_begin, *refname_end; - - int error = GIT_SUCCESS; - int refname_len; - char refname[GIT_REFNAME_MAX]; - git_oid id; - - refname_begin = (buffer + GIT_OID_HEXSZ + 1); - if (refname_begin >= buffer_end || - refname_begin[-1] != ' ') { - error = GIT_EPACKEDREFSCORRUPTED; - goto cleanup; - } - - /* Is this a valid object id? */ - if ((error = git_oid_fromstr(&id, buffer)) < GIT_SUCCESS) - goto cleanup; - - refname_end = memchr(refname_begin, '\n', buffer_end - refname_begin); - if (refname_end == NULL) { - error = GIT_EPACKEDREFSCORRUPTED; - goto cleanup; - } - - refname_len = refname_end - refname_begin; - - memcpy(refname, refname_begin, refname_len); - refname[refname_len] = 0; - - if (refname[refname_len - 1] == '\r') - refname[refname_len - 1] = 0; - - error = reference_create((git_reference **)&ref, repo, refname, GIT_REF_OID); - if (error < GIT_SUCCESS) - goto cleanup; - - git_oid_cpy(&ref->oid, &id); - ref->ref.type |= GIT_REF_PACKED; - - *ref_out = ref; - *buffer_out = refname_end + 1; - - return GIT_SUCCESS; - -cleanup: - reference_free((git_reference *)ref); - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to parse OID of packed reference"); -} - -static int packed_load(git_repository *repo) -{ - int error = GIT_SUCCESS, updated; - git_fbuffer packfile = GIT_FBUFFER_INIT; - const char *buffer_start, *buffer_end; - git_refcache *ref_cache = &repo->references; - - /* First we make sure we have allocated the hash table */ - if (ref_cache->packfile == NULL) { - ref_cache->packfile = git_hashtable_alloc( - default_table_size, - reftable_hash, - (git_hash_keyeq_ptr)(&git__strcmp_cb)); - - if (ref_cache->packfile == NULL) { - error = GIT_ENOMEM; - goto cleanup; - } - } - - error = reference_read(&packfile, &ref_cache->packfile_time, - repo->path_repository, GIT_PACKEDREFS_FILE, &updated); - - /* - * If we couldn't find the file, we need to clear the table and - * return. On any other error, we return that error. If everything - * went fine and the file wasn't updated, then there's nothing new - * for us here, so just return. Anything else means we need to - * refresh the packed refs. - */ - if (error == GIT_ENOTFOUND) { - git_hashtable_clear(ref_cache->packfile); - return GIT_SUCCESS; - } else if (error < GIT_SUCCESS) { - return git__rethrow(error, "Failed to read packed refs"); - } else if (!updated) { - return GIT_SUCCESS; - } - - /* - * At this point, we want to refresh the packed refs. We already - * have the contents in our buffer. - */ - - git_hashtable_clear(ref_cache->packfile); - - buffer_start = (const char *)packfile.data; - buffer_end = (const char *)(buffer_start) + packfile.len; - - while (buffer_start < buffer_end && buffer_start[0] == '#') { - buffer_start = strchr(buffer_start, '\n'); - if (buffer_start == NULL) { - error = GIT_EPACKEDREFSCORRUPTED; - goto cleanup; - } - buffer_start++; - } - - while (buffer_start < buffer_end) { - reference_oid *ref = NULL; - - error = packed_parse_oid(&ref, repo, &buffer_start, buffer_end); - if (error < GIT_SUCCESS) - goto cleanup; - - if (buffer_start[0] == '^') { - error = packed_parse_peel(ref, &buffer_start, buffer_end); - if (error < GIT_SUCCESS) - goto cleanup; - } - - error = git_hashtable_insert(ref_cache->packfile, ref->ref.name, ref); - if (error < GIT_SUCCESS) { - reference_free((git_reference *)ref); - goto cleanup; - } - } - - git_futils_freebuffer(&packfile); - return GIT_SUCCESS; - -cleanup: - git_hashtable_free(ref_cache->packfile); - ref_cache->packfile = NULL; - git_futils_freebuffer(&packfile); - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to load packed references"); -} - - - - -struct dirent_list_data { - git_repository *repo; - size_t repo_path_len; - unsigned int list_flags; - - int (*callback)(const char *, void *); - void *callback_payload; -}; - -static int _dirent_loose_listall(void *_data, char *full_path) -{ - struct dirent_list_data *data = (struct dirent_list_data *)_data; - char *file_path = full_path + data->repo_path_len; - - if (git_futils_isdir(full_path) == GIT_SUCCESS) - return git_futils_direach(full_path, GIT_PATH_MAX, _dirent_loose_listall, _data); - - /* do not add twice a reference that exists already in the packfile */ - if ((data->list_flags & GIT_REF_PACKED) != 0 && - git_hashtable_lookup(data->repo->references.packfile, file_path) != NULL) - return GIT_SUCCESS; - - if (data->list_flags != GIT_REF_LISTALL) { - if ((data->list_flags & loose_guess_rtype(full_path)) == 0) - return GIT_SUCCESS; /* we are filtering out this reference */ - } - - return data->callback(file_path, data->callback_payload); -} - -static int _dirent_loose_load(void *data, char *full_path) -{ - git_repository *repository = (git_repository *)data; - git_reference *reference, *old_ref; - char *file_path; - int error; - - if (git_futils_isdir(full_path) == GIT_SUCCESS) - return git_futils_direach(full_path, GIT_PATH_MAX, _dirent_loose_load, repository); - - file_path = full_path + strlen(repository->path_repository); - error = loose_lookup(&reference, repository, file_path, 1); - if (error == GIT_SUCCESS && reference != NULL) { - reference->type |= GIT_REF_PACKED; - - if (git_hashtable_insert2(repository->references.packfile, reference->name, reference, (void **)&old_ref) < GIT_SUCCESS) { - reference_free(reference); - return GIT_ENOMEM; - } - - if (old_ref != NULL) - reference_free(old_ref); - } - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to load loose dirent"); -} - -/* - * Load all the loose references from the repository - * into the in-memory Packfile, and build a vector with - * all the references so it can be written back to - * disk. - */ -static int packed_loadloose(git_repository *repository) -{ - char refs_path[GIT_PATH_MAX]; - - /* the packfile must have been previously loaded! */ - assert(repository->references.packfile); - - git_path_join(refs_path, repository->path_repository, GIT_REFS_DIR); - - /* Remove any loose references from the cache */ - { - const void *GIT_UNUSED(_unused); - git_reference *reference; - - GIT_HASHTABLE_FOREACH(repository->references.loose_cache, _unused, reference, - reference_free(reference); - ); - } - - git_hashtable_clear(repository->references.loose_cache); - - /* - * Load all the loose files from disk into the Packfile table. - * This will overwrite any old packed entries with their - * updated loose versions - */ - return git_futils_direach(refs_path, GIT_PATH_MAX, _dirent_loose_load, repository); -} - -/* - * Write a single reference into a packfile - */ -static int packed_write_ref(reference_oid *ref, git_filebuf *file) -{ - int error; - char oid[GIT_OID_HEXSZ + 1]; - - git_oid_fmt(oid, &ref->oid); - oid[GIT_OID_HEXSZ] = 0; - - /* - * For references that peel to an object in the repo, we must - * write the resulting peel on a separate line, e.g. - * - * 6fa8a902cc1d18527e1355773c86721945475d37 refs/tags/libgit2-0.4 - * ^2ec0cb7959b0bf965d54f95453f5b4b34e8d3100 - * - * This obviously only applies to tags. - * The required peels have already been loaded into `ref->peel_target`. - */ - if (ref->ref.type & GIT_REF_HAS_PEEL) { - char peel[GIT_OID_HEXSZ + 1]; - git_oid_fmt(peel, &ref->peel_target); - peel[GIT_OID_HEXSZ] = 0; - - error = git_filebuf_printf(file, "%s %s\n^%s\n", oid, ref->ref.name, peel); - } else { - error = git_filebuf_printf(file, "%s %s\n", oid, ref->ref.name); - } - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to write packed reference"); -} - -/* - * Find out what object this reference resolves to. - * - * For references that point to a 'big' tag (e.g. an - * actual tag object on the repository), we need to - * cache on the packfile the OID of the object to - * which that 'big tag' is pointing to. - */ -static int packed_find_peel(reference_oid *ref) -{ - git_object *object; - int error; - - if (ref->ref.type & GIT_REF_HAS_PEEL) - return GIT_SUCCESS; - - /* - * Only applies to tags, i.e. references - * in the /refs/tags folder - */ - if (git__prefixcmp(ref->ref.name, GIT_REFS_TAGS_DIR) != 0) - return GIT_SUCCESS; - - /* - * Find the tagged object in the repository - */ - error = git_object_lookup(&object, ref->ref.owner, &ref->oid, GIT_OBJ_ANY); - if (error < GIT_SUCCESS) - return git__throw(GIT_EOBJCORRUPTED, "Failed to find packed reference"); - - /* - * If the tagged object is a Tag object, we need to resolve it; - * if the ref is actually a 'weak' ref, we don't need to resolve - * anything. - */ - if (git_object_type(object) == GIT_OBJ_TAG) { - git_tag *tag = (git_tag *)object; - - /* - * Find the object pointed at by this tag - */ - git_oid_cpy(&ref->peel_target, git_tag_target_oid(tag)); - ref->ref.type |= GIT_REF_HAS_PEEL; - - /* - * The reference has now cached the resolved OID, and is - * marked at such. When written to the packfile, it'll be - * accompanied by this resolved oid - */ - } - - git_object_close(object); - - return GIT_SUCCESS; -} - -/* - * Remove all loose references - * - * Once we have successfully written a packfile, - * all the loose references that were packed must be - * removed from disk. - * - * This is a dangerous method; make sure the packfile - * is well-written, because we are destructing references - * here otherwise. - */ -static int packed_remove_loose(git_repository *repo, git_vector *packing_list) -{ - unsigned int i; - char full_path[GIT_PATH_MAX]; - int error = GIT_SUCCESS; - git_reference *reference; - - for (i = 0; i < packing_list->length; ++i) { - git_reference *ref = git_vector_get(packing_list, i); - - /* Ensure the packed reference doesn't exist - * in a (more up-to-date?) state as a loose reference - */ - reference = git_hashtable_lookup(ref->owner->references.loose_cache, ref->name); - if (reference != NULL) - continue; - - git_path_join(full_path, repo->path_repository, ref->name); - - if (git_futils_exists(full_path) == GIT_SUCCESS && - p_unlink(full_path) < GIT_SUCCESS) - error = GIT_EOSERR; - - /* - * if we fail to remove a single file, this is *not* good, - * but we should keep going and remove as many as possible. - * After we've removed as many files as possible, we return - * the error code anyway. - * - * TODO: mark this with a very special error code? - * GIT_EFAILTORMLOOSE - */ - } - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to remove loose packed reference"); -} - -static int packed_sort(const void *a, const void *b) -{ - const git_reference *ref_a = (const git_reference *)a; - const git_reference *ref_b = (const git_reference *)b; - - return strcmp(ref_a->name, ref_b->name); -} - -/* - * Write all the contents in the in-memory packfile to disk. - */ -static int packed_write(git_repository *repo) -{ - git_filebuf pack_file; - int error; - unsigned int i; - char pack_file_path[GIT_PATH_MAX]; - - git_vector packing_list; - size_t total_refs; - - assert(repo && repo->references.packfile); - - total_refs = repo->references.packfile->key_count; - if ((error = git_vector_init(&packing_list, total_refs, packed_sort)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to write packed reference"); - - /* Load all the packfile into a vector */ - { - git_reference *reference; - const void *GIT_UNUSED(_unused); - - GIT_HASHTABLE_FOREACH(repo->references.packfile, _unused, reference, - git_vector_insert(&packing_list, reference); /* cannot fail: vector already has the right size */ - ); - } - - /* sort the vector so the entries appear sorted on the packfile */ - git_vector_sort(&packing_list); - - /* Now we can open the file! */ - git_path_join(pack_file_path, repo->path_repository, GIT_PACKEDREFS_FILE); - if ((error = git_filebuf_open(&pack_file, pack_file_path, 0)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to write packed reference"); - - /* Packfiles have a header... apparently - * This is in fact not required, but we might as well print it - * just for kicks */ - if ((error = git_filebuf_printf(&pack_file, "%s\n", GIT_PACKEDREFS_HEADER)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to write packed reference"); - - for (i = 0; i < packing_list.length; ++i) { - reference_oid *ref = (reference_oid *)git_vector_get(&packing_list, i); - - /* only direct references go to the packfile; otherwise - * this is a disaster */ - assert(ref->ref.type & GIT_REF_OID); - - if ((error = packed_find_peel(ref)) < GIT_SUCCESS) { - error = git__throw(GIT_EOBJCORRUPTED, "A reference cannot be peeled"); - goto cleanup; - } - - - if ((error = packed_write_ref(ref, &pack_file)) < GIT_SUCCESS) - goto cleanup; - } - -cleanup: - /* if we've written all the references properly, we can commit - * the packfile to make the changes effective */ - if (error == GIT_SUCCESS) { - error = git_filebuf_commit(&pack_file); - - /* when and only when the packfile has been properly written, - * we can go ahead and remove the loose refs */ - if (error == GIT_SUCCESS) { - struct stat st; - - error = packed_remove_loose(repo, &packing_list); - - if (p_stat(pack_file_path, &st) == GIT_SUCCESS) - repo->references.packfile_time = st.st_mtime; - } - } - else git_filebuf_cleanup(&pack_file); - - git_vector_free(&packing_list); - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to write packed reference"); -} - -static int _reference_available_cb(const char *ref, void *data) -{ - const char *new, *old; - git_vector *refs; - - assert(ref && data); - - refs = (git_vector *)data; - - new = (const char *)git_vector_get(refs, 0); - old = (const char *)git_vector_get(refs, 1); - - if (!old || strcmp(old, ref)) { - int reflen = strlen(ref); - int newlen = strlen(new); - int cmplen = reflen < newlen ? reflen : newlen; - const char *lead = reflen < newlen ? new : ref; - - if (!strncmp(new, ref, cmplen) && - lead[cmplen] == '/') - return GIT_EEXISTS; - } - - return GIT_SUCCESS; -} - -static int reference_available(git_repository *repo, const char *ref, const char* old_ref) -{ - int error; - git_vector refs; - - if (git_vector_init(&refs, 2, NULL) < GIT_SUCCESS) - return GIT_ENOMEM; - - git_vector_insert(&refs, (void *)ref); - git_vector_insert(&refs, (void *)old_ref); - - error = git_reference_foreach(repo, GIT_REF_LISTALL, _reference_available_cb, (void *)&refs); - - git_vector_free(&refs); - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__throw(GIT_EEXISTS, "Reference name `%s` conflicts with existing reference", ref); -} - -/***************************************** - * External Library API - *****************************************/ - -/** - * Constructors - */ -int git_reference_lookup(git_reference **ref_out, git_repository *repo, const char *name) -{ - int error; - char normalized_name[GIT_REFNAME_MAX]; - - assert(ref_out && repo && name); - - *ref_out = NULL; - - error = normalize_name(normalized_name, sizeof(normalized_name), name, 0); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to lookup reference"); - - /* First, check has been previously loaded and cached */ - *ref_out = git_hashtable_lookup(repo->references.loose_cache, normalized_name); - if (*ref_out != NULL) - return loose_update(*ref_out); - - /* Then check if there is a loose file for that reference.*/ - error = loose_lookup(ref_out, repo, normalized_name, 0); - - /* If the file exists, we store it on the cache */ - if (error == GIT_SUCCESS) - return git_hashtable_insert(repo->references.loose_cache, (*ref_out)->name, (*ref_out)); - - /* The loose lookup has failed, but not because the reference wasn't found; - * probably the loose reference is corrupted. this is bad. */ - if (error != GIT_ENOTFOUND) - return git__rethrow(error, "Failed to lookup reference"); - - /* - * If we cannot find a loose reference, we look into the packfile - * Load the packfile first if it hasn't been loaded - */ - /* load all the packed references */ - error = packed_load(repo); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to lookup reference"); - - /* Look up on the packfile */ - *ref_out = git_hashtable_lookup(repo->references.packfile, normalized_name); - if (*ref_out != NULL) - return GIT_SUCCESS; - - /* The reference doesn't exist anywhere */ - return git__throw(GIT_ENOTFOUND, "Failed to lookup reference. Reference doesn't exist"); -} - -/** - * Getters - */ -git_rtype git_reference_type(git_reference *ref) -{ - assert(ref); - - if (ref->type & GIT_REF_OID) - return GIT_REF_OID; - - if (ref->type & GIT_REF_SYMBOLIC) - return GIT_REF_SYMBOLIC; - - return GIT_REF_INVALID; -} - -const char *git_reference_name(git_reference *ref) -{ - assert(ref); - return ref->name; -} - -git_repository *git_reference_owner(git_reference *ref) -{ - assert(ref); - return ref->owner; -} - -const git_oid *git_reference_oid(git_reference *ref) -{ - assert(ref); - - if ((ref->type & GIT_REF_OID) == 0) - return NULL; - - if (loose_update(ref) < GIT_SUCCESS) - return NULL; - - return &((reference_oid *)ref)->oid; -} - -const char *git_reference_target(git_reference *ref) -{ - assert(ref); - - if ((ref->type & GIT_REF_SYMBOLIC) == 0) - return NULL; - - if (loose_update(ref) < GIT_SUCCESS) - return NULL; - - return ((reference_symbolic *)ref)->target; -} - -int git_reference_create_symbolic(git_reference **ref_out, git_repository *repo, const char *name, const char *target, int force) -{ - char normalized[GIT_REFNAME_MAX]; - int error = GIT_SUCCESS, updated = 0; - git_reference *ref = NULL, *old_ref = NULL; - - if (git_reference_lookup(&ref, repo, name) == GIT_SUCCESS && !force) - return git__throw(GIT_EEXISTS, "Failed to create symbolic reference. Reference already exists"); - - /* - * If they old ref was of the same type, then we can just update - * it (once we've checked that the target is valid). Otherwise we - * need a new reference because we can't make a symbolic ref out - * of an oid one. - * If if didn't exist, then we need to create a new one anyway. - */ - if (ref && ref->type & GIT_REF_SYMBOLIC){ - updated = 1; - } else { - ref = NULL; - error = reference_create(&ref, repo, name, GIT_REF_SYMBOLIC); - if (error < GIT_SUCCESS) - goto cleanup; - } - - /* The target can aither be the name of an object id reference or the name of another symbolic reference */ - error = normalize_name(normalized, sizeof(normalized), target, 0); - if (error < GIT_SUCCESS) - goto cleanup; - - /* set the target; this will write the reference on disk */ - error = git_reference_set_target(ref, normalized); - if (error < GIT_SUCCESS) - goto cleanup; - - /* - * If we didn't update the ref, then we need to insert or replace - * it in the loose cache. If we replaced a ref, free it. - */ - if (!updated){ - error = git_hashtable_insert2(repo->references.loose_cache, ref->name, ref, (void **) &old_ref); - if (error < GIT_SUCCESS) - goto cleanup; - - if(old_ref) - reference_free(old_ref); - } - - *ref_out = ref; - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to create symbolic reference"); - -cleanup: - reference_free(ref); - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to create symbolic reference"); -} - -int git_reference_create_oid(git_reference **ref_out, git_repository *repo, const char *name, const git_oid *id, int force) -{ - int error = GIT_SUCCESS, updated = 0; - git_reference *ref = NULL, *old_ref = NULL; - - if(git_reference_lookup(&ref, repo, name) == GIT_SUCCESS && !force) - return git__throw(GIT_EEXISTS, "Failed to create reference OID. Reference already exists"); - - if ((error = reference_available(repo, name, NULL)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to create reference"); - - /* - * If they old ref was of the same type, then we can just update - * it (once we've checked that the target is valid). Otherwise we - * need a new reference because we can't make a symbolic ref out - * of an oid one. - * If if didn't exist, then we need to create a new one anyway. - */ - if (ref && ref-> type & GIT_REF_OID){ - updated = 1; - } else { - ref = NULL; - error = reference_create(&ref, repo, name, GIT_REF_OID); - if (error < GIT_SUCCESS) - goto cleanup; - } - - /* set the oid; this will write the reference on disk */ - error = git_reference_set_oid(ref, id); - if (error < GIT_SUCCESS) - goto cleanup; - - if(!updated){ - error = git_hashtable_insert2(repo->references.loose_cache, ref->name, ref, (void **) &old_ref); - if (error < GIT_SUCCESS) - goto cleanup; - - if(old_ref) - reference_free(old_ref); - } - - *ref_out = ref; - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to create reference OID"); - -cleanup: - reference_free(ref); - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to create reference OID"); -} - -/** - * Setters - */ - -/* - * Change the OID target of a reference. - * - * For loose references, just change the oid in memory - * and overwrite the file in disk. - * - * For packed files, this is not pretty: - * For performance reasons, we write the new reference - * loose on disk (it replaces the old on the packfile), - * but we cannot invalidate the pointer to the reference, - * and most importantly, the `packfile` object must stay - * consistent with the representation of the packfile - * on disk. This is what we need to: - * - * 1. Copy the reference - * 2. Change the oid on the original - * 3. Write the original to disk - * 4. Write the original to the loose cache - * 5. Replace the original with the copy (old reference) in the packfile cache - */ -int git_reference_set_oid(git_reference *ref, const git_oid *id) -{ - reference_oid *ref_oid; - reference_oid *ref_old = NULL; - int error = GIT_SUCCESS; - - if ((ref->type & GIT_REF_OID) == 0) - return git__throw(GIT_EINVALIDREFSTATE, "Failed to set OID target of reference. Not an OID reference"); - - ref_oid = (reference_oid *)ref; - - assert(ref->owner); - - /* Don't let the user create references to OIDs that - * don't exist in the ODB */ - if (!git_odb_exists(git_repository_database(ref->owner), id)) - return git__throw(GIT_ENOTFOUND, "Failed to set OID target of reference. OID doesn't exist in ODB"); - - /* duplicate the reference; - * this copy will stay on the packfile cache */ - if (ref->type & GIT_REF_PACKED) { - ref_old = git__malloc(sizeof(reference_oid)); - if (ref_old == NULL) - return GIT_ENOMEM; - - ref_old->ref.name = git__strdup(ref->name); - if (ref_old->ref.name == NULL) { - free(ref_old); - return GIT_ENOMEM; - } - } - - git_oid_cpy(&ref_oid->oid, id); - ref->type &= ~GIT_REF_HAS_PEEL; - - error = loose_write(ref); - if (error < GIT_SUCCESS) - goto cleanup; - - if (ref->type & GIT_REF_PACKED) { - /* insert the original on the loose cache */ - error = git_hashtable_insert(ref->owner->references.loose_cache, ref->name, ref); - if (error < GIT_SUCCESS) - goto cleanup; - - ref->type &= ~GIT_REF_PACKED; - - /* replace the original in the packfile with the copy */ - error = git_hashtable_insert(ref->owner->references.packfile, ref_old->ref.name, ref_old); - if (error < GIT_SUCCESS) - goto cleanup; - } - - return GIT_SUCCESS; - -cleanup: - reference_free((git_reference *)ref_old); - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to set OID target of reference"); -} - -/* - * Change the target of a symbolic reference. - * - * This is easy because symrefs cannot be inside - * a pack. We just change the target in memory - * and overwrite the file on disk. - */ -int git_reference_set_target(git_reference *ref, const char *target) -{ - reference_symbolic *ref_sym; - - if ((ref->type & GIT_REF_SYMBOLIC) == 0) - return git__throw(GIT_EINVALIDREFSTATE, "Failed to set reference target. Not a symbolic reference"); - - ref_sym = (reference_symbolic *)ref; - - free(ref_sym->target); - ref_sym->target = git__strdup(target); - if (ref_sym->target == NULL) - return GIT_ENOMEM; - - return loose_write(ref); -} - -/** - * Other - */ - -int git_reference_rename(git_reference *ref, const char *new_name, int force) -{ - int error; - char *old_name = NULL; - - char aux_path[GIT_PATH_MAX]; - char normalized[GIT_REFNAME_MAX]; - - const char *target_ref = NULL; - const char *head_target = NULL; - const git_oid *target_oid = NULL; - git_reference *new_ref = NULL, *old_ref = NULL, *head = NULL; - - assert(ref); - - error = normalize_name(normalized, sizeof(normalized), new_name, ref->type & GIT_REF_OID); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to rename reference. Invalid name"); - - new_name = normalized; - - error = git_reference_lookup(&new_ref, ref->owner, new_name); - if (error == GIT_SUCCESS) { - if (!force) - return git__throw(GIT_EEXISTS, "Failed to rename reference. Reference already exists"); - - error = git_reference_delete(new_ref); - } - - if (error < GIT_SUCCESS && error != GIT_ENOTFOUND) - goto cleanup; - - if ((error = reference_available(ref->owner, new_name, ref->name)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to rename reference. Reference already exists"); - - /* - * First, we backup the reference targets. Just keeping the old - * reference won't work, since we may have to remove it to create - * the new reference, e.g. when renaming foo/bar -> foo. - */ - - old_name = git__strdup(ref->name); - - if (ref->type & GIT_REF_SYMBOLIC) { - if ((target_ref = git_reference_target(ref)) == NULL) - goto cleanup; - } else { - if ((target_oid = git_reference_oid(ref)) == NULL) - goto cleanup; - } - - /* - * Now delete the old ref and remove an possibly existing directory - * named `new_name`. - */ - - if (ref->type & GIT_REF_PACKED) { - ref->type &= ~GIT_REF_PACKED; - - git_hashtable_remove(ref->owner->references.packfile, old_name); - if ((error = packed_write(ref->owner)) < GIT_SUCCESS) - goto rollback; - } else { - git_path_join(aux_path, ref->owner->path_repository, old_name); - if ((error = p_unlink(aux_path)) < GIT_SUCCESS) - goto cleanup; - - git_hashtable_remove(ref->owner->references.loose_cache, old_name); - } - - /* build new path */ - git_path_join(aux_path, ref->owner->path_repository, new_name); - - if (git_futils_exists(aux_path) == GIT_SUCCESS) { - if (git_futils_isdir(aux_path) == GIT_SUCCESS) { - if ((error = git_futils_rmdir_r(aux_path, 0)) < GIT_SUCCESS) - goto rollback; - } else goto rollback; - } - - /* - * Crude hack: delete any logs till we support proper reflogs. - * Otherwise git.git will possibly fail and leave a mess. git.git - * writes reflogs by default in any repo with a working directory: - * - * "We only enable reflogs in repositories that have a working directory - * associated with them, as shared/bare repositories do not have - * an easy means to prune away old log entries, or may fail logging - * entirely if the user's gecos information is not valid during a push. - * This heuristic was suggested on the mailing list by Junio." - * - * Shawn O. Pearce - 0bee59186976b1d9e6b2dd77332480c9480131d5 - * - * TODO - * - */ - - git_path_join_n(aux_path, 3, ref->owner->path_repository, "logs", old_name); - if (git_futils_isfile(aux_path) == GIT_SUCCESS) { - if ((error = p_unlink(aux_path)) < GIT_SUCCESS) - goto rollback; - } - - /* - * Finally we can create the new reference. - */ - if (ref->type & GIT_REF_SYMBOLIC) { - if ((error = git_reference_create_symbolic(&new_ref, ref->owner, new_name, target_ref, 0)) < GIT_SUCCESS) - goto rollback; - } else { - if ((error = git_reference_create_oid(&new_ref, ref->owner, new_name, target_oid, 0)) < GIT_SUCCESS) - goto rollback; - } - - free(ref->name); - ref->name = new_ref->name; - - /* - * No need in new_ref anymore. We created it to fix the change on disk. - * TODO: Refactoring required. - */ - new_ref->name = NULL; - reference_free(new_ref); - - if ((error = git_hashtable_insert2(ref->owner->references.loose_cache, ref->name, ref, (void **)&old_ref)) < GIT_SUCCESS) - goto rollback; - - /* - * Check if we have to update HEAD. - */ - - if ((error = git_reference_lookup(&head, ref->owner, GIT_HEAD_FILE)) < GIT_SUCCESS) - goto cleanup; - - head_target = git_reference_target(head); - - if (head_target && !strcmp(head_target, old_name)) - if ((error = git_reference_create_symbolic(&head, ref->owner, "HEAD", ref->name, 1)) < GIT_SUCCESS) - goto rollback; - -cleanup: - free(old_name); - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to rename reference"); - -rollback: - /* - * Try to create the old reference again. - */ - if (ref->type & GIT_REF_SYMBOLIC) - error = git_reference_create_symbolic(&new_ref, ref->owner, old_name, target_ref, 0); - else - error = git_reference_create_oid(&new_ref, ref->owner, old_name, target_oid, 0); - - ref->name = old_name; - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to rename reference. Failed to rollback"); -} - -/* - * Delete a reference. - * - * If the reference is packed, this is an expensive - * operation. We need to remove the reference from - * the memory cache and then rewrite the whole pack - * - * If the reference is loose, we remove it on - * the filesystem and update the in-memory cache - * accordingly. We also make sure that an older version - * of it doesn't exist as a packed reference. If this - * is the case, this packed reference is removed as well. - * - * This obviously invalidates the `ref` pointer. - */ -int git_reference_delete(git_reference *ref) -{ - int error; - git_reference *reference; - - assert(ref); - - if (ref->type & GIT_REF_PACKED) { - /* load the existing packfile */ - if ((error = packed_load(ref->owner)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to delete reference"); - - if (git_hashtable_remove(ref->owner->references.packfile, ref->name) < GIT_SUCCESS) - return git__throw(GIT_ENOTFOUND, "Reference not found"); - - error = packed_write(ref->owner); - } else { - char full_path[GIT_PATH_MAX]; - git_path_join(full_path, ref->owner->path_repository, ref->name); - git_hashtable_remove(ref->owner->references.loose_cache, ref->name); - error = p_unlink(full_path); - if (error < GIT_SUCCESS) - goto cleanup; - - /* When deleting a loose reference, we have to ensure that an older - * packed version of it doesn't exist - */ - if (!git_reference_lookup(&reference, ref->owner, ref->name)) { - assert((reference->type & GIT_REF_PACKED) != 0); - error = git_reference_delete(reference); - } - } - -cleanup: - reference_free(ref); - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to delete reference"); -} - -int git_reference_resolve(git_reference **resolved_ref, git_reference *ref) -{ - git_repository *repo; - int error, i; - - assert(resolved_ref && ref); - *resolved_ref = NULL; - - if ((error = loose_update(ref)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to resolve reference"); - - repo = ref->owner; - - for (i = 0; i < MAX_NESTING_LEVEL; ++i) { - reference_symbolic *ref_sym; - - *resolved_ref = ref; - - if (ref->type & GIT_REF_OID) - return GIT_SUCCESS; - - ref_sym = (reference_symbolic *)ref; - if ((error = git_reference_lookup(&ref, repo, ref_sym->target)) < GIT_SUCCESS) - return error; - } - - return git__throw(GIT_ENOMEM, "Failed to resolve reference. Reference is too nested"); -} - -int git_reference_packall(git_repository *repo) -{ - int error; - - /* load the existing packfile */ - if ((error = packed_load(repo)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to pack references"); - - /* update it in-memory with all the loose references */ - if ((error = packed_loadloose(repo)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to pack references"); - - /* write it back to disk */ - return packed_write(repo); -} - -int git_reference_foreach(git_repository *repo, unsigned int list_flags, int (*callback)(const char *, void *), void *payload) -{ - int error; - struct dirent_list_data data; - char refs_path[GIT_PATH_MAX]; - - /* list all the packed references first */ - if (list_flags & GIT_REF_PACKED) { - const char *ref_name; - void *GIT_UNUSED(_unused); - - if ((error = packed_load(repo)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to list references"); - - GIT_HASHTABLE_FOREACH(repo->references.packfile, ref_name, _unused, - if ((error = callback(ref_name, payload)) < GIT_SUCCESS) - return git__throw(error, "Failed to list references. User callback failed"); - ); - } - - /* now list the loose references, trying not to - * duplicate the ref names already in the packed-refs file */ - - data.repo_path_len = strlen(repo->path_repository); - data.list_flags = list_flags; - data.repo = repo; - data.callback = callback; - data.callback_payload = payload; - - - git_path_join(refs_path, repo->path_repository, GIT_REFS_DIR); - return git_futils_direach(refs_path, GIT_PATH_MAX, _dirent_loose_listall, &data); -} - -int cb__reflist_add(const char *ref, void *data) -{ - return git_vector_insert((git_vector *)data, git__strdup(ref)); -} - -int git_reference_listall(git_strarray *array, git_repository *repo, unsigned int list_flags) -{ - int error; - git_vector ref_list; - - assert(array && repo); - - array->strings = NULL; - array->count = 0; - - if (git_vector_init(&ref_list, 8, NULL) < GIT_SUCCESS) - return GIT_ENOMEM; - - error = git_reference_foreach(repo, list_flags, &cb__reflist_add, (void *)&ref_list); - - if (error < GIT_SUCCESS) { - git_vector_free(&ref_list); - return error; - } - - array->strings = (char **)ref_list.contents; - array->count = ref_list.length; - return GIT_SUCCESS; -} - - - - -/***************************************** - * Init/free (repository API) - *****************************************/ -int git_repository__refcache_init(git_refcache *refs) -{ - assert(refs); - - refs->loose_cache = git_hashtable_alloc( - default_table_size, - reftable_hash, - (git_hash_keyeq_ptr)(&git__strcmp_cb)); - - /* packfile loaded lazily */ - refs->packfile = NULL; - refs->packfile_time = 0; - - return (refs->loose_cache) ? GIT_SUCCESS : GIT_ENOMEM; -} - -void git_repository__refcache_free(git_refcache *refs) -{ - git_reference *reference; - const void *GIT_UNUSED(_unused); - - assert(refs); - - GIT_HASHTABLE_FOREACH(refs->loose_cache, _unused, reference, - reference_free(reference); - ); - - git_hashtable_free(refs->loose_cache); - - if (refs->packfile) { - GIT_HASHTABLE_FOREACH(refs->packfile, _unused, reference, - reference_free(reference); - ); - - git_hashtable_free(refs->packfile); - } -} - - - -/***************************************** - * Name normalization - *****************************************/ -static int check_valid_ref_char(char ch) -{ - if ((unsigned) ch <= ' ') - return GIT_ERROR; - - switch (ch) { - case '~': - case '^': - case ':': - case '\\': - case '?': - case '[': - case '*': - return GIT_ERROR; - default: - return GIT_SUCCESS; - } -} - -static int normalize_name(char *buffer_out, size_t out_size, const char *name, int is_oid_ref) -{ - const char *name_end, *buffer_out_start; - const char *current; - int contains_a_slash = 0; - - assert(name && buffer_out); - - buffer_out_start = buffer_out; - current = name; - name_end = name + strlen(name); - - /* Terminating null byte */ - out_size--; - - /* A refname can not be empty */ - if (name_end == name) - return git__throw(GIT_EINVALIDREFNAME, "Failed to normalize name. Reference name is empty"); - - /* A refname can not end with a dot or a slash */ - if (*(name_end - 1) == '.' || *(name_end - 1) == '/') - return git__throw(GIT_EINVALIDREFNAME, "Failed to normalize name. Reference name ends with dot or slash"); - - while (current < name_end && out_size) { - if (check_valid_ref_char(*current)) - return git__throw(GIT_EINVALIDREFNAME, "Failed to normalize name. Reference name contains invalid characters"); - - if (buffer_out > buffer_out_start) { - char prev = *(buffer_out - 1); - - /* A refname can not start with a dot nor contain a double dot */ - if (*current == '.' && ((prev == '.') || (prev == '/'))) - return git__throw(GIT_EINVALIDREFNAME, "Failed to normalize name. Reference name starts with a dot or contains a double dot"); - - /* '@{' is forbidden within a refname */ - if (*current == '{' && prev == '@') - return git__throw(GIT_EINVALIDREFNAME, "Failed to normalize name. Reference name contains '@{'"); - - /* Prevent multiple slashes from being added to the output */ - if (*current == '/' && prev == '/') { - current++; - continue; - } - } - - if (*current == '/') - contains_a_slash = 1; - - *buffer_out++ = *current++; - out_size--; - } - - if (!out_size) - return git__throw(GIT_EINVALIDREFNAME, "Reference name is too long"); - - /* Object id refname have to contain at least one slash, except - * for HEAD in a detached state or MERGE_HEAD if we're in the - * middle of a merge */ - if (is_oid_ref && !contains_a_slash && (strcmp(name, GIT_HEAD_FILE) && strcmp(name, GIT_MERGE_HEAD_FILE))) - return git__throw(GIT_EINVALIDREFNAME, "Failed to normalize name. Reference name contains no slashes"); - - /* A refname can not end with ".lock" */ - if (!git__suffixcmp(name, GIT_FILELOCK_EXTENSION)) - return git__throw(GIT_EINVALIDREFNAME, "Failed to normalize name. Reference name ends with '.lock'"); - - *buffer_out = '\0'; - - /* - * For object id references, name has to start with refs/. Again, - * we need to allow HEAD to be in a detached state. - */ - if (is_oid_ref && !(git__prefixcmp(buffer_out_start, GIT_REFS_DIR) || - strcmp(buffer_out_start, GIT_HEAD_FILE))) - return git__throw(GIT_EINVALIDREFNAME, "Failed to normalize name. Reference name does not start with 'refs/'"); - - return GIT_SUCCESS; -} - -int git_reference__normalize_name(char *buffer_out, size_t out_size, const char *name) -{ - return normalize_name(buffer_out, out_size, name, 0); -} - -int git_reference__normalize_name_oid(char *buffer_out, size_t out_size, const char *name) -{ - return normalize_name(buffer_out, out_size, name, 1); -} diff --git a/vendor/libgit2/src/refs.h b/vendor/libgit2/src/refs.h deleted file mode 100644 index dfac455e0..000000000 --- a/vendor/libgit2/src/refs.h +++ /dev/null @@ -1,46 +0,0 @@ -#ifndef INCLUDE_refs_h__ -#define INCLUDE_refs_h__ - -#include "common.h" -#include "git2/oid.h" -#include "git2/refs.h" -#include "hashtable.h" - -#define GIT_REFS_DIR "refs/" -#define GIT_REFS_HEADS_DIR GIT_REFS_DIR "heads/" -#define GIT_REFS_TAGS_DIR GIT_REFS_DIR "tags/" -#define GIT_REFS_REMOTES_DIR GIT_REFS_DIR "remotes/" - -#define GIT_RENAMED_REF_FILE GIT_REFS_DIR "RENAMED-REF" - -#define GIT_SYMREF "ref: " -#define GIT_PACKEDREFS_FILE "packed-refs" -#define GIT_PACKEDREFS_HEADER "# pack-refs with: peeled " - -#define GIT_HEAD_FILE "HEAD" -#define GIT_MERGE_HEAD_FILE "MERGE_HEAD" -#define GIT_REFS_HEADS_MASTER_FILE GIT_REFS_HEADS_DIR "master" - -#define GIT_REFNAME_MAX 1024 - -struct git_reference { - git_repository *owner; - char *name; - unsigned int type; - time_t mtime; -}; - -typedef struct { - git_hashtable *packfile; - git_hashtable *loose_cache; - time_t packfile_time; -} git_refcache; - - -void git_repository__refcache_free(git_refcache *refs); -int git_repository__refcache_init(git_refcache *refs); - -int git_reference__normalize_name(char *buffer_out, size_t out_size, const char *name); -int git_reference__normalize_name_oid(char *buffer_out, size_t out_size, const char *name); - -#endif diff --git a/vendor/libgit2/src/refspec.c b/vendor/libgit2/src/refspec.c deleted file mode 100644 index 8500e07ea..000000000 --- a/vendor/libgit2/src/refspec.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "git2/errors.h" - -#include "common.h" -#include "refspec.h" -#include "util.h" - -int git_refspec_parse(git_refspec *refspec, const char *str) -{ - char *delim; - - memset(refspec, 0x0, sizeof(git_refspec)); - - if (*str == '+') { - refspec->force = 1; - str++; - } - - delim = strchr(str, ':'); - if (delim == NULL) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse refspec. No ':'"); - - refspec->src = git__strndup(str, delim - str); - if (refspec->src == NULL) - return GIT_ENOMEM; - - refspec->dst = git__strdup(delim + 1); - if (refspec->dst == NULL) { - free(refspec->src); - refspec->src = NULL; - return GIT_ENOMEM; - } - - return GIT_SUCCESS; -} - -const char *git_refspec_src(const git_refspec *refspec) -{ - return refspec->src; -} - -const char *git_refspec_dst(const git_refspec *refspec) -{ - return refspec->dst; -} - -int git_refspec_src_match(const git_refspec *refspec, const char *refname) -{ - return git__fnmatch(refspec->src, refname, 0); -} - -int git_refspec_transform(char *out, size_t outlen, const git_refspec *spec, const char *name) -{ - size_t baselen, namelen; - - baselen = strlen(spec->dst); - if (outlen <= baselen) - return git__throw(GIT_EINVALIDREFNAME, "Reference name too long"); - - /* - * No '*' at the end means that it's mapped to one specific local - * branch, so no actual transformation is needed. - */ - if (spec->dst[baselen - 1] != '*') { - memcpy(out, spec->dst, baselen + 1); /* include '\0' */ - return GIT_SUCCESS; - } - - /* There's a '*' at the end, so remove its length */ - baselen--; - - /* skip the prefix, -1 is for the '*' */ - name += strlen(spec->src) - 1; - - namelen = strlen(name); - - if (outlen <= baselen + namelen) - return git__throw(GIT_EINVALIDREFNAME, "Reference name too long"); - - memcpy(out, spec->dst, baselen); - memcpy(out + baselen, name, namelen + 1); - - return GIT_SUCCESS; -} diff --git a/vendor/libgit2/src/refspec.h b/vendor/libgit2/src/refspec.h deleted file mode 100644 index 230135a4a..000000000 --- a/vendor/libgit2/src/refspec.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef INCLUDE_refspec_h__ -#define INCLUDE_refspec_h__ - -#include "git2/refspec.h" - -struct git_refspec { - int force; - char *src; - char *dst; -}; - -int git_refspec_parse(struct git_refspec *refspec, const char *str); - -#endif diff --git a/vendor/libgit2/src/remote.c b/vendor/libgit2/src/remote.c deleted file mode 100644 index 297789a69..000000000 --- a/vendor/libgit2/src/remote.c +++ /dev/null @@ -1,283 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "git2/remote.h" -#include "git2/config.h" -#include "git2/types.h" - -#include "config.h" -#include "repository.h" -#include "remote.h" -#include "fetch.h" -#include "refs.h" - -static int refspec_parse(git_refspec *refspec, const char *str) -{ - char *delim; - - memset(refspec, 0x0, sizeof(git_refspec)); - - if (*str == '+') { - refspec->force = 1; - str++; - } - - delim = strchr(str, ':'); - if (delim == NULL) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse refspec. No ':'"); - - refspec->src = git__strndup(str, delim - str); - if (refspec->src == NULL) - return GIT_ENOMEM; - - refspec->dst = git__strdup(delim + 1); - if (refspec->dst == NULL) { - free(refspec->src); - refspec->src = NULL; - return GIT_ENOMEM; - } - - return GIT_SUCCESS; -} - -static int parse_remote_refspec(git_config *cfg, git_refspec *refspec, const char *var) -{ - const char *val; - int error; - - error = git_config_get_string(cfg, var, &val); - if (error < GIT_SUCCESS) - return error; - - return refspec_parse(refspec, val); -} - -int git_remote_new(git_remote **out, git_repository *repo, const char *url) -{ - git_remote *remote; - - remote = git__malloc(sizeof(git_remote)); - if (remote == NULL) - return GIT_ENOMEM; - - memset(remote, 0x0, sizeof(git_remote)); - remote->repo = repo; - remote->url = git__strdup(url); - if (remote->url == NULL) { - free(remote); - return GIT_ENOMEM; - } - - *out = remote; - return GIT_SUCCESS; -} - -int git_remote_get(git_remote **out, git_config *cfg, const char *name) -{ - git_remote *remote; - char *buf = NULL; - const char *val; - int ret, error, buf_len; - - remote = git__malloc(sizeof(git_remote)); - if (remote == NULL) - return GIT_ENOMEM; - - memset(remote, 0x0, sizeof(git_remote)); - remote->name = git__strdup(name); - if (remote->name == NULL) { - error = GIT_ENOMEM; - goto cleanup; - } - - /* "fetch" is the longest var name we're interested in */ - buf_len = strlen("remote.") + strlen(".fetch") + strlen(name) + 1; - buf = git__malloc(buf_len); - if (buf == NULL) { - error = GIT_ENOMEM; - goto cleanup; - } - - ret = p_snprintf(buf, buf_len, "%s.%s.%s", "remote", name, "url"); - if (ret < 0) { - error = git__throw(GIT_EOSERR, "Failed to build config var name"); - goto cleanup; - } - - error = git_config_get_string(cfg, buf, &val); - if (error < GIT_SUCCESS) { - error = git__rethrow(error, "Remote's url doesn't exist"); - goto cleanup; - } - - remote->repo = cfg->repo; - remote->url = git__strdup(val); - if (remote->url == NULL) { - error = GIT_ENOMEM; - goto cleanup; - } - - ret = p_snprintf(buf, buf_len, "%s.%s.%s", "remote", name, "fetch"); - if (ret < 0) { - error = git__throw(GIT_EOSERR, "Failed to build config var name"); - goto cleanup; - } - - error = parse_remote_refspec(cfg, &remote->fetch, buf); - if (error < GIT_SUCCESS) { - error = git__rethrow(error, "Failed to get fetch refspec"); - goto cleanup; - } - - ret = p_snprintf(buf, buf_len, "%s.%s.%s", "remote", name, "push"); - if (ret < 0) { - error = git__throw(GIT_EOSERR, "Failed to build config var name"); - goto cleanup; - } - - error = parse_remote_refspec(cfg, &remote->push, buf); - /* Not finding push is fine */ - if (error == GIT_ENOTFOUND) - error = GIT_SUCCESS; - - if (error < GIT_SUCCESS) - goto cleanup; - - *out = remote; - -cleanup: - free(buf); - if (error < GIT_SUCCESS) - git_remote_free(remote); - - return error; -} - -const char *git_remote_name(struct git_remote *remote) -{ - return remote->name; -} - -const char *git_remote_url(struct git_remote *remote) -{ - return remote->url; -} - -const git_refspec *git_remote_fetchspec(struct git_remote *remote) -{ - return &remote->fetch; -} - -const git_refspec *git_remote_pushspec(struct git_remote *remote) -{ - return &remote->push; -} - -int git_remote_connect(git_remote *remote, int direction) -{ - int error; - git_transport *t; - - error = git_transport_new(&t, remote->url); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to create transport"); - - error = t->connect(t, direction); - if (error < GIT_SUCCESS) { - error = git__rethrow(error, "Failed to connect the transport"); - goto cleanup; - } - - remote->transport = t; - -cleanup: - if (error < GIT_SUCCESS) - t->free(t); - - return error; -} - -int git_remote_ls(git_remote *remote, git_headarray *refs) -{ - return remote->transport->ls(remote->transport, refs); -} - -int git_remote_negotiate(git_remote *remote) -{ - return git_fetch_negotiate(remote); -} - -int git_remote_download(char **filename, git_remote *remote) -{ - return git_fetch_download_pack(filename, remote); -} - -git_headarray *git_remote_tips(git_remote *remote) -{ - return &remote->refs; -} - -int git_remote_update_tips(struct git_remote *remote) -{ - int error = GIT_SUCCESS; - unsigned int i; - char refname[GIT_PATH_MAX]; - git_headarray *refs = &remote->refs; - git_remote_head *head; - git_reference *ref; - struct git_refspec *spec = &remote->fetch; - - memset(refname, 0x0, sizeof(refname)); - - for (i = 0; i < refs->len; ++i) { - head = refs->heads[i]; - error = git_refspec_transform(refname, sizeof(refname), spec, head->name); - if (error < GIT_SUCCESS) - return error; - - error = git_reference_create_oid(&ref, remote->repo, refname, &head->oid, 1); - if (error < GIT_SUCCESS) - return error; - } - - return GIT_SUCCESS; -} - -void git_remote_free(git_remote *remote) -{ - free(remote->fetch.src); - free(remote->fetch.dst); - free(remote->push.src); - free(remote->push.dst); - free(remote->url); - free(remote->name); - if (remote->transport != NULL) { - if (remote->transport->connected) - remote->transport->close(remote->transport); - - remote->transport->free(remote->transport); - } - free(remote); -} diff --git a/vendor/libgit2/src/remote.h b/vendor/libgit2/src/remote.h deleted file mode 100644 index 21313acd4..000000000 --- a/vendor/libgit2/src/remote.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef INCLUDE_remote_h__ -#define INCLUDE_remote_h__ - -#include "refspec.h" -#include "transport.h" -#include "repository.h" - -struct git_remote { - char *name; - char *url; - git_headarray refs; - struct git_refspec fetch; - struct git_refspec push; - git_transport *transport; - git_repository *repo; - int need_pack:1; -}; - -#endif diff --git a/vendor/libgit2/src/repository.c b/vendor/libgit2/src/repository.c deleted file mode 100644 index 1b06c4f03..000000000 --- a/vendor/libgit2/src/repository.c +++ /dev/null @@ -1,794 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include - -#include "git2/object.h" - -#include "common.h" -#include "repository.h" -#include "commit.h" -#include "tag.h" -#include "blob.h" -#include "fileops.h" -#include "config.h" -#include "refs.h" - -#define GIT_OBJECTS_INFO_DIR GIT_OBJECTS_DIR "info/" -#define GIT_OBJECTS_PACK_DIR GIT_OBJECTS_DIR "pack/" - -#define GIT_FILE_CONTENT_PREFIX "gitdir: " - -#define GIT_BRANCH_MASTER "master" - -/* - * Git repository open methods - * - * Open a repository object from its path - */ -static int assign_repository_dirs( - git_repository *repo, - const char *git_dir, - const char *git_object_directory, - const char *git_index_file, - const char *git_work_tree) -{ - char path_aux[GIT_PATH_MAX]; - int error = GIT_SUCCESS; - - assert(repo); - - if (git_dir == NULL) - return git__throw(GIT_ENOTFOUND, "Failed to open repository. Git dir not found"); - - error = git_path_prettify_dir(path_aux, git_dir, NULL); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to open repository"); - - /* store GIT_DIR */ - repo->path_repository = git__strdup(path_aux); - if (repo->path_repository == NULL) - return GIT_ENOMEM; - - /* path to GIT_OBJECT_DIRECTORY */ - if (git_object_directory == NULL) - git_path_join(path_aux, repo->path_repository, GIT_OBJECTS_DIR); - else { - error = git_path_prettify_dir(path_aux, git_object_directory, NULL); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to open repository"); - } - - /* Store GIT_OBJECT_DIRECTORY */ - repo->path_odb = git__strdup(path_aux); - if (repo->path_odb == NULL) - return GIT_ENOMEM; - - /* path to GIT_WORK_TREE */ - if (git_work_tree == NULL) - repo->is_bare = 1; - else { - error = git_path_prettify_dir(path_aux, git_work_tree, NULL); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to open repository"); - - /* Store GIT_WORK_TREE */ - repo->path_workdir = git__strdup(path_aux); - if (repo->path_workdir == NULL) - return GIT_ENOMEM; - - /* Path to GIT_INDEX_FILE */ - if (git_index_file == NULL) - git_path_join(path_aux, repo->path_repository, GIT_INDEX_FILE); - else { - error = git_path_prettify(path_aux, git_index_file, NULL); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to open repository"); - } - - /* store GIT_INDEX_FILE */ - repo->path_index = git__strdup(path_aux); - if (repo->path_index == NULL) - return GIT_ENOMEM; - } - - return GIT_SUCCESS; -} - -static int check_repository_dirs(git_repository *repo) -{ - char path_aux[GIT_PATH_MAX]; - - if (git_futils_isdir(repo->path_repository) < GIT_SUCCESS) - return git__throw(GIT_ENOTAREPO, "`%s` is not a folder", repo->path_repository); - - /* Ensure GIT_OBJECT_DIRECTORY exists */ - if (git_futils_isdir(repo->path_odb) < GIT_SUCCESS) - return git__throw(GIT_ENOTAREPO, "`%s` does not exist", repo->path_odb); - - /* Ensure HEAD file exists */ - git_path_join(path_aux, repo->path_repository, GIT_HEAD_FILE); - if (git_futils_isfile(path_aux) < 0) - return git__throw(GIT_ENOTAREPO, "HEAD file is missing"); - - return GIT_SUCCESS; -} - -static int guess_repository_dirs(git_repository *repo, const char *repository_path) -{ - char buffer[GIT_PATH_MAX]; - const char *path_work_tree = NULL; - - /* Git directory name */ - if (git_path_basename_r(buffer, sizeof(buffer), repository_path) < 0) - return git__throw(GIT_EINVALIDPATH, "Unable to parse folder name from `%s`", repository_path); - - if (strcmp(buffer, DOT_GIT) == 0) { - /* Path to working dir */ - if (git_path_dirname_r(buffer, sizeof(buffer), repository_path) < 0) - return git__throw(GIT_EINVALIDPATH, "Unable to parse parent folder name from `%s`", repository_path); - path_work_tree = buffer; - } - - return assign_repository_dirs(repo, repository_path, NULL, NULL, path_work_tree); -} - -static int quickcheck_repository_dir(const char *repository_path) -{ - char path_aux[GIT_PATH_MAX]; - - /* Ensure HEAD file exists */ - git_path_join(path_aux, repository_path, GIT_HEAD_FILE); - if (git_futils_isfile(path_aux) < 0) - return GIT_ERROR; - - git_path_join(path_aux, repository_path, GIT_OBJECTS_DIR); - if (git_futils_isdir(path_aux) < 0) - return GIT_ERROR; - - git_path_join(path_aux, repository_path, GIT_REFS_DIR); - if (git_futils_isdir(path_aux) < 0) - return GIT_ERROR; - - return GIT_SUCCESS; -} - -static git_repository *repository_alloc() -{ - int error; - - git_repository *repo = git__malloc(sizeof(git_repository)); - if (!repo) - return NULL; - - memset(repo, 0x0, sizeof(git_repository)); - - error = git_cache_init(&repo->objects, GIT_DEFAULT_CACHE_SIZE, &git_object__free); - if (error < GIT_SUCCESS) { - free(repo); - return NULL; - } - - if (git_repository__refcache_init(&repo->references) < GIT_SUCCESS) { - free(repo); - return NULL; - } - - return repo; -} - -static int init_odb(git_repository *repo) -{ - return git_odb_open(&repo->db, repo->path_odb); -} - -int git_repository_open3(git_repository **repo_out, - const char *git_dir, - git_odb *object_database, - const char *git_index_file, - const char *git_work_tree) -{ - git_repository *repo; - int error = GIT_SUCCESS; - - assert(repo_out); - - if (object_database == NULL) - return git__throw(GIT_EINVALIDARGS, "Failed to open repository. `object_database` can't be null"); - - repo = repository_alloc(); - if (repo == NULL) - return GIT_ENOMEM; - - error = assign_repository_dirs(repo, - git_dir, - NULL, - git_index_file, - git_work_tree); - - if (error < GIT_SUCCESS) - goto cleanup; - - error = check_repository_dirs(repo); - if (error < GIT_SUCCESS) - goto cleanup; - - repo->db = object_database; - - *repo_out = repo; - return GIT_SUCCESS; - -cleanup: - git_repository_free(repo); - return git__rethrow(error, "Failed to open repository"); -} - - -int git_repository_open2(git_repository **repo_out, - const char *git_dir, - const char *git_object_directory, - const char *git_index_file, - const char *git_work_tree) -{ - git_repository *repo; - int error = GIT_SUCCESS; - - assert(repo_out); - - repo = repository_alloc(); - if (repo == NULL) - return GIT_ENOMEM; - - error = assign_repository_dirs(repo, - git_dir, - git_object_directory, - git_index_file, - git_work_tree); - - if (error < GIT_SUCCESS) - goto cleanup; - - error = check_repository_dirs(repo); - if (error < GIT_SUCCESS) - goto cleanup; - - error = init_odb(repo); - if (error < GIT_SUCCESS) - goto cleanup; - - *repo_out = repo; - return GIT_SUCCESS; - -cleanup: - git_repository_free(repo); - return git__rethrow(error, "Failed to open repository"); -} - -int git_repository_config( - git_config **out, - git_repository *repo, - const char *user_config_path, - const char *system_config_path) -{ - char config_path[GIT_PATH_MAX]; - int error; - - assert(out && repo); - - error = git_config_new(out); - if (error < GIT_SUCCESS) - return error; - - git_path_join(config_path, repo->path_repository, GIT_CONFIG_FILENAME_INREPO); - error = git_config_add_file_ondisk(*out, config_path, 3); - if (error < GIT_SUCCESS) - goto cleanup; - - if (user_config_path != NULL) { - error = git_config_add_file_ondisk(*out, user_config_path, 2); - if (error < GIT_SUCCESS) - goto cleanup; - } - - if (system_config_path != NULL) { - error = git_config_add_file_ondisk(*out, system_config_path, 1); - if (error < GIT_SUCCESS) - goto cleanup; - } - - (*out)->repo = repo; - return GIT_SUCCESS; - -cleanup: - git_config_free(*out); - return error; -} - -static int discover_repository_dirs(git_repository *repo, const char *path) -{ - int error; - - error = guess_repository_dirs(repo, path); - if (error < GIT_SUCCESS) - return error; - - error = check_repository_dirs(repo); - if (error < GIT_SUCCESS) - return error; - - return GIT_SUCCESS; -} - -int git_repository_open(git_repository **repo_out, const char *path) -{ - git_repository *repo; - int error = GIT_SUCCESS; - - assert(repo_out && path); - - repo = repository_alloc(); - if (repo == NULL) - return GIT_ENOMEM; - - error = discover_repository_dirs(repo, path); - if (error < GIT_SUCCESS) - goto cleanup; - - error = init_odb(repo); - if (error < GIT_SUCCESS) - goto cleanup; - - *repo_out = repo; - return GIT_SUCCESS; - -cleanup: - git_repository_free(repo); - return git__rethrow(error, "Failed to open repository"); -} - -static int retrieve_device(dev_t *device_out, const char *path) -{ - struct stat path_info; - - assert(device_out); - - if (p_lstat(path, &path_info)) - return git__throw(GIT_EOSERR, "Failed to get file informations: %s", path); - - *device_out = path_info.st_dev; - - return GIT_SUCCESS; -} - -static int retrieve_ceiling_directories_offset(const char *path, const char *ceiling_directories) -{ - char buf[GIT_PATH_MAX + 1]; - char buf2[GIT_PATH_MAX + 1]; - const char *ceil, *sep; - int len, max_len = -1; - int min_len; - - assert(path); - - min_len = git_path_root(path) + 1; - - if (ceiling_directories == NULL || min_len == 0) - return min_len; - - for (sep = ceil = ceiling_directories; *sep; ceil = sep + 1) { - for (sep = ceil; *sep && *sep != GIT_PATH_LIST_SEPARATOR; sep++); - len = sep - ceil; - - if (len == 0 || len > GIT_PATH_MAX || git_path_root(ceil) == -1) - continue; - - strncpy(buf, ceil, len); - buf[len] = '\0'; - - if (p_realpath(buf, buf2) == NULL) - continue; - - len = strlen(buf2); - if (len > 0 && buf2[len-1] == '/') - buf[--len] = '\0'; - - if (!strncmp(path, buf2, len) && - path[len] == '/' && - len > max_len) - { - max_len = len; - } - } - - return max_len <= min_len ? min_len : max_len; -} - -static int read_gitfile(char *path_out, const char *file_path, const char *base_path) -{ - git_fbuffer file; - int error; - size_t end_offset; - char *data; - - assert(path_out && file_path && base_path); - - error = git_futils_readbuffer(&file, file_path); - - if (error < GIT_SUCCESS) - return error; - - data = (char*)(file.data); - - if (git__prefixcmp(data, GIT_FILE_CONTENT_PREFIX)) { - git_futils_freebuffer(&file); - return git__throw(GIT_ENOTFOUND, "Invalid gitfile format `%s`", file_path); - } - - end_offset = strlen(data) - 1; - - for (;data[end_offset] == '\r' || data[end_offset] == '\n'; --end_offset); - data[end_offset + 1] = '\0'; - - if (strlen(GIT_FILE_CONTENT_PREFIX) == end_offset + 1) { - git_futils_freebuffer(&file); - return git__throw(GIT_ENOTFOUND, "No path in git file `%s`", file_path); - } - - data = data + strlen(GIT_FILE_CONTENT_PREFIX); - error = git_path_prettify_dir(path_out, data, base_path); - git_futils_freebuffer(&file); - - if (error == 0 && git_futils_exists(path_out) == 0) - return GIT_SUCCESS; - - return git__throw(GIT_EOBJCORRUPTED, "The `.git` file points to an inexisting path"); -} - -static void git_repository__free_dirs(git_repository *repo) -{ - free(repo->path_workdir); - repo->path_workdir = NULL; - free(repo->path_index); - repo->path_index = NULL; - free(repo->path_repository); - repo->path_repository = NULL; - free(repo->path_odb); - repo->path_odb = NULL; -} - -void git_repository_free(git_repository *repo) -{ - if (repo == NULL) - return; - - git_cache_free(&repo->objects); - git_repository__refcache_free(&repo->references); - git_repository__free_dirs(repo); - - if (repo->db != NULL) - git_odb_close(repo->db); - - free(repo); -} - -int git_repository_discover(char *repository_path, size_t size, const char *start_path, int across_fs, const char *ceiling_dirs) -{ - int error, ceiling_offset; - char bare_path[GIT_PATH_MAX]; - char normal_path[GIT_PATH_MAX]; - char *found_path; - dev_t current_device = 0; - - assert(start_path && repository_path); - - error = git_path_prettify_dir(bare_path, start_path, NULL); - if (error < GIT_SUCCESS) - return error; - - if (!across_fs) { - error = retrieve_device(¤t_device, bare_path); - if (error < GIT_SUCCESS) - return error; - } - - ceiling_offset = retrieve_ceiling_directories_offset(bare_path, ceiling_dirs); - git_path_join(normal_path, bare_path, DOT_GIT); - - while(1) { - /** - * If the `.git` file is regular instead of - * a directory, it should contain the path of the actual git repository - */ - if (git_futils_isfile(normal_path) == GIT_SUCCESS) { - error = read_gitfile(repository_path, normal_path, bare_path); - - if (error < GIT_SUCCESS) - return git__rethrow(error, "Unable to read git file `%s`", normal_path); - - error = quickcheck_repository_dir(repository_path); - if (error < GIT_SUCCESS) - return git__throw(GIT_ENOTFOUND, "The `.git` file found at '%s' points" - "to an inexisting Git folder", normal_path); - - return GIT_SUCCESS; - } - - /** - * If the `.git` file is a folder, we check inside of it - */ - if (git_futils_isdir(normal_path) == GIT_SUCCESS) { - error = quickcheck_repository_dir(normal_path); - if (error == GIT_SUCCESS) { - found_path = normal_path; - break; - } - } - - /** - * Otherwise, the repository may be bare, let's check - * the root anyway - */ - error = quickcheck_repository_dir(bare_path); - if (error == GIT_SUCCESS) { - found_path = bare_path; - break; - } - - if (git_path_dirname_r(normal_path, sizeof(normal_path), bare_path) < GIT_SUCCESS) - return git__throw(GIT_EOSERR, "Failed to dirname '%s'", bare_path); - - if (!across_fs) { - dev_t new_device; - error = retrieve_device(&new_device, normal_path); - - if (error < GIT_SUCCESS || current_device != new_device) { - return git__throw(GIT_ENOTAREPO,"Not a git repository (or any parent up to mount parent %s)\n" - "Stopping at filesystem boundary.", bare_path); - } - current_device = new_device; - } - - strcpy(bare_path, normal_path); - git_path_join(normal_path, bare_path, DOT_GIT); - - // nothing has been found, lets try the parent directory - if (bare_path[ceiling_offset] == '\0') { - return git__throw(GIT_ENOTAREPO,"Not a git repository (or any of the parent directories): %s", start_path); - } - } - - if (size < (strlen(found_path) + 2) * sizeof(char)) { - return git__throw(GIT_EOVERFLOW, "The repository buffer is not long enough to handle the repository path `%s`", found_path); - } - - git_path_join(repository_path, found_path, ""); - return GIT_SUCCESS; -} - -git_odb *git_repository_database(git_repository *repo) -{ - assert(repo); - return repo->db; -} - -static int repo_init_reinit(const char *repository_path, int is_bare) -{ - /* TODO: reinit the repository */ - return git__throw(GIT_ENOTIMPLEMENTED, - "Failed to reinitialize the %srepository at '%s'. " - "This feature is not yet implemented", - is_bare ? "bare" : "", repository_path); -} - -static int repo_init_createhead(git_repository *repo) -{ - git_reference *head_reference; - return git_reference_create_symbolic(&head_reference, repo, GIT_HEAD_FILE, GIT_REFS_HEADS_MASTER_FILE, 0); -} - -static int repo_init_structure(const char *git_dir, int is_bare) -{ - const int mode = 0755; /* or 0777 ? */ - int error; - - char temp_path[GIT_PATH_MAX]; - - if (git_futils_mkdir_r(git_dir, mode)) - return git__throw(GIT_ERROR, "Failed to initialize repository structure. Could not mkdir"); - - /* Hides the ".git" directory */ - if (!is_bare) { -#ifdef GIT_WIN32 - error = p_hide_directory__w32(git_dir); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to initialize repository structure"); -#endif - } - - /* Creates the '/objects/info/' directory */ - git_path_join(temp_path, git_dir, GIT_OBJECTS_INFO_DIR); - error = git_futils_mkdir_r(temp_path, mode); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to initialize repository structure"); - - /* Creates the '/objects/pack/' directory */ - git_path_join(temp_path, git_dir, GIT_OBJECTS_PACK_DIR); - error = p_mkdir(temp_path, mode); - if (error < GIT_SUCCESS) - return git__throw(error, "Unable to create `%s` folder", temp_path); - - /* Creates the '/refs/heads/' directory */ - git_path_join(temp_path, git_dir, GIT_REFS_HEADS_DIR); - error = git_futils_mkdir_r(temp_path, mode); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to initialize repository structure"); - - /* Creates the '/refs/tags/' directory */ - git_path_join(temp_path, git_dir, GIT_REFS_TAGS_DIR); - error = p_mkdir(temp_path, mode); - if (error < GIT_SUCCESS) - return git__throw(error, "Unable to create `%s` folder", temp_path); - - /* TODO: what's left? templates? */ - - return GIT_SUCCESS; -} - -int git_repository_init(git_repository **repo_out, const char *path, unsigned is_bare) -{ - int error = GIT_SUCCESS; - git_repository *repo = NULL; - char repository_path[GIT_PATH_MAX]; - - assert(repo_out && path); - - git_path_join(repository_path, path, is_bare ? "" : GIT_DIR); - - if (git_futils_isdir(repository_path)) { - if (quickcheck_repository_dir(repository_path) == GIT_SUCCESS) - return repo_init_reinit(repository_path, is_bare); - } - - error = repo_init_structure(repository_path, is_bare); - if (error < GIT_SUCCESS) - goto cleanup; - - repo = repository_alloc(); - if (repo == NULL) { - error = GIT_ENOMEM; - goto cleanup; - } - - error = guess_repository_dirs(repo, repository_path); - if (error < GIT_SUCCESS) - goto cleanup; - - assert(repo->is_bare == is_bare); - - error = init_odb(repo); - if (error < GIT_SUCCESS) - goto cleanup; - - error = repo_init_createhead(repo); - if (error < GIT_SUCCESS) - goto cleanup; - - /* should never fail */ - assert(check_repository_dirs(repo) == GIT_SUCCESS); - - *repo_out = repo; - return GIT_SUCCESS; - -cleanup: - git_repository_free(repo); - return git__rethrow(error, "Failed to (re)init the repository `%s`", path); -} - -int git_repository_head_detached(git_repository *repo) -{ - git_reference *ref; - int error; - size_t GIT_UNUSED(_size); - git_otype type; - - error = git_reference_lookup(&ref, repo, GIT_HEAD_FILE); - if (error < GIT_SUCCESS) - return error; - - if (git_reference_type(ref) == GIT_REF_SYMBOLIC) - return 0; - - error = git_odb_read_header(&_size, &type, repo->db, git_reference_oid(ref)); - if (error < GIT_SUCCESS) - return error; - - if (type != GIT_OBJ_COMMIT) - return git__throw(GIT_EOBJCORRUPTED, "HEAD is not a commit"); - - return 1; -} - -int git_repository_head_orphan(git_repository *repo) -{ - git_reference *ref; - int error; - - error = git_reference_lookup(&ref, repo, GIT_HEAD_FILE); - if (error < GIT_SUCCESS) - return error; - - if (git_reference_type(ref) == GIT_REF_OID) - return 0; - - error = git_reference_resolve(&ref, ref); - - return error == GIT_ENOTFOUND ? 1 : error; -} - -int git_repository_is_empty(git_repository *repo) -{ - git_reference *head, *branch; - int error; - - error = git_reference_lookup(&head, repo, "HEAD"); - if (error < GIT_SUCCESS) - return git__throw(error, "Corrupted repository. HEAD does not exist"); - - if (git_reference_type(head) != GIT_REF_SYMBOLIC) - return 0; - - if (strcmp(git_reference_target(head), "refs/heads/master") != 0) - return 0; - - error = git_reference_resolve(&branch, head); - return error == GIT_ENOTFOUND ? 1 : error; -} - -const char *git_repository_path(git_repository *repo, git_repository_pathid id) -{ - assert(repo); - - switch (id) { - case GIT_REPO_PATH: - return repo->path_repository; - - case GIT_REPO_PATH_INDEX: - return repo->path_index; - - case GIT_REPO_PATH_ODB: - return repo->path_odb; - - case GIT_REPO_PATH_WORKDIR: - return repo->path_workdir; - - default: - return NULL; - } -} - -int git_repository_is_bare(git_repository *repo) -{ - assert(repo); - return repo->is_bare; -} diff --git a/vendor/libgit2/src/repository.h b/vendor/libgit2/src/repository.h deleted file mode 100644 index 2e0b9e352..000000000 --- a/vendor/libgit2/src/repository.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef INCLUDE_repository_h__ -#define INCLUDE_repository_h__ - -#include "git2/common.h" -#include "git2/oid.h" -#include "git2/odb.h" -#include "git2/repository.h" -#include "git2/object.h" - -#include "hashtable.h" -#include "index.h" -#include "cache.h" -#include "refs.h" -#include "buffer.h" - -#define DOT_GIT ".git" -#define GIT_DIR DOT_GIT "/" -#define GIT_OBJECTS_DIR "objects/" -#define GIT_INDEX_FILE "index" - -struct git_object { - git_cached_obj cached; - git_repository *repo; - git_otype type; -}; - -struct git_repository { - git_odb *db; - - git_cache objects; - git_refcache references; - - char *path_repository; - char *path_index; - char *path_odb; - char *path_workdir; - - unsigned is_bare:1; - unsigned int lru_counter; -}; - -/* fully free the object; internal method, do not - * export */ -void git_object__free(void *object); - -int git_oid__parse(git_oid *oid, const char **buffer_out, const char *buffer_end, const char *header); -void git_oid__writebuf(git_buf *buf, const char *header, const git_oid *oid); - -#endif diff --git a/vendor/libgit2/src/revwalk.c b/vendor/libgit2/src/revwalk.c deleted file mode 100644 index 538928cb1..000000000 --- a/vendor/libgit2/src/revwalk.c +++ /dev/null @@ -1,578 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "commit.h" -#include "odb.h" -#include "hashtable.h" -#include "pqueue.h" - -#include "git2/revwalk.h" - -typedef struct commit_object { - git_oid oid; - uint32_t time; - unsigned int seen:1, - uninteresting:1, - topo_delay:1, - parsed:1; - - unsigned short in_degree; - unsigned short out_degree; - - struct commit_object **parents; -} commit_object; - -typedef struct commit_list { - commit_object *item; - struct commit_list *next; -} commit_list; - -struct git_revwalk { - git_repository *repo; - - git_hashtable *commits; - - commit_list *iterator_topo; - commit_list *iterator_rand; - commit_list *iterator_reverse; - git_pqueue iterator_time; - - int (*get_next)(commit_object **, git_revwalk *); - int (*enqueue)(git_revwalk *, commit_object *); - - git_vector memory_alloc; - size_t chunk_size; - - unsigned walking:1; - unsigned int sorting; -}; - -commit_list *commit_list_insert(commit_object *item, commit_list **list_p) -{ - commit_list *new_list = git__malloc(sizeof(commit_list)); - new_list->item = item; - new_list->next = *list_p; - *list_p = new_list; - return new_list; -} - -void commit_list_free(commit_list **list_p) -{ - commit_list *list = *list_p; - - while (list) { - commit_list *temp = list; - list = temp->next; - free(temp); - } - - *list_p = NULL; -} - -commit_object *commit_list_pop(commit_list **stack) -{ - commit_list *top = *stack; - commit_object *item = top ? top->item : NULL; - - if (top) { - *stack = top->next; - free(top); - } - return item; -} - -static int commit_time_cmp(void *a, void *b) -{ - commit_object *commit_a = (commit_object *)a; - commit_object *commit_b = (commit_object *)b; - - return (commit_a->time < commit_b->time); -} - -static uint32_t object_table_hash(const void *key, int hash_id) -{ - uint32_t r; - const git_oid *id = key; - - memcpy(&r, id->id + (hash_id * sizeof(uint32_t)), sizeof(r)); - return r; -} - -#define COMMITS_PER_CHUNK 128 -#define CHUNK_STEP 64 -#define PARENTS_PER_COMMIT ((CHUNK_STEP - sizeof(commit_object)) / sizeof(commit_object *)) - -static int alloc_chunk(git_revwalk *walk) -{ - void *chunk; - - chunk = git__calloc(COMMITS_PER_CHUNK, CHUNK_STEP); - if (chunk == NULL) - return GIT_ENOMEM; - - walk->chunk_size = 0; - return git_vector_insert(&walk->memory_alloc, chunk); -} - -static commit_object *alloc_commit(git_revwalk *walk) -{ - unsigned char *chunk; - - if (walk->chunk_size == COMMITS_PER_CHUNK) - alloc_chunk(walk); - - chunk = git_vector_get(&walk->memory_alloc, walk->memory_alloc.length - 1); - chunk += (walk->chunk_size * CHUNK_STEP); - walk->chunk_size++; - - return (commit_object *)chunk; -} - -static commit_object **alloc_parents(commit_object *commit, size_t n_parents) -{ - if (n_parents <= PARENTS_PER_COMMIT) - return (commit_object **)((unsigned char *)commit + sizeof(commit_object)); - - return git__malloc(n_parents * sizeof(commit_object *)); -} - - -static commit_object *commit_lookup(git_revwalk *walk, const git_oid *oid) -{ - commit_object *commit; - - if ((commit = git_hashtable_lookup(walk->commits, oid)) != NULL) - return commit; - - commit = alloc_commit(walk); - if (commit == NULL) - return NULL; - - git_oid_cpy(&commit->oid, oid); - - if (git_hashtable_insert(walk->commits, &commit->oid, commit) < GIT_SUCCESS) { - free(commit); - return NULL; - } - - return commit; -} - -static int commit_quick_parse(git_revwalk *walk, commit_object *commit, git_rawobj *raw) -{ - const int parent_len = strlen("parent ") + GIT_OID_HEXSZ + 1; - - unsigned char *buffer = raw->data; - unsigned char *buffer_end = buffer + raw->len; - unsigned char *parents_start; - - int i, parents = 0; - long commit_time; - - buffer += strlen("tree ") + GIT_OID_HEXSZ + 1; - - parents_start = buffer; - while (buffer + parent_len < buffer_end && memcmp(buffer, "parent ", strlen("parent ")) == 0) { - parents++; - buffer += parent_len; - } - - commit->parents = alloc_parents(commit, parents); - if (commit->parents == NULL) - return GIT_ENOMEM; - - buffer = parents_start; - for (i = 0; i < parents; ++i) { - git_oid oid; - - if (git_oid_fromstr(&oid, (char *)buffer + strlen("parent ")) < GIT_SUCCESS) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse commit. Parent object is corrupted"); - - commit->parents[i] = commit_lookup(walk, &oid); - if (commit->parents[i] == NULL) - return GIT_ENOMEM; - - buffer += parent_len; - } - - commit->out_degree = (unsigned short)parents; - - if ((buffer = memchr(buffer, '\n', buffer_end - buffer)) == NULL) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse commit. Object is corrupted"); - - buffer = memchr(buffer, '>', buffer_end - buffer); - if (buffer == NULL) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse commit. Can't find author"); - - if (git__strtol32(&commit_time, (char *)buffer + 2, NULL, 10) < GIT_SUCCESS) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse commit. Can't parse commit time"); - - commit->time = (time_t)commit_time; - commit->parsed = 1; - return GIT_SUCCESS; -} - -static int commit_parse(git_revwalk *walk, commit_object *commit) -{ - git_odb_object *obj; - int error; - - if (commit->parsed) - return GIT_SUCCESS; - - if ((error = git_odb_read(&obj, walk->repo->db, &commit->oid)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to parse commit. Can't read object"); - - if (obj->raw.type != GIT_OBJ_COMMIT) { - git_odb_object_close(obj); - return git__throw(GIT_EOBJTYPE, "Failed to parse commit. Object is no commit object"); - } - - error = commit_quick_parse(walk, commit, &obj->raw); - git_odb_object_close(obj); - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to parse commit"); -} - -static void mark_uninteresting(commit_object *commit) -{ - unsigned short i; - assert(commit); - - commit->uninteresting = 1; - - for (i = 0; i < commit->out_degree; ++i) - if (!commit->parents[i]->uninteresting) - mark_uninteresting(commit->parents[i]); -} - -static int process_commit(git_revwalk *walk, commit_object *commit, int hide) -{ - int error; - - if (hide) - mark_uninteresting(commit); - - if (commit->seen) - return GIT_SUCCESS; - - commit->seen = 1; - - if ((error = commit_parse(walk, commit)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to process commit"); - - return walk->enqueue(walk, commit); -} - -static int process_commit_parents(git_revwalk *walk, commit_object *commit) -{ - unsigned short i; - int error = GIT_SUCCESS; - - for (i = 0; i < commit->out_degree && error == GIT_SUCCESS; ++i) { - error = process_commit(walk, commit->parents[i], commit->uninteresting); - } - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to process commit parents"); -} - -static int push_commit(git_revwalk *walk, const git_oid *oid, int uninteresting) -{ - commit_object *commit; - - commit = commit_lookup(walk, oid); - if (commit == NULL) - return git__throw(GIT_ENOTFOUND, "Failed to push commit. Object not found"); - - return process_commit(walk, commit, uninteresting); -} - -int git_revwalk_push(git_revwalk *walk, const git_oid *oid) -{ - assert(walk && oid); - return push_commit(walk, oid, 0); -} - -int git_revwalk_hide(git_revwalk *walk, const git_oid *oid) -{ - assert(walk && oid); - return push_commit(walk, oid, 1); -} - -static int revwalk_enqueue_timesort(git_revwalk *walk, commit_object *commit) -{ - return git_pqueue_insert(&walk->iterator_time, commit); -} - -static int revwalk_enqueue_unsorted(git_revwalk *walk, commit_object *commit) -{ - return commit_list_insert(commit, &walk->iterator_rand) ? GIT_SUCCESS : GIT_ENOMEM; -} - -static int revwalk_next_timesort(commit_object **object_out, git_revwalk *walk) -{ - int error; - commit_object *next; - - while ((next = git_pqueue_pop(&walk->iterator_time)) != NULL) { - if ((error = process_commit_parents(walk, next)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to load next revision"); - - if (!next->uninteresting) { - *object_out = next; - return GIT_SUCCESS; - } - } - - return git__throw(GIT_EREVWALKOVER, "Failed to load next revision"); -} - -static int revwalk_next_unsorted(commit_object **object_out, git_revwalk *walk) -{ - int error; - commit_object *next; - - while ((next = commit_list_pop(&walk->iterator_rand)) != NULL) { - if ((error = process_commit_parents(walk, next)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to load next revision"); - - if (!next->uninteresting) { - *object_out = next; - return GIT_SUCCESS; - } - } - - return git__throw(GIT_EREVWALKOVER, "Failed to load next revision"); -} - -static int revwalk_next_toposort(commit_object **object_out, git_revwalk *walk) -{ - commit_object *next; - unsigned short i; - - for (;;) { - next = commit_list_pop(&walk->iterator_topo); - if (next == NULL) - return git__throw(GIT_EREVWALKOVER, "Failed to load next revision"); - - if (next->in_degree > 0) { - next->topo_delay = 1; - continue; - } - - for (i = 0; i < next->out_degree; ++i) { - commit_object *parent = next->parents[i]; - - if (--parent->in_degree == 0 && parent->topo_delay) { - parent->topo_delay = 0; - commit_list_insert(parent, &walk->iterator_topo); - } - } - - *object_out = next; - return GIT_SUCCESS; - } -} - -static int revwalk_next_reverse(commit_object **object_out, git_revwalk *walk) -{ - *object_out = commit_list_pop(&walk->iterator_reverse); - return *object_out ? GIT_SUCCESS : GIT_EREVWALKOVER; -} - - -static int prepare_walk(git_revwalk *walk) -{ - int error; - commit_object *next; - - if (walk->sorting & GIT_SORT_TOPOLOGICAL) { - unsigned short i; - - while ((error = walk->get_next(&next, walk)) == GIT_SUCCESS) { - for (i = 0; i < next->out_degree; ++i) { - commit_object *parent = next->parents[i]; - parent->in_degree++; - } - - commit_list_insert(next, &walk->iterator_topo); - } - - if (error != GIT_EREVWALKOVER) - return git__rethrow(error, "Failed to prepare revision walk"); - - walk->get_next = &revwalk_next_toposort; - } - - if (walk->sorting & GIT_SORT_REVERSE) { - - while ((error = walk->get_next(&next, walk)) == GIT_SUCCESS) - commit_list_insert(next, &walk->iterator_reverse); - - if (error != GIT_EREVWALKOVER) - return git__rethrow(error, "Failed to prepare revision walk"); - - walk->get_next = &revwalk_next_reverse; - } - - walk->walking = 1; - return GIT_SUCCESS; -} - - - - - -int git_revwalk_new(git_revwalk **revwalk_out, git_repository *repo) -{ - git_revwalk *walk; - - walk = git__malloc(sizeof(git_revwalk)); - if (walk == NULL) - return GIT_ENOMEM; - - memset(walk, 0x0, sizeof(git_revwalk)); - - walk->commits = git_hashtable_alloc(64, - object_table_hash, - (git_hash_keyeq_ptr)git_oid_cmp); - - if (walk->commits == NULL) { - free(walk); - return GIT_ENOMEM; - } - - git_pqueue_init(&walk->iterator_time, 8, commit_time_cmp); - git_vector_init(&walk->memory_alloc, 8, NULL); - alloc_chunk(walk); - - walk->get_next = &revwalk_next_unsorted; - walk->enqueue = &revwalk_enqueue_unsorted; - - walk->repo = repo; - - *revwalk_out = walk; - return GIT_SUCCESS; -} - -void git_revwalk_free(git_revwalk *walk) -{ - unsigned int i; - const void *GIT_UNUSED(_unused); - commit_object *commit; - - if (walk == NULL) - return; - - git_revwalk_reset(walk); - - /* if the parent has more than PARENTS_PER_COMMIT parents, - * we had to allocate a separate array for those parents. - * make sure it's being free'd */ - GIT_HASHTABLE_FOREACH(walk->commits, _unused, commit, { - if (commit->out_degree > PARENTS_PER_COMMIT) - free(commit->parents); - }); - - git_hashtable_free(walk->commits); - git_pqueue_free(&walk->iterator_time); - - for (i = 0; i < walk->memory_alloc.length; ++i) - free(git_vector_get(&walk->memory_alloc, i)); - - git_vector_free(&walk->memory_alloc); - free(walk); -} - -git_repository *git_revwalk_repository(git_revwalk *walk) -{ - assert(walk); - return walk->repo; -} - -void git_revwalk_sorting(git_revwalk *walk, unsigned int sort_mode) -{ - assert(walk); - - if (walk->walking) - git_revwalk_reset(walk); - - walk->sorting = sort_mode; - - if (walk->sorting & GIT_SORT_TIME) { - walk->get_next = &revwalk_next_timesort; - walk->enqueue = &revwalk_enqueue_timesort; - } else { - walk->get_next = &revwalk_next_unsorted; - walk->enqueue = &revwalk_enqueue_unsorted; - } -} - -int git_revwalk_next(git_oid *oid, git_revwalk *walk) -{ - int error; - commit_object *next; - - assert(walk && oid); - - if (!walk->walking) { - if ((error = prepare_walk(walk)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to load next revision"); - } - - error = walk->get_next(&next, walk); - - if (error == GIT_EREVWALKOVER) { - git_revwalk_reset(walk); - return GIT_EREVWALKOVER; - } - - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to load next revision"); - - git_oid_cpy(oid, &next->oid); - return GIT_SUCCESS; -} - -void git_revwalk_reset(git_revwalk *walk) -{ - const void *GIT_UNUSED(_unused); - commit_object *commit; - - assert(walk); - - GIT_HASHTABLE_FOREACH(walk->commits, _unused, commit, - commit->seen = 0; - commit->in_degree = 0; - commit->topo_delay = 0; - ); - - git_pqueue_clear(&walk->iterator_time); - commit_list_free(&walk->iterator_topo); - commit_list_free(&walk->iterator_rand); - commit_list_free(&walk->iterator_reverse); - walk->walking = 0; -} - diff --git a/vendor/libgit2/src/sha1.c b/vendor/libgit2/src/sha1.c deleted file mode 100644 index 0bccb4953..000000000 --- a/vendor/libgit2/src/sha1.c +++ /dev/null @@ -1,281 +0,0 @@ -/* - * SHA1 routine optimized to do word accesses rather than byte accesses, - * and to avoid unnecessary copies into the context array. - * - * This was initially based on the Mozilla SHA1 implementation, although - * none of the original Mozilla code remains. - */ - -#include "common.h" -#include "sha1.h" - -#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) - -/* - * Force usage of rol or ror by selecting the one with the smaller constant. - * It _can_ generate slightly smaller code (a constant of 1 is special), but - * perhaps more importantly it's possibly faster on any uarch that does a - * rotate with a loop. - */ - -#define SHA_ASM(op, x, n) ({ unsigned int __res; __asm__(op " %1,%0":"=r" (__res):"i" (n), "0" (x)); __res; }) -#define SHA_ROL(x,n) SHA_ASM("rol", x, n) -#define SHA_ROR(x,n) SHA_ASM("ror", x, n) - -#else - -#define SHA_ROT(X,l,r) (((X) << (l)) | ((X) >> (r))) -#define SHA_ROL(X,n) SHA_ROT(X,n,32-(n)) -#define SHA_ROR(X,n) SHA_ROT(X,32-(n),n) - -#endif - -/* - * If you have 32 registers or more, the compiler can (and should) - * try to change the array[] accesses into registers. However, on - * machines with less than ~25 registers, that won't really work, - * and at least gcc will make an unholy mess of it. - * - * So to avoid that mess which just slows things down, we force - * the stores to memory to actually happen (we might be better off - * with a 'W(t)=(val);asm("":"+m" (W(t))' there instead, as - * suggested by Artur Skawina - that will also make gcc unable to - * try to do the silly "optimize away loads" part because it won't - * see what the value will be). - * - * Ben Herrenschmidt reports that on PPC, the C version comes close - * to the optimized asm with this (ie on PPC you don't want that - * 'volatile', since there are lots of registers). - * - * On ARM we get the best code generation by forcing a full memory barrier - * between each SHA_ROUND, otherwise gcc happily get wild with spilling and - * the stack frame size simply explode and performance goes down the drain. - */ - -#if defined(__i386__) || defined(__x86_64__) - #define setW(x, val) (*(volatile unsigned int *)&W(x) = (val)) -#elif defined(__GNUC__) && defined(__arm__) - #define setW(x, val) do { W(x) = (val); __asm__("":::"memory"); } while (0) -#else - #define setW(x, val) (W(x) = (val)) -#endif - -/* - * Performance might be improved if the CPU architecture is OK with - * unaligned 32-bit loads and a fast ntohl() is available. - * Otherwise fall back to byte loads and shifts which is portable, - * and is faster on architectures with memory alignment issues. - */ - -#if defined(__i386__) || defined(__x86_64__) || \ - defined(_M_IX86) || defined(_M_X64) || \ - defined(__ppc__) || defined(__ppc64__) || \ - defined(__powerpc__) || defined(__powerpc64__) || \ - defined(__s390__) || defined(__s390x__) - -#define get_be32(p) ntohl(*(const unsigned int *)(p)) -#define put_be32(p, v) do { *(unsigned int *)(p) = htonl(v); } while (0) - -#else - -#define get_be32(p) ( \ - (*((const unsigned char *)(p) + 0) << 24) | \ - (*((const unsigned char *)(p) + 1) << 16) | \ - (*((const unsigned char *)(p) + 2) << 8) | \ - (*((const unsigned char *)(p) + 3) << 0) ) -#define put_be32(p, v) do { \ - unsigned int __v = (v); \ - *((unsigned char *)(p) + 0) = __v >> 24; \ - *((unsigned char *)(p) + 1) = __v >> 16; \ - *((unsigned char *)(p) + 2) = __v >> 8; \ - *((unsigned char *)(p) + 3) = __v >> 0; } while (0) - -#endif - -/* This "rolls" over the 512-bit array */ -#define W(x) (array[(x)&15]) - -/* - * Where do we get the source from? The first 16 iterations get it from - * the input data, the next mix it from the 512-bit array. - */ -#define SHA_SRC(t) get_be32(data + t) -#define SHA_MIX(t) SHA_ROL(W(t+13) ^ W(t+8) ^ W(t+2) ^ W(t), 1) - -#define SHA_ROUND(t, input, fn, constant, A, B, C, D, E) do { \ - unsigned int TEMP = input(t); setW(t, TEMP); \ - E += TEMP + SHA_ROL(A,5) + (fn) + (constant); \ - B = SHA_ROR(B, 2); } while (0) - -#define T_0_15(t, A, B, C, D, E) SHA_ROUND(t, SHA_SRC, (((C^D)&B)^D) , 0x5a827999, A, B, C, D, E ) -#define T_16_19(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (((C^D)&B)^D) , 0x5a827999, A, B, C, D, E ) -#define T_20_39(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (B^C^D) , 0x6ed9eba1, A, B, C, D, E ) -#define T_40_59(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, ((B&C)+(D&(B^C))) , 0x8f1bbcdc, A, B, C, D, E ) -#define T_60_79(t, A, B, C, D, E) SHA_ROUND(t, SHA_MIX, (B^C^D) , 0xca62c1d6, A, B, C, D, E ) - -static void blk_SHA1_Block(blk_SHA_CTX *ctx, const unsigned int *data) -{ - unsigned int A,B,C,D,E; - unsigned int array[16]; - - A = ctx->H[0]; - B = ctx->H[1]; - C = ctx->H[2]; - D = ctx->H[3]; - E = ctx->H[4]; - - /* Round 1 - iterations 0-16 take their input from 'data' */ - T_0_15( 0, A, B, C, D, E); - T_0_15( 1, E, A, B, C, D); - T_0_15( 2, D, E, A, B, C); - T_0_15( 3, C, D, E, A, B); - T_0_15( 4, B, C, D, E, A); - T_0_15( 5, A, B, C, D, E); - T_0_15( 6, E, A, B, C, D); - T_0_15( 7, D, E, A, B, C); - T_0_15( 8, C, D, E, A, B); - T_0_15( 9, B, C, D, E, A); - T_0_15(10, A, B, C, D, E); - T_0_15(11, E, A, B, C, D); - T_0_15(12, D, E, A, B, C); - T_0_15(13, C, D, E, A, B); - T_0_15(14, B, C, D, E, A); - T_0_15(15, A, B, C, D, E); - - /* Round 1 - tail. Input from 512-bit mixing array */ - T_16_19(16, E, A, B, C, D); - T_16_19(17, D, E, A, B, C); - T_16_19(18, C, D, E, A, B); - T_16_19(19, B, C, D, E, A); - - /* Round 2 */ - T_20_39(20, A, B, C, D, E); - T_20_39(21, E, A, B, C, D); - T_20_39(22, D, E, A, B, C); - T_20_39(23, C, D, E, A, B); - T_20_39(24, B, C, D, E, A); - T_20_39(25, A, B, C, D, E); - T_20_39(26, E, A, B, C, D); - T_20_39(27, D, E, A, B, C); - T_20_39(28, C, D, E, A, B); - T_20_39(29, B, C, D, E, A); - T_20_39(30, A, B, C, D, E); - T_20_39(31, E, A, B, C, D); - T_20_39(32, D, E, A, B, C); - T_20_39(33, C, D, E, A, B); - T_20_39(34, B, C, D, E, A); - T_20_39(35, A, B, C, D, E); - T_20_39(36, E, A, B, C, D); - T_20_39(37, D, E, A, B, C); - T_20_39(38, C, D, E, A, B); - T_20_39(39, B, C, D, E, A); - - /* Round 3 */ - T_40_59(40, A, B, C, D, E); - T_40_59(41, E, A, B, C, D); - T_40_59(42, D, E, A, B, C); - T_40_59(43, C, D, E, A, B); - T_40_59(44, B, C, D, E, A); - T_40_59(45, A, B, C, D, E); - T_40_59(46, E, A, B, C, D); - T_40_59(47, D, E, A, B, C); - T_40_59(48, C, D, E, A, B); - T_40_59(49, B, C, D, E, A); - T_40_59(50, A, B, C, D, E); - T_40_59(51, E, A, B, C, D); - T_40_59(52, D, E, A, B, C); - T_40_59(53, C, D, E, A, B); - T_40_59(54, B, C, D, E, A); - T_40_59(55, A, B, C, D, E); - T_40_59(56, E, A, B, C, D); - T_40_59(57, D, E, A, B, C); - T_40_59(58, C, D, E, A, B); - T_40_59(59, B, C, D, E, A); - - /* Round 4 */ - T_60_79(60, A, B, C, D, E); - T_60_79(61, E, A, B, C, D); - T_60_79(62, D, E, A, B, C); - T_60_79(63, C, D, E, A, B); - T_60_79(64, B, C, D, E, A); - T_60_79(65, A, B, C, D, E); - T_60_79(66, E, A, B, C, D); - T_60_79(67, D, E, A, B, C); - T_60_79(68, C, D, E, A, B); - T_60_79(69, B, C, D, E, A); - T_60_79(70, A, B, C, D, E); - T_60_79(71, E, A, B, C, D); - T_60_79(72, D, E, A, B, C); - T_60_79(73, C, D, E, A, B); - T_60_79(74, B, C, D, E, A); - T_60_79(75, A, B, C, D, E); - T_60_79(76, E, A, B, C, D); - T_60_79(77, D, E, A, B, C); - T_60_79(78, C, D, E, A, B); - T_60_79(79, B, C, D, E, A); - - ctx->H[0] += A; - ctx->H[1] += B; - ctx->H[2] += C; - ctx->H[3] += D; - ctx->H[4] += E; -} - -void git__blk_SHA1_Init(blk_SHA_CTX *ctx) -{ - ctx->size = 0; - - /* Initialize H with the magic constants (see FIPS180 for constants) */ - ctx->H[0] = 0x67452301; - ctx->H[1] = 0xefcdab89; - ctx->H[2] = 0x98badcfe; - ctx->H[3] = 0x10325476; - ctx->H[4] = 0xc3d2e1f0; -} - -void git__blk_SHA1_Update(blk_SHA_CTX *ctx, const void *data, unsigned long len) -{ - unsigned int lenW = ctx->size & 63; - - ctx->size += len; - - /* Read the data into W and process blocks as they get full */ - if (lenW) { - unsigned int left = 64 - lenW; - if (len < left) - left = len; - memcpy(lenW + (char *)ctx->W, data, left); - lenW = (lenW + left) & 63; - len -= left; - data = ((const char *)data + left); - if (lenW) - return; - blk_SHA1_Block(ctx, ctx->W); - } - while (len >= 64) { - blk_SHA1_Block(ctx, data); - data = ((const char *)data + 64); - len -= 64; - } - if (len) - memcpy(ctx->W, data, len); -} - -void git__blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx) -{ - static const unsigned char pad[64] = { 0x80 }; - unsigned int padlen[2]; - int i; - - /* Pad with a binary 1 (ie 0x80), then zeroes, then length */ - padlen[0] = htonl((uint32_t)(ctx->size >> 29)); - padlen[1] = htonl((uint32_t)(ctx->size << 3)); - - i = ctx->size & 63; - git__blk_SHA1_Update(ctx, pad, 1+ (63 & (55 - i))); - git__blk_SHA1_Update(ctx, padlen, 8); - - /* Output hash */ - for (i = 0; i < 5; i++) - put_be32(hashout + i*4, ctx->H[i]); -} diff --git a/vendor/libgit2/src/sha1.h b/vendor/libgit2/src/sha1.h deleted file mode 100644 index 558d6aece..000000000 --- a/vendor/libgit2/src/sha1.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * SHA1 routine optimized to do word accesses rather than byte accesses, - * and to avoid unnecessary copies into the context array. - * - * This was initially based on the Mozilla SHA1 implementation, although - * none of the original Mozilla code remains. - */ - -typedef struct { - unsigned long long size; - unsigned int H[5]; - unsigned int W[16]; -} blk_SHA_CTX; - -void git__blk_SHA1_Init(blk_SHA_CTX *ctx); -void git__blk_SHA1_Update(blk_SHA_CTX *ctx, const void *dataIn, unsigned long len); -void git__blk_SHA1_Final(unsigned char hashout[20], blk_SHA_CTX *ctx); - -#define SHA_CTX blk_SHA_CTX -#define SHA1_Init git__blk_SHA1_Init -#define SHA1_Update git__blk_SHA1_Update -#define SHA1_Final git__blk_SHA1_Final diff --git a/vendor/libgit2/src/sha1_lookup.c b/vendor/libgit2/src/sha1_lookup.c deleted file mode 100644 index 6ac00c5aa..000000000 --- a/vendor/libgit2/src/sha1_lookup.c +++ /dev/null @@ -1,196 +0,0 @@ -/* - * This file is basically taken from git code. - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include - -#include "sha1_lookup.h" -#include "common.h" - -/* - * Conventional binary search loop looks like this: - * - * unsigned lo, hi; - * do { - * unsigned mi = (lo + hi) / 2; - * int cmp = "entry pointed at by mi" minus "target"; - * if (!cmp) - * return (mi is the wanted one) - * if (cmp > 0) - * hi = mi; "mi is larger than target" - * else - * lo = mi+1; "mi is smaller than target" - * } while (lo < hi); - * - * The invariants are: - * - * - When entering the loop, lo points at a slot that is never - * above the target (it could be at the target), hi points at a - * slot that is guaranteed to be above the target (it can never - * be at the target). - * - * - We find a point 'mi' between lo and hi (mi could be the same - * as lo, but never can be as same as hi), and check if it hits - * the target. There are three cases: - * - * - if it is a hit, we are happy. - * - * - if it is strictly higher than the target, we set it to hi, - * and repeat the search. - * - * - if it is strictly lower than the target, we update lo to - * one slot after it, because we allow lo to be at the target. - * - * If the loop exits, there is no matching entry. - * - * When choosing 'mi', we do not have to take the "middle" but - * anywhere in between lo and hi, as long as lo <= mi < hi is - * satisfied. When we somehow know that the distance between the - * target and lo is much shorter than the target and hi, we could - * pick mi that is much closer to lo than the midway. - * - * Now, we can take advantage of the fact that SHA-1 is a good hash - * function, and as long as there are enough entries in the table, we - * can expect uniform distribution. An entry that begins with for - * example "deadbeef..." is much likely to appear much later than in - * the midway of the table. It can reasonably be expected to be near - * 87% (222/256) from the top of the table. - * - * However, we do not want to pick "mi" too precisely. If the entry at - * the 87% in the above example turns out to be higher than the target - * we are looking for, we would end up narrowing the search space down - * only by 13%, instead of 50% we would get if we did a simple binary - * search. So we would want to hedge our bets by being less aggressive. - * - * The table at "table" holds at least "nr" entries of "elem_size" - * bytes each. Each entry has the SHA-1 key at "key_offset". The - * table is sorted by the SHA-1 key of the entries. The caller wants - * to find the entry with "key", and knows that the entry at "lo" is - * not higher than the entry it is looking for, and that the entry at - * "hi" is higher than the entry it is looking for. - */ -int sha1_entry_pos(const void *table, - size_t elem_size, - size_t key_offset, - unsigned lo, unsigned hi, unsigned nr, - const unsigned char *key) -{ - const unsigned char *base = (const unsigned char*)table; - const unsigned char *hi_key, *lo_key; - unsigned ofs_0; - - if (!nr || lo >= hi) - return -1; - - if (nr == hi) - hi_key = NULL; - else - hi_key = base + elem_size * hi + key_offset; - lo_key = base + elem_size * lo + key_offset; - - ofs_0 = 0; - do { - int cmp; - unsigned ofs, mi, range; - unsigned lov, hiv, kyv; - const unsigned char *mi_key; - - range = hi - lo; - if (hi_key) { - for (ofs = ofs_0; ofs < 20; ofs++) - if (lo_key[ofs] != hi_key[ofs]) - break; - ofs_0 = ofs; - /* - * byte 0 thru (ofs-1) are the same between - * lo and hi; ofs is the first byte that is - * different. - */ - hiv = hi_key[ofs_0]; - if (ofs_0 < 19) - hiv = (hiv << 8) | hi_key[ofs_0+1]; - } else { - hiv = 256; - if (ofs_0 < 19) - hiv <<= 8; - } - lov = lo_key[ofs_0]; - kyv = key[ofs_0]; - if (ofs_0 < 19) { - lov = (lov << 8) | lo_key[ofs_0+1]; - kyv = (kyv << 8) | key[ofs_0+1]; - } - assert(lov < hiv); - - if (kyv < lov) - return -1 - lo; - if (hiv < kyv) - return -1 - hi; - - /* - * Even if we know the target is much closer to 'hi' - * than 'lo', if we pick too precisely and overshoot - * (e.g. when we know 'mi' is closer to 'hi' than to - * 'lo', pick 'mi' that is higher than the target), we - * end up narrowing the search space by a smaller - * amount (i.e. the distance between 'mi' and 'hi') - * than what we would have (i.e. about half of 'lo' - * and 'hi'). Hedge our bets to pick 'mi' less - * aggressively, i.e. make 'mi' a bit closer to the - * middle than we would otherwise pick. - */ - kyv = (kyv * 6 + lov + hiv) / 8; - if (lov < hiv - 1) { - if (kyv == lov) - kyv++; - else if (kyv == hiv) - kyv--; - } - mi = (range - 1) * (kyv - lov) / (hiv - lov) + lo; - -#ifdef INDEX_DEBUG_LOOKUP - printf("lo %u hi %u rg %u mi %u ", lo, hi, range, mi); - printf("ofs %u lov %x, hiv %x, kyv %x\n", - ofs_0, lov, hiv, kyv); -#endif - - if (!(lo <= mi && mi < hi)) { - return git__throw(GIT_ERROR, "Assertion failure. Binary search invariant is false"); - } - - mi_key = base + elem_size * mi + key_offset; - cmp = memcmp(mi_key + ofs_0, key + ofs_0, 20 - ofs_0); - if (!cmp) - return mi; - if (cmp > 0) { - hi = mi; - hi_key = mi_key; - } else { - lo = mi + 1; - lo_key = mi_key + elem_size; - } - } while (lo < hi); - return -((int)lo)-1; -} diff --git a/vendor/libgit2/src/sha1_lookup.h b/vendor/libgit2/src/sha1_lookup.h deleted file mode 100644 index 5caa2f5ed..000000000 --- a/vendor/libgit2/src/sha1_lookup.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef INCLUDE_sha1_lookup_h__ -#define INCLUDE_sha1_lookup_h__ - -#include - -int sha1_entry_pos(const void *table, - size_t elem_size, - size_t key_offset, - unsigned lo, unsigned hi, unsigned nr, - const unsigned char *key); - -#endif diff --git a/vendor/libgit2/src/signature.c b/vendor/libgit2/src/signature.c deleted file mode 100644 index 327efe247..000000000 --- a/vendor/libgit2/src/signature.c +++ /dev/null @@ -1,353 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "signature.h" -#include "repository.h" -#include "git2/common.h" - -void git_signature_free(git_signature *sig) -{ - if (sig == NULL) - return; - - free(sig->name); - free(sig->email); - free(sig); -} - -static const char *skip_leading_spaces(const char *buffer, const char *buffer_end) -{ - while (*buffer == ' ' && buffer < buffer_end) - buffer++; - - return buffer; -} - -static const char *skip_trailing_spaces(const char *buffer_start, const char *buffer_end) -{ - while (*buffer_end == ' ' && buffer_end > buffer_start) - buffer_end--; - - return buffer_end; -} - -static int process_trimming(const char *input, char **storage, const char *input_end, int fail_when_empty) -{ - const char *left, *right; - int trimmed_input_length; - - left = skip_leading_spaces(input, input_end); - right = skip_trailing_spaces(input, input_end - 1); - - if (right < left) { - if (fail_when_empty) - return git__throw(GIT_EINVALIDARGS, "Failed to trim. Input is either empty or only contains spaces"); - else - right = left - 1; - } - - trimmed_input_length = right - left + 1; - - *storage = git__malloc(trimmed_input_length + 1); - if (*storage == NULL) - return GIT_ENOMEM; - - memcpy(*storage, left, trimmed_input_length); - (*storage)[trimmed_input_length] = 0; - - return GIT_SUCCESS; -} - -int git_signature_new(git_signature **sig_out, const char *name, const char *email, git_time_t time, int offset) -{ - int error; - git_signature *p = NULL; - - assert(name && email); - - *sig_out = NULL; - - if ((p = git__malloc(sizeof(git_signature))) == NULL) { - error = GIT_ENOMEM; - goto cleanup; - } - - memset(p, 0x0, sizeof(git_signature)); - - error = process_trimming(name, &p->name, name + strlen(name), 1); - if (error < GIT_SUCCESS) { - git__rethrow(GIT_EINVALIDARGS, "Failed to create signature. 'name' argument is invalid"); - goto cleanup; - } - - error = process_trimming(email, &p->email, email + strlen(email), 1); - if (error < GIT_SUCCESS) { - git__rethrow(GIT_EINVALIDARGS, "Failed to create signature. 'email' argument is invalid"); - goto cleanup; - } - - p->when.time = time; - p->when.offset = offset; - - *sig_out = p; - - return error; - -cleanup: - git_signature_free(p); - return error; -} - -git_signature *git_signature_dup(const git_signature *sig) -{ - git_signature *new; - if (git_signature_new(&new, sig->name, sig->email, sig->when.time, sig->when.offset) < GIT_SUCCESS) - return NULL; - return new; -} - -int git_signature_now(git_signature **sig_out, const char *name, const char *email) -{ - int error; - time_t now; - time_t offset; - struct tm *utc_tm, *local_tm; - git_signature *sig; - -#ifndef GIT_WIN32 - struct tm _utc, _local; -#endif - - *sig_out = NULL; - - time(&now); - - /** - * On Win32, `gmtime_r` doesn't exist but - * `gmtime` is threadsafe, so we can use that - */ -#ifdef GIT_WIN32 - utc_tm = gmtime(&now); - local_tm = localtime(&now); -#else - utc_tm = gmtime_r(&now, &_utc); - local_tm = localtime_r(&now, &_local); -#endif - - offset = mktime(local_tm) - mktime(utc_tm); - offset /= 60; - - /* mktime takes care of setting tm_isdst correctly */ - if (local_tm->tm_isdst) - offset += 60; - - if ((error = git_signature_new(&sig, name, email, now, (int)offset)) < GIT_SUCCESS) - return error; - - *sig_out = sig; - - return error; -} - -static int parse_timezone_offset(const char *buffer, int *offset_out) -{ - long dec_offset; - int mins, hours, offset; - - const char *offset_start; - const char *offset_end; - - offset_start = buffer; - - if (*offset_start == '\n') { - *offset_out = 0; - return GIT_SUCCESS; - } - - if (offset_start[0] != '-' && offset_start[0] != '+') - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset. It doesn't start with '+' or '-'"); - - if (offset_start[1] < '0' || offset_start[1] > '9') - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset."); - - if (git__strtol32(&dec_offset, offset_start + 1, &offset_end, 10) < GIT_SUCCESS) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset. It isn't a number"); - - if (offset_end - offset_start != 5) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset. Invalid length"); - - if (dec_offset > 1400) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset. Value too large"); - - hours = dec_offset / 100; - mins = dec_offset % 100; - - if (hours > 14) // see http://www.worldtimezone.com/faq.html - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset. Hour value too large"); - - if (mins > 59) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse TZ offset. Minute value too large"); - - offset = (hours * 60) + mins; - - if (offset_start[0] == '-') - offset *= -1; - - *offset_out = offset; - - return GIT_SUCCESS; -} - -int process_next_token(const char **buffer_out, char **storage, - const char *token_end, const char *right_boundary) -{ - int error = process_trimming(*buffer_out, storage, token_end, 0); - if (error < GIT_SUCCESS) - return error; - - *buffer_out = token_end + 1; - - if (*buffer_out > right_boundary) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Signature too short"); - - return GIT_SUCCESS; -} - -const char *scan_for_previous_token(const char *buffer, const char *left_boundary) -{ - const char *start; - - if (buffer <= left_boundary) - return NULL; - - start = skip_trailing_spaces(left_boundary, buffer); - - /* Search for previous occurence of space */ - while (start[-1] != ' ' && start > left_boundary) - start--; - - return start; -} - -int parse_time(git_time_t *time_out, const char *buffer) -{ - long time; - int error; - - if (*buffer == '+' || *buffer == '-') - return git__throw(GIT_ERROR, "Failed while parsing time. '%s' rather look like a timezone offset.", buffer); - - error = git__strtol32(&time, buffer, &buffer, 10); - - if (error < GIT_SUCCESS) - return error; - - *time_out = (git_time_t)time; - - return GIT_SUCCESS; -} - -int git_signature__parse(git_signature *sig, const char **buffer_out, - const char *buffer_end, const char *header, char ender) -{ - const char *buffer = *buffer_out; - const char *line_end, *name_end, *email_end, *tz_start, *time_start; - int error = GIT_SUCCESS; - - memset(sig, 0x0, sizeof(git_signature)); - - if ((line_end = memchr(buffer, ender, buffer_end - buffer)) == NULL) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. No newline given"); - - if (header) { - const size_t header_len = strlen(header); - - if (memcmp(buffer, header, header_len) != 0) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Expected prefix '%s' doesn't match actual", header); - - buffer += header_len; - } - - if (buffer > line_end) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Signature too short"); - - if ((name_end = strchr(buffer, '<')) == NULL) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Cannot find '<' in signature"); - - if ((email_end = strchr(buffer, '>')) == NULL) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Cannot find '>' in signature"); - - if (email_end < name_end) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse signature. Malformed e-mail"); - - error = process_next_token(&buffer, &sig->name, name_end, line_end); - if (error < GIT_SUCCESS) - return error; - - error = process_next_token(&buffer, &sig->email, email_end, line_end); - if (error < GIT_SUCCESS) - return error; - - tz_start = scan_for_previous_token(line_end - 1, buffer); - - if (tz_start == NULL) - goto clean_exit; /* No timezone nor date */ - - time_start = scan_for_previous_token(tz_start - 1, buffer); - if (time_start == NULL || parse_time(&sig->when.time, time_start) < GIT_SUCCESS) { - /* The tz_start might point at the time */ - parse_time(&sig->when.time, tz_start); - goto clean_exit; - } - - if (parse_timezone_offset(tz_start, &sig->when.offset) < GIT_SUCCESS) { - sig->when.time = 0; /* Bogus timezone, we reset the time */ - } - -clean_exit: - *buffer_out = line_end + 1; - return GIT_SUCCESS; -} - -void git_signature__writebuf(git_buf *buf, const char *header, const git_signature *sig) -{ - int offset, hours, mins; - char sign; - - offset = sig->when.offset; - sign = (sig->when.offset < 0) ? '-' : '+'; - - if (offset < 0) - offset = -offset; - - hours = offset / 60; - mins = offset % 60; - - git_buf_printf(buf, "%s%s <%s> %u %c%02d%02d\n", - header ? header : "", sig->name, sig->email, - (unsigned)sig->when.time, sign, hours, mins); -} - diff --git a/vendor/libgit2/src/signature.h b/vendor/libgit2/src/signature.h deleted file mode 100644 index 2fe6cd7c9..000000000 --- a/vendor/libgit2/src/signature.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef INCLUDE_signature_h__ -#define INCLUDE_signature_h__ - -#include "git2/common.h" -#include "git2/signature.h" -#include "repository.h" -#include - -int git_signature__parse(git_signature *sig, const char **buffer_out, const char *buffer_end, const char *header, char ender); -void git_signature__writebuf(git_buf *buf, const char *header, const git_signature *sig); - -#endif diff --git a/vendor/libgit2/src/status.c b/vendor/libgit2/src/status.c deleted file mode 100644 index d9613c129..000000000 --- a/vendor/libgit2/src/status.c +++ /dev/null @@ -1,361 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "git2.h" -#include "fileops.h" -#include "hash.h" -#include "vector.h" -#include "tree.h" -#include "git2/status.h" - -struct status_entry { - char path[GIT_PATH_MAX]; - - git_index_time mtime; - - git_oid head_oid; - git_oid index_oid; - git_oid wt_oid; - - unsigned int status_flags:6; -}; - -static int status_cmp(const void *a, const void *b) -{ - const struct status_entry *entry_a = (const struct status_entry *)(a); - const struct status_entry *entry_b = (const struct status_entry *)(b); - - return strcmp(entry_a->path, entry_b->path); -} - -static int status_srch(const void *key, const void *array_member) -{ - const char *path = (const char *)key; - const struct status_entry *entry = (const struct status_entry *)(array_member); - - return strcmp(path, entry->path); -} - -static int find_status_entry(git_vector *entries, const char *path) -{ - return git_vector_bsearch2(entries, status_srch, path); -} - -static struct status_entry *new_status_entry(git_vector *entries, const char *path) -{ - struct status_entry *e = git__malloc(sizeof(struct status_entry)); - memset(e, 0x0, sizeof(struct status_entry)); - if (entries != NULL) - git_vector_insert(entries, e); - strcpy(e->path, path); - return e; -} - -static void recurse_tree_entries(git_tree *tree, git_vector *entries, char *path) -{ - int i, cnt, idx; - struct status_entry *e; - char file_path[GIT_PATH_MAX]; - git_tree *subtree; - - cnt = git_tree_entrycount(tree); - for (i = 0; i < cnt; ++i) { - const git_tree_entry *tree_entry = git_tree_entry_byindex(tree, i); - - git_path_join(file_path, path, tree_entry->filename); - - if (git_tree_lookup(&subtree, tree->object.repo, &tree_entry->oid) == GIT_SUCCESS) { - recurse_tree_entries(subtree, entries, file_path); - git_tree_close(subtree); - continue; - } - - if ((idx = find_status_entry(entries, file_path)) != GIT_ENOTFOUND) - e = (struct status_entry *)git_vector_get(entries, idx); - else - e = new_status_entry(entries, file_path); - - git_oid_cpy(&e->head_oid, &tree_entry->oid); - } -} - -static void recurse_tree_entry(git_tree *tree, struct status_entry *e, const char *path) -{ - char *dir_sep; - char buffer[GIT_PATH_MAX]; - const git_tree_entry *tree_entry; - git_tree *subtree; - - strcpy(buffer, path); - - dir_sep = strchr(buffer, '/'); - if (dir_sep) { - *dir_sep = '\0'; - - tree_entry = git_tree_entry_byname(tree, buffer); - if (tree_entry != NULL) { - if (git_tree_lookup(&subtree, tree->object.repo, &tree_entry->oid) == GIT_SUCCESS) { - recurse_tree_entry(subtree, e, dir_sep+1); - git_tree_close(subtree); - return; - } - } - } - - tree_entry = git_tree_entry_byname(tree, path); - if (tree_entry != NULL) { - git_oid_cpy(&e->head_oid, &tree_entry->oid); - } -} - -struct status_st { - union { - git_vector *vector; - struct status_entry *e; - } entry; - - int workdir_path_len; -}; - -static int dirent_cb(void *state, char *full_path) -{ - int idx; - struct status_entry *e; - struct status_st *st = (struct status_st *)state; - char *file_path = full_path + st->workdir_path_len; - struct stat filest; - git_oid oid; - - if ((git_futils_isdir(full_path) == GIT_SUCCESS) && (!strcmp(".git", file_path))) - return 0; - - if (git_futils_isdir(full_path) == GIT_SUCCESS) - return git_futils_direach(full_path, GIT_PATH_MAX, dirent_cb, state); - - if ((idx = find_status_entry(st->entry.vector, file_path)) != GIT_ENOTFOUND) { - e = (struct status_entry *)git_vector_get(st->entry.vector, idx); - - if (p_stat(full_path, &filest) < 0) - return git__throw(GIT_EOSERR, "Failed to read file %s", full_path); - - if (e->mtime.seconds == (git_time_t)filest.st_mtime) { - git_oid_cpy(&e->wt_oid, &e->index_oid); - return 0; - } - } else { - e = new_status_entry(st->entry.vector, file_path); - } - - git_odb_hashfile(&oid, full_path, GIT_OBJ_BLOB); - git_oid_cpy(&e->wt_oid, &oid); - - return 0; -} - -static int single_dirent_cb(void *state, char *full_path) -{ - struct status_st *st = (struct status_st *)state; - struct status_entry *e = st->entry.e; - - char *file_path = full_path + st->workdir_path_len; - struct stat filest; - git_oid oid; - - if ((git_futils_isdir(full_path) == GIT_SUCCESS) && (!strcmp(".git", file_path))) - return 0; - - if (git_futils_isdir(full_path) == GIT_SUCCESS) - return git_futils_direach(full_path, GIT_PATH_MAX, single_dirent_cb, state); - - if (!strcmp(file_path, e->path)) { - if (p_stat(full_path, &filest) < 0) - return git__throw(GIT_EOSERR, "Failed to read file %s", full_path); - - if (e->mtime.seconds == (git_time_t)filest.st_mtime) { - git_oid_cpy(&e->wt_oid, &e->index_oid); - return 1; - } - - git_odb_hashfile(&oid, full_path, GIT_OBJ_BLOB); - git_oid_cpy(&e->wt_oid, &oid); - return 1; - } - - return 0; -} - -static int set_status_flags(struct status_entry *e) -{ - git_oid zero; - int head_zero, index_zero, wt_zero; - - memset(&zero, 0x0, sizeof(git_oid)); - - head_zero = git_oid_cmp(&zero, &e->head_oid); - index_zero = git_oid_cmp(&zero, &e->index_oid); - wt_zero = git_oid_cmp(&zero, &e->wt_oid); - - if (head_zero == 0 && index_zero == 0 && wt_zero == 0) - return GIT_ENOTFOUND; - - if (head_zero == 0 && index_zero != 0) - e->status_flags |= GIT_STATUS_INDEX_NEW; - else if (index_zero == 0 && head_zero != 0) - e->status_flags |= GIT_STATUS_INDEX_DELETED; - else if (git_oid_cmp(&e->head_oid, &e->index_oid) != 0) - e->status_flags |= GIT_STATUS_INDEX_MODIFIED; - - if (index_zero == 0 && wt_zero != 0) - e->status_flags |= GIT_STATUS_WT_NEW; - else if (wt_zero == 0 && index_zero != 0) - e->status_flags |= GIT_STATUS_WT_DELETED; - else if (git_oid_cmp(&e->index_oid, &e->wt_oid) != 0) - e->status_flags |= GIT_STATUS_WT_MODIFIED; - - return GIT_SUCCESS; -} - -int git_status_foreach(git_repository *repo, int (*callback)(const char *, unsigned int, void *), void *payload) -{ - git_vector entries; - struct status_entry *e; - git_index *index; - unsigned int i, cnt; - git_index_entry *index_entry; - char temp_path[GIT_PATH_MAX]; - int error; - git_tree *tree; - struct status_st dirent_st; - - git_reference *head_ref, *resolved_head_ref; - git_commit *head_commit; - - git_repository_index(&index, repo); - - cnt = git_index_entrycount(index); - git_vector_init(&entries, cnt, status_cmp); - for (i = 0; i < cnt; ++i) { - index_entry = git_index_get(index, i); - - e = new_status_entry(&entries, index_entry->path); - git_oid_cpy(&e->index_oid, &index_entry->oid); - e->mtime = index_entry->mtime; - } - git_index_free(index); - - git_reference_lookup(&head_ref, repo, GIT_HEAD_FILE); - git_reference_resolve(&resolved_head_ref, head_ref); - - git_commit_lookup(&head_commit, repo, git_reference_oid(resolved_head_ref)); - - // recurse through tree entries - git_commit_tree(&tree, head_commit); - recurse_tree_entries(tree, &entries, ""); - git_tree_close(tree); - git_commit_close(head_commit); - - dirent_st.workdir_path_len = strlen(repo->path_workdir); - dirent_st.entry.vector = &entries; - strcpy(temp_path, repo->path_workdir); - git_futils_direach(temp_path, GIT_PATH_MAX, dirent_cb, &dirent_st); - - for (i = 0; i < entries.length; ++i) { - e = (struct status_entry *)git_vector_get(&entries, i); - - set_status_flags(e); - } - - - for (i = 0; i < entries.length; ++i) { - e = (struct status_entry *)git_vector_get(&entries, i); - - if ((error = callback(e->path, e->status_flags, payload)) < GIT_SUCCESS) - return git__throw(error, "Failed to list statuses. User callback failed"); - } - - for (i = 0; i < entries.length; ++i) { - e = (struct status_entry *)git_vector_get(&entries, i); - free(e); - } - git_vector_free(&entries); - - return GIT_SUCCESS; -} - -int git_status_file(unsigned int *status_flags, git_repository *repo, const char *path) -{ - struct status_entry *e; - git_index *index; - git_index_entry *index_entry; - char temp_path[GIT_PATH_MAX]; - int idx, error; - git_tree *tree; - git_reference *head_ref, *resolved_head_ref; - git_commit *head_commit; - struct status_st dirent_st; - - assert(status_flags); - - e = new_status_entry(NULL, path); - - // Find file in Index - git_repository_index(&index, repo); - idx = git_index_find(index, path); - if (idx >= 0) { - index_entry = git_index_get(index, idx); - git_oid_cpy(&e->index_oid, &index_entry->oid); - e->mtime = index_entry->mtime; - } - git_index_free(index); - - // Find file in HEAD - git_reference_lookup(&head_ref, repo, GIT_HEAD_FILE); - git_reference_resolve(&resolved_head_ref, head_ref); - - git_commit_lookup(&head_commit, repo, git_reference_oid(resolved_head_ref)); - - git_commit_tree(&tree, head_commit); - recurse_tree_entry(tree, e, path); - git_tree_close(tree); - git_commit_close(head_commit); - - // Find file in Workdir - dirent_st.workdir_path_len = strlen(repo->path_workdir); - dirent_st.entry.e = e; - strcpy(temp_path, repo->path_workdir); - git_futils_direach(temp_path, GIT_PATH_MAX, single_dirent_cb, &dirent_st); - - if ((error = set_status_flags(e)) < GIT_SUCCESS) { - free(e); - return git__throw(error, "Nonexistent file"); - } - - *status_flags = e->status_flags; - - free(e); - - return GIT_SUCCESS; -} diff --git a/vendor/libgit2/src/t03-data.h b/vendor/libgit2/src/t03-data.h deleted file mode 100644 index a4b73fec3..000000000 --- a/vendor/libgit2/src/t03-data.h +++ /dev/null @@ -1,344 +0,0 @@ - -typedef struct object_data { - char *id; /* object id (sha1) */ - char *dir; /* object store (fan-out) directory name */ - char *file; /* object store filename */ -} object_data; - -static object_data commit = { - "3d7f8a6af076c8c3f20071a8935cdbe8228594d1", - "test-objects/3d", - "test-objects/3d/7f8a6af076c8c3f20071a8935cdbe8228594d1", -}; - -static unsigned char commit_data[] = { - 0x74, 0x72, 0x65, 0x65, 0x20, 0x64, 0x66, 0x66, - 0x32, 0x64, 0x61, 0x39, 0x30, 0x62, 0x32, 0x35, - 0x34, 0x65, 0x31, 0x62, 0x65, 0x62, 0x38, 0x38, - 0x39, 0x64, 0x31, 0x66, 0x31, 0x66, 0x31, 0x32, - 0x38, 0x38, 0x62, 0x65, 0x31, 0x38, 0x30, 0x33, - 0x37, 0x38, 0x32, 0x64, 0x66, 0x0a, 0x61, 0x75, - 0x74, 0x68, 0x6f, 0x72, 0x20, 0x41, 0x20, 0x55, - 0x20, 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, - 0x75, 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, - 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, - 0x6d, 0x3e, 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, - 0x31, 0x34, 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, - 0x30, 0x30, 0x30, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, - 0x69, 0x74, 0x74, 0x65, 0x72, 0x20, 0x43, 0x20, - 0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72, - 0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, - 0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e, - 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34, - 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30, - 0x30, 0x0a, 0x0a, 0x41, 0x20, 0x6f, 0x6e, 0x65, - 0x2d, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x63, 0x6f, - 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x73, 0x75, 0x6d, - 0x6d, 0x61, 0x72, 0x79, 0x0a, 0x0a, 0x54, 0x68, - 0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x6f, - 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, - 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x6d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x2c, 0x20, 0x63, 0x6f, - 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67, - 0x20, 0x66, 0x75, 0x72, 0x74, 0x68, 0x65, 0x72, - 0x20, 0x65, 0x78, 0x70, 0x6c, 0x61, 0x6e, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x6f, 0x66, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x72, 0x70, - 0x6f, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x67, - 0x65, 0x73, 0x20, 0x69, 0x6e, 0x74, 0x72, 0x6f, - 0x64, 0x75, 0x63, 0x65, 0x64, 0x20, 0x62, 0x79, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6d, - 0x6d, 0x69, 0x74, 0x2e, 0x0a, 0x0a, 0x53, 0x69, - 0x67, 0x6e, 0x65, 0x64, 0x2d, 0x6f, 0x66, 0x2d, - 0x62, 0x79, 0x3a, 0x20, 0x41, 0x20, 0x55, 0x20, - 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, 0x75, - 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, 0x61, - 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, - 0x3e, 0x0a, -}; - -static git_rawobj commit_obj = { - commit_data, - sizeof(commit_data), - GIT_OBJ_COMMIT -}; - -static object_data tree = { - "dff2da90b254e1beb889d1f1f1288be1803782df", - "test-objects/df", - "test-objects/df/f2da90b254e1beb889d1f1f1288be1803782df", -}; - -static unsigned char tree_data[] = { - 0x31, 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x6f, - 0x6e, 0x65, 0x00, 0x8b, 0x13, 0x78, 0x91, 0x79, - 0x1f, 0xe9, 0x69, 0x27, 0xad, 0x78, 0xe6, 0x4b, - 0x0a, 0xad, 0x7b, 0xde, 0xd0, 0x8b, 0xdc, 0x31, - 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x73, 0x6f, - 0x6d, 0x65, 0x00, 0xfd, 0x84, 0x30, 0xbc, 0x86, - 0x4c, 0xfc, 0xd5, 0xf1, 0x0e, 0x55, 0x90, 0xf8, - 0xa4, 0x47, 0xe0, 0x1b, 0x94, 0x2b, 0xfe, 0x31, - 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x74, 0x77, - 0x6f, 0x00, 0x78, 0x98, 0x19, 0x22, 0x61, 0x3b, - 0x2a, 0xfb, 0x60, 0x25, 0x04, 0x2f, 0xf6, 0xbd, - 0x87, 0x8a, 0xc1, 0x99, 0x4e, 0x85, 0x31, 0x30, - 0x30, 0x36, 0x34, 0x34, 0x20, 0x7a, 0x65, 0x72, - 0x6f, 0x00, 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, - 0xd6, 0x43, 0x4b, 0x8b, 0x29, 0xae, 0x77, 0x5a, - 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91, -}; - -static git_rawobj tree_obj = { - tree_data, - sizeof(tree_data), - GIT_OBJ_TREE -}; - -static object_data tag = { - "09d373e1dfdc16b129ceec6dd649739911541e05", - "test-objects/09", - "test-objects/09/d373e1dfdc16b129ceec6dd649739911541e05", -}; - -static unsigned char tag_data[] = { - 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x33, - 0x64, 0x37, 0x66, 0x38, 0x61, 0x36, 0x61, 0x66, - 0x30, 0x37, 0x36, 0x63, 0x38, 0x63, 0x33, 0x66, - 0x32, 0x30, 0x30, 0x37, 0x31, 0x61, 0x38, 0x39, - 0x33, 0x35, 0x63, 0x64, 0x62, 0x65, 0x38, 0x32, - 0x32, 0x38, 0x35, 0x39, 0x34, 0x64, 0x31, 0x0a, - 0x74, 0x79, 0x70, 0x65, 0x20, 0x63, 0x6f, 0x6d, - 0x6d, 0x69, 0x74, 0x0a, 0x74, 0x61, 0x67, 0x20, - 0x76, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0a, 0x74, - 0x61, 0x67, 0x67, 0x65, 0x72, 0x20, 0x43, 0x20, - 0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72, - 0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, - 0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e, - 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34, - 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30, - 0x30, 0x0a, 0x0a, 0x54, 0x68, 0x69, 0x73, 0x20, - 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, - 0x61, 0x67, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, - 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x72, 0x65, - 0x6c, 0x65, 0x61, 0x73, 0x65, 0x20, 0x76, 0x30, - 0x2e, 0x30, 0x2e, 0x31, 0x0a, -}; - -static git_rawobj tag_obj = { - tag_data, - sizeof(tag_data), - GIT_OBJ_TAG -}; - -static object_data zero = { - "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", - "test-objects/e6", - "test-objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391", -}; - -static unsigned char zero_data[] = { - 0x00 /* dummy data */ -}; - -static git_rawobj zero_obj = { - zero_data, - 0, - GIT_OBJ_BLOB -}; - -static object_data one = { - "8b137891791fe96927ad78e64b0aad7bded08bdc", - "test-objects/8b", - "test-objects/8b/137891791fe96927ad78e64b0aad7bded08bdc", -}; - -static unsigned char one_data[] = { - 0x0a, -}; - -static git_rawobj one_obj = { - one_data, - sizeof(one_data), - GIT_OBJ_BLOB -}; - -static object_data two = { - "78981922613b2afb6025042ff6bd878ac1994e85", - "test-objects/78", - "test-objects/78/981922613b2afb6025042ff6bd878ac1994e85", -}; - -static unsigned char two_data[] = { - 0x61, 0x0a, -}; - -static git_rawobj two_obj = { - two_data, - sizeof(two_data), - GIT_OBJ_BLOB -}; - -static object_data some = { - "fd8430bc864cfcd5f10e5590f8a447e01b942bfe", - "test-objects/fd", - "test-objects/fd/8430bc864cfcd5f10e5590f8a447e01b942bfe", -}; - -static unsigned char some_data[] = { - 0x2f, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x54, 0x68, - 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, - 0x69, 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, - 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x3b, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x63, 0x61, - 0x6e, 0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74, - 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x69, - 0x74, 0x20, 0x61, 0x6e, 0x64, 0x2f, 0x6f, 0x72, - 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x0a, - 0x20, 0x2a, 0x20, 0x69, 0x74, 0x20, 0x75, 0x6e, - 0x64, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x74, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x6f, 0x66, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55, - 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, - 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, - 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2c, - 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, - 0x20, 0x32, 0x2c, 0x0a, 0x20, 0x2a, 0x20, 0x61, - 0x73, 0x20, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, - 0x68, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20, - 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2e, 0x0a, 0x20, 0x2a, 0x0a, - 0x20, 0x2a, 0x20, 0x49, 0x6e, 0x20, 0x61, 0x64, - 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, - 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x65, - 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, - 0x73, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, - 0x20, 0x47, 0x4e, 0x55, 0x20, 0x47, 0x65, 0x6e, - 0x65, 0x72, 0x61, 0x6c, 0x20, 0x50, 0x75, 0x62, - 0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69, 0x63, 0x65, - 0x6e, 0x73, 0x65, 0x2c, 0x0a, 0x20, 0x2a, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x61, 0x75, 0x74, 0x68, - 0x6f, 0x72, 0x73, 0x20, 0x67, 0x69, 0x76, 0x65, - 0x20, 0x79, 0x6f, 0x75, 0x20, 0x75, 0x6e, 0x6c, - 0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x20, 0x70, - 0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, - 0x6e, 0x20, 0x74, 0x6f, 0x20, 0x6c, 0x69, 0x6e, - 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x0a, 0x20, - 0x2a, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, - 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69, - 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x69, - 0x6e, 0x74, 0x6f, 0x20, 0x63, 0x6f, 0x6d, 0x62, - 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, - 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x6f, 0x74, - 0x68, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x67, - 0x72, 0x61, 0x6d, 0x73, 0x2c, 0x0a, 0x20, 0x2a, - 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x6f, 0x20, - 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, - 0x74, 0x65, 0x20, 0x74, 0x68, 0x6f, 0x73, 0x65, - 0x20, 0x63, 0x6f, 0x6d, 0x62, 0x69, 0x6e, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69, - 0x74, 0x68, 0x6f, 0x75, 0x74, 0x20, 0x61, 0x6e, - 0x79, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72, 0x69, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, 0x2a, - 0x20, 0x63, 0x6f, 0x6d, 0x69, 0x6e, 0x67, 0x20, - 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, - 0x20, 0x75, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, - 0x74, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, - 0x65, 0x2e, 0x20, 0x20, 0x28, 0x54, 0x68, 0x65, - 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, - 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, - 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a, - 0x20, 0x2a, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72, - 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, - 0x64, 0x6f, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, - 0x20, 0x69, 0x6e, 0x20, 0x6f, 0x74, 0x68, 0x65, - 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x65, 0x63, - 0x74, 0x73, 0x3b, 0x20, 0x66, 0x6f, 0x72, 0x20, - 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2c, - 0x20, 0x74, 0x68, 0x65, 0x79, 0x20, 0x63, 0x6f, - 0x76, 0x65, 0x72, 0x0a, 0x20, 0x2a, 0x20, 0x6d, - 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x2c, - 0x20, 0x61, 0x6e, 0x64, 0x20, 0x64, 0x69, 0x73, - 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x6e, - 0x6f, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x6b, 0x65, - 0x64, 0x20, 0x69, 0x6e, 0x74, 0x6f, 0x0a, 0x20, - 0x2a, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6d, 0x62, - 0x69, 0x6e, 0x65, 0x64, 0x20, 0x65, 0x78, 0x65, - 0x63, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, - 0x29, 0x0a, 0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20, - 0x54, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, - 0x65, 0x20, 0x69, 0x73, 0x20, 0x64, 0x69, 0x73, - 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, - 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x68, 0x6f, 0x70, 0x65, 0x20, 0x74, 0x68, 0x61, - 0x74, 0x20, 0x69, 0x74, 0x20, 0x77, 0x69, 0x6c, - 0x6c, 0x20, 0x62, 0x65, 0x20, 0x75, 0x73, 0x65, - 0x66, 0x75, 0x6c, 0x2c, 0x20, 0x62, 0x75, 0x74, - 0x0a, 0x20, 0x2a, 0x20, 0x57, 0x49, 0x54, 0x48, - 0x4f, 0x55, 0x54, 0x20, 0x41, 0x4e, 0x59, 0x20, - 0x57, 0x41, 0x52, 0x52, 0x41, 0x4e, 0x54, 0x59, - 0x3b, 0x20, 0x77, 0x69, 0x74, 0x68, 0x6f, 0x75, - 0x74, 0x20, 0x65, 0x76, 0x65, 0x6e, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x69, - 0x65, 0x64, 0x20, 0x77, 0x61, 0x72, 0x72, 0x61, - 0x6e, 0x74, 0x79, 0x20, 0x6f, 0x66, 0x0a, 0x20, - 0x2a, 0x20, 0x4d, 0x45, 0x52, 0x43, 0x48, 0x41, - 0x4e, 0x54, 0x41, 0x42, 0x49, 0x4c, 0x49, 0x54, - 0x59, 0x20, 0x6f, 0x72, 0x20, 0x46, 0x49, 0x54, - 0x4e, 0x45, 0x53, 0x53, 0x20, 0x46, 0x4f, 0x52, - 0x20, 0x41, 0x20, 0x50, 0x41, 0x52, 0x54, 0x49, - 0x43, 0x55, 0x4c, 0x41, 0x52, 0x20, 0x50, 0x55, - 0x52, 0x50, 0x4f, 0x53, 0x45, 0x2e, 0x20, 0x20, - 0x53, 0x65, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x47, 0x4e, 0x55, 0x0a, 0x20, 0x2a, 0x20, 0x47, - 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x50, - 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69, - 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x66, 0x6f, - 0x72, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x64, - 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x2e, 0x0a, - 0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x59, 0x6f, - 0x75, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, - 0x20, 0x68, 0x61, 0x76, 0x65, 0x20, 0x72, 0x65, - 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x20, 0x61, - 0x20, 0x63, 0x6f, 0x70, 0x79, 0x20, 0x6f, 0x66, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55, - 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, - 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, - 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a, - 0x20, 0x2a, 0x20, 0x61, 0x6c, 0x6f, 0x6e, 0x67, - 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, - 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72, - 0x61, 0x6d, 0x3b, 0x20, 0x73, 0x65, 0x65, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, - 0x20, 0x43, 0x4f, 0x50, 0x59, 0x49, 0x4e, 0x47, - 0x2e, 0x20, 0x20, 0x49, 0x66, 0x20, 0x6e, 0x6f, - 0x74, 0x2c, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, - 0x20, 0x74, 0x6f, 0x0a, 0x20, 0x2a, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20, - 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x35, 0x31, 0x20, - 0x46, 0x72, 0x61, 0x6e, 0x6b, 0x6c, 0x69, 0x6e, - 0x20, 0x53, 0x74, 0x72, 0x65, 0x65, 0x74, 0x2c, - 0x20, 0x46, 0x69, 0x66, 0x74, 0x68, 0x20, 0x46, - 0x6c, 0x6f, 0x6f, 0x72, 0x2c, 0x0a, 0x20, 0x2a, - 0x20, 0x42, 0x6f, 0x73, 0x74, 0x6f, 0x6e, 0x2c, - 0x20, 0x4d, 0x41, 0x20, 0x30, 0x32, 0x31, 0x31, - 0x30, 0x2d, 0x31, 0x33, 0x30, 0x31, 0x2c, 0x20, - 0x55, 0x53, 0x41, 0x2e, 0x0a, 0x20, 0x2a, 0x2f, - 0x0a, -}; - -static git_rawobj some_obj = { - some_data, - sizeof(some_data), - GIT_OBJ_BLOB -}; diff --git a/vendor/libgit2/src/tag.c b/vendor/libgit2/src/tag.c deleted file mode 100644 index 21bc3c726..000000000 --- a/vendor/libgit2/src/tag.c +++ /dev/null @@ -1,435 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "commit.h" -#include "tag.h" -#include "signature.h" -#include "git2/object.h" -#include "git2/repository.h" -#include "git2/signature.h" - -void git_tag__free(git_tag *tag) -{ - git_signature_free(tag->tagger); - free(tag->message); - free(tag->tag_name); - free(tag); -} - -const git_oid *git_tag_id(git_tag *c) -{ - return git_object_id((git_object *)c); -} - -int git_tag_target(git_object **target, git_tag *t) -{ - assert(t); - return git_object_lookup(target, t->object.repo, &t->target, t->type); -} - -const git_oid *git_tag_target_oid(git_tag *t) -{ - assert(t); - return &t->target; -} - -git_otype git_tag_type(git_tag *t) -{ - assert(t); - return t->type; -} - -const char *git_tag_name(git_tag *t) -{ - assert(t); - return t->tag_name; -} - -const git_signature *git_tag_tagger(git_tag *t) -{ - return t->tagger; -} - -const char *git_tag_message(git_tag *t) -{ - assert(t); - return t->message; -} - -static int parse_tag_buffer(git_tag *tag, const char *buffer, const char *buffer_end) -{ - static const char *tag_types[] = { - NULL, "commit\n", "tree\n", "blob\n", "tag\n" - }; - - unsigned int i, text_len; - char *search; - int error; - - if ((error = git_oid__parse(&tag->target, &buffer, buffer_end, "object ")) < 0) - return git__rethrow(error, "Failed to parse tag. Object field invalid"); - - if (buffer + 5 >= buffer_end) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tag. Object too short"); - - if (memcmp(buffer, "type ", 5) != 0) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tag. Type field not found"); - buffer += 5; - - tag->type = GIT_OBJ_BAD; - - for (i = 1; i < ARRAY_SIZE(tag_types); ++i) { - size_t type_length = strlen(tag_types[i]); - - if (buffer + type_length >= buffer_end) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tag. Object too short"); - - if (memcmp(buffer, tag_types[i], type_length) == 0) { - tag->type = i; - buffer += type_length; - break; - } - } - - if (tag->type == GIT_OBJ_BAD) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tag. Invalid object type"); - - if (buffer + 4 >= buffer_end) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tag. Object too short"); - - if (memcmp(buffer, "tag ", 4) != 0) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tag. Tag field not found"); - - buffer += 4; - - search = memchr(buffer, '\n', buffer_end - buffer); - if (search == NULL) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tag. Object too short"); - - text_len = search - buffer; - - tag->tag_name = git__malloc(text_len + 1); - if (tag->tag_name == NULL) - return GIT_ENOMEM; - - memcpy(tag->tag_name, buffer, text_len); - tag->tag_name[text_len] = '\0'; - - buffer = search + 1; - - tag->tagger = git__malloc(sizeof(git_signature)); - if (tag->tagger == NULL) - return GIT_ENOMEM; - - if ((error = git_signature__parse(tag->tagger, &buffer, buffer_end, "tagger ", '\n')) != 0) { - free(tag->tag_name); - git_signature_free(tag->tagger); - return git__rethrow(error, "Failed to parse tag"); - } - - if( *buffer != '\n' ) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tag. No new line before message"); - - text_len = buffer_end - ++buffer; - - tag->message = git__malloc(text_len + 1); - if (tag->message == NULL) - return GIT_ENOMEM; - - memcpy(tag->message, buffer, text_len); - tag->message[text_len] = '\0'; - - return GIT_SUCCESS; -} - -static int retrieve_tag_reference(git_reference **tag_reference_out, char *ref_name_out, git_repository *repo, const char *tag_name) -{ - git_reference *tag_ref; - int error; - - git_path_join(ref_name_out, GIT_REFS_TAGS_DIR, tag_name); - error = git_reference_lookup(&tag_ref, repo, ref_name_out); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to retrieve tag reference"); - - *tag_reference_out = tag_ref; - - return GIT_SUCCESS; -} - -static int write_tag_annotation( - git_oid *oid, - git_repository *repo, - const char *tag_name, - const git_object *target, - const git_signature *tagger, - const char *message) -{ - int error = GIT_SUCCESS; - git_buf tag = GIT_BUF_INIT; - - git_oid__writebuf(&tag, "object ", git_object_id(target)); - git_buf_printf(&tag, "type %s\n", git_object_type2string(git_object_type(target))); - git_buf_printf(&tag, "tag %s\n", tag_name); - git_signature__writebuf(&tag, "tagger ", tagger); - git_buf_putc(&tag, '\n'); - git_buf_puts(&tag, message); - - if (git_buf_oom(&tag)) { - git_buf_free(&tag); - return git__throw(GIT_ENOMEM, "Not enough memory to build the tag data"); - } - - error = git_odb_write(oid, git_repository_database(repo), tag.ptr, tag.size, GIT_OBJ_TAG); - git_buf_free(&tag); - - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to create tag annotation"); - - return error; -} - -static int git_tag_create__internal( - git_oid *oid, - git_repository *repo, - const char *tag_name, - const git_object *target, - const git_signature *tagger, - const char *message, - int allow_ref_overwrite, - int create_tag_annotation) -{ - git_reference *new_ref = NULL; - char ref_name[GIT_REFNAME_MAX]; - - int error, should_update_ref = 0; - - assert(repo && tag_name && target); - assert(!create_tag_annotation || (tagger && message)); - - if (git_object_owner(target) != repo) - return git__throw(GIT_EINVALIDARGS, "The given target does not belong to this repository"); - - error = retrieve_tag_reference(&new_ref, ref_name, repo, tag_name); - - switch (error) { - case GIT_SUCCESS: - case GIT_ENOTFOUND: - break; - - default: - return git__rethrow(error, "Failed to create tag"); - } - - /** Ensure the tag name doesn't conflict with an already existing - * reference unless overwriting has explictly been requested **/ - if (new_ref != NULL) { - if (!allow_ref_overwrite) { - git_oid_cpy(oid, git_reference_oid(new_ref)); - return git__throw(GIT_EEXISTS, "Tag already exists"); - } else { - should_update_ref = 1; - } - } - - if (create_tag_annotation) { - if ((error = write_tag_annotation(oid, repo, tag_name, target, tagger, message)) < GIT_SUCCESS) - return error; - } else - git_oid_cpy(oid, git_object_id(target)); - - if (!should_update_ref) - error = git_reference_create_oid(&new_ref, repo, ref_name, oid, 0); - else - error = git_reference_set_oid(new_ref, oid); - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to create tag"); -} - -int git_tag_create( - git_oid *oid, - git_repository *repo, - const char *tag_name, - const git_object *target, - const git_signature *tagger, - const char *message, - int allow_ref_overwrite) -{ - return git_tag_create__internal(oid, repo, tag_name, target, tagger, message, allow_ref_overwrite, 1); -} - -int git_tag_create_lightweight( - git_oid *oid, - git_repository *repo, - const char *tag_name, - const git_object *target, - int allow_ref_overwrite) -{ - return git_tag_create__internal(oid, repo, tag_name, target, NULL, NULL, allow_ref_overwrite, 0); -} - -int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *buffer, int allow_ref_overwrite) -{ - git_tag tag; - int error, should_update_ref = 0; - git_odb_stream *stream; - git_odb_object *target_obj; - - git_reference *new_ref; - char ref_name[GIT_REFNAME_MAX]; - - assert(oid && buffer); - - memset(&tag, 0, sizeof(tag)); - - /* validate the buffer */ - if ((error = parse_tag_buffer(&tag, buffer, buffer + strlen(buffer))) < GIT_SUCCESS) - return git__rethrow(error, "Failed to create tag"); - - /* validate the target */ - if ((error = git_odb_read(&target_obj, repo->db, &tag.target)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to create tag"); - - if (tag.type != target_obj->raw.type) - return git__throw(error, "The type for the given target is invalid"); - - git_odb_object_close(target_obj); - - error = retrieve_tag_reference(&new_ref, ref_name, repo, tag.tag_name); - - switch (error) { - case GIT_SUCCESS: - case GIT_ENOTFOUND: - break; - - default: - return git__rethrow(error, "Failed to create tag"); - } - - /** Ensure the tag name doesn't conflict with an already existing - * reference unless overwriting has explictly been requested **/ - if (new_ref != NULL) { - if (!allow_ref_overwrite) { - git_oid_cpy(oid, git_reference_oid(new_ref)); - return git__throw(GIT_EEXISTS, "Tag already exists"); - } else { - should_update_ref = 1; - } - } - - /* write the buffer */ - if ((error = git_odb_open_wstream(&stream, repo->db, strlen(buffer), GIT_OBJ_TAG)) < GIT_SUCCESS) - return git__rethrow(error, "Failed to create tag"); - - stream->write(stream, buffer, strlen(buffer)); - - error = stream->finalize_write(oid, stream); - stream->free(stream); - - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to create tag"); - - if (!should_update_ref) - error = git_reference_create_oid(&new_ref, repo, ref_name, oid, 0); - else - error = git_reference_set_oid(new_ref, oid); - - git_signature_free(tag.tagger); - free(tag.tag_name); - free(tag.message); - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to create tag"); -} - -int git_tag_delete(git_repository *repo, const char *tag_name) -{ - int error; - git_reference *tag_ref; - char ref_name[GIT_REFNAME_MAX]; - - error = retrieve_tag_reference(&tag_ref, ref_name, repo, tag_name); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to delete tag"); - - return git_reference_delete(tag_ref); -} - -int git_tag__parse(git_tag *tag, git_odb_object *obj) -{ - assert(tag); - return parse_tag_buffer(tag, obj->raw.data, (char *)obj->raw.data + obj->raw.len); -} - -typedef struct { - git_vector *taglist; - const char *pattern; -} tag_filter_data; - -#define GIT_REFS_TAGS_DIR_LEN strlen(GIT_REFS_TAGS_DIR) - -static int tag_list_cb(const char *tag_name, void *payload) -{ - tag_filter_data *filter; - - if (git__prefixcmp(tag_name, GIT_REFS_TAGS_DIR) != 0) - return GIT_SUCCESS; - - filter = (tag_filter_data *)payload; - if (!*filter->pattern || p_fnmatch(filter->pattern, tag_name + GIT_REFS_TAGS_DIR_LEN, 0) == GIT_SUCCESS) - return git_vector_insert(filter->taglist, git__strdup(tag_name)); - - return GIT_SUCCESS; -} - -int git_tag_list_match(git_strarray *tag_names, const char *pattern, git_repository *repo) -{ - int error; - tag_filter_data filter; - git_vector taglist; - - assert(tag_names && repo && pattern); - - if (git_vector_init(&taglist, 8, NULL) < GIT_SUCCESS) - return GIT_ENOMEM; - - filter.taglist = &taglist; - filter.pattern = pattern; - - error = git_reference_foreach(repo, GIT_REF_OID|GIT_REF_PACKED, &tag_list_cb, (void *)&filter); - if (error < GIT_SUCCESS) { - git_vector_free(&taglist); - return git__rethrow(error, "Failed to list tags"); - } - - tag_names->strings = (char **)taglist.contents; - tag_names->count = taglist.length; - return GIT_SUCCESS; -} - -int git_tag_list(git_strarray *tag_names, git_repository *repo) -{ - return git_tag_list_match(tag_names, "", repo); -} diff --git a/vendor/libgit2/src/tag.h b/vendor/libgit2/src/tag.h deleted file mode 100644 index eddf8fa3a..000000000 --- a/vendor/libgit2/src/tag.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef INCLUDE_tag_h__ -#define INCLUDE_tag_h__ - -#include "git2/tag.h" -#include "repository.h" -#include "odb.h" - -struct git_tag { - git_object object; - - git_oid target; - git_otype type; - - char *tag_name; - git_signature *tagger; - char *message; -}; - -void git_tag__free(git_tag *tag); -int git_tag__parse(git_tag *tag, git_odb_object *obj); - -#endif diff --git a/vendor/libgit2/src/thread-utils.c b/vendor/libgit2/src/thread-utils.c deleted file mode 100644 index 5e8220f46..000000000 --- a/vendor/libgit2/src/thread-utils.c +++ /dev/null @@ -1,49 +0,0 @@ -#include "common.h" -#include "thread-utils.h" - -#ifdef _WIN32 -# define WIN32_LEAN_AND_MEAN -# include -#elif defined(hpux) || defined(__hpux) || defined(_hpux) -# include -#endif - -/* - * By doing this in two steps we can at least get - * the function to be somewhat coherent, even - * with this disgusting nest of #ifdefs. - */ -#ifndef _SC_NPROCESSORS_ONLN -# ifdef _SC_NPROC_ONLN -# define _SC_NPROCESSORS_ONLN _SC_NPROC_ONLN -# elif defined _SC_CRAY_NCPU -# define _SC_NPROCESSORS_ONLN _SC_CRAY_NCPU -# endif -#endif - -int git_online_cpus(void) -{ -#ifdef _SC_NPROCESSORS_ONLN - long ncpus; -#endif - -#ifdef _WIN32 - SYSTEM_INFO info; - GetSystemInfo(&info); - - if ((int)info.dwNumberOfProcessors > 0) - return (int)info.dwNumberOfProcessors; -#elif defined(hpux) || defined(__hpux) || defined(_hpux) - struct pst_dynamic psd; - - if (!pstat_getdynamic(&psd, sizeof(psd), (size_t)1, 0)) - return (int)psd.psd_proc_cnt; -#endif - -#ifdef _SC_NPROCESSORS_ONLN - if ((ncpus = (long)sysconf(_SC_NPROCESSORS_ONLN)) > 0) - return (int)ncpus; -#endif - - return 1; -} diff --git a/vendor/libgit2/src/thread-utils.h b/vendor/libgit2/src/thread-utils.h deleted file mode 100644 index 20d6022ea..000000000 --- a/vendor/libgit2/src/thread-utils.h +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef INCLUDE_thread_utils_h__ -#define INCLUDE_thread_utils_h__ - - - -/* Common operations even if threading has been disabled */ -typedef struct { -#if defined(_MSC_VER) - volatile long val; -#else - volatile int val; -#endif -} git_atomic; - -GIT_INLINE(void) git_atomic_set(git_atomic *a, int val) -{ - a->val = val; -} - -#ifdef GIT_THREADS - -#define git_thread pthread_t -#define git_thread_create(thread, attr, start_routine, arg) pthread_create(thread, attr, start_routine, arg) -#define git_thread_kill(thread) pthread_cancel(thread) -#define git_thread_exit(status) pthread_exit(status) -#define git_thread_join(id, status) pthread_join(id, status) - -/* Pthreads Mutex */ -#define git_mutex pthread_mutex_t -#define git_mutex_init(a) pthread_mutex_init(a, NULL) -#define git_mutex_lock(a) pthread_mutex_lock(a) -#define git_mutex_unlock(a) pthread_mutex_unlock(a) -#define git_mutex_free(a) pthread_mutex_destroy(a) - -/* Pthreads condition vars -- disabled by now */ -#define git_cond unsigned int //pthread_cond_t -#define git_cond_init(c, a) (void)0 //pthread_cond_init(c, a) -#define git_cond_free(c) (void)0 //pthread_cond_destroy(c) -#define git_cond_wait(c, l) (void)0 //pthread_cond_wait(c, l) -#define git_cond_signal(c) (void)0 //pthread_cond_signal(c) -#define git_cond_broadcast(c) (void)0 //pthread_cond_broadcast(c) - -GIT_INLINE(int) git_atomic_inc(git_atomic *a) -{ -#ifdef __GNUC__ - return __sync_add_and_fetch(&a->val, 1); -#elif defined(_MSC_VER) - return InterlockedIncrement(&a->val); -#else -# error "Unsupported architecture for atomic operations" -#endif -} - -GIT_INLINE(int) git_atomic_dec(git_atomic *a) -{ -#ifdef __GNUC__ - return __sync_sub_and_fetch(&a->val, 1); -#elif defined(_MSC_VER) - return InterlockedDecrement(&a->val); -#else -# error "Unsupported architecture for atomic operations" -#endif -} - -#else - -#define git_thread unsigned int -#define git_thread_create(thread, attr, start_routine, arg) (void)0 -#define git_thread_kill(thread) (void)0 -#define git_thread_exit(status) (void)0 -#define git_thread_join(id, status) (void)0 - -/* Pthreads Mutex */ -#define git_mutex unsigned int -#define git_mutex_init(a) (void)0 -#define git_mutex_lock(a) (void)0 -#define git_mutex_unlock(a) (void)0 -#define git_mutex_free(a) (void)0 - -/* Pthreads condition vars */ -#define git_cond unsigned int -#define git_cond_init(c, a) (void)0 -#define git_cond_free(c) (void)0 -#define git_cond_wait(c, l) (void)0 -#define git_cond_signal(c) (void)0 -#define git_cond_broadcast(c) (void)0 - -GIT_INLINE(int) git_atomic_inc(git_atomic *a) -{ - return ++a->val; -} - -GIT_INLINE(int) git_atomic_dec(git_atomic *a) -{ - return --a->val; -} - -#endif - -extern int git_online_cpus(void); - -#endif /* INCLUDE_thread_utils_h__ */ diff --git a/vendor/libgit2/src/transport.c b/vendor/libgit2/src/transport.c deleted file mode 100644 index 91f621c46..000000000 --- a/vendor/libgit2/src/transport.c +++ /dev/null @@ -1,71 +0,0 @@ -#include "common.h" -#include "git2/types.h" -#include "git2/transport.h" -#include "git2/net.h" -#include "transport.h" - -struct { - char *prefix; - git_transport_cb fn; -} transports[] = { - {"git://", git_transport_git}, - {"http://", git_transport_dummy}, - {"https://", git_transport_dummy}, - {"file://", git_transport_local}, - {"git+ssh://", git_transport_dummy}, - {"ssh+git://", git_transport_dummy}, - {NULL, 0} -}; - -static git_transport_cb transport_new_fn(const char *url) -{ - int i = 0; - - while (1) { - if (transports[i].prefix == NULL) - break; - - if (!strncasecmp(url, transports[i].prefix, strlen(transports[i].prefix))) - return transports[i].fn; - - ++i; - } - - /* - * If we still haven't found the transport, we assume we mean a - * local file. - * TODO: Parse "example.com:project.git" as an SSH URL - */ - return git_transport_local; -} - -/************** - * Public API * - **************/ - -int git_transport_dummy(git_transport **GIT_UNUSED(transport)) -{ - GIT_UNUSED_ARG(transport); - return git__throw(GIT_ENOTIMPLEMENTED, "This protocol isn't implemented. Sorry"); -} - -int git_transport_new(git_transport **out, const char *url) -{ - git_transport_cb fn; - git_transport *transport; - int error; - - fn = transport_new_fn(url); - - error = fn(&transport); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to create new transport"); - - transport->url = git__strdup(url); - if (transport->url == NULL) - return GIT_ENOMEM; - - *out = transport; - - return GIT_SUCCESS; -} diff --git a/vendor/libgit2/src/transport.h b/vendor/libgit2/src/transport.h deleted file mode 100644 index 9489ac803..000000000 --- a/vendor/libgit2/src/transport.h +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef INCLUDE_transport_h__ -#define INCLUDE_transport_h__ - -#include "git2/transport.h" -#include "git2/net.h" -#include "vector.h" - -#define GIT_CAP_OFS_DELTA "ofs-delta" - -typedef struct git_transport_caps { - int common:1, - ofs_delta:1; -} git_transport_caps; - -/* - * A day in the life of a network operation - * ======================================== - * - * The library gets told to ls-remote/push/fetch on/to/from some - * remote. We look at the URL of the remote and fill the function - * table with whatever is appropriate (the remote may be git over git, - * ssh or http(s). It may even be an hg or svn repository, the library - * at this level doesn't care, it just calls the helpers. - * - * The first call is to ->connect() which connects to the remote, - * making use of the direction if necessary. This function must also - * store the remote heads and any other information it needs. - * - * The next useful step is to call ->ls() to get the list of - * references available to the remote. These references may have been - * collected on connect, or we may build them now. For ls-remote, - * nothing else is needed other than closing the connection. - * Otherwise, the higher leves decide which objects we want to - * have. ->send_have() is used to tell the other end what we have. If - * we do need to download a pack, ->download_pack() is called. - * - * When we're done, we call ->close() to close the - * connection. ->free() takes care of freeing all the resources. - */ - -struct git_transport { - /** - * Where the repo lives - */ - char *url; - /** - * Whether we want to push or fetch - */ - int direction : 1, /* 0 fetch, 1 push */ - connected : 1; - /** - * Connect and store the remote heads - */ - int (*connect)(struct git_transport *transport, int dir); - /** - * Give a list of references, useful for ls-remote - */ - int (*ls)(struct git_transport *transport, git_headarray *headarray); - /** - * Push the changes over - */ - int (*push)(struct git_transport *transport); - /** - * Send the list of 'want' refs - */ - int (*send_wants)(struct git_transport *transport, git_headarray *list); - /** - * Send the list of 'have' refs - */ - int (*send_have)(struct git_transport *transport, git_oid *oid); - /** - * Send a 'done' message - */ - int (*send_done)(struct git_transport *transport); - /** - * Negotiate the minimal amount of objects that need to be - * retrieved - */ - int (*negotiate_fetch)(struct git_transport *transport, git_repository *repo, git_headarray *list); - /** - * Send a flush - */ - int (*send_flush)(struct git_transport *transport); - /** - * Download the packfile - */ - int (*download_pack)(char **out, struct git_transport *transport, git_repository *repo); - /** - * Fetch the changes - */ - int (*fetch)(struct git_transport *transport); - /** - * Close the connection - */ - int (*close)(struct git_transport *transport); - /** - * Free the associated resources - */ - void (*free)(struct git_transport *transport); -}; - -int git_transport_local(struct git_transport **transport); -int git_transport_git(struct git_transport **transport); -int git_transport_dummy(struct git_transport **transport); - -#endif diff --git a/vendor/libgit2/src/transport_git.c b/vendor/libgit2/src/transport_git.c deleted file mode 100644 index 7b0edcfef..000000000 --- a/vendor/libgit2/src/transport_git.c +++ /dev/null @@ -1,606 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "git2/net.h" -#include "git2/common.h" -#include "git2/types.h" -#include "git2/errors.h" -#include "git2/net.h" -#include "git2/revwalk.h" - -#include "vector.h" -#include "transport.h" -#include "pkt.h" -#include "common.h" -#include "netops.h" -#include "filebuf.h" -#include "repository.h" - -typedef struct { - git_transport parent; - int socket; - git_vector refs; - git_remote_head **heads; - git_transport_caps caps; -} transport_git; - -/* - * Create a git procol request. - * - * For example: 0035git-upload-pack /libgit2/libgit2\0host=github.com\0 - */ -static int gen_proto(char **out, int *outlen, const char *cmd, const char *url) -{ - char *delim, *repo, *ptr; - char default_command[] = "git-upload-pack"; - char host[] = "host="; - int len; - - delim = strchr(url, '/'); - if (delim == NULL) - return git__throw(GIT_EOBJCORRUPTED, "Failed to create proto-request: malformed URL"); - - repo = delim; - - delim = strchr(url, ':'); - if (delim == NULL) - delim = strchr(url, '/'); - - if (cmd == NULL) - cmd = default_command; - - len = 4 + strlen(cmd) + 1 + strlen(repo) + 1 + strlen(host) + (delim - url) + 2; - - *out = git__malloc(len); - if (*out == NULL) - return GIT_ENOMEM; - - *outlen = len - 1; - ptr = *out; - memset(ptr, 0x0, len); - /* We expect the return value to be > len - 1 so don't bother checking it */ - snprintf(ptr, len -1, "%04x%s %s%c%s%s", len - 1, cmd, repo, 0, host, url); - - return GIT_SUCCESS; -} - -static int send_request(int s, const char *cmd, const char *url) -{ - int error, len; - char *msg = NULL; - - error = gen_proto(&msg, &len, cmd, url); - if (error < GIT_SUCCESS) - goto cleanup; - - error = gitno_send(s, msg, len, 0); - -cleanup: - free(msg); - return error; -} - -/* The URL should already have been stripped of the protocol */ -static int extract_host_and_port(char **host, char **port, const char *url) -{ - char *colon, *slash, *delim; - int error = GIT_SUCCESS; - - colon = strchr(url, ':'); - slash = strchr(url, '/'); - - if (slash == NULL) - return git__throw(GIT_EOBJCORRUPTED, "Malformed URL: missing /"); - - if (colon == NULL) { - *port = git__strdup(GIT_DEFAULT_PORT); - } else { - *port = git__strndup(colon + 1, slash - colon - 1); - } - if (*port == NULL) - return GIT_ENOMEM;; - - - delim = colon == NULL ? slash : colon; - *host = git__strndup(url, delim - url); - if (*host == NULL) { - free(*port); - error = GIT_ENOMEM; - } - - return error; -} - -/* - * Parse the URL and connect to a server, storing the socket in - * out. For convenience this also takes care of asking for the remote - * refs - */ -static int do_connect(transport_git *t, const char *url) -{ - int s = -1; - char *host, *port; - const char prefix[] = "git://"; - int error, connected = 0; - - if (!git__prefixcmp(url, prefix)) - url += strlen(prefix); - - error = extract_host_and_port(&host, &port, url); - if (error < GIT_SUCCESS) - return error; - s = gitno_connect(host, port); - connected = 1; - error = send_request(s, NULL, url); - t->socket = s; - - free(host); - free(port); - - if (error < GIT_SUCCESS && s > 0) - close(s); - if (!connected) - error = git__throw(GIT_EOSERR, "Failed to connect to any of the addresses"); - - return error; -} - -/* - * Read from the socket and store the references in the vector - */ -static int store_refs(transport_git *t) -{ - gitno_buffer buf; - int s = t->socket; - git_vector *refs = &t->refs; - int error = GIT_SUCCESS; - char buffer[1024]; - const char *line_end, *ptr; - git_pkt *pkt; - - gitno_buffer_setup(&buf, buffer, sizeof(buffer), s); - - while (1) { - error = gitno_recv(&buf); - if (error < GIT_SUCCESS) - return git__rethrow(GIT_EOSERR, "Failed to receive data"); - if (error == GIT_SUCCESS) /* Orderly shutdown, so exit */ - return GIT_SUCCESS; - - ptr = buf.data; - while (1) { - if (buf.offset == 0) - break; - error = git_pkt_parse_line(&pkt, ptr, &line_end, buf.offset); - /* - * If the error is GIT_ESHORTBUFFER, it means the buffer - * isn't long enough to satisfy the request. Break out and - * wait for more input. - * On any other error, fail. - */ - if (error == GIT_ESHORTBUFFER) { - break; - } - if (error < GIT_SUCCESS) { - return error; - } - - /* Get rid of the part we've used already */ - gitno_consume(&buf, line_end); - - error = git_vector_insert(refs, pkt); - if (error < GIT_SUCCESS) - return error; - - if (pkt->type == GIT_PKT_FLUSH) - return GIT_SUCCESS; - - } - } - - return error; -} - -static int detect_caps(transport_git *t) -{ - git_vector *refs = &t->refs; - git_pkt_ref *pkt; - git_transport_caps *caps = &t->caps; - const char *ptr; - - pkt = git_vector_get(refs, 0); - /* No refs or capabilites, odd but not a problem */ - if (pkt == NULL || pkt->capabilities == NULL) - return GIT_SUCCESS; - - ptr = pkt->capabilities; - while (ptr != NULL && *ptr != '\0') { - if (*ptr == ' ') - ptr++; - - if(!git__prefixcmp(ptr, GIT_CAP_OFS_DELTA)) { - caps->common = caps->ofs_delta = 1; - ptr += strlen(GIT_CAP_OFS_DELTA); - continue; - } - - /* We don't know this capability, so skip it */ - ptr = strchr(ptr, ' '); - } - - return GIT_SUCCESS; -} - -/* - * Since this is a network connection, we need to parse and store the - * pkt-lines at this stage and keep them there. - */ -static int git_connect(git_transport *transport, int direction) -{ - transport_git *t = (transport_git *) transport; - int error = GIT_SUCCESS; - - if (direction == GIT_DIR_PUSH) - return git__throw(GIT_EINVALIDARGS, "Pushing is not supported with the git protocol"); - - t->parent.direction = direction; - error = git_vector_init(&t->refs, 16, NULL); - if (error < GIT_SUCCESS) - goto cleanup; - - /* Connect and ask for the refs */ - error = do_connect(t, transport->url); - if (error < GIT_SUCCESS) - return error; - - t->parent.connected = 1; - error = store_refs(t); - if (error < GIT_SUCCESS) - return error; - - error = detect_caps(t); - -cleanup: - if (error < GIT_SUCCESS) { - git_vector_free(&t->refs); - } - - return error; -} - -static int git_ls(git_transport *transport, git_headarray *array) -{ - transport_git *t = (transport_git *) transport; - git_vector *refs = &t->refs; - int len = 0; - unsigned int i; - - array->heads = git__calloc(refs->length, sizeof(git_remote_head *)); - if (array->heads == NULL) - return GIT_ENOMEM; - - for (i = 0; i < refs->length; ++i) { - git_pkt *p = git_vector_get(refs, i); - if (p->type != GIT_PKT_REF) - continue; - - ++len; - array->heads[i] = &(((git_pkt_ref *) p)->head); - } - array->len = len; - t->heads = array->heads; - - return GIT_SUCCESS; -} - -static int git_send_wants(git_transport *transport, git_headarray *array) -{ - transport_git *t = (transport_git *) transport; - - return git_pkt_send_wants(array, &t->caps, t->socket); -} - -static int git_send_have(git_transport *transport, git_oid *oid) -{ - transport_git *t = (transport_git *) transport; - - return git_pkt_send_have(oid, t->socket); -} - -static int git_negotiate_fetch(git_transport *transport, git_repository *repo, git_headarray *GIT_UNUSED(list)) -{ - transport_git *t = (transport_git *) transport; - git_revwalk *walk; - git_reference *ref; - git_strarray refs; - git_oid oid; - int error; - unsigned int i; - char buff[128]; - gitno_buffer buf; - GIT_UNUSED_ARG(list); - - gitno_buffer_setup(&buf, buff, sizeof(buff), t->socket); - - error = git_reference_listall(&refs, repo, GIT_REF_LISTALL); - if (error < GIT_ERROR) - return git__rethrow(error, "Failed to list all references"); - - error = git_revwalk_new(&walk, repo); - if (error < GIT_ERROR) { - error = git__rethrow(error, "Failed to list all references"); - goto cleanup; - } - git_revwalk_sorting(walk, GIT_SORT_TIME); - - for (i = 0; i < refs.count; ++i) { - /* No tags */ - if (!git__prefixcmp(refs.strings[i], GIT_REFS_TAGS_DIR)) - continue; - - error = git_reference_lookup(&ref, repo, refs.strings[i]); - if (error < GIT_ERROR) { - error = git__rethrow(error, "Failed to lookup %s", refs.strings[i]); - goto cleanup; - } - - if (git_reference_type(ref) == GIT_REF_SYMBOLIC) - continue; - error = git_revwalk_push(walk, git_reference_oid(ref)); - if (error < GIT_ERROR) { - error = git__rethrow(error, "Failed to push %s", refs.strings[i]); - goto cleanup; - } - } - git_strarray_free(&refs); - - /* - * We don't support any kind of ACK extensions, so the negotiation - * boils down to sending what we have and listening for an ACK - * every once in a while. - */ - i = 0; - while ((error = git_revwalk_next(&oid, walk)) == GIT_SUCCESS) { - error = git_pkt_send_have(&oid, t->socket); - i++; - if (i % 20 == 0) { - const char *ptr = buf.data, *line_end; - git_pkt *pkt; - git_pkt_send_flush(t->socket); - while (1) { - /* Wait for max. 1 second */ - error = gitno_select_in(&buf, 1, 0); - if (error < GIT_SUCCESS) { - error = git__throw(GIT_EOSERR, "Error in select"); - } else if (error == 0) { - /* - * Some servers don't respond immediately, so if this - * happens, we keep sending information until it - * answers. - */ - break; - } - - error = gitno_recv(&buf); - if (error < GIT_SUCCESS) { - error = git__rethrow(error, "Error receiving data"); - goto cleanup; - } - error = git_pkt_parse_line(&pkt, ptr, &line_end, buf.offset); - if (error == GIT_ESHORTBUFFER) - continue; - if (error < GIT_SUCCESS) { - error = git__rethrow(error, "Failed to get answer"); - goto cleanup; - } - - gitno_consume(&buf, line_end); - - if (pkt->type == GIT_PKT_ACK) { - error = GIT_SUCCESS; - goto done; - } else if (pkt->type == GIT_PKT_NAK) { - break; - } else { - error = git__throw(GIT_ERROR, "Got unexpected pkt type"); - goto cleanup; - } - } - } - } - if (error == GIT_EREVWALKOVER) - error = GIT_SUCCESS; - -done: - git_pkt_send_flush(t->socket); - git_pkt_send_done(t->socket); - -cleanup: - git_revwalk_free(walk); - return error; -} - -static int git_send_flush(git_transport *transport) -{ - transport_git *t = (transport_git *) transport; - - return git_pkt_send_flush(t->socket); -} - -static int git_send_done(git_transport *transport) -{ - transport_git *t = (transport_git *) transport; - - return git_pkt_send_done(t->socket); -} - -static int store_pack(char **out, gitno_buffer *buf, git_repository *repo) -{ - git_filebuf file; - int error; - char path[GIT_PATH_MAX], suff[] = "/objects/pack/pack-received\0"; - off_t off = 0; - - strcpy(path, repo->path_repository); - off += strlen(repo->path_repository); - strcat(path, suff); - //memcpy(path + off, suff, GIT_PATH_MAX - off - strlen(suff) - 1); - - if (memcmp(buf->data, "PACK", strlen("PACK"))) { - return git__throw(GIT_ERROR, "The pack doesn't start with the signature"); - } - - error = git_filebuf_open(&file, path, GIT_FILEBUF_TEMPORARY); - if (error < GIT_SUCCESS) - goto cleanup; - - while (1) { - /* Part of the packfile has been received, don't loose it */ - error = git_filebuf_write(&file, buf->data, buf->offset); - if (error < GIT_SUCCESS) - goto cleanup; - - gitno_consume_n(buf, buf->offset); - error = gitno_recv(buf); - if (error < GIT_SUCCESS) - goto cleanup; - if (error == 0) /* Orderly shutdown */ - break; - } - - *out = git__strdup(file.path_lock); - if (*out == NULL) { - error = GIT_ENOMEM; - goto cleanup; - } - - /* A bit dodgy, but we need to keep the pack at the temporary path */ - error = git_filebuf_commit_at(&file, file.path_lock); -cleanup: - if (error < GIT_SUCCESS) - git_filebuf_cleanup(&file); - - return error; -} - -static int git_download_pack(char **out, git_transport *transport, git_repository *repo) -{ - transport_git *t = (transport_git *) transport; - int s = t->socket, error = GIT_SUCCESS; - gitno_buffer buf; - char buffer[1024]; - git_pkt *pkt; - const char *line_end, *ptr; - - gitno_buffer_setup(&buf, buffer, sizeof(buffer), s); - /* - * For now, we ignore everything and wait for the pack - */ - while (1) { - error = gitno_recv(&buf); - if (error < GIT_SUCCESS) - return git__rethrow(GIT_EOSERR, "Failed to receive data"); - if (error == 0) /* Orderly shutdown */ - return GIT_SUCCESS; - - ptr = buf.data; - /* Whilst we're searching for the pack */ - while (1) { - if (buf.offset == 0) - break; - error = git_pkt_parse_line(&pkt, ptr, &line_end, buf.offset); - if (error == GIT_ESHORTBUFFER) - break; - if (error < GIT_SUCCESS) - return error; - - if (pkt->type == GIT_PKT_PACK) - return store_pack(out, &buf, repo); - - /* For now we don't care about anything */ - free(pkt); - gitno_consume(&buf, line_end); - } - } -} - - -static int git_close(git_transport *transport) -{ - transport_git *t = (transport_git*) transport; - int s = t->socket; - int error; - - /* Can't do anything if there's an error, so don't bother checking */ - git_pkt_send_flush(s); - error = close(s); - if (error < 0) - error = git__throw(GIT_EOSERR, "Failed to close socket"); - - return error; -} - -static void git_free(git_transport *transport) -{ - transport_git *t = (transport_git *) transport; - git_vector *refs = &t->refs; - unsigned int i; - - for (i = 0; i < refs->length; ++i) { - git_pkt *p = git_vector_get(refs, i); - git_pkt_free(p); - } - - git_vector_free(refs); - free(t->heads); - free(t->parent.url); - free(t); -} - -int git_transport_git(git_transport **out) -{ - transport_git *t; - - t = git__malloc(sizeof(transport_git)); - if (t == NULL) - return GIT_ENOMEM; - - memset(t, 0x0, sizeof(transport_git)); - - t->parent.connect = git_connect; - t->parent.ls = git_ls; - t->parent.send_wants = git_send_wants; - t->parent.send_have = git_send_have; - t->parent.negotiate_fetch = git_negotiate_fetch; - t->parent.send_flush = git_send_flush; - t->parent.send_done = git_send_done; - t->parent.download_pack = git_download_pack; - t->parent.close = git_close; - t->parent.free = git_free; - - *out = (git_transport *) t; - - return GIT_SUCCESS; -} diff --git a/vendor/libgit2/src/transport_local.c b/vendor/libgit2/src/transport_local.c deleted file mode 100644 index ab0922cf2..000000000 --- a/vendor/libgit2/src/transport_local.c +++ /dev/null @@ -1,234 +0,0 @@ -#include "common.h" -#include "git2/types.h" -#include "git2/transport.h" -#include "git2/net.h" -#include "git2/repository.h" -#include "git2/object.h" -#include "git2/tag.h" -#include "refs.h" -#include "transport.h" -#include "posix.h" - -typedef struct { - git_transport parent; - git_repository *repo; - git_vector *refs; - git_headarray wants_list; -} transport_local; - -/* - * Try to open the url as a git directory. The direction doesn't - * matter in this case because we're calulating the heads ourselves. - */ -static int local_connect(git_transport *transport, int GIT_UNUSED(direction)) -{ - git_repository *repo; - int error; - transport_local *t = (transport_local *) transport; - const char *path; - const char file_prefix[] = "file://"; - GIT_UNUSED_ARG(direction); - - /* The repo layer doesn't want the prefix */ - if (!git__prefixcmp(transport->url, file_prefix)) - path = transport->url + strlen(file_prefix); - else - path = transport->url; - - error = git_repository_open(&repo, path); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to open remote"); - - t->repo = repo; - t->parent.connected = 1; - - return GIT_SUCCESS; -} - -static int add_ref(const char *name, git_repository *repo, git_vector *vec) -{ - const char peeled[] = "^{}"; - git_remote_head *head; - git_reference *ref; - git_object *obj = NULL; - int error = GIT_SUCCESS, peel_len, ret; - - head = git__malloc(sizeof(git_remote_head)); - if (head == NULL) - return GIT_ENOMEM; - - head->name = git__strdup(name); - if (head->name == NULL) { - error = GIT_ENOMEM; - goto out; - } - - error = git_reference_lookup(&ref, repo, name); - if (error < GIT_SUCCESS) - goto out; - - error = git_reference_resolve(&ref, ref); - if (error < GIT_SUCCESS) - goto out; - - git_oid_cpy(&head->oid, git_reference_oid(ref)); - - error = git_vector_insert(vec, head); - if (error < GIT_SUCCESS) - goto out; - - /* If it's not a tag, we don't need to try to peel it */ - if (git__prefixcmp(name, GIT_REFS_TAGS_DIR)) - goto out; - - error = git_object_lookup(&obj, repo, &head->oid, GIT_OBJ_ANY); - if (error < GIT_SUCCESS) { - git__rethrow(error, "Failed to lookup object"); - } - - /* If it's not an annotated tag, just get out */ - if (git_object_type(obj) != GIT_OBJ_TAG) - goto out; - - /* And if it's a tag, peel it, and add it to the list */ - head = git__malloc(sizeof(git_remote_head)); - peel_len = strlen(name) + strlen(peeled); - head->name = git__malloc(peel_len + 1); - ret = p_snprintf(head->name, peel_len + 1, "%s%s", name, peeled); - if (ret >= peel_len + 1) { - error = git__throw(GIT_ERROR, "The string is magically to long"); - } - - git_oid_cpy(&head->oid, git_tag_target_oid((git_tag *) obj)); - - error = git_vector_insert(vec, head); - if (error < GIT_SUCCESS) - goto out; - - out: - git_object_close(obj); - if (error < GIT_SUCCESS) { - free(head->name); - free(head); - } - return error; -} - -static int local_ls(git_transport *transport, git_headarray *array) -{ - int error; - unsigned int i; - git_repository *repo; - git_vector *vec; - git_strarray refs; - transport_local *t = (transport_local *) transport; - - assert(transport && transport->connected); - - repo = t->repo; - - error = git_reference_listall(&refs, repo, GIT_REF_LISTALL); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to list remote heads"); - - vec = git__malloc(sizeof(git_vector)); - if (vec == NULL) { - error = GIT_ENOMEM; - goto out; - } - - error = git_vector_init(vec, refs.count, NULL); - if (error < GIT_SUCCESS) - return error; - - /* Sort the references first */ - git__tsort((void **)refs.strings, refs.count, &git__strcmp_cb); - - /* Add HEAD */ - error = add_ref(GIT_HEAD_FILE, repo, vec); - if (error < GIT_SUCCESS) - goto out; - - for (i = 0; i < refs.count; ++i) { - error = add_ref(refs.strings[i], repo, vec); - if (error < GIT_SUCCESS) - goto out; - } - - array->len = vec->length; - array->heads = (git_remote_head **)vec->contents; - - t->refs = vec; - - out: - - git_strarray_free(&refs); - - return error; -} - -static int local_send_wants(git_transport *transport, git_headarray *array) -{ - transport_local *t = (transport_local *) transport; - git_headarray *wants = &t->wants_list; - - /* - * We need to store the list of wanted references so we can figure - * out what to transmit later. - */ - wants->len = array->len; - wants->heads = array->heads; - - /* We're local anyway, so we don't need this */ - return GIT_SUCCESS; -} - -static int local_close(git_transport *GIT_UNUSED(transport)) -{ - /* Nothing to do */ - GIT_UNUSED_ARG(transport); - return GIT_SUCCESS; -} - -static void local_free(git_transport *transport) -{ - unsigned int i; - transport_local *t = (transport_local *) transport; - git_vector *vec = t->refs; - - assert(transport); - - for (i = 0; i < vec->length; ++i) { - git_remote_head *h = git_vector_get(vec, i); - free(h->name); - free(h); - } - git_vector_free(vec); - free(vec); - git_repository_free(t->repo); - free(t->parent.url); - free(t); -} - -/************** - * Public API * - **************/ - -int git_transport_local(git_transport **out) -{ - transport_local *t; - - t = git__malloc(sizeof(transport_local)); - if (t == NULL) - return GIT_ENOMEM; - - t->parent.connect = local_connect; - t->parent.ls = local_ls; - t->parent.send_wants = local_send_wants; - t->parent.close = local_close; - t->parent.free = local_free; - - *out = (git_transport *) t; - - return GIT_SUCCESS; -} diff --git a/vendor/libgit2/src/tree.c b/vendor/libgit2/src/tree.c deleted file mode 100644 index d993d549a..000000000 --- a/vendor/libgit2/src/tree.c +++ /dev/null @@ -1,526 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "commit.h" -#include "tree.h" -#include "git2/repository.h" -#include "git2/object.h" - -#define DEFAULT_TREE_SIZE 16 -#define MAX_FILEMODE 0777777 -#define MAX_FILEMODE_BYTES 6 - -static int valid_attributes(const int attributes) { - return attributes >= 0 && attributes <= MAX_FILEMODE; -} - -struct tree_key_search { - const char *filename; - size_t filename_len; -}; - -int entry_search_cmp(const void *key, const void *array_member) -{ - const struct tree_key_search *ksearch = key; - const git_tree_entry *entry = array_member; - - int result = - git_futils_cmp_path( - ksearch->filename, ksearch->filename_len, entry->attr & 040000, - entry->filename, entry->filename_len, entry->attr & 040000); - - return result ? result : ((int)ksearch->filename_len - (int)entry->filename_len); -} - -int entry_sort_cmp(const void *a, const void *b) -{ - const git_tree_entry *entry_a = (const git_tree_entry *)(a); - const git_tree_entry *entry_b = (const git_tree_entry *)(b); - - return git_futils_cmp_path( - entry_a->filename, entry_a->filename_len, entry_a->attr & 040000, - entry_b->filename, entry_b->filename_len, entry_b->attr & 040000); -} - -static int build_ksearch(struct tree_key_search *ksearch, const char *path) -{ - size_t len = strlen(path); - - if (len && path[len - 1] == '/') - len--; - - if (len == 0 || memchr(path, '/', len) != NULL) - return GIT_ERROR; - - ksearch->filename = path; - ksearch->filename_len = len; - - return GIT_SUCCESS; -} - -void git_tree__free(git_tree *tree) -{ - unsigned int i; - - for (i = 0; i < tree->entries.length; ++i) { - git_tree_entry *e; - e = git_vector_get(&tree->entries, i); - - free(e->filename); - free(e); - } - - git_vector_free(&tree->entries); - free(tree); -} - -const git_oid *git_tree_id(git_tree *c) -{ - return git_object_id((git_object *)c); -} - -unsigned int git_tree_entry_attributes(const git_tree_entry *entry) -{ - return entry->attr; -} - -const char *git_tree_entry_name(const git_tree_entry *entry) -{ - assert(entry); - return entry->filename; -} - -const git_oid *git_tree_entry_id(const git_tree_entry *entry) -{ - assert(entry); - return &entry->oid; -} - -git_otype git_tree_entry_type(const git_tree_entry *entry) -{ - assert(entry); - - if (S_ISGITLINK(entry->attr)) - return GIT_OBJ_COMMIT; - else if (S_ISDIR(entry->attr)) - return GIT_OBJ_TREE; - else - return GIT_OBJ_BLOB; -} - -int git_tree_entry_2object(git_object **object_out, git_repository *repo, const git_tree_entry *entry) -{ - assert(entry && object_out); - return git_object_lookup(object_out, repo, &entry->oid, GIT_OBJ_ANY); -} - -const git_tree_entry *git_tree_entry_byname(git_tree *tree, const char *filename) -{ - int idx; - struct tree_key_search ksearch; - - assert(tree && filename); - - if (build_ksearch(&ksearch, filename) < GIT_SUCCESS) - return NULL; - - idx = git_vector_bsearch2(&tree->entries, entry_search_cmp, &ksearch); - if (idx == GIT_ENOTFOUND) - return NULL; - - return git_vector_get(&tree->entries, idx); -} - -const git_tree_entry *git_tree_entry_byindex(git_tree *tree, unsigned int idx) -{ - assert(tree); - return git_vector_get(&tree->entries, idx); -} - -unsigned int git_tree_entrycount(git_tree *tree) -{ - assert(tree); - return tree->entries.length; -} - -static int tree_parse_buffer(git_tree *tree, const char *buffer, const char *buffer_end) -{ - int error = GIT_SUCCESS; - - if (git_vector_init(&tree->entries, DEFAULT_TREE_SIZE, entry_sort_cmp) < GIT_SUCCESS) - return GIT_ENOMEM; - - while (buffer < buffer_end) { - git_tree_entry *entry; - - entry = git__calloc(1, sizeof(git_tree_entry)); - if (entry == NULL) { - error = GIT_ENOMEM; - break; - } - - if (git_vector_insert(&tree->entries, entry) < GIT_SUCCESS) - return GIT_ENOMEM; - - if (git__strtol32((long *)&entry->attr, buffer, &buffer, 8) < GIT_SUCCESS) - return git__throw(GIT_EOBJCORRUPTED, "Failed to parse tree. Can't parse attributes"); - - if (*buffer++ != ' ') { - error = git__throw(GIT_EOBJCORRUPTED, "Failed to parse tree. Object it corrupted"); - break; - } - - if (memchr(buffer, 0, buffer_end - buffer) == NULL) { - error = git__throw(GIT_EOBJCORRUPTED, "Failed to parse tree. Object it corrupted"); - break; - } - - entry->filename = git__strdup(buffer); - entry->filename_len = strlen(buffer); - - while (buffer < buffer_end && *buffer != 0) - buffer++; - - buffer++; - - git_oid_fromraw(&entry->oid, (const unsigned char *)buffer); - buffer += GIT_OID_RAWSZ; - } - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to parse buffer"); -} - -int git_tree__parse(git_tree *tree, git_odb_object *obj) -{ - assert(tree); - return tree_parse_buffer(tree, (char *)obj->raw.data, (char *)obj->raw.data + obj->raw.len); -} - -static int write_index_entry(char *buffer, int mode, const char *path, size_t path_len, const git_oid *oid) -{ - int written; - written = sprintf(buffer, "%o %.*s%c", mode, (int)path_len, path, 0); - memcpy(buffer + written, &oid->id, GIT_OID_RAWSZ); - return written + GIT_OID_RAWSZ; -} - -static int write_index(git_oid *oid, git_index *index, const char *base, int baselen, int entry_no, int maxentries) -{ - size_t size, offset; - char *buffer; - int nr, error; - - /* Guess at some random initial size */ - size = maxentries * 40; - buffer = git__malloc(size); - if (buffer == NULL) - return GIT_ENOMEM; - - offset = 0; - - for (nr = entry_no; nr < maxentries; ++nr) { - git_index_entry *entry = git_index_get(index, nr); - - const char *pathname = entry->path, *filename, *dirname; - int pathlen = strlen(pathname), entrylen; - - unsigned int write_mode; - git_oid subtree_oid; - git_oid *write_oid; - - /* Did we hit the end of the directory? Return how many we wrote */ - if (baselen >= pathlen || memcmp(base, pathname, baselen) != 0) - break; - - /* Do we have _further_ subdirectories? */ - filename = pathname + baselen; - dirname = strchr(filename, '/'); - - write_oid = &entry->oid; - write_mode = entry->mode; - - if (dirname) { - int subdir_written; - -#if 0 - if (entry->mode != S_IFDIR) { - free(buffer); - return GIT_EOBJCORRUPTED; - } -#endif - subdir_written = write_index(&subtree_oid, index, pathname, dirname - pathname + 1, nr, maxentries); - - if (subdir_written < GIT_SUCCESS) { - free(buffer); - return subdir_written; - } - - nr = subdir_written - 1; - - /* Now we need to write out the directory entry into this tree.. */ - pathlen = dirname - pathname; - write_oid = &subtree_oid; - write_mode = S_IFDIR; - } - - entrylen = pathlen - baselen; - if (offset + entrylen + 32 > size) { - size = alloc_nr(offset + entrylen + 32); - buffer = git__realloc(buffer, size); - - if (buffer == NULL) - return GIT_ENOMEM; - } - - offset += write_index_entry(buffer + offset, write_mode, filename, entrylen, write_oid); - } - - error = git_odb_write(oid, index->repository->db, buffer, offset, GIT_OBJ_TREE); - free(buffer); - - return (error == GIT_SUCCESS) ? nr : git__rethrow(error, "Failed to write index"); -} - -int git_tree_create_fromindex(git_oid *oid, git_index *index) -{ - int error; - - if (index->repository == NULL) - return git__throw(GIT_EBAREINDEX, "Failed to create tree. The index file is not backed up by an existing repository"); - - error = write_index(oid, index, "", 0, 0, git_index_entrycount(index)); - return (error < GIT_SUCCESS) ? git__rethrow(error, "Failed to create tree") : GIT_SUCCESS; -} - -static void sort_entries(git_treebuilder *bld) -{ - git_vector_sort(&bld->entries); -} - -int git_treebuilder_create(git_treebuilder **builder_p, const git_tree *source) -{ - git_treebuilder *bld; - unsigned int i, source_entries = DEFAULT_TREE_SIZE; - - assert(builder_p); - - bld = git__calloc(1, sizeof(git_treebuilder)); - if (bld == NULL) - return GIT_ENOMEM; - - if (source != NULL) - source_entries = source->entries.length; - - if (git_vector_init(&bld->entries, source_entries, entry_sort_cmp) < GIT_SUCCESS) { - free(bld); - return GIT_ENOMEM; - } - - if (source != NULL) { - bld->entry_count = source_entries; - for (i = 0; i < source->entries.length; ++i) { - git_tree_entry *entry_src = source->entries.contents[i]; - git_tree_entry *entry = git__calloc(1, sizeof(git_tree_entry)); - - if (entry == NULL) { - git_treebuilder_free(bld); - return GIT_ENOMEM; - } - - entry->filename = git__strdup(entry_src->filename); - - if (entry->filename == NULL) { - free(entry); - git_treebuilder_free(bld); - return GIT_ENOMEM; - } - - entry->filename_len = entry_src->filename_len; - git_oid_cpy(&entry->oid, &entry_src->oid); - entry->attr = entry_src->attr; - - git_vector_insert(&bld->entries, entry); - } - } - - *builder_p = bld; - return GIT_SUCCESS; -} - -int git_treebuilder_insert(git_tree_entry **entry_out, git_treebuilder *bld, const char *filename, const git_oid *id, unsigned int attributes) -{ - git_tree_entry *entry; - int pos; - struct tree_key_search ksearch; - - assert(bld && id && filename); - - if (!valid_attributes(attributes)) - return git__throw(GIT_ERROR, "Failed to insert entry. Invalid attributes"); - - if (build_ksearch(&ksearch, filename) < GIT_SUCCESS) - return git__throw(GIT_ERROR, "Failed to insert entry. Invalid filename '%s'", filename); - - if ((pos = git_vector_bsearch2(&bld->entries, entry_search_cmp, &ksearch)) != GIT_ENOTFOUND) { - entry = git_vector_get(&bld->entries, pos); - if (entry->removed) { - entry->removed = 0; - bld->entry_count++; - } - } else { - if ((entry = git__malloc(sizeof(git_tree_entry))) == NULL) - return GIT_ENOMEM; - - memset(entry, 0x0, sizeof(git_tree_entry)); - entry->filename = git__strdup(filename); - entry->filename_len = strlen(entry->filename); - - bld->entry_count++; - } - - git_oid_cpy(&entry->oid, id); - entry->attr = attributes; - - if (pos == GIT_ENOTFOUND) { - if (git_vector_insert(&bld->entries, entry) < 0) - return GIT_ENOMEM; - } - - if (entry_out != NULL) - *entry_out = entry; - - return GIT_SUCCESS; -} - -static git_tree_entry *treebuilder_get(git_treebuilder *bld, const char *filename) -{ - int idx; - git_tree_entry *entry; - struct tree_key_search ksearch; - - assert(bld && filename); - - if (build_ksearch(&ksearch, filename) < GIT_SUCCESS) - return NULL; - - idx = git_vector_bsearch2(&bld->entries, entry_search_cmp, &ksearch); - if (idx == GIT_ENOTFOUND) - return NULL; - - entry = git_vector_get(&bld->entries, idx); - if (entry->removed) - return NULL; - - return entry; -} - -const git_tree_entry *git_treebuilder_get(git_treebuilder *bld, const char *filename) -{ - return treebuilder_get(bld, filename); -} - -int git_treebuilder_remove(git_treebuilder *bld, const char *filename) -{ - git_tree_entry *remove_ptr = treebuilder_get(bld, filename); - - if (remove_ptr == NULL || remove_ptr->removed) - return git__throw(GIT_ENOTFOUND, "Failed to remove entry. File isn't in the tree"); - - remove_ptr->removed = 1; - bld->entry_count--; - return GIT_SUCCESS; -} - -int git_treebuilder_write(git_oid *oid, git_repository *repo, git_treebuilder *bld) -{ - unsigned int i; - int error; - git_buf tree = GIT_BUF_INIT; - - assert(bld); - - sort_entries(bld); - - /* Grow the buffer beforehand to an estimated size */ - git_buf_grow(&tree, bld->entries.length * 72); - - for (i = 0; i < bld->entries.length; ++i) { - git_tree_entry *entry = bld->entries.contents[i]; - - if (entry->removed) - continue; - - git_buf_printf(&tree, "%o ", entry->attr); - git_buf_put(&tree, entry->filename, entry->filename_len + 1); - git_buf_put(&tree, (char *)entry->oid.id, GIT_OID_RAWSZ); - } - - if (git_buf_oom(&tree)) { - git_buf_free(&tree); - return git__throw(GIT_ENOMEM, "Not enough memory to build the tree data"); - } - - error = git_odb_write(oid, git_repository_database(repo), tree.ptr, tree.size, GIT_OBJ_TREE); - git_buf_free(&tree); - - return error == GIT_SUCCESS ? GIT_SUCCESS : git__rethrow(error, "Failed to write tree"); -} - -void git_treebuilder_filter(git_treebuilder *bld, int (*filter)(const git_tree_entry *, void *), void *payload) -{ - unsigned int i; - - assert(bld && filter); - - for (i = 0; i < bld->entries.length; ++i) { - git_tree_entry *entry = bld->entries.contents[i]; - if (!entry->removed && filter(entry, payload)) - entry->removed = 1; - } -} - -void git_treebuilder_clear(git_treebuilder *bld) -{ - unsigned int i; - assert(bld); - - for (i = 0; i < bld->entries.length; ++i) { - git_tree_entry *e = bld->entries.contents[i]; - free(e->filename); - free(e); - } - - git_vector_clear(&bld->entries); -} - -void git_treebuilder_free(git_treebuilder *bld) -{ - git_treebuilder_clear(bld); - git_vector_free(&bld->entries); - free(bld); -} - - diff --git a/vendor/libgit2/src/tree.h b/vendor/libgit2/src/tree.h deleted file mode 100644 index bff3f8edb..000000000 --- a/vendor/libgit2/src/tree.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef INCLUDE_tree_h__ -#define INCLUDE_tree_h__ - -#include "git2/tree.h" -#include "repository.h" -#include "odb.h" -#include "vector.h" - -struct git_tree_entry { - unsigned int attr; - char *filename; - git_oid oid; - size_t filename_len; - int removed; -}; - -struct git_tree { - git_object object; - git_vector entries; -}; - -struct git_treebuilder { - git_vector entries; - size_t entry_count; -}; - - -void git_tree__free(git_tree *tree); -int git_tree__parse(git_tree *tree, git_odb_object *obj); - -#endif diff --git a/vendor/libgit2/src/tsort.c b/vendor/libgit2/src/tsort.c deleted file mode 100644 index 14b15c232..000000000 --- a/vendor/libgit2/src/tsort.c +++ /dev/null @@ -1,359 +0,0 @@ - -#include "common.h" - -/** - * An array-of-pointers implementation of Python's Timsort - * Based on code by Christopher Swenson under the MIT license - * - * Copyright (c) 2010 Christopher Swenson - * Copyright (c) 2011 Vicent Marti - */ - -#ifndef MAX -# define MAX(x,y) (((x) > (y) ? (x) : (y))) -#endif - -#ifndef MIN -# define MIN(x,y) (((x) < (y) ? (x) : (y))) -#endif - -typedef int (*cmp_ptr_t)(const void *, const void *); - -static int binsearch(void **dst, const void *x, size_t size, cmp_ptr_t cmp) -{ - int l, c, r; - void *lx, *cx; - - l = 0; - r = size - 1; - c = r >> 1; - lx = dst[l]; - - /* check for beginning conditions */ - if (cmp(x, lx) < 0) - return 0; - - else if (cmp(x, lx) == 0) { - int i = 1; - while (cmp(x, dst[i]) == 0) - i++; - return i; - } - - /* guaranteed not to be >= rx */ - cx = dst[c]; - while (1) { - const int val = cmp(x, cx); - if (val < 0) { - if (c - l <= 1) return c; - r = c; - } else if (val > 0) { - if (r - c <= 1) return c + 1; - l = c; - lx = cx; - } else { - do { - cx = dst[++c]; - } while (cmp(x, cx) == 0); - return c; - } - c = l + ((r - l) >> 1); - cx = dst[c]; - } -} - -/* Binary insertion sort, but knowing that the first "start" entries are sorted. Used in timsort. */ -static void bisort(void **dst, size_t start, size_t size, cmp_ptr_t cmp) -{ - size_t i; - void *x; - int location; - - for (i = start; i < size; i++) { - int j; - /* If this entry is already correct, just move along */ - if (cmp(dst[i - 1], dst[i]) <= 0) - continue; - - /* Else we need to find the right place, shift everything over, and squeeze in */ - x = dst[i]; - location = binsearch(dst, x, i, cmp); - for (j = i - 1; j >= location; j--) { - dst[j + 1] = dst[j]; - } - dst[location] = x; - } -} - - -/* timsort implementation, based on timsort.txt */ -struct tsort_run { - ssize_t start; - ssize_t length; -}; - -struct tsort_store { - size_t alloc; - cmp_ptr_t cmp; - void **storage; -}; - -static void reverse_elements(void **dst, int start, int end) -{ - while (start < end) { - void *tmp = dst[start]; - dst[start] = dst[end]; - dst[end] = tmp; - - start++; - end--; - } -} - -static int count_run(void **dst, ssize_t start, ssize_t size, struct tsort_store *store) -{ - ssize_t curr = start + 2; - - if (size - start == 1) - return 1; - - if (start >= size - 2) { - if (store->cmp(dst[size - 2], dst[size - 1]) > 0) { - void *tmp = dst[size - 1]; - dst[size - 1] = dst[size - 2]; - dst[size - 2] = tmp; - } - - return 2; - } - - if (store->cmp(dst[start], dst[start + 1]) <= 0) { - while (curr < size - 1 && store->cmp(dst[curr - 1], dst[curr]) <= 0) - curr++; - - return curr - start; - } else { - while (curr < size - 1 && store->cmp(dst[curr - 1], dst[curr]) > 0) - curr++; - - /* reverse in-place */ - reverse_elements(dst, start, curr - 1); - return curr - start; - } -} - -static int compute_minrun(size_t n) -{ - int r = 0; - while (n >= 64) { - r |= n & 1; - n >>= 1; - } - return n + r; -} - -static int check_invariant(struct tsort_run *stack, int stack_curr) -{ - if (stack_curr < 2) - return 1; - - else if (stack_curr == 2) { - const int A = stack[stack_curr - 2].length; - const int B = stack[stack_curr - 1].length; - return (A > B); - } else { - const int A = stack[stack_curr - 3].length; - const int B = stack[stack_curr - 2].length; - const int C = stack[stack_curr - 1].length; - return !((A <= B + C) || (B <= C)); - } -} - -static int resize(struct tsort_store *store, size_t new_size) -{ - if (store->alloc < new_size) { - void **tempstore = realloc(store->storage, new_size * sizeof(void *)); - - /** - * Do not propagate on OOM; this will abort the sort and - * leave the array unsorted, but no error code will be - * raised - */ - if (tempstore == NULL) - return -1; - - store->storage = tempstore; - store->alloc = new_size; - } - - return 0; -} - -static void merge(void **dst, const struct tsort_run *stack, int stack_curr, struct tsort_store *store) -{ - const ssize_t A = stack[stack_curr - 2].length; - const ssize_t B = stack[stack_curr - 1].length; - const ssize_t curr = stack[stack_curr - 2].start; - - void **storage; - ssize_t i, j, k; - - if (resize(store, MIN(A, B)) < 0) - return; - - storage = store->storage; - - /* left merge */ - if (A < B) { - memcpy(storage, &dst[curr], A * sizeof(void *)); - i = 0; - j = curr + A; - - for (k = curr; k < curr + A + B; k++) { - if ((i < A) && (j < curr + A + B)) { - if (store->cmp(storage[i], dst[j]) <= 0) - dst[k] = storage[i++]; - else - dst[k] = dst[j++]; - } else if (i < A) { - dst[k] = storage[i++]; - } else - dst[k] = dst[j++]; - } - } else { - memcpy(storage, &dst[curr + A], B * sizeof(void *)); - i = B - 1; - j = curr + A - 1; - - for (k = curr + A + B - 1; k >= curr; k--) { - if ((i >= 0) && (j >= curr)) { - if (store->cmp(dst[j], storage[i]) > 0) - dst[k] = dst[j--]; - else - dst[k] = storage[i--]; - } else if (i >= 0) - dst[k] = storage[i--]; - else - dst[k] = dst[j--]; - } - } -} - -static ssize_t collapse(void **dst, struct tsort_run *stack, ssize_t stack_curr, struct tsort_store *store, ssize_t size) -{ - ssize_t A, B, C; - - while (1) { - /* if the stack only has one thing on it, we are done with the collapse */ - if (stack_curr <= 1) - break; - - /* if this is the last merge, just do it */ - if ((stack_curr == 2) && (stack[0].length + stack[1].length == size)) { - merge(dst, stack, stack_curr, store); - stack[0].length += stack[1].length; - stack_curr--; - break; - } - - /* check if the invariant is off for a stack of 2 elements */ - else if ((stack_curr == 2) && (stack[0].length <= stack[1].length)) { - merge(dst, stack, stack_curr, store); - stack[0].length += stack[1].length; - stack_curr--; - break; - } - else if (stack_curr == 2) - break; - - A = stack[stack_curr - 3].length; - B = stack[stack_curr - 2].length; - C = stack[stack_curr - 1].length; - - /* check first invariant */ - if (A <= B + C) { - if (A < C) { - merge(dst, stack, stack_curr - 1, store); - stack[stack_curr - 3].length += stack[stack_curr - 2].length; - stack[stack_curr - 2] = stack[stack_curr - 1]; - stack_curr--; - } else { - merge(dst, stack, stack_curr, store); - stack[stack_curr - 2].length += stack[stack_curr - 1].length; - stack_curr--; - } - } else if (B <= C) { - merge(dst, stack, stack_curr, store); - stack[stack_curr - 2].length += stack[stack_curr - 1].length; - stack_curr--; - } else - break; - } - - return stack_curr; -} - -#define PUSH_NEXT() do {\ - len = count_run(dst, curr, size, store);\ - run = minrun;\ - if (run < minrun) run = minrun;\ - if (run > (ssize_t)size - curr) run = size - curr;\ - if (run > len) {\ - bisort(&dst[curr], len, run, cmp);\ - len = run;\ - }\ - run_stack[stack_curr].start = curr;\ - run_stack[stack_curr++].length = len;\ - curr += len;\ - if (curr == (ssize_t)size) {\ - /* finish up */ \ - while (stack_curr > 1) { \ - merge(dst, run_stack, stack_curr, store); \ - run_stack[stack_curr - 2].length += run_stack[stack_curr - 1].length; \ - stack_curr--; \ - } \ - if (store->storage != NULL) {\ - free(store->storage);\ - store->storage = NULL;\ - }\ - return;\ - }\ -}\ -while (0) - -void git__tsort(void **dst, size_t size, cmp_ptr_t cmp) -{ - struct tsort_store _store, *store = &_store; - struct tsort_run run_stack[128]; - - ssize_t stack_curr = 0; - ssize_t len, run; - ssize_t curr = 0; - ssize_t minrun; - - if (size < 64) { - bisort(dst, 1, size, cmp); - return; - } - - /* compute the minimum run length */ - minrun = compute_minrun(size); - - /* temporary storage for merges */ - store->alloc = 0; - store->storage = NULL; - store->cmp = cmp; - - PUSH_NEXT(); - PUSH_NEXT(); - PUSH_NEXT(); - - while (1) { - if (!check_invariant(run_stack, stack_curr)) { - stack_curr = collapse(dst, run_stack, stack_curr, store, size); - continue; - } - - PUSH_NEXT(); - } -} diff --git a/vendor/libgit2/src/unix/map.c b/vendor/libgit2/src/unix/map.c deleted file mode 100644 index 5192c8e4c..000000000 --- a/vendor/libgit2/src/unix/map.c +++ /dev/null @@ -1,64 +0,0 @@ -#include - -#ifndef GIT_WIN32 - -#include "map.h" -#include -#include - -int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset) -{ - int mprot = 0; - int mflag = 0; - - assert((out != NULL) && (len > 0)); - - if ((out == NULL) || (len == 0)) { - errno = EINVAL; - return git__throw(GIT_ERROR, "Failed to mmap. No map or zero length"); - } - - out->data = NULL; - out->len = 0; - - if (prot & GIT_PROT_WRITE) - mprot = PROT_WRITE; - else if (prot & GIT_PROT_READ) - mprot = PROT_READ; - else { - errno = EINVAL; - return git__throw(GIT_ERROR, "Failed to mmap. Invalid protection parameters"); - } - - if ((flags & GIT_MAP_TYPE) == GIT_MAP_SHARED) - mflag = MAP_SHARED; - else if ((flags & GIT_MAP_TYPE) == GIT_MAP_PRIVATE) - mflag = MAP_PRIVATE; - - if (flags & GIT_MAP_FIXED) { - errno = EINVAL; - return git__throw(GIT_ERROR, "Failed to mmap. FIXED not set"); - } - - out->data = mmap(NULL, len, mprot, mflag, fd, offset); - if (!out->data || out->data == MAP_FAILED) - return git__throw(GIT_EOSERR, "Failed to mmap. Could not write data"); - out->len = len; - - return GIT_SUCCESS; -} - -int p_munmap(git_map *map) -{ - assert(map != NULL); - - if (!map) - return git__throw(GIT_ERROR, "Failed to munmap. Map does not exist"); - - munmap(map->data, map->len); - - return GIT_SUCCESS; -} - -#endif - diff --git a/vendor/libgit2/src/unix/posix.h b/vendor/libgit2/src/unix/posix.h deleted file mode 100644 index a49a5cfe7..000000000 --- a/vendor/libgit2/src/unix/posix.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef INCLUDE_posix__w32_h__ -#define INCLUDE_posix__w32_h__ - -#include - -#define p_lstat(p,b) lstat(p,b) -#define p_readlink(a, b, c) readlink(a, b, c) -#define p_link(o,n) link(o, n) -#define p_unlink(p) unlink(p) -#define p_mkdir(p,m) mkdir(p, m) -#define p_fsync(fd) fsync(fd) -#define p_realpath(p, po) realpath(p, po) -#define p_fnmatch(p, s, f) fnmatch(p, s, f) -#define p_vsnprintf(b, c, f, a) vsnprintf(b, c, f, a) -#define p_snprintf(b, c, f, ...) snprintf(b, c, f, __VA_ARGS__) -#define p_mkstemp(p) mkstemp(p) - -#endif diff --git a/vendor/libgit2/src/util.c b/vendor/libgit2/src/util.c deleted file mode 100644 index 29bf755f8..000000000 --- a/vendor/libgit2/src/util.c +++ /dev/null @@ -1,357 +0,0 @@ -#include -#include "common.h" -#include -#include -#include -#include "posix.h" - -#ifdef _MSC_VER -# include -#endif - -void git_libgit2_version(int *major, int *minor, int *rev) -{ - *major = LIBGIT2_VER_MAJOR; - *minor = LIBGIT2_VER_MINOR; - *rev = LIBGIT2_VER_REVISION; -} - -void git_strarray_free(git_strarray *array) -{ - size_t i; - for (i = 0; i < array->count; ++i) - free(array->strings[i]); - - free(array->strings); -} - -int git__fnmatch(const char *pattern, const char *name, int flags) -{ - int ret; - - ret = p_fnmatch(pattern, name, flags); - switch (ret) { - case 0: - return GIT_SUCCESS; - case FNM_NOMATCH: - return GIT_ENOMATCH; - default: - return git__throw(GIT_EOSERR, "Error trying to match path"); - } -} - -int git__strtol32(long *result, const char *nptr, const char **endptr, int base) -{ - const char *p; - long n, nn; - int c, ovfl, v, neg, ndig; - - p = nptr; - neg = 0; - n = 0; - ndig = 0; - ovfl = 0; - - /* - * White space - */ - while (isspace(*p)) - p++; - - /* - * Sign - */ - if (*p == '-' || *p == '+') - if (*p++ == '-') - neg = 1; - - /* - * Base - */ - if (base == 0) { - if (*p != '0') - base = 10; - else { - base = 8; - if (p[1] == 'x' || p[1] == 'X') { - p += 2; - base = 16; - } - } - } else if (base == 16 && *p == '0') { - if (p[1] == 'x' || p[1] == 'X') - p += 2; - } else if (base < 0 || 36 < base) - goto Return; - - /* - * Non-empty sequence of digits - */ - for (;; p++,ndig++) { - c = *p; - v = base; - if ('0'<=c && c<='9') - v = c - '0'; - else if ('a'<=c && c<='z') - v = c - 'a' + 10; - else if ('A'<=c && c<='Z') - v = c - 'A' + 10; - if (v >= base) - break; - nn = n*base + v; - if (nn < n) - ovfl = 1; - n = nn; - } - -Return: - if (ndig == 0) - return git__throw(GIT_ENOTNUM, "Failed to convert string to long. Not a number"); - - if (endptr) - *endptr = p; - - if (ovfl) - return git__throw(GIT_EOVERFLOW, "Failed to convert string to long. Overflow error"); - - *result = neg ? -n : n; - return GIT_SUCCESS; -} - -void git__strntolower(char *str, int len) -{ - int i; - - for (i = 0; i < len; ++i) { - str[i] = (char) tolower(str[i]); - } -} - -void git__strtolower(char *str) -{ - git__strntolower(str, strlen(str)); -} - -int git__prefixcmp(const char *str, const char *prefix) -{ - for (;;) { - char p = *(prefix++), s; - if (!p) - return 0; - if ((s = *(str++)) != p) - return s - p; - } -} - -int git__suffixcmp(const char *str, const char *suffix) -{ - size_t a = strlen(str); - size_t b = strlen(suffix); - if (a < b) - return -1; - return strcmp(str + (a - b), suffix); -} - -char *git__strtok(char **end, const char *sep) -{ - char *ptr = *end; - - while (*ptr && strchr(sep, *ptr)) - ++ptr; - - if (*ptr) { - char *start = ptr; - *end = start + 1; - - while (**end && !strchr(sep, **end)) - ++*end; - - if (**end) { - **end = '\0'; - ++*end; - } - - return start; - } - - return NULL; -} - -void git__hexdump(const char *buffer, size_t len) -{ - static const size_t LINE_WIDTH = 16; - - size_t line_count, last_line, i, j; - const char *line; - - line_count = (len / LINE_WIDTH); - last_line = (len % LINE_WIDTH); - - for (i = 0; i < line_count; ++i) { - line = buffer + (i * LINE_WIDTH); - for (j = 0; j < LINE_WIDTH; ++j, ++line) - printf("%02X ", (unsigned char)*line & 0xFF); - - printf("| "); - - line = buffer + (i * LINE_WIDTH); - for (j = 0; j < LINE_WIDTH; ++j, ++line) - printf("%c", (*line >= 32 && *line <= 126) ? *line : '.'); - - printf("\n"); - } - - if (last_line > 0) { - - line = buffer + (line_count * LINE_WIDTH); - for (j = 0; j < last_line; ++j, ++line) - printf("%02X ", (unsigned char)*line & 0xFF); - - for (j = 0; j < (LINE_WIDTH - last_line); ++j) - printf(" "); - - printf("| "); - - line = buffer + (line_count * LINE_WIDTH); - for (j = 0; j < last_line; ++j, ++line) - printf("%c", (*line >= 32 && *line <= 126) ? *line : '.'); - - printf("\n"); - } - - printf("\n"); -} - -#ifdef GIT_LEGACY_HASH -uint32_t git__hash(const void *key, int len, unsigned int seed) -{ - const uint32_t m = 0x5bd1e995; - const int r = 24; - uint32_t h = seed ^ len; - - const unsigned char *data = (const unsigned char *)key; - - while(len >= 4) { - uint32_t k = *(uint32_t *)data; - - k *= m; - k ^= k >> r; - k *= m; - - h *= m; - h ^= k; - - data += 4; - len -= 4; - } - - switch(len) { - case 3: h ^= data[2] << 16; - case 2: h ^= data[1] << 8; - case 1: h ^= data[0]; - h *= m; - }; - - h ^= h >> 13; - h *= m; - h ^= h >> 15; - - return h; -} -#else -/* - Cross-platform version of Murmurhash3 - http://code.google.com/p/smhasher/wiki/MurmurHash3 - by Austin Appleby (aappleby@gmail.com) - - This code is on the public domain. -*/ -uint32_t git__hash(const void *key, int len, uint32_t seed) -{ - -#define MURMUR_BLOCK() {\ - k1 *= c1; \ - k1 = git__rotl(k1,11);\ - k1 *= c2;\ - h1 ^= k1;\ - h1 = h1*3 + 0x52dce729;\ - c1 = c1*5 + 0x7b7d159c;\ - c2 = c2*5 + 0x6bce6396;\ -} - - const uint8_t *data = (const uint8_t*)key; - const int nblocks = len / 4; - - const uint32_t *blocks = (const uint32_t *)(data + nblocks * 4); - const uint8_t *tail = (const uint8_t *)(data + nblocks * 4); - - uint32_t h1 = 0x971e137b ^ seed; - uint32_t k1; - - uint32_t c1 = 0x95543787; - uint32_t c2 = 0x2ad7eb25; - - int i; - - for (i = -nblocks; i; i++) { - k1 = blocks[i]; - MURMUR_BLOCK(); - } - - k1 = 0; - - switch(len & 3) { - case 3: k1 ^= tail[2] << 16; - case 2: k1 ^= tail[1] << 8; - case 1: k1 ^= tail[0]; - MURMUR_BLOCK(); - } - - h1 ^= len; - h1 ^= h1 >> 16; - h1 *= 0x85ebca6b; - h1 ^= h1 >> 13; - h1 *= 0xc2b2ae35; - h1 ^= h1 >> 16; - - return h1; -} -#endif - -/** - * A modified `bsearch` from the BSD glibc. - * - * Copyright (c) 1990 Regents of the University of California. - * All rights reserved. - */ -void **git__bsearch(const void *key, void **base, size_t nmemb, int (*compar)(const void *, const void *)) -{ - int lim, cmp; - void **p; - - for (lim = nmemb; lim != 0; lim >>= 1) { - p = base + (lim >> 1); - cmp = (*compar)(key, *p); - if (cmp > 0) { /* key > p: move right */ - base = p + 1; - lim--; - } else if (cmp == 0) { - return (void **)p; - } /* else move left */ - } - return NULL; -} - -/** - * A strcmp wrapper - * - * We don't want direct pointers to the CRT on Windows, we may - * get stdcall conflicts. - */ -int git__strcmp_cb(const void *a, const void *b) -{ - const char *stra = (const char *)a; - const char *strb = (const char *)b; - - return strcmp(stra, strb); -} diff --git a/vendor/libgit2/src/util.h b/vendor/libgit2/src/util.h deleted file mode 100644 index 78f9f8276..000000000 --- a/vendor/libgit2/src/util.h +++ /dev/null @@ -1,123 +0,0 @@ -#ifndef INCLUDE_util_h__ -#define INCLUDE_util_h__ - -#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0])) -#define bitsizeof(x) (CHAR_BIT * sizeof(x)) -#define MSB(x, bits) ((x) & (~0ULL << (bitsizeof(x) - (bits)))) -#ifndef min -# define min(a,b) ((a) < (b) ? (a) : (b)) -#endif - -/* - * Custom memory allocation wrappers - * that set error code and error message - * on allocation failure - */ -GIT_INLINE(void *) git__malloc(size_t len) -{ - void *ptr = malloc(len); - if (!ptr) - git__throw(GIT_ENOMEM, "Out of memory. Failed to allocate %d bytes.", (int)len); - return ptr; -} - -GIT_INLINE(void *) git__calloc(size_t nelem, size_t elsize) -{ - void *ptr = calloc(nelem, elsize); - if (!ptr) - git__throw(GIT_ENOMEM, "Out of memory. Failed to allocate %d bytes.", (int)elsize); - return ptr; -} - -GIT_INLINE(char *) git__strdup(const char *str) -{ - char *ptr = strdup(str); - if (!ptr) - git__throw(GIT_ENOMEM, "Out of memory. Failed to duplicate string"); - return ptr; -} - -GIT_INLINE(char *) git__strndup(const char *str, size_t n) -{ - size_t length; - char *ptr; - - length = strlen(str); - if (n < length) - length = n; - - ptr = (char*)malloc(length + 1); - if (!ptr) { - git__throw(GIT_ENOMEM, "Out of memory. Failed to duplicate string"); - return NULL; - } - - memcpy(ptr, str, length); - ptr[length] = '\0'; - - return ptr; -} - -GIT_INLINE(void *) git__realloc(void *ptr, size_t size) -{ - void *new_ptr = realloc(ptr, size); - if (!new_ptr) - git__throw(GIT_ENOMEM, "Out of memory. Failed to allocate %d bytes.", (int)size); - return new_ptr; -} - -extern int git__prefixcmp(const char *str, const char *prefix); -extern int git__suffixcmp(const char *str, const char *suffix); - -extern int git__strtol32(long *n, const char *buff, const char **end_buf, int base); - -extern void git__hexdump(const char *buffer, size_t n); -extern uint32_t git__hash(const void *key, int len, uint32_t seed); - -/** @return true if p fits into the range of a size_t */ -GIT_INLINE(int) git__is_sizet(git_off_t p) -{ - size_t r = (size_t)p; - return p == (git_off_t)r; -} - -/* 32-bit cross-platform rotl */ -#ifdef _MSC_VER /* use built-in method in MSVC */ -# define git__rotl(v, s) (uint32_t)_rotl(v, s) -#else /* use bitops in GCC; with o2 this gets optimized to a rotl instruction */ -# define git__rotl(v, s) (uint32_t)(((uint32_t)(v) << (s)) | ((uint32_t)(v) >> (32 - (s)))) -#endif - -extern char *git__strtok(char **end, const char *sep); - -extern void git__strntolower(char *str, int len); -extern void git__strtolower(char *str); - -extern int git__fnmatch(const char *pattern, const char *name, int flags); - -/* - * Realloc the buffer pointed at by variable 'x' so that it can hold - * at least 'nr' entries; the number of entries currently allocated - * is 'alloc', using the standard growing factor alloc_nr() macro. - * - * DO NOT USE any expression with side-effect for 'x' or 'alloc'. - */ -#define alloc_nr(x) (((x)+16)*3/2) -#define ALLOC_GROW(x, nr, alloc) \ - do { \ - if ((nr) > alloc) { \ - if (alloc_nr(alloc) < (nr)) \ - alloc = (nr); \ - else \ - alloc = alloc_nr(alloc); \ - x = xrealloc((x), alloc * sizeof(*(x))); \ - } \ - } while (0) - -extern void git__tsort(void **dst, size_t size, int (*cmp)(const void *, const void *)); -extern void **git__bsearch(const void *key, void **base, size_t nmemb, - int (*compar)(const void *, const void *)); - -extern int git__strcmp_cb(const void *a, const void *b); - -#endif /* INCLUDE_util_h__ */ diff --git a/vendor/libgit2/src/vector.c b/vendor/libgit2/src/vector.c deleted file mode 100644 index 0b83b8b0d..000000000 --- a/vendor/libgit2/src/vector.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "repository.h" -#include "vector.h" - -static const double resize_factor = 1.75; -static const size_t minimum_size = 8; - -static int resize_vector(git_vector *v) -{ - v->_alloc_size = ((unsigned int)(v->_alloc_size * resize_factor)) + 1; - if (v->_alloc_size < minimum_size) - v->_alloc_size = minimum_size; - - v->contents = realloc(v->contents, v->_alloc_size * sizeof(void *)); - if (v->contents == NULL) - return GIT_ENOMEM; - - return GIT_SUCCESS; -} - - -void git_vector_free(git_vector *v) -{ - assert(v); - free(v->contents); -} - -int git_vector_init(git_vector *v, unsigned int initial_size, git_vector_cmp cmp) -{ - assert(v); - - memset(v, 0x0, sizeof(git_vector)); - - if (initial_size == 0) - initial_size = minimum_size; - - v->_alloc_size = initial_size; - v->_cmp = cmp; - - v->length = 0; - v->sorted = 1; - - v->contents = git__malloc(v->_alloc_size * sizeof(void *)); - if (v->contents == NULL) - return GIT_ENOMEM; - - return GIT_SUCCESS; -} - -int git_vector_insert(git_vector *v, void *element) -{ - assert(v); - - if (v->length >= v->_alloc_size) { - if (resize_vector(v) < 0) - return GIT_ENOMEM; - } - - v->contents[v->length++] = element; - v->sorted = 0; - - return GIT_SUCCESS; -} - -void git_vector_sort(git_vector *v) -{ - assert(v); - - if (v->sorted || v->_cmp == NULL) - return; - - git__tsort(v->contents, v->length, v->_cmp); - v->sorted = 1; -} - -int git_vector_bsearch2(git_vector *v, git_vector_cmp key_lookup, const void *key) -{ - void **find; - - assert(v && key && key_lookup); - - /* need comparison function to sort the vector */ - if (v->_cmp == NULL) - return git__throw(GIT_ENOTFOUND, "Can't sort vector. No comparison function set"); - - git_vector_sort(v); - - find = git__bsearch(key, v->contents, v->length, key_lookup); - if (find != NULL) - return (int)(find - v->contents); - - return git__throw(GIT_ENOTFOUND, "Can't find element"); -} - -int git_vector_search2(git_vector *v, git_vector_cmp key_lookup, const void *key) -{ - unsigned int i; - - assert(v && key && key_lookup); - - for (i = 0; i < v->length; ++i) { - if (key_lookup(key, v->contents[i]) == 0) - return i; - } - - return git__throw(GIT_ENOTFOUND, "Can't find element"); -} - -static int strict_comparison(const void *a, const void *b) -{ - return (a == b) ? 0 : -1; -} - -int git_vector_search(git_vector *v, const void *entry) -{ - return git_vector_search2(v, v->_cmp ? v->_cmp : strict_comparison, entry); -} - -int git_vector_bsearch(git_vector *v, const void *key) -{ - return git_vector_bsearch2(v, v->_cmp, key); -} - -int git_vector_remove(git_vector *v, unsigned int idx) -{ - unsigned int i; - - assert(v); - - if (idx >= v->length || v->length == 0) - return git__throw(GIT_ENOTFOUND, "Can't remove element. Index out of bounds"); - - for (i = idx; i < v->length - 1; ++i) - v->contents[i] = v->contents[i + 1]; - - v->length--; - return GIT_SUCCESS; -} - -void git_vector_uniq(git_vector *v) -{ - git_vector_cmp cmp; - unsigned int i, j; - - if (v->length <= 1) - return; - - git_vector_sort(v); - cmp = v->_cmp ? v->_cmp : strict_comparison; - - for (i = 0, j = 1 ; j < v->length; ++j) - if (!cmp(v->contents[i], v->contents[j])) - v->contents[i] = v->contents[j]; - else - v->contents[++i] = v->contents[j]; - - v->length -= j - i - 1; -} - -void git_vector_clear(git_vector *v) -{ - assert(v); - v->length = 0; - v->sorted = 1; -} - - diff --git a/vendor/libgit2/src/vector.h b/vendor/libgit2/src/vector.h deleted file mode 100644 index c43a7ce07..000000000 --- a/vendor/libgit2/src/vector.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef INCLUDE_vector_h__ -#define INCLUDE_vector_h__ - -#include "git2/common.h" - -typedef int (*git_vector_cmp)(const void *, const void *); - -typedef struct git_vector { - unsigned int _alloc_size; - git_vector_cmp _cmp; - void **contents; - unsigned int length; - int sorted; -} git_vector; - -int git_vector_init(git_vector *v, unsigned int initial_size, git_vector_cmp cmp); -void git_vector_free(git_vector *v); -void git_vector_clear(git_vector *v); - -int git_vector_search(git_vector *v, const void *entry); -int git_vector_search2(git_vector *v, git_vector_cmp cmp, const void *key); - -int git_vector_bsearch(git_vector *v, const void *entry); -int git_vector_bsearch2(git_vector *v, git_vector_cmp cmp, const void *key); - -void git_vector_sort(git_vector *v); - -GIT_INLINE(void *) git_vector_get(git_vector *v, unsigned int position) -{ - return (position < v->length) ? v->contents[position] : NULL; -} - -#define git_vector_foreach(v, iter, elem) \ - for ((iter) = 0; (iter) < (v)->length && ((elem) = (v)->contents[(iter)], 1); (iter)++ ) - -int git_vector_insert(git_vector *v, void *element); -int git_vector_remove(git_vector *v, unsigned int idx); -void git_vector_uniq(git_vector *v); -#endif diff --git a/vendor/libgit2/src/win32/dir.c b/vendor/libgit2/src/win32/dir.c deleted file mode 100644 index 069a41c3a..000000000 --- a/vendor/libgit2/src/win32/dir.c +++ /dev/null @@ -1,98 +0,0 @@ -#define GIT__WIN32_NO_WRAP_DIR -#include "dir.h" - -static int init_filter(char *filter, size_t n, const char *dir) -{ - size_t len = strlen(dir); - - if (len+3 >= n) - return 0; - - strcpy(filter, dir); - if (len && dir[len-1] != '/') - strcat(filter, "/"); - strcat(filter, "*"); - - return 1; -} - -git__DIR *git__opendir(const char *dir) -{ - char filter[4096]; - git__DIR *new; - - if (!dir || !init_filter(filter, sizeof(filter), dir)) - return NULL; - - new = git__malloc(sizeof(*new)); - if (!new) - return NULL; - - new->dir = git__malloc(strlen(dir)+1); - if (!new->dir) { - free(new); - return NULL; - } - strcpy(new->dir, dir); - - new->h = FindFirstFile(filter, &new->f); - if (new->h == INVALID_HANDLE_VALUE) { - free(new->dir); - free(new); - return NULL; - } - new->first = 1; - - return new; -} - -struct git__dirent *git__readdir(git__DIR *d) -{ - if (!d || d->h == INVALID_HANDLE_VALUE) - return NULL; - - if (d->first) - d->first = 0; - else { - if (!FindNextFile(d->h, &d->f)) - return NULL; - } - - if (strlen(d->f.cFileName) >= sizeof(d->entry.d_name)) - return NULL; - - d->entry.d_ino = 0; - strcpy(d->entry.d_name, d->f.cFileName); - - return &d->entry; -} - -void git__rewinddir(git__DIR *d) -{ - char filter[4096]; - - if (d) { - if (d->h != INVALID_HANDLE_VALUE) - FindClose(d->h); - d->h = INVALID_HANDLE_VALUE; - d->first = 0; - if (init_filter(filter, sizeof(filter), d->dir)) { - d->h = FindFirstFile(filter, &d->f); - if (d->h != INVALID_HANDLE_VALUE) - d->first = 1; - } - } -} - -int git__closedir(git__DIR *d) -{ - if (d) { - if (d->h != INVALID_HANDLE_VALUE) - FindClose(d->h); - if (d->dir) - free(d->dir); - free(d); - } - return 0; -} - diff --git a/vendor/libgit2/src/win32/fileops.c b/vendor/libgit2/src/win32/fileops.c deleted file mode 100644 index d435e706e..000000000 --- a/vendor/libgit2/src/win32/fileops.c +++ /dev/null @@ -1,41 +0,0 @@ -#define GIT__WIN32_NO_HIDE_FILEOPS -#include "fileops.h" -#include - -int git__unlink(const char *path) -{ - chmod(path, 0666); - return unlink(path); -} - -int git__mkstemp(char *template) -{ - char *file = mktemp(template); - if (file == NULL) - return -1; - return open(file, O_RDWR | O_CREAT | O_BINARY, 0600); -} - -int git__fsync(int fd) -{ - HANDLE fh = (HANDLE)_get_osfhandle(fd); - - if (fh == INVALID_HANDLE_VALUE) { - errno = EBADF; - return -1; - } - - if (!FlushFileBuffers(fh)) { - DWORD code = GetLastError(); - - if (code == ERROR_INVALID_HANDLE) - errno = EINVAL; - else - errno = EIO; - - return -1; - } - - return 0; -} - diff --git a/vendor/libgit2/src/win32/fnmatch.c b/vendor/libgit2/src/win32/fnmatch.c deleted file mode 100644 index de2f3e74f..000000000 --- a/vendor/libgit2/src/win32/fnmatch.c +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 1989, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Guido van Rossum. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -/* - * Function fnmatch() as specified in POSIX 1003.2-1992, section B.6. - * Compares a filename or pathname to a pattern. - */ - -#include -#include -#include - -#include "fnmatch.h" - -#define EOS '\0' - -#define RANGE_MATCH 1 -#define RANGE_NOMATCH 0 -#define RANGE_ERROR (-1) - -static int rangematch(const char *, char, int, char **); - -int -p_fnmatch(const char *pattern, const char *string, int flags) -{ - const char *stringstart; - char *newp; - char c, test; - - for (stringstart = string;;) - switch (c = *pattern++) { - case EOS: - if ((flags & FNM_LEADING_DIR) && *string == '/') - return (0); - return (*string == EOS ? 0 : FNM_NOMATCH); - case '?': - if (*string == EOS) - return (FNM_NOMATCH); - if (*string == '/' && (flags & FNM_PATHNAME)) - return (FNM_NOMATCH); - if (*string == '.' && (flags & FNM_PERIOD) && - (string == stringstart || - ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) - return (FNM_NOMATCH); - ++string; - break; - case '*': - c = *pattern; - /* Collapse multiple stars. */ - while (c == '*') - c = *++pattern; - - if (*string == '.' && (flags & FNM_PERIOD) && - (string == stringstart || - ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) - return (FNM_NOMATCH); - - /* Optimize for pattern with * at end or before /. */ - if (c == EOS) { - if (flags & FNM_PATHNAME) - return ((flags & FNM_LEADING_DIR) || - strchr(string, '/') == NULL ? - 0 : FNM_NOMATCH); - else - return (0); - } else if (c == '/' && (flags & FNM_PATHNAME)) { - if ((string = strchr(string, '/')) == NULL) - return (FNM_NOMATCH); - break; - } - - /* General case, use recursion. */ - while ((test = *string) != EOS) { - if (!p_fnmatch(pattern, string, flags & ~FNM_PERIOD)) - return (0); - if (test == '/' && (flags & FNM_PATHNAME)) - break; - ++string; - } - return (FNM_NOMATCH); - case '[': - if (*string == EOS) - return (FNM_NOMATCH); - if (*string == '/' && (flags & FNM_PATHNAME)) - return (FNM_NOMATCH); - if (*string == '.' && (flags & FNM_PERIOD) && - (string == stringstart || - ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) - return (FNM_NOMATCH); - - switch (rangematch(pattern, *string, flags, &newp)) { - case RANGE_ERROR: - /* not a good range, treat as normal text */ - goto normal; - case RANGE_MATCH: - pattern = newp; - break; - case RANGE_NOMATCH: - return (FNM_NOMATCH); - } - ++string; - break; - case '\\': - if (!(flags & FNM_NOESCAPE)) { - if ((c = *pattern++) == EOS) { - c = '\\'; - --pattern; - } - } - /* FALLTHROUGH */ - default: - normal: - if (c != *string && !((flags & FNM_CASEFOLD) && - (tolower((unsigned char)c) == - tolower((unsigned char)*string)))) - return (FNM_NOMATCH); - ++string; - break; - } - /* NOTREACHED */ -} - -static int -rangematch(const char *pattern, char test, int flags, char **newp) -{ - int negate, ok; - char c, c2; - - /* - * A bracket expression starting with an unquoted circumflex - * character produces unspecified results (IEEE 1003.2-1992, - * 3.13.2). This implementation treats it like '!', for - * consistency with the regular expression syntax. - * J.T. Conklin (conklin@ngai.kaleida.com) - */ - if ((negate = (*pattern == '!' || *pattern == '^')) != 0) - ++pattern; - - if (flags & FNM_CASEFOLD) - test = (char)tolower((unsigned char)test); - - /* - * A right bracket shall lose its special meaning and represent - * itself in a bracket expression if it occurs first in the list. - * -- POSIX.2 2.8.3.2 - */ - ok = 0; - c = *pattern++; - do { - if (c == '\\' && !(flags & FNM_NOESCAPE)) - c = *pattern++; - if (c == EOS) - return (RANGE_ERROR); - if (c == '/' && (flags & FNM_PATHNAME)) - return (RANGE_NOMATCH); - if ((flags & FNM_CASEFOLD)) - c = (char)tolower((unsigned char)c); - if (*pattern == '-' - && (c2 = *(pattern+1)) != EOS && c2 != ']') { - pattern += 2; - if (c2 == '\\' && !(flags & FNM_NOESCAPE)) - c2 = *pattern++; - if (c2 == EOS) - return (RANGE_ERROR); - if (flags & FNM_CASEFOLD) - c2 = (char)tolower((unsigned char)c2); - if (c <= test && test <= c2) - ok = 1; - } else if (c == test) - ok = 1; - } while ((c = *pattern++) != ']'); - - *newp = (char *)pattern; - return (ok == negate ? RANGE_NOMATCH : RANGE_MATCH); -} - diff --git a/vendor/libgit2/src/win32/fnmatch.h b/vendor/libgit2/src/win32/fnmatch.h deleted file mode 100644 index 1309c6e9a..000000000 --- a/vendor/libgit2/src/win32/fnmatch.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2008 The Android Open Source Project - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT - * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ -#ifndef INCLUDE_fnmatch__w32_h__ -#define INCLUDE_fnmatch__w32_h__ - -#include "common.h" - -#define FNM_NOMATCH 1 /* Match failed. */ -#define FNM_NOSYS 2 /* Function not supported (unused). */ - -#define FNM_NOESCAPE 0x01 /* Disable backslash escaping. */ -#define FNM_PATHNAME 0x02 /* Slash must be matched by slash. */ -#define FNM_PERIOD 0x04 /* Period must be matched by period. */ -#define FNM_LEADING_DIR 0x08 /* Ignore / after Imatch. */ -#define FNM_CASEFOLD 0x10 /* Case insensitive search. */ - -#define FNM_IGNORECASE FNM_CASEFOLD -#define FNM_FILE_NAME FNM_PATHNAME - -extern int p_fnmatch(const char *pattern, const char *string, int flags); - -#endif /* _FNMATCH_H */ - diff --git a/vendor/libgit2/src/win32/map.c b/vendor/libgit2/src/win32/map.c deleted file mode 100644 index 76b926490..000000000 --- a/vendor/libgit2/src/win32/map.c +++ /dev/null @@ -1,125 +0,0 @@ - -#include "map.h" -#include - - -static DWORD get_page_size(void) -{ - static DWORD page_size; - SYSTEM_INFO sys; - - if (!page_size) { - GetSystemInfo(&sys); - page_size = sys.dwAllocationGranularity; - } - - return page_size; -} - -int p_mmap(git_map *out, size_t len, int prot, int flags, int fd, git_off_t offset) -{ - HANDLE fh = (HANDLE)_get_osfhandle(fd); - DWORD page_size = get_page_size(); - DWORD fmap_prot = 0; - DWORD view_prot = 0; - DWORD off_low = 0; - DWORD off_hi = 0; - git_off_t page_start; - git_off_t page_offset; - - assert((out != NULL) && (len > 0)); - - if ((out == NULL) || (len == 0)) { - errno = EINVAL; - return git__throw(GIT_ERROR, "Failed to mmap. No map or zero length"); - } - - out->data = NULL; - out->len = 0; - out->fmh = NULL; - - if (fh == INVALID_HANDLE_VALUE) { - errno = EBADF; - return git__throw(GIT_ERROR, "Failed to mmap. Invalid handle value"); - } - - if (prot & GIT_PROT_WRITE) - fmap_prot |= PAGE_READWRITE; - else if (prot & GIT_PROT_READ) - fmap_prot |= PAGE_READONLY; - else { - errno = EINVAL; - return git__throw(GIT_ERROR, "Failed to mmap. Invalid protection parameters"); - } - - if (prot & GIT_PROT_WRITE) - view_prot |= FILE_MAP_WRITE; - if (prot & GIT_PROT_READ) - view_prot |= FILE_MAP_READ; - - if (flags & GIT_MAP_FIXED) { - errno = EINVAL; - return git__throw(GIT_ERROR, "Failed to mmap. FIXED not set"); - } - - page_start = (offset / page_size) * page_size; - page_offset = offset - page_start; - - if (page_offset != 0) { /* offset must be multiple of page size */ - errno = EINVAL; - return git__throw(GIT_ERROR, "Failed to mmap. Offset must be multiple of page size"); - } - - out->fmh = CreateFileMapping(fh, NULL, fmap_prot, 0, 0, NULL); - if (!out->fmh || out->fmh == INVALID_HANDLE_VALUE) { - /* errno = ? */ - out->fmh = NULL; - return git__throw(GIT_ERROR, "Failed to mmap. Invalid handle value"); - } - - assert(sizeof(git_off_t) == 8); - off_low = (DWORD)(page_start); - off_hi = (DWORD)(page_start >> 32); - out->data = MapViewOfFile(out->fmh, view_prot, off_hi, off_low, len); - if (!out->data) { - /* errno = ? */ - CloseHandle(out->fmh); - out->fmh = NULL; - return git__throw(GIT_ERROR, "Failed to mmap. No data written"); - } - out->len = len; - - return GIT_SUCCESS; -} - -int p_munmap(git_map *map) -{ - assert(map != NULL); - - if (!map) - return git__throw(GIT_ERROR, "Failed to munmap. Map does not exist"); - - if (map->data) { - if (!UnmapViewOfFile(map->data)) { - /* errno = ? */ - CloseHandle(map->fmh); - map->data = NULL; - map->fmh = NULL; - return git__throw(GIT_ERROR, "Failed to munmap. Could not unmap view of file"); - } - map->data = NULL; - } - - if (map->fmh) { - if (!CloseHandle(map->fmh)) { - /* errno = ? */ - map->fmh = NULL; - return git__throw(GIT_ERROR, "Failed to munmap. Could not close handle"); - } - map->fmh = NULL; - } - - return GIT_SUCCESS; -} - - diff --git a/vendor/libgit2/src/win32/mingw-compat.h b/vendor/libgit2/src/win32/mingw-compat.h deleted file mode 100644 index 64d780b16..000000000 --- a/vendor/libgit2/src/win32/mingw-compat.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef INCLUDE_mingw_compat__ -#define INCLUDE_mingw_compat__ - -#if defined(__MINGW32__) - -/* use a 64-bit file offset type */ -# define lseek _lseeki64 -# define stat _stati64 -# define fstat _fstati64 - -/* stat: file mode type testing macros */ -# define _S_IFLNK 0120000 -# define S_IFLNK _S_IFLNK -# define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) - -#endif - -#endif /* INCLUDE_mingw_compat__ */ diff --git a/vendor/libgit2/src/win32/msvc-compat.h b/vendor/libgit2/src/win32/msvc-compat.h deleted file mode 100644 index df3e62d11..000000000 --- a/vendor/libgit2/src/win32/msvc-compat.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef INCLUDE_msvc_compat__ -#define INCLUDE_msvc_compat__ - -#if defined(_MSC_VER) - -/* access() mode parameter #defines */ -# define F_OK 0 /* existence check */ -# define W_OK 2 /* write mode check */ -# define R_OK 4 /* read mode check */ - -# define lseek _lseeki64 -# define stat _stat64 -# define fstat _fstat64 - -/* stat: file mode type testing macros */ -# define _S_IFLNK 0120000 -# define S_IFLNK _S_IFLNK - -# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) -# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) -# define S_ISFIFO(m) (((m) & _S_IFMT) == _S_IFIFO) -# define S_ISLNK(m) (((m) & _S_IFMT) == _S_IFLNK) - -# define mode_t unsigned short - -/* case-insensitive string comparison */ -# define strcasecmp _stricmp -# define strncasecmp _strnicmp - -#if (_MSC_VER >= 1600) -# include -#else -/* add some missing typedef's */ -typedef signed char int8_t; -typedef unsigned char uint8_t; - -typedef short int16_t; -typedef unsigned short uint16_t; - -typedef long int32_t; -typedef unsigned long uint32_t; - -typedef long long int64_t; -typedef unsigned long long uint64_t; - -typedef long long intmax_t; -typedef unsigned long long uintmax_t; -#endif - -#endif - -#endif /* INCLUDE_msvc_compat__ */ diff --git a/vendor/libgit2/src/win32/posix.c b/vendor/libgit2/src/win32/posix.c deleted file mode 100644 index be6a7c0d0..000000000 --- a/vendor/libgit2/src/win32/posix.c +++ /dev/null @@ -1,248 +0,0 @@ -#include "posix.h" -#include "path.h" -#include -#include - -int p_unlink(const char *path) -{ - chmod(path, 0666); - return unlink(path); -} - -int p_fsync(int fd) -{ - HANDLE fh = (HANDLE)_get_osfhandle(fd); - - if (fh == INVALID_HANDLE_VALUE) { - errno = EBADF; - return -1; - } - - if (!FlushFileBuffers(fh)) { - DWORD code = GetLastError(); - - if (code == ERROR_INVALID_HANDLE) - errno = EINVAL; - else - errno = EIO; - - return -1; - } - - return 0; -} - -GIT_INLINE(time_t) filetime_to_time_t(const FILETIME *ft) -{ - long long winTime = ((long long)ft->dwHighDateTime << 32) + ft->dwLowDateTime; - winTime -= 116444736000000000LL; /* Windows to Unix Epoch conversion */ - winTime /= 10000000; /* Nano to seconds resolution */ - return (time_t)winTime; -} - -static int do_lstat(const char *file_name, struct stat *buf) -{ - WIN32_FILE_ATTRIBUTE_DATA fdata; - - if (GetFileAttributesExA(file_name, GetFileExInfoStandard, &fdata)) { - int fMode = S_IREAD; - - if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) - fMode |= S_IFDIR; - else - fMode |= S_IFREG; - - if (!(fdata.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) - fMode |= S_IWRITE; - - if (fdata.dwFileAttributes & FILE_ATTRIBUTE_REPARSE_POINT) - fMode |= S_IFLNK; - - buf->st_ino = 0; - buf->st_gid = 0; - buf->st_uid = 0; - buf->st_nlink = 1; - buf->st_mode = (mode_t)fMode; - buf->st_size = fdata.nFileSizeLow; /* Can't use nFileSizeHigh, since it's not a stat64 */ - buf->st_dev = buf->st_rdev = (_getdrive() - 1); - buf->st_atime = filetime_to_time_t(&(fdata.ftLastAccessTime)); - buf->st_mtime = filetime_to_time_t(&(fdata.ftLastWriteTime)); - buf->st_ctime = filetime_to_time_t(&(fdata.ftCreationTime)); - return GIT_SUCCESS; - } - - switch (GetLastError()) { - case ERROR_ACCESS_DENIED: - case ERROR_SHARING_VIOLATION: - case ERROR_LOCK_VIOLATION: - case ERROR_SHARING_BUFFER_EXCEEDED: - return GIT_EOSERR; - - case ERROR_BUFFER_OVERFLOW: - case ERROR_NOT_ENOUGH_MEMORY: - return GIT_ENOMEM; - - default: - return GIT_EINVALIDPATH; - } -} - -int p_lstat(const char *file_name, struct stat *buf) -{ - int namelen, error; - char alt_name[GIT_PATH_MAX]; - - if ((error = do_lstat(file_name, buf)) == GIT_SUCCESS) - return GIT_SUCCESS; - - /* if file_name ended in a '/', Windows returned ENOENT; - * try again without trailing slashes - */ - if (error != GIT_EINVALIDPATH) - return git__throw(GIT_EOSERR, "Failed to lstat file"); - - namelen = strlen(file_name); - if (namelen && file_name[namelen-1] != '/') - return git__throw(GIT_EOSERR, "Failed to lstat file"); - - while (namelen && file_name[namelen-1] == '/') - --namelen; - - if (!namelen || namelen >= GIT_PATH_MAX) - return git__throw(GIT_ENOMEM, "Failed to lstat file"); - - memcpy(alt_name, file_name, namelen); - alt_name[namelen] = 0; - return do_lstat(alt_name, buf); -} - -int p_readlink(const char *link, char *target, size_t target_len) -{ - typedef DWORD (WINAPI *fpath_func)(HANDLE, LPTSTR, DWORD, DWORD); - static fpath_func pGetFinalPath = NULL; - HANDLE hFile; - DWORD dwRet; - - /* - * Try to load the pointer to pGetFinalPath dynamically, because - * it is not available in platforms older than Vista - */ - if (pGetFinalPath == NULL) { - HINSTANCE library = LoadLibrary("kernel32"); - - if (library != NULL) - pGetFinalPath = (fpath_func)GetProcAddress(library, "GetFinalPathNameByHandleA"); - - if (pGetFinalPath == NULL) - return git__throw(GIT_EOSERR, - "'GetFinalPathNameByHandleA' is not available in this platform"); - } - - hFile = CreateFile(link, // file to open - GENERIC_READ, // open for reading - FILE_SHARE_READ, // share for reading - NULL, // default security - OPEN_EXISTING, // existing file only - FILE_FLAG_BACKUP_SEMANTICS, // normal file - NULL); // no attr. template - - if (hFile == INVALID_HANDLE_VALUE) - return GIT_EOSERR; - - dwRet = pGetFinalPath(hFile, target, target_len, 0x0); - if (dwRet >= target_len) - return GIT_ENOMEM; - - CloseHandle(hFile); - - if (dwRet > 4) { - /* Skip first 4 characters if they are "\\?\" */ - if (target[0] == '\\' && target[1] == '\\' && target[2] == '?' && target[3] == '\\') { - char tmp[GIT_PATH_MAX]; - unsigned int offset = 4; - dwRet -= 4; - - /* \??\UNC\ */ - if (dwRet > 7 && target[4] == 'U' && target[5] == 'N' && target[6] == 'C') { - offset += 2; - dwRet -= 2; - target[offset] = '\\'; - } - - memcpy(tmp, target + offset, dwRet); - memcpy(target, tmp, dwRet); - } - } - - target[dwRet] = '\0'; - return dwRet; -} - -int p_hide_directory__w32(const char *path) -{ - int error; - - error = SetFileAttributes(path, FILE_ATTRIBUTE_HIDDEN) != 0 ? - GIT_SUCCESS : GIT_ERROR; /* MSDN states a "non zero" value indicates a success */ - - if (error < GIT_SUCCESS) - error = git__throw(GIT_EOSERR, "Failed to hide directory '%s'", path); - - return error; -} - -char *p_realpath(const char *orig_path, char *buffer) -{ - int ret, alloc = 0; - - if (buffer == NULL) { - buffer = (char *)git__malloc(GIT_PATH_MAX); - alloc = 1; - } - - ret = GetFullPathName(orig_path, GIT_PATH_MAX, buffer, NULL); - if (!ret || ret > GIT_PATH_MAX) { - if (alloc) free(buffer); - return NULL; - } - - git_path_mkposix(buffer); - return buffer; -} - -int p_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr) -{ -#ifdef _MSC_VER - int len = _vsnprintf(buffer, count, format, argptr); - return (len < 0) ? _vscprintf(format, argptr) : len; -#else /* MinGW */ - return vsnprintf(buffer, count, format, argptr); -#endif -} - -int p_snprintf(char *buffer, size_t count, const char *format, ...) -{ - va_list va; - int r; - - va_start(va, format); - r = p_vsnprintf(buffer, count, format, va); - va_end(va); - - return r; -} - -extern int p_creat(const char *path, int mode); - -int p_mkstemp(char *tmp_path) -{ -#if defined(_MSC_VER) - if (_mktemp_s(tmp_path, GIT_PATH_MAX) != 0) - return GIT_EOSERR; -#else - if (_mktemp(tmp_path) == NULL) - return GIT_EOSERR; -#endif - - return p_creat(tmp_path, 0744); -} diff --git a/vendor/libgit2/src/win32/posix.h b/vendor/libgit2/src/win32/posix.h deleted file mode 100644 index 28d978959..000000000 --- a/vendor/libgit2/src/win32/posix.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef INCLUDE_posix__w32_h__ -#define INCLUDE_posix__w32_h__ - -#include "common.h" -#include "fnmatch.h" - -GIT_INLINE(int) p_link(const char *GIT_UNUSED(old), const char *GIT_UNUSED(new)) -{ - GIT_UNUSED_ARG(old) - GIT_UNUSED_ARG(new) - errno = ENOSYS; - return -1; -} - -GIT_INLINE(int) p_mkdir(const char *path, int GIT_UNUSED(mode)) -{ - GIT_UNUSED_ARG(mode) - return mkdir(path); -} - -extern int p_unlink(const char *path); -extern int p_lstat(const char *file_name, struct stat *buf); -extern int p_readlink(const char *link, char *target, size_t target_len); -extern int p_hide_directory__w32(const char *path); -extern char *p_realpath(const char *orig_path, char *buffer); -extern int p_vsnprintf(char *buffer, size_t count, const char *format, va_list argptr); -extern int p_snprintf(char *buffer, size_t count, const char *format, ...) GIT_FORMAT_PRINTF(3, 4); -extern int p_mkstemp(char *tmp_path); - -#endif diff --git a/vendor/libgit2/src/win32/pthread.c b/vendor/libgit2/src/win32/pthread.c deleted file mode 100644 index 41cf5b35b..000000000 --- a/vendor/libgit2/src/win32/pthread.c +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Original code by Ramiro Polla (Public Domain) - */ - -#include "pthread.h" - -int pthread_create(pthread_t *GIT_RESTRICT thread, - const pthread_attr_t *GIT_RESTRICT GIT_UNUSED(attr), - void *(*start_routine)(void*), void *GIT_RESTRICT arg) -{ - GIT_UNUSED_ARG(attr); - *thread = (pthread_t) CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)start_routine, arg, 0, NULL); - return *thread ? GIT_SUCCESS : git__throw(GIT_EOSERR, "Failed to create pthread"); -} - -int pthread_join(pthread_t thread, void **value_ptr) -{ - int ret; - ret = WaitForSingleObject(thread, INFINITE); - if (ret && value_ptr) - GetExitCodeThread(thread, (void*) value_ptr); - return -(!!ret); -} - -int pthread_mutex_init(pthread_mutex_t *GIT_RESTRICT mutex, - const pthread_mutexattr_t *GIT_RESTRICT GIT_UNUSED(mutexattr)) -{ - GIT_UNUSED_ARG(mutexattr); - InitializeCriticalSection(mutex); - return 0; -} - -int pthread_mutex_destroy(pthread_mutex_t *mutex) -{ - DeleteCriticalSection(mutex); - return 0; -} - -int pthread_mutex_lock(pthread_mutex_t *mutex) -{ - EnterCriticalSection(mutex); - return 0; -} - -int pthread_mutex_unlock(pthread_mutex_t *mutex) -{ - LeaveCriticalSection(mutex); - return 0; -} - -int pthread_num_processors_np(void) -{ - DWORD_PTR p, s; - int n = 0; - - if (GetProcessAffinityMask(GetCurrentProcess(), &p, &s)) - for (; p; p >>= 1) - n += p&1; - - return n ? n : 1; -} - diff --git a/vendor/libgit2/src/win32/pthread.h b/vendor/libgit2/src/win32/pthread.h deleted file mode 100644 index 10949f1eb..000000000 --- a/vendor/libgit2/src/win32/pthread.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - * - * Original code by Ramiro Polla (Public Domain) - */ - -#ifndef GIT_PTHREAD_H -#define GIT_PTHREAD_H - -#include "../common.h" - -#if defined (_MSC_VER) -# define GIT_RESTRICT __restrict -#else -# define GIT_RESTRICT __restrict__ -#endif - -typedef int pthread_mutexattr_t; -typedef int pthread_condattr_t; -typedef int pthread_attr_t; -typedef CRITICAL_SECTION pthread_mutex_t; -typedef HANDLE pthread_t; - -#define PTHREAD_MUTEX_INITIALIZER {(void*)-1}; - -int pthread_create(pthread_t *GIT_RESTRICT, - const pthread_attr_t *GIT_RESTRICT, - void *(*start_routine)(void*), void *__restrict); - -int pthread_join(pthread_t, void **); - -int pthread_mutex_init(pthread_mutex_t *GIT_RESTRICT, const pthread_mutexattr_t *GIT_RESTRICT); -int pthread_mutex_destroy(pthread_mutex_t *); -int pthread_mutex_lock(pthread_mutex_t *); -int pthread_mutex_unlock(pthread_mutex_t *); - -int pthread_num_processors_np(void); - -#endif diff --git a/vendor/libgit2/tests/.gitignore b/vendor/libgit2/tests/.gitignore deleted file mode 100644 index 690624bdf..000000000 --- a/vendor/libgit2/tests/.gitignore +++ /dev/null @@ -1 +0,0 @@ -*.toc diff --git a/vendor/libgit2/tests/NAMING b/vendor/libgit2/tests/NAMING deleted file mode 100644 index c2da0163f..000000000 --- a/vendor/libgit2/tests/NAMING +++ /dev/null @@ -1,52 +0,0 @@ -Test sources should be named: - - t????-function.c - -where ???? is a four digit code. The first two digits classify -the test into a major category; the final two digits indicate the -sequence of the test within that category. The function part of -the test name should give a rough indication of what it does. - -Categories ----------- - -00__: Core library routines based only on the standard library, - and that are essential for everything else to run. E.g. - errno and malloc. - -01__: Basic hashing functions, needed to handle the content - addressable store. - -02__: Basic object read access. - -03__: Basic object writing. - -04__: Parsing and loading commit data - -05__: Revision walking - -06__: Index reading, writing and searching - -07__: Tests for the internal hashtable code - -08__: Tag reading and writing - -09__: Reading tree objects - -10__: Symbolic, loose and packed references reading and writing. - -11__: SQLite backend - -12__: Repository init and opening - -13__: Threads, empty as of now - -14__: Redis backend - -15__: Configuration parsing - -16__: Remotes - -17__: Buffers - -18__: File Status diff --git a/vendor/libgit2/tests/resources/.gitignore b/vendor/libgit2/tests/resources/.gitignore deleted file mode 100644 index 43a19cc9d..000000000 --- a/vendor/libgit2/tests/resources/.gitignore +++ /dev/null @@ -1 +0,0 @@ -discover.git diff --git a/vendor/libgit2/tests/resources/big.index b/vendor/libgit2/tests/resources/big.index deleted file mode 100644 index 66932f14b..000000000 Binary files a/vendor/libgit2/tests/resources/big.index and /dev/null differ diff --git a/vendor/libgit2/tests/resources/config/.gitconfig b/vendor/libgit2/tests/resources/config/.gitconfig deleted file mode 100644 index fa72bddfc..000000000 --- a/vendor/libgit2/tests/resources/config/.gitconfig +++ /dev/null @@ -1,3 +0,0 @@ -[core] - repositoryformatversion = 5 - something = 2 \ No newline at end of file diff --git a/vendor/libgit2/tests/resources/config/config0 b/vendor/libgit2/tests/resources/config/config0 deleted file mode 100644 index 85235c501..000000000 --- a/vendor/libgit2/tests/resources/config/config0 +++ /dev/null @@ -1,7 +0,0 @@ -# This is a test -; of different comments -[core] - repositoryformatversion = 0 - filemode = true - bare = false - logallrefupdates = true \ No newline at end of file diff --git a/vendor/libgit2/tests/resources/config/config1 b/vendor/libgit2/tests/resources/config/config1 deleted file mode 100644 index 211dc9e7d..000000000 --- a/vendor/libgit2/tests/resources/config/config1 +++ /dev/null @@ -1,5 +0,0 @@ -# This one checks for case sensitivity -[this "that"] - other = true -[this "That"] - other = yes diff --git a/vendor/libgit2/tests/resources/config/config10 b/vendor/libgit2/tests/resources/config/config10 deleted file mode 100644 index dde17911b..000000000 --- a/vendor/libgit2/tests/resources/config/config10 +++ /dev/null @@ -1 +0,0 @@ -[empty] diff --git a/vendor/libgit2/tests/resources/config/config2 b/vendor/libgit2/tests/resources/config/config2 deleted file mode 100644 index 60a389827..000000000 --- a/vendor/libgit2/tests/resources/config/config2 +++ /dev/null @@ -1,5 +0,0 @@ -; This one tests for multiline values -[this "That"] - and = one one one \ -two two \ -three three \ No newline at end of file diff --git a/vendor/libgit2/tests/resources/config/config3 b/vendor/libgit2/tests/resources/config/config3 deleted file mode 100644 index 44a5e50ea..000000000 --- a/vendor/libgit2/tests/resources/config/config3 +++ /dev/null @@ -1,3 +0,0 @@ -# A [section.subsection] header is case-insensitive -[section.SuBsection] - var = hello diff --git a/vendor/libgit2/tests/resources/config/config4 b/vendor/libgit2/tests/resources/config/config4 deleted file mode 100644 index 741fa0ffd..000000000 --- a/vendor/libgit2/tests/resources/config/config4 +++ /dev/null @@ -1,3 +0,0 @@ -# A variable name on its own is valid -[some.section] - variable diff --git a/vendor/libgit2/tests/resources/config/config5 b/vendor/libgit2/tests/resources/config/config5 deleted file mode 100644 index 8ab60ccec..000000000 --- a/vendor/libgit2/tests/resources/config/config5 +++ /dev/null @@ -1,9 +0,0 @@ -# Test for number suffixes -[number] - simple = 1 - k = 1k - kk = 1K - m = 1m - mm = 1M - g = 1g - gg = 1G diff --git a/vendor/libgit2/tests/resources/config/config6 b/vendor/libgit2/tests/resources/config/config6 deleted file mode 100644 index 0f8f90ac9..000000000 --- a/vendor/libgit2/tests/resources/config/config6 +++ /dev/null @@ -1,5 +0,0 @@ -[valid "subsection"] - something = true - -[something "else"] - something = false diff --git a/vendor/libgit2/tests/resources/config/config7 b/vendor/libgit2/tests/resources/config/config7 deleted file mode 100644 index 6af6fcf25..000000000 --- a/vendor/libgit2/tests/resources/config/config7 +++ /dev/null @@ -1,5 +0,0 @@ -[valid "subsection"] - something = a -; we don't allow anything after closing " -[sec "subsec"x] - bleh = blah diff --git a/vendor/libgit2/tests/resources/config/config8 b/vendor/libgit2/tests/resources/config/config8 deleted file mode 100644 index e69de29bb..000000000 diff --git a/vendor/libgit2/tests/resources/config/config9 b/vendor/libgit2/tests/resources/config/config9 deleted file mode 100644 index 34fdc07a5..000000000 --- a/vendor/libgit2/tests/resources/config/config9 +++ /dev/null @@ -1,3 +0,0 @@ -[core] - dummy2 = 42 - dummy = 1 diff --git a/vendor/libgit2/tests/resources/empty_bare.git/HEAD b/vendor/libgit2/tests/resources/empty_bare.git/HEAD deleted file mode 100644 index cb089cd89..000000000 --- a/vendor/libgit2/tests/resources/empty_bare.git/HEAD +++ /dev/null @@ -1 +0,0 @@ -ref: refs/heads/master diff --git a/vendor/libgit2/tests/resources/empty_bare.git/config b/vendor/libgit2/tests/resources/empty_bare.git/config deleted file mode 100644 index 90e16477b..000000000 --- a/vendor/libgit2/tests/resources/empty_bare.git/config +++ /dev/null @@ -1,7 +0,0 @@ -[core] - repositoryformatversion = 0 - filemode = false - bare = true - symlinks = false - ignorecase = true - hideDotFiles = dotGitOnly diff --git a/vendor/libgit2/tests/resources/empty_bare.git/description b/vendor/libgit2/tests/resources/empty_bare.git/description deleted file mode 100644 index 498b267a8..000000000 --- a/vendor/libgit2/tests/resources/empty_bare.git/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/vendor/libgit2/tests/resources/empty_bare.git/info/exclude b/vendor/libgit2/tests/resources/empty_bare.git/info/exclude deleted file mode 100644 index a5196d1be..000000000 --- a/vendor/libgit2/tests/resources/empty_bare.git/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/vendor/libgit2/tests/resources/empty_bare.git/objects/info/dummy-marker.txt b/vendor/libgit2/tests/resources/empty_bare.git/objects/info/dummy-marker.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/vendor/libgit2/tests/resources/empty_bare.git/objects/pack/dummy-marker.txt b/vendor/libgit2/tests/resources/empty_bare.git/objects/pack/dummy-marker.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/vendor/libgit2/tests/resources/empty_bare.git/refs/heads/dummy-marker.txt b/vendor/libgit2/tests/resources/empty_bare.git/refs/heads/dummy-marker.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/vendor/libgit2/tests/resources/empty_bare.git/refs/tags/dummy-marker.txt b/vendor/libgit2/tests/resources/empty_bare.git/refs/tags/dummy-marker.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/HEAD b/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/HEAD deleted file mode 100644 index cb089cd89..000000000 --- a/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/HEAD +++ /dev/null @@ -1 +0,0 @@ -ref: refs/heads/master diff --git a/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/config b/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/config deleted file mode 100644 index 78387c50b..000000000 --- a/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/config +++ /dev/null @@ -1,8 +0,0 @@ -[core] - repositoryformatversion = 0 - filemode = false - bare = false - logallrefupdates = true - symlinks = false - ignorecase = true - hideDotFiles = dotGitOnly diff --git a/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/description b/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/description deleted file mode 100644 index 498b267a8..000000000 --- a/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/info/exclude b/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/info/exclude deleted file mode 100644 index a5196d1be..000000000 --- a/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/objects/info/dummy-marker.txt b/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/objects/info/dummy-marker.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/objects/pack/dummy-marker.txt b/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/objects/pack/dummy-marker.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/refs/heads/dummy-marker.txt b/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/refs/heads/dummy-marker.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/refs/tags/dummy-marker.txt b/vendor/libgit2/tests/resources/empty_standard_repo/.gitted/refs/tags/dummy-marker.txt deleted file mode 100644 index e69de29bb..000000000 diff --git a/vendor/libgit2/tests/resources/gitgit.index b/vendor/libgit2/tests/resources/gitgit.index deleted file mode 100644 index 215da649e..000000000 Binary files a/vendor/libgit2/tests/resources/gitgit.index and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/COMMIT_EDITMSG b/vendor/libgit2/tests/resources/status/.gitted/COMMIT_EDITMSG deleted file mode 100644 index ff887ba13..000000000 --- a/vendor/libgit2/tests/resources/status/.gitted/COMMIT_EDITMSG +++ /dev/null @@ -1 +0,0 @@ -add subdir diff --git a/vendor/libgit2/tests/resources/status/.gitted/HEAD b/vendor/libgit2/tests/resources/status/.gitted/HEAD deleted file mode 100644 index cb089cd89..000000000 --- a/vendor/libgit2/tests/resources/status/.gitted/HEAD +++ /dev/null @@ -1 +0,0 @@ -ref: refs/heads/master diff --git a/vendor/libgit2/tests/resources/status/.gitted/ORIG_HEAD b/vendor/libgit2/tests/resources/status/.gitted/ORIG_HEAD deleted file mode 100644 index c2805f422..000000000 --- a/vendor/libgit2/tests/resources/status/.gitted/ORIG_HEAD +++ /dev/null @@ -1 +0,0 @@ -0017bd4ab1ec30440b17bae1680cff124ab5f1f6 diff --git a/vendor/libgit2/tests/resources/status/.gitted/config b/vendor/libgit2/tests/resources/status/.gitted/config deleted file mode 100644 index af107929f..000000000 --- a/vendor/libgit2/tests/resources/status/.gitted/config +++ /dev/null @@ -1,6 +0,0 @@ -[core] - repositoryformatversion = 0 - filemode = true - bare = false - logallrefupdates = true - ignorecase = true diff --git a/vendor/libgit2/tests/resources/status/.gitted/description b/vendor/libgit2/tests/resources/status/.gitted/description deleted file mode 100644 index 498b267a8..000000000 --- a/vendor/libgit2/tests/resources/status/.gitted/description +++ /dev/null @@ -1 +0,0 @@ -Unnamed repository; edit this file 'description' to name the repository. diff --git a/vendor/libgit2/tests/resources/status/.gitted/index b/vendor/libgit2/tests/resources/status/.gitted/index deleted file mode 100644 index 5c4b18841..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/index and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/info/exclude b/vendor/libgit2/tests/resources/status/.gitted/info/exclude deleted file mode 100644 index a5196d1be..000000000 --- a/vendor/libgit2/tests/resources/status/.gitted/info/exclude +++ /dev/null @@ -1,6 +0,0 @@ -# git ls-files --others --exclude-from=.git/info/exclude -# Lines that start with '#' are comments. -# For a project mostly in C, the following would be a good set of -# exclude patterns (uncomment them if you want to use them): -# *.[oa] -# *~ diff --git a/vendor/libgit2/tests/resources/status/.gitted/logs/HEAD b/vendor/libgit2/tests/resources/status/.gitted/logs/HEAD deleted file mode 100644 index e876bd80b..000000000 --- a/vendor/libgit2/tests/resources/status/.gitted/logs/HEAD +++ /dev/null @@ -1,2 +0,0 @@ -0000000000000000000000000000000000000000 0017bd4ab1ec30440b17bae1680cff124ab5f1f6 Jason Penny 1308050070 -0400 commit (initial): initial -0017bd4ab1ec30440b17bae1680cff124ab5f1f6 735b6a258cd196a8f7c9428419b02c1dca93fd75 Jason Penny 1308954538 -0400 commit: add subdir diff --git a/vendor/libgit2/tests/resources/status/.gitted/logs/refs/heads/master b/vendor/libgit2/tests/resources/status/.gitted/logs/refs/heads/master deleted file mode 100644 index e876bd80b..000000000 --- a/vendor/libgit2/tests/resources/status/.gitted/logs/refs/heads/master +++ /dev/null @@ -1,2 +0,0 @@ -0000000000000000000000000000000000000000 0017bd4ab1ec30440b17bae1680cff124ab5f1f6 Jason Penny 1308050070 -0400 commit (initial): initial -0017bd4ab1ec30440b17bae1680cff124ab5f1f6 735b6a258cd196a8f7c9428419b02c1dca93fd75 Jason Penny 1308954538 -0400 commit: add subdir diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/00/17bd4ab1ec30440b17bae1680cff124ab5f1f6 b/vendor/libgit2/tests/resources/status/.gitted/objects/00/17bd4ab1ec30440b17bae1680cff124ab5f1f6 deleted file mode 100644 index b256d95a3..000000000 --- a/vendor/libgit2/tests/resources/status/.gitted/objects/00/17bd4ab1ec30440b17bae1680cff124ab5f1f6 +++ /dev/null @@ -1,2 +0,0 @@ -xA E]sй€fh)‰1]»ò -#SÀTºðö¶Wp÷ßK^~¨9§šÜ¡-"àC'Ø…)FvõbƒvÉ Þ"¶wŽŽ¼EÅk{Ö®ü©nRÊίÞû6ã#sšO¡æ 舄pDƒ¨6»6ù3W©¤–xV?¨Å9é \ No newline at end of file diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/06/1d42a44cacde5726057b67558821d95db96f19 b/vendor/libgit2/tests/resources/status/.gitted/objects/06/1d42a44cacde5726057b67558821d95db96f19 deleted file mode 100644 index 82e02cb0e..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/06/1d42a44cacde5726057b67558821d95db96f19 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/18/88c805345ba265b0ee9449b8877b6064592058 b/vendor/libgit2/tests/resources/status/.gitted/objects/18/88c805345ba265b0ee9449b8877b6064592058 deleted file mode 100644 index e3cad2f02..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/18/88c805345ba265b0ee9449b8877b6064592058 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/19/d9cc8584ac2c7dcf57d2680375e80f099dc481 b/vendor/libgit2/tests/resources/status/.gitted/objects/19/d9cc8584ac2c7dcf57d2680375e80f099dc481 deleted file mode 100644 index 2d5e711b9..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/19/d9cc8584ac2c7dcf57d2680375e80f099dc481 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/32/504b727382542f9f089e24fddac5e78533e96c b/vendor/libgit2/tests/resources/status/.gitted/objects/32/504b727382542f9f089e24fddac5e78533e96c deleted file mode 100644 index 7fca67be8..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/32/504b727382542f9f089e24fddac5e78533e96c and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/45/2e4244b5d083ddf0460acf1ecc74db9dcfa11a b/vendor/libgit2/tests/resources/status/.gitted/objects/45/2e4244b5d083ddf0460acf1ecc74db9dcfa11a deleted file mode 100644 index 5b47461e9..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/45/2e4244b5d083ddf0460acf1ecc74db9dcfa11a and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/52/9a16e8e762d4acb7b9636ff540a00831f9155a b/vendor/libgit2/tests/resources/status/.gitted/objects/52/9a16e8e762d4acb7b9636ff540a00831f9155a deleted file mode 100644 index 615009ad0..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/52/9a16e8e762d4acb7b9636ff540a00831f9155a and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/53/ace0d1cc1145a5f4fe4f78a186a60263190733 b/vendor/libgit2/tests/resources/status/.gitted/objects/53/ace0d1cc1145a5f4fe4f78a186a60263190733 deleted file mode 100644 index cdb7e961a..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/53/ace0d1cc1145a5f4fe4f78a186a60263190733 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/54/52d32f1dd538eb0405e8a83cc185f79e25e80f b/vendor/libgit2/tests/resources/status/.gitted/objects/54/52d32f1dd538eb0405e8a83cc185f79e25e80f deleted file mode 100644 index a72dff646..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/54/52d32f1dd538eb0405e8a83cc185f79e25e80f and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/55/d316c9ba708999f1918e9677d01dfcae69c6b9 b/vendor/libgit2/tests/resources/status/.gitted/objects/55/d316c9ba708999f1918e9677d01dfcae69c6b9 deleted file mode 100644 index 72807f3d0..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/55/d316c9ba708999f1918e9677d01dfcae69c6b9 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/70/bd9443ada07063e7fbf0b3ff5c13f7494d89c2 b/vendor/libgit2/tests/resources/status/.gitted/objects/70/bd9443ada07063e7fbf0b3ff5c13f7494d89c2 deleted file mode 100644 index 3665a8f7c..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/70/bd9443ada07063e7fbf0b3ff5c13f7494d89c2 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/73/5b6a258cd196a8f7c9428419b02c1dca93fd75 b/vendor/libgit2/tests/resources/status/.gitted/objects/73/5b6a258cd196a8f7c9428419b02c1dca93fd75 deleted file mode 100644 index 08e6fd246..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/73/5b6a258cd196a8f7c9428419b02c1dca93fd75 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/75/6e27627e67bfbc048d01ece5819c6de733d7ea b/vendor/libgit2/tests/resources/status/.gitted/objects/75/6e27627e67bfbc048d01ece5819c6de733d7ea deleted file mode 100644 index 8f3fa89e5..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/75/6e27627e67bfbc048d01ece5819c6de733d7ea and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/90/6ee7711f4f4928ddcb2a5f8fbc500deba0d2a8 b/vendor/libgit2/tests/resources/status/.gitted/objects/90/6ee7711f4f4928ddcb2a5f8fbc500deba0d2a8 deleted file mode 100644 index bb732b08e..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/90/6ee7711f4f4928ddcb2a5f8fbc500deba0d2a8 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/90/b8c29d8ba39434d1c63e1b093daaa26e5bd972 b/vendor/libgit2/tests/resources/status/.gitted/objects/90/b8c29d8ba39434d1c63e1b093daaa26e5bd972 deleted file mode 100644 index 7a96618ff..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/90/b8c29d8ba39434d1c63e1b093daaa26e5bd972 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/9c/2e02cdffa8d73e6c189074594477a6baf87960 b/vendor/libgit2/tests/resources/status/.gitted/objects/9c/2e02cdffa8d73e6c189074594477a6baf87960 deleted file mode 100644 index 20a3c497e..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/9c/2e02cdffa8d73e6c189074594477a6baf87960 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/a0/de7e0ac200c489c41c59dfa910154a70264e6e b/vendor/libgit2/tests/resources/status/.gitted/objects/a0/de7e0ac200c489c41c59dfa910154a70264e6e deleted file mode 100644 index a1789c9a6..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/a0/de7e0ac200c489c41c59dfa910154a70264e6e and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/a6/191982709b746d5650e93c2acf34ef74e11504 b/vendor/libgit2/tests/resources/status/.gitted/objects/a6/191982709b746d5650e93c2acf34ef74e11504 deleted file mode 100644 index cc1f377b3..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/a6/191982709b746d5650e93c2acf34ef74e11504 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/a6/be623522ce87a1d862128ac42672604f7b468b b/vendor/libgit2/tests/resources/status/.gitted/objects/a6/be623522ce87a1d862128ac42672604f7b468b deleted file mode 100644 index c47298347..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/a6/be623522ce87a1d862128ac42672604f7b468b and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/aa/27a641456848200fdb7f7c99ba36f8a0952877 b/vendor/libgit2/tests/resources/status/.gitted/objects/aa/27a641456848200fdb7f7c99ba36f8a0952877 deleted file mode 100644 index a4669ccbb..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/aa/27a641456848200fdb7f7c99ba36f8a0952877 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/da/bc8af9bd6e9f5bbe96a176f1a24baf3d1f8916 b/vendor/libgit2/tests/resources/status/.gitted/objects/da/bc8af9bd6e9f5bbe96a176f1a24baf3d1f8916 deleted file mode 100644 index 3e3c03c96..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/da/bc8af9bd6e9f5bbe96a176f1a24baf3d1f8916 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/e9/b9107f290627c04d097733a10055af941f6bca b/vendor/libgit2/tests/resources/status/.gitted/objects/e9/b9107f290627c04d097733a10055af941f6bca deleted file mode 100644 index 1266d3eac..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/e9/b9107f290627c04d097733a10055af941f6bca and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/objects/ed/062903b8f6f3dccb2fa81117ba6590944ef9bd b/vendor/libgit2/tests/resources/status/.gitted/objects/ed/062903b8f6f3dccb2fa81117ba6590944ef9bd deleted file mode 100644 index 8fa8c1707..000000000 Binary files a/vendor/libgit2/tests/resources/status/.gitted/objects/ed/062903b8f6f3dccb2fa81117ba6590944ef9bd and /dev/null differ diff --git a/vendor/libgit2/tests/resources/status/.gitted/refs/heads/master b/vendor/libgit2/tests/resources/status/.gitted/refs/heads/master deleted file mode 100644 index b46871fd6..000000000 --- a/vendor/libgit2/tests/resources/status/.gitted/refs/heads/master +++ /dev/null @@ -1 +0,0 @@ -735b6a258cd196a8f7c9428419b02c1dca93fd75 diff --git a/vendor/libgit2/tests/resources/status/current_file b/vendor/libgit2/tests/resources/status/current_file deleted file mode 100644 index a0de7e0ac..000000000 --- a/vendor/libgit2/tests/resources/status/current_file +++ /dev/null @@ -1 +0,0 @@ -current_file diff --git a/vendor/libgit2/tests/resources/status/modified_file b/vendor/libgit2/tests/resources/status/modified_file deleted file mode 100644 index 0a5396305..000000000 --- a/vendor/libgit2/tests/resources/status/modified_file +++ /dev/null @@ -1,2 +0,0 @@ -modified_file -modified_file diff --git a/vendor/libgit2/tests/resources/status/new_file b/vendor/libgit2/tests/resources/status/new_file deleted file mode 100644 index d4fa8600b..000000000 --- a/vendor/libgit2/tests/resources/status/new_file +++ /dev/null @@ -1 +0,0 @@ -new_file diff --git a/vendor/libgit2/tests/resources/status/staged_changes b/vendor/libgit2/tests/resources/status/staged_changes deleted file mode 100644 index 55d316c9b..000000000 --- a/vendor/libgit2/tests/resources/status/staged_changes +++ /dev/null @@ -1,2 +0,0 @@ -staged_changes -staged_changes diff --git a/vendor/libgit2/tests/resources/status/staged_changes_modified_file b/vendor/libgit2/tests/resources/status/staged_changes_modified_file deleted file mode 100644 index 011c3440d..000000000 --- a/vendor/libgit2/tests/resources/status/staged_changes_modified_file +++ /dev/null @@ -1,3 +0,0 @@ -staged_changes_modified_file -staged_changes_modified_file -staged_changes_modified_file diff --git a/vendor/libgit2/tests/resources/status/staged_delete_modified_file b/vendor/libgit2/tests/resources/status/staged_delete_modified_file deleted file mode 100644 index dabc8af9b..000000000 --- a/vendor/libgit2/tests/resources/status/staged_delete_modified_file +++ /dev/null @@ -1 +0,0 @@ -staged_delete_modified_file diff --git a/vendor/libgit2/tests/resources/status/staged_new_file b/vendor/libgit2/tests/resources/status/staged_new_file deleted file mode 100644 index 529a16e8e..000000000 --- a/vendor/libgit2/tests/resources/status/staged_new_file +++ /dev/null @@ -1 +0,0 @@ -staged_new_file diff --git a/vendor/libgit2/tests/resources/status/staged_new_file_modified_file b/vendor/libgit2/tests/resources/status/staged_new_file_modified_file deleted file mode 100644 index 8b090c06d..000000000 --- a/vendor/libgit2/tests/resources/status/staged_new_file_modified_file +++ /dev/null @@ -1,2 +0,0 @@ -staged_new_file_modified_file -staged_new_file_modified_file diff --git a/vendor/libgit2/tests/resources/status/subdir/current_file b/vendor/libgit2/tests/resources/status/subdir/current_file deleted file mode 100644 index 53ace0d1c..000000000 --- a/vendor/libgit2/tests/resources/status/subdir/current_file +++ /dev/null @@ -1 +0,0 @@ -subdir/current_file diff --git a/vendor/libgit2/tests/resources/status/subdir/modified_file b/vendor/libgit2/tests/resources/status/subdir/modified_file deleted file mode 100644 index 57274b75e..000000000 --- a/vendor/libgit2/tests/resources/status/subdir/modified_file +++ /dev/null @@ -1,2 +0,0 @@ -subdir/modified_file -subdir/modified_file diff --git a/vendor/libgit2/tests/resources/status/subdir/new_file b/vendor/libgit2/tests/resources/status/subdir/new_file deleted file mode 100644 index 80a86a693..000000000 --- a/vendor/libgit2/tests/resources/status/subdir/new_file +++ /dev/null @@ -1 +0,0 @@ -subdir/new_file diff --git a/vendor/libgit2/tests/resources/testrepo.git/HEAD b/vendor/libgit2/tests/resources/testrepo.git/HEAD deleted file mode 100644 index cb089cd89..000000000 --- a/vendor/libgit2/tests/resources/testrepo.git/HEAD +++ /dev/null @@ -1 +0,0 @@ -ref: refs/heads/master diff --git a/vendor/libgit2/tests/resources/testrepo.git/config b/vendor/libgit2/tests/resources/testrepo.git/config deleted file mode 100644 index 1a5aacdfa..000000000 --- a/vendor/libgit2/tests/resources/testrepo.git/config +++ /dev/null @@ -1,8 +0,0 @@ -[core] - repositoryformatversion = 0 - filemode = true - bare = true - logallrefupdates = true -[remote "test"] - url = git://github.com/libgit2/libgit2 - fetch = +refs/heads/*:refs/remotes/test/* diff --git a/vendor/libgit2/tests/resources/testrepo.git/head-tracker b/vendor/libgit2/tests/resources/testrepo.git/head-tracker deleted file mode 100644 index 40d876b4c..000000000 --- a/vendor/libgit2/tests/resources/testrepo.git/head-tracker +++ /dev/null @@ -1 +0,0 @@ -ref: HEAD diff --git a/vendor/libgit2/tests/resources/testrepo.git/index b/vendor/libgit2/tests/resources/testrepo.git/index deleted file mode 100644 index a27fb9c96..000000000 Binary files a/vendor/libgit2/tests/resources/testrepo.git/index and /dev/null differ diff --git a/vendor/libgit2/tests/resources/testrepo.git/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08 b/vendor/libgit2/tests/resources/testrepo.git/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08 deleted file mode 100644 index cedb2a22e..000000000 Binary files a/vendor/libgit2/tests/resources/testrepo.git/objects/13/85f264afb75a56a5bec74243be9b367ba4ca08 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/testrepo.git/objects/18/1037049a54a1eb5fab404658a3a250b44335d7 b/vendor/libgit2/tests/resources/testrepo.git/objects/18/1037049a54a1eb5fab404658a3a250b44335d7 deleted file mode 100644 index 93a16f146..000000000 Binary files a/vendor/libgit2/tests/resources/testrepo.git/objects/18/1037049a54a1eb5fab404658a3a250b44335d7 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/testrepo.git/objects/18/10dff58d8a660512d4832e740f692884338ccd b/vendor/libgit2/tests/resources/testrepo.git/objects/18/10dff58d8a660512d4832e740f692884338ccd deleted file mode 100644 index ba0bfb30c..000000000 Binary files a/vendor/libgit2/tests/resources/testrepo.git/objects/18/10dff58d8a660512d4832e740f692884338ccd and /dev/null differ diff --git a/vendor/libgit2/tests/resources/testrepo.git/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 b/vendor/libgit2/tests/resources/testrepo.git/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 deleted file mode 100644 index 7ca4ceed5..000000000 Binary files a/vendor/libgit2/tests/resources/testrepo.git/objects/45/b983be36b73c0788dc9cbcb76cbb80fc7bb057 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/testrepo.git/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045 b/vendor/libgit2/tests/resources/testrepo.git/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045 deleted file mode 100644 index 8953b6cef..000000000 --- a/vendor/libgit2/tests/resources/testrepo.git/objects/4a/202b346bb0fb0db7eff3cffeb3c70babbd2045 +++ /dev/null @@ -1,2 +0,0 @@ -xŽQ -Â0DýÎ)öÊ6›Í¦ "xO°‰‰-ØFb¼¿EoàÏ0 ¼Ç¤º,ske×[ÎPn8R,EpD?±gŸ}Ê^3² âÙ<µåµGŽhYKÄèÒ8ЖDAÉ)¿ÉÈ;gôݧÚàšjïp™4Õޝô-çû¢óãêr‚ÁŠ;°s°GA4Ûº=ìùÖ(ôin7øIÌKÍFE \ No newline at end of file diff --git a/vendor/libgit2/tests/resources/testrepo.git/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644 b/vendor/libgit2/tests/resources/testrepo.git/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644 deleted file mode 100644 index c1f22c54f..000000000 --- a/vendor/libgit2/tests/resources/testrepo.git/objects/5b/5b025afb0b4c913b4c338a42934a3863bf3644 +++ /dev/null @@ -1,2 +0,0 @@ -xŽÛ 1EýNi@™Ék2 "X‚$ÙYW0YcÿíÀ¿Ã…s¸¥ÕzïÚÚõMDÏ€0æœ8!¶†ÉÌÞs‰ XŠªgÚdí::@X0»P¢wÙ"F/‰‰œÍRàˆUz÷¥múZZïú²¤ÒV}|•/œo5݇ÒêI£!¬1z Æ:vùÇUim}ê/¢> -öF- \ No newline at end of file diff --git a/vendor/libgit2/tests/resources/testrepo.git/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a b/vendor/libgit2/tests/resources/testrepo.git/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a deleted file mode 100644 index 2ef4faa0f..000000000 Binary files a/vendor/libgit2/tests/resources/testrepo.git/objects/75/057dd4114e74cca1d750d0aee1647c903cb60a and /dev/null differ diff --git a/vendor/libgit2/tests/resources/testrepo.git/objects/7b/4384978d2493e851f9cca7858815fac9b10980 b/vendor/libgit2/tests/resources/testrepo.git/objects/7b/4384978d2493e851f9cca7858815fac9b10980 deleted file mode 100644 index 23c462f34..000000000 Binary files a/vendor/libgit2/tests/resources/testrepo.git/objects/7b/4384978d2493e851f9cca7858815fac9b10980 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/testrepo.git/objects/81/4889a078c031f61ed08ab5fa863aea9314344d b/vendor/libgit2/tests/resources/testrepo.git/objects/81/4889a078c031f61ed08ab5fa863aea9314344d deleted file mode 100644 index 2f9b6b6e3..000000000 Binary files a/vendor/libgit2/tests/resources/testrepo.git/objects/81/4889a078c031f61ed08ab5fa863aea9314344d and /dev/null differ diff --git a/vendor/libgit2/tests/resources/testrepo.git/objects/84/96071c1b46c854b31185ea97743be6a8774479 b/vendor/libgit2/tests/resources/testrepo.git/objects/84/96071c1b46c854b31185ea97743be6a8774479 deleted file mode 100644 index 5df58dda5..000000000 Binary files a/vendor/libgit2/tests/resources/testrepo.git/objects/84/96071c1b46c854b31185ea97743be6a8774479 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/testrepo.git/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a b/vendor/libgit2/tests/resources/testrepo.git/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a deleted file mode 100644 index a79612435..000000000 --- a/vendor/libgit2/tests/resources/testrepo.git/objects/9f/d738e8f7967c078dceed8190330fc8648ee56a +++ /dev/null @@ -1,3 +0,0 @@ -xŽ[ -Â0EýÎ*fÊäÕ¤ "¸W0“‡-ØFâtÿÝ—çpS[–YÀ˜x^ -Díb CLhutɉ}¥8X*4Zí¬sY½¨—UÀ‘AÃÖ ÌX3‡R«Mµ¶) s6è¼¢M¦ÖážšÜ&Jm…ó;}Çõ±Ðü<¥¶\@›à‚ÑÞpÄ€¨vº?”ò«jÛºLð«¨Ø?Hå \ No newline at end of file diff --git a/vendor/libgit2/tests/resources/testrepo.git/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f b/vendor/libgit2/tests/resources/testrepo.git/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f deleted file mode 100644 index f8588696b..000000000 --- a/vendor/libgit2/tests/resources/testrepo.git/objects/a4/a7dce85cf63874e984719f4fdd239f5145052f +++ /dev/null @@ -1,2 +0,0 @@ -x;j1DëmdÓú·À˜ÇŽ|M«µ3`ŒV{ >€³âQ¯ ¸·vL0I?Í!š4–Z=Ê! ×¦8²F¢Ã’!rÖsQßyÈ9]$DŽ&„l6AÇ>jFWüÒµ IKNiûë§Z¢%¡SˆŒ‘ -‹Ò ­ÅʉøU~̽øä>'¼ï™û ¯wþ ×[ËÇ× ÷öÚDGÚ¡±ðŒQ-ºMù«>dܶ‘OÞáÒò}í\à8g_ШÂoYr \ No newline at end of file diff --git a/vendor/libgit2/tests/resources/testrepo.git/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd b/vendor/libgit2/tests/resources/testrepo.git/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd deleted file mode 100644 index d0d7e736e..000000000 Binary files a/vendor/libgit2/tests/resources/testrepo.git/objects/a7/1586c1dfe8a71c6cbf6c129f404c5642ff31bd and /dev/null differ diff --git a/vendor/libgit2/tests/resources/testrepo.git/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 b/vendor/libgit2/tests/resources/testrepo.git/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 deleted file mode 100644 index 18a7f61c2..000000000 Binary files a/vendor/libgit2/tests/resources/testrepo.git/objects/a8/233120f6ad708f843d861ce2b7228ec4e3dec6 and /dev/null differ diff --git a/vendor/libgit2/tests/resources/testrepo.git/objects/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1 b/vendor/libgit2/tests/resources/testrepo.git/objects/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1 deleted file mode 100644 index f460f2547..000000000 --- a/vendor/libgit2/tests/resources/testrepo.git/objects/b2/5fa35b38051e4ae45d4222e795f9df2e43f1d1 +++ /dev/null @@ -1,2 +0,0 @@ -xÌA -Â0…a×9ÅìIÒ ™€ˆp'î§1Ѷ‘v\x{cáýðVŸpƒvWûgŠ¾ÇŽ0xº[ ]"g†#{rDÆ Cot ­äûN œU $­ò?9-p+1Í^¤ÀQx®¯Ï9O\ÆC¬Ó Œm'D {mµVêú(+´ñælè¶,Þ \ No newline at end of file diff --git a/vendor/libgit2/tests/resources/testrepo.git/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644 b/vendor/libgit2/tests/resources/testrepo.git/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644 deleted file mode 100644 index 0817229bc..000000000 --- a/vendor/libgit2/tests/resources/testrepo.git/objects/be/3563ae3f795b2b4353bcce3a527ad0a4f7f644 +++ /dev/null @@ -1,3 +0,0 @@ -xKj1D³Ö)zçUBëÛ-0ÁuV9¦Õò<#£È÷ÏȲ+ŠW 0); - must_be_true(git__prefixcmp("ab", "a") == 0); - must_be_true(git__prefixcmp("ab", "ac") < 0); - must_be_true(git__prefixcmp("ab", "aa") > 0); -END_TEST - -BEGIN_TEST(string1, "compare suffixes") - must_be_true(git__suffixcmp("", "") == 0); - must_be_true(git__suffixcmp("a", "") == 0); - must_be_true(git__suffixcmp("", "a") < 0); - must_be_true(git__suffixcmp("a", "b") < 0); - must_be_true(git__suffixcmp("b", "a") > 0); - must_be_true(git__suffixcmp("ba", "a") == 0); - must_be_true(git__suffixcmp("zaa", "ac") < 0); - must_be_true(git__suffixcmp("zaz", "ac") > 0); -END_TEST - - -BEGIN_TEST(vector0, "initial size of 1 would cause writing past array bounds") - git_vector x; - int i; - git_vector_init(&x, 1, NULL); - for (i = 0; i < 10; ++i) { - git_vector_insert(&x, (void*) 0xabc); - } - git_vector_free(&x); -END_TEST - -BEGIN_TEST(vector1, "don't read past array bounds on remove()") - git_vector x; - // make initial capacity exact for our insertions. - git_vector_init(&x, 3, NULL); - git_vector_insert(&x, (void*) 0xabc); - git_vector_insert(&x, (void*) 0xdef); - git_vector_insert(&x, (void*) 0x123); - - git_vector_remove(&x, 0); // used to read past array bounds. - git_vector_free(&x); -END_TEST - -static int test_cmp(const void *a, const void *b) -{ - return *(const int *)a - *(const int *)b; -} - -BEGIN_TEST(vector2, "remove duplicates") - git_vector x; - int *ptrs[2]; - - ptrs[0] = git__malloc(sizeof(int)); - ptrs[1] = git__malloc(sizeof(int)); - - *ptrs[0] = 2; - *ptrs[1] = 1; - - must_pass(git_vector_init(&x, 5, test_cmp)); - must_pass(git_vector_insert(&x, ptrs[0])); - must_pass(git_vector_insert(&x, ptrs[1])); - must_pass(git_vector_insert(&x, ptrs[1])); - must_pass(git_vector_insert(&x, ptrs[0])); - must_pass(git_vector_insert(&x, ptrs[1])); - must_be_true(x.length == 5); - git_vector_uniq(&x); - must_be_true(x.length == 2); - git_vector_free(&x); - - free(ptrs[0]); - free(ptrs[1]); -END_TEST - - -BEGIN_TEST(path0, "get the dirname of a path") - char dir[64], *dir2; - -#define DIRNAME_TEST(A, B) { \ - must_be_true(git_path_dirname_r(dir, sizeof(dir), A) >= 0); \ - must_be_true(strcmp(dir, B) == 0); \ - must_be_true((dir2 = git_path_dirname(A)) != NULL); \ - must_be_true(strcmp(dir2, B) == 0); \ - free(dir2); \ -} - - DIRNAME_TEST(NULL, "."); - DIRNAME_TEST("", "."); - DIRNAME_TEST("a", "."); - DIRNAME_TEST("/", "/"); - DIRNAME_TEST("/usr", "/"); - DIRNAME_TEST("/usr/", "/"); - DIRNAME_TEST("/usr/lib", "/usr"); - DIRNAME_TEST("/usr/lib/", "/usr"); - DIRNAME_TEST("/usr/lib//", "/usr"); - DIRNAME_TEST("usr/lib", "usr"); - DIRNAME_TEST("usr/lib/", "usr"); - DIRNAME_TEST("usr/lib//", "usr"); - DIRNAME_TEST(".git/", "."); - -#undef DIRNAME_TEST - -END_TEST - -BEGIN_TEST(path1, "get the base name of a path") - char base[64], *base2; - -#define BASENAME_TEST(A, B) { \ - must_be_true(git_path_basename_r(base, sizeof(base), A) >= 0); \ - must_be_true(strcmp(base, B) == 0); \ - must_be_true((base2 = git_path_basename(A)) != NULL); \ - must_be_true(strcmp(base2, B) == 0); \ - free(base2); \ -} - - BASENAME_TEST(NULL, "."); - BASENAME_TEST("", "."); - BASENAME_TEST("a", "a"); - BASENAME_TEST("/", "/"); - BASENAME_TEST("/usr", "usr"); - BASENAME_TEST("/usr/", "usr"); - BASENAME_TEST("/usr/lib", "lib"); - BASENAME_TEST("/usr/lib//", "lib"); - BASENAME_TEST("usr/lib", "lib"); - -#undef BASENAME_TEST - -END_TEST - -BEGIN_TEST(path2, "get the latest component in a path") - const char *dir; - -#define TOPDIR_TEST(A, B) { \ - must_be_true((dir = git_path_topdir(A)) != NULL); \ - must_be_true(strcmp(dir, B) == 0); \ -} - - TOPDIR_TEST(".git/", ".git/"); - TOPDIR_TEST("/.git/", ".git/"); - TOPDIR_TEST("usr/local/.git/", ".git/"); - TOPDIR_TEST("./.git/", ".git/"); - TOPDIR_TEST("/usr/.git/", ".git/"); - TOPDIR_TEST("/", "/"); - TOPDIR_TEST("a/", "a/"); - - must_be_true(git_path_topdir("/usr/.git") == NULL); - must_be_true(git_path_topdir(".") == NULL); - must_be_true(git_path_topdir("") == NULL); - must_be_true(git_path_topdir("a") == NULL); - -#undef TOPDIR_TEST -END_TEST - -static int ensure_joinpath(const char *path_a, const char *path_b, const char *expected_path) -{ - char joined_path[GIT_PATH_MAX]; - git_path_join(joined_path, path_a, path_b); - return strcmp(joined_path, expected_path) == 0 ? GIT_SUCCESS : GIT_ERROR; -} - -BEGIN_TEST(path5, "properly join path components") - must_pass(ensure_joinpath("", "", "")); - must_pass(ensure_joinpath("", "a", "a")); - must_pass(ensure_joinpath("", "/a", "/a")); - must_pass(ensure_joinpath("a", "", "a/")); - must_pass(ensure_joinpath("a", "/", "a/")); - must_pass(ensure_joinpath("a", "b", "a/b")); - must_pass(ensure_joinpath("/", "a", "/a")); - must_pass(ensure_joinpath("/", "", "/")); - must_pass(ensure_joinpath("/a", "/b", "/a/b")); - must_pass(ensure_joinpath("/a", "/b/", "/a/b/")); - must_pass(ensure_joinpath("/a/", "b/", "/a/b/")); - must_pass(ensure_joinpath("/a/", "/b/", "/a/b/")); -END_TEST - -static int ensure_joinpath_n(const char *path_a, const char *path_b, const char *path_c, const char *path_d, const char *expected_path) -{ - char joined_path[GIT_PATH_MAX]; - git_path_join_n(joined_path, 4, path_a, path_b, path_c, path_d); - return strcmp(joined_path, expected_path) == 0 ? GIT_SUCCESS : GIT_ERROR; -} - -BEGIN_TEST(path6, "properly join path components for more than one path") - must_pass(ensure_joinpath_n("", "", "", "", "")); - must_pass(ensure_joinpath_n("", "a", "", "", "a/")); - must_pass(ensure_joinpath_n("a", "", "", "", "a/")); - must_pass(ensure_joinpath_n("", "", "", "a", "a")); - must_pass(ensure_joinpath_n("a", "b", "", "/c/d/", "a/b/c/d/")); - must_pass(ensure_joinpath_n("a", "b", "", "/c/d", "a/b/c/d")); -END_TEST - -typedef struct name_data { - int count; /* return count */ - char *name; /* filename */ -} name_data; - -typedef struct walk_data { - char *sub; /* sub-directory name */ - name_data *names; /* name state data */ -} walk_data; - - -static char path_buffer[GIT_PATH_MAX]; -static char *top_dir = "dir-walk"; -static walk_data *state_loc; - -static int error(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vfprintf(stderr, fmt, ap); - va_end(ap); - fprintf(stderr, "\n"); - return -1; -} - -static int setup(walk_data *d) -{ - name_data *n; - - if (p_mkdir(top_dir, 0755) < 0) - return error("can't mkdir(\"%s\")", top_dir); - - if (p_chdir(top_dir) < 0) - return error("can't chdir(\"%s\")", top_dir); - - if (strcmp(d->sub, ".") != 0) - if (p_mkdir(d->sub, 0755) < 0) - return error("can't mkdir(\"%s\")", d->sub); - - strcpy(path_buffer, d->sub); - state_loc = d; - - for (n = d->names; n->name; n++) { - git_file fd = p_creat(n->name, 0600); - if (fd < 0) - return GIT_ERROR; - p_close(fd); - n->count = 0; - } - - return 0; -} - -static int knockdown(walk_data *d) -{ - name_data *n; - - for (n = d->names; n->name; n++) { - if (p_unlink(n->name) < 0) - return error("can't unlink(\"%s\")", n->name); - } - - if (strcmp(d->sub, ".") != 0) - if (p_rmdir(d->sub) < 0) - return error("can't rmdir(\"%s\")", d->sub); - - if (p_chdir("..") < 0) - return error("can't chdir(\"..\")"); - - if (p_rmdir(top_dir) < 0) - return error("can't rmdir(\"%s\")", top_dir); - - return 0; -} - -static int check_counts(walk_data *d) -{ - int ret = 0; - name_data *n; - - for (n = d->names; n->name; n++) { - if (n->count != 1) - ret = error("count (%d, %s)", n->count, n->name); - } - return ret; -} - -static int one_entry(void *state, char *path) -{ - walk_data *d = (walk_data *) state; - name_data *n; - - if (state != state_loc) - return GIT_ERROR; - - if (path != path_buffer) - return GIT_ERROR; - - for (n = d->names; n->name; n++) { - if (!strcmp(n->name, path)) { - n->count++; - return 0; - } - } - - return GIT_ERROR; -} - - -static name_data dot_names[] = { - { 0, "./a" }, - { 0, "./asdf" }, - { 0, "./pack-foo.pack" }, - { 0, NULL } -}; -static walk_data dot = { - ".", - dot_names -}; - -BEGIN_TEST(dirent0, "make sure that the '.' folder is not traversed") - - must_pass(setup(&dot)); - - must_pass(git_futils_direach(path_buffer, - sizeof(path_buffer), - one_entry, - &dot)); - - must_pass(check_counts(&dot)); - - must_pass(knockdown(&dot)); -END_TEST - -static name_data sub_names[] = { - { 0, "sub/a" }, - { 0, "sub/asdf" }, - { 0, "sub/pack-foo.pack" }, - { 0, NULL } -}; -static walk_data sub = { - "sub", - sub_names -}; - -BEGIN_TEST(dirent1, "traverse a subfolder") - - must_pass(setup(&sub)); - - must_pass(git_futils_direach(path_buffer, - sizeof(path_buffer), - one_entry, - &sub)); - - must_pass(check_counts(&sub)); - - must_pass(knockdown(&sub)); -END_TEST - -static walk_data sub_slash = { - "sub/", - sub_names -}; - -BEGIN_TEST(dirent2, "traverse a slash-terminated subfolder") - - must_pass(setup(&sub_slash)); - - must_pass(git_futils_direach(path_buffer, - sizeof(path_buffer), - one_entry, - &sub_slash)); - - must_pass(check_counts(&sub_slash)); - - must_pass(knockdown(&sub_slash)); -END_TEST - -static name_data empty_names[] = { - { 0, NULL } -}; -static walk_data empty = { - "empty", - empty_names -}; - -static int dont_call_me(void *GIT_UNUSED(state), char *GIT_UNUSED(path)) -{ - GIT_UNUSED_ARG(state) - GIT_UNUSED_ARG(path) - return GIT_ERROR; -} - -BEGIN_TEST(dirent3, "make sure that empty folders are not traversed") - - must_pass(setup(&empty)); - - must_pass(git_futils_direach(path_buffer, - sizeof(path_buffer), - one_entry, - &empty)); - - must_pass(check_counts(&empty)); - - /* make sure callback not called */ - must_pass(git_futils_direach(path_buffer, - sizeof(path_buffer), - dont_call_me, - &empty)); - - must_pass(knockdown(&empty)); -END_TEST - -static name_data odd_names[] = { - { 0, "odd/.a" }, - { 0, "odd/..c" }, - /* the following don't work on cygwin/win32 */ - /* { 0, "odd/.b." }, */ - /* { 0, "odd/..d.." }, */ - { 0, NULL } -}; -static walk_data odd = { - "odd", - odd_names -}; - -BEGIN_TEST(dirent4, "make sure that strange looking filenames ('..c') are traversed") - - must_pass(setup(&odd)); - - must_pass(git_futils_direach(path_buffer, - sizeof(path_buffer), - one_entry, - &odd)); - - must_pass(check_counts(&odd)); - - must_pass(knockdown(&odd)); -END_TEST - -BEGIN_TEST(filebuf0, "make sure git_filebuf_open doesn't delete an existing lock") - git_filebuf file; - int fd; - char test[] = "test", testlock[] = "test.lock"; - - fd = p_creat(testlock, 0744); - must_pass(fd); - must_pass(p_close(fd)); - must_fail(git_filebuf_open(&file, test, 0)); - must_pass(git_futils_exists(testlock)); - must_pass(p_unlink(testlock)); -END_TEST - -BEGIN_TEST(filebuf1, "make sure GIT_FILEBUF_APPEND works as expected") - git_filebuf file; - int fd; - char test[] = "test"; - - fd = p_creat(test, 0644); - must_pass(fd); - must_pass(p_write(fd, "libgit2 rocks\n", 14)); - must_pass(p_close(fd)); - - must_pass(git_filebuf_open(&file, test, GIT_FILEBUF_APPEND)); - must_pass(git_filebuf_printf(&file, "%s\n", "libgit2 rocks")); - must_pass(git_filebuf_commit(&file)); - - must_pass(p_unlink(test)); -END_TEST - -BEGIN_TEST(filebuf2, "make sure git_filebuf_write writes large buffer correctly") - git_filebuf file; - char test[] = "test"; - unsigned char buf[4096 * 4]; /* 2 * WRITE_BUFFER_SIZE */ - - memset(buf, 0xfe, sizeof(buf)); - must_pass(git_filebuf_open(&file, test, 0)); - must_pass(git_filebuf_write(&file, buf, sizeof(buf))); - must_pass(git_filebuf_commit(&file)); - - must_pass(p_unlink(test)); -END_TEST - -static char *empty_tmp_dir = "test_gitfo_rmdir_recurs_test"; - -static int setup_empty_tmp_dir() -{ - char path[GIT_PATH_MAX]; - - if (p_mkdir(empty_tmp_dir, 0755)) - return -1; - - git_path_join(path, empty_tmp_dir, "/one"); - if (p_mkdir(path, 0755)) - return -1; - - git_path_join(path, empty_tmp_dir, "/one/two_one"); - if (p_mkdir(path, 0755)) - return -1; - - git_path_join(path, empty_tmp_dir, "/one/two_two"); - if (p_mkdir(path, 0755)) - return -1; - - git_path_join(path, empty_tmp_dir, "/one/two_two/three"); - if (p_mkdir(path, 0755)) - return -1; - - git_path_join(path, empty_tmp_dir, "/two"); - if (p_mkdir(path, 0755)) - return -1; - - return 0; -} - -BEGIN_TEST(rmdir0, "make sure empty dir can be deleted recusively") - must_pass(setup_empty_tmp_dir()); - must_pass(git_futils_rmdir_r(empty_tmp_dir, 0)); -END_TEST - -BEGIN_TEST(rmdir1, "make sure non-empty dir cannot be deleted recusively") - char file[GIT_PATH_MAX]; - int fd; - - must_pass(setup_empty_tmp_dir()); - git_path_join(file, empty_tmp_dir, "/two/file.txt"); - fd = p_creat(file, 0755); - must_pass(fd); - must_pass(p_close(fd)); - must_fail(git_futils_rmdir_r(empty_tmp_dir, 0)); - must_pass(p_unlink(file)); - must_pass(git_futils_rmdir_r(empty_tmp_dir, 0)); -END_TEST - -BEGIN_SUITE(core) - ADD_TEST(string0); - ADD_TEST(string1); - - ADD_TEST(vector0); - ADD_TEST(vector1); - ADD_TEST(vector2); - - ADD_TEST(path0); - ADD_TEST(path1); - ADD_TEST(path2); - ADD_TEST(path5); - ADD_TEST(path6); - - ADD_TEST(dirent0); - ADD_TEST(dirent1); - ADD_TEST(dirent2); - ADD_TEST(dirent3); - ADD_TEST(dirent4); - - ADD_TEST(filebuf0); - ADD_TEST(filebuf1); - ADD_TEST(filebuf2); - - ADD_TEST(rmdir0); - ADD_TEST(rmdir1); -END_SUITE diff --git a/vendor/libgit2/tests/t01-data.h b/vendor/libgit2/tests/t01-data.h deleted file mode 100644 index 268269d69..000000000 --- a/vendor/libgit2/tests/t01-data.h +++ /dev/null @@ -1,322 +0,0 @@ - -/* - * Raw data - */ -static unsigned char commit_data[] = { - 0x74, 0x72, 0x65, 0x65, 0x20, 0x64, 0x66, 0x66, - 0x32, 0x64, 0x61, 0x39, 0x30, 0x62, 0x32, 0x35, - 0x34, 0x65, 0x31, 0x62, 0x65, 0x62, 0x38, 0x38, - 0x39, 0x64, 0x31, 0x66, 0x31, 0x66, 0x31, 0x32, - 0x38, 0x38, 0x62, 0x65, 0x31, 0x38, 0x30, 0x33, - 0x37, 0x38, 0x32, 0x64, 0x66, 0x0a, 0x61, 0x75, - 0x74, 0x68, 0x6f, 0x72, 0x20, 0x41, 0x20, 0x55, - 0x20, 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, - 0x75, 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, - 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, - 0x6d, 0x3e, 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, - 0x31, 0x34, 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, - 0x30, 0x30, 0x30, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, - 0x69, 0x74, 0x74, 0x65, 0x72, 0x20, 0x43, 0x20, - 0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72, - 0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, - 0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e, - 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34, - 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30, - 0x30, 0x0a, 0x0a, 0x41, 0x20, 0x6f, 0x6e, 0x65, - 0x2d, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x63, 0x6f, - 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x73, 0x75, 0x6d, - 0x6d, 0x61, 0x72, 0x79, 0x0a, 0x0a, 0x54, 0x68, - 0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x6f, - 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, - 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x6d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x2c, 0x20, 0x63, 0x6f, - 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67, - 0x20, 0x66, 0x75, 0x72, 0x74, 0x68, 0x65, 0x72, - 0x20, 0x65, 0x78, 0x70, 0x6c, 0x61, 0x6e, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x6f, 0x66, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x72, 0x70, - 0x6f, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x67, - 0x65, 0x73, 0x20, 0x69, 0x6e, 0x74, 0x72, 0x6f, - 0x64, 0x75, 0x63, 0x65, 0x64, 0x20, 0x62, 0x79, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6d, - 0x6d, 0x69, 0x74, 0x2e, 0x0a, 0x0a, 0x53, 0x69, - 0x67, 0x6e, 0x65, 0x64, 0x2d, 0x6f, 0x66, 0x2d, - 0x62, 0x79, 0x3a, 0x20, 0x41, 0x20, 0x55, 0x20, - 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, 0x75, - 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, 0x61, - 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, - 0x3e, 0x0a, -}; - - -static unsigned char tree_data[] = { - 0x31, 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x6f, - 0x6e, 0x65, 0x00, 0x8b, 0x13, 0x78, 0x91, 0x79, - 0x1f, 0xe9, 0x69, 0x27, 0xad, 0x78, 0xe6, 0x4b, - 0x0a, 0xad, 0x7b, 0xde, 0xd0, 0x8b, 0xdc, 0x31, - 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x73, 0x6f, - 0x6d, 0x65, 0x00, 0xfd, 0x84, 0x30, 0xbc, 0x86, - 0x4c, 0xfc, 0xd5, 0xf1, 0x0e, 0x55, 0x90, 0xf8, - 0xa4, 0x47, 0xe0, 0x1b, 0x94, 0x2b, 0xfe, 0x31, - 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x74, 0x77, - 0x6f, 0x00, 0x78, 0x98, 0x19, 0x22, 0x61, 0x3b, - 0x2a, 0xfb, 0x60, 0x25, 0x04, 0x2f, 0xf6, 0xbd, - 0x87, 0x8a, 0xc1, 0x99, 0x4e, 0x85, 0x31, 0x30, - 0x30, 0x36, 0x34, 0x34, 0x20, 0x7a, 0x65, 0x72, - 0x6f, 0x00, 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, - 0xd6, 0x43, 0x4b, 0x8b, 0x29, 0xae, 0x77, 0x5a, - 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91, -}; - -static unsigned char tag_data[] = { - 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x33, - 0x64, 0x37, 0x66, 0x38, 0x61, 0x36, 0x61, 0x66, - 0x30, 0x37, 0x36, 0x63, 0x38, 0x63, 0x33, 0x66, - 0x32, 0x30, 0x30, 0x37, 0x31, 0x61, 0x38, 0x39, - 0x33, 0x35, 0x63, 0x64, 0x62, 0x65, 0x38, 0x32, - 0x32, 0x38, 0x35, 0x39, 0x34, 0x64, 0x31, 0x0a, - 0x74, 0x79, 0x70, 0x65, 0x20, 0x63, 0x6f, 0x6d, - 0x6d, 0x69, 0x74, 0x0a, 0x74, 0x61, 0x67, 0x20, - 0x76, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0a, 0x74, - 0x61, 0x67, 0x67, 0x65, 0x72, 0x20, 0x43, 0x20, - 0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72, - 0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, - 0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e, - 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34, - 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30, - 0x30, 0x0a, 0x0a, 0x54, 0x68, 0x69, 0x73, 0x20, - 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, - 0x61, 0x67, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, - 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x72, 0x65, - 0x6c, 0x65, 0x61, 0x73, 0x65, 0x20, 0x76, 0x30, - 0x2e, 0x30, 0x2e, 0x31, 0x0a, -}; - -static unsigned char zero_data[] = { - 0x00 /* dummy data */ -}; - -static unsigned char one_data[] = { - 0x0a, -}; - -static unsigned char two_data[] = { - 0x61, 0x0a, -}; - -static unsigned char some_data[] = { - 0x2f, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x54, 0x68, - 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, - 0x69, 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, - 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x3b, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x63, 0x61, - 0x6e, 0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74, - 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x69, - 0x74, 0x20, 0x61, 0x6e, 0x64, 0x2f, 0x6f, 0x72, - 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x0a, - 0x20, 0x2a, 0x20, 0x69, 0x74, 0x20, 0x75, 0x6e, - 0x64, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x74, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x6f, 0x66, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55, - 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, - 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, - 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2c, - 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, - 0x20, 0x32, 0x2c, 0x0a, 0x20, 0x2a, 0x20, 0x61, - 0x73, 0x20, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, - 0x68, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20, - 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2e, 0x0a, 0x20, 0x2a, 0x0a, - 0x20, 0x2a, 0x20, 0x49, 0x6e, 0x20, 0x61, 0x64, - 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, - 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x65, - 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, - 0x73, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, - 0x20, 0x47, 0x4e, 0x55, 0x20, 0x47, 0x65, 0x6e, - 0x65, 0x72, 0x61, 0x6c, 0x20, 0x50, 0x75, 0x62, - 0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69, 0x63, 0x65, - 0x6e, 0x73, 0x65, 0x2c, 0x0a, 0x20, 0x2a, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x61, 0x75, 0x74, 0x68, - 0x6f, 0x72, 0x73, 0x20, 0x67, 0x69, 0x76, 0x65, - 0x20, 0x79, 0x6f, 0x75, 0x20, 0x75, 0x6e, 0x6c, - 0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x20, 0x70, - 0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, - 0x6e, 0x20, 0x74, 0x6f, 0x20, 0x6c, 0x69, 0x6e, - 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x0a, 0x20, - 0x2a, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, - 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69, - 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x69, - 0x6e, 0x74, 0x6f, 0x20, 0x63, 0x6f, 0x6d, 0x62, - 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, - 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x6f, 0x74, - 0x68, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x67, - 0x72, 0x61, 0x6d, 0x73, 0x2c, 0x0a, 0x20, 0x2a, - 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x6f, 0x20, - 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, - 0x74, 0x65, 0x20, 0x74, 0x68, 0x6f, 0x73, 0x65, - 0x20, 0x63, 0x6f, 0x6d, 0x62, 0x69, 0x6e, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69, - 0x74, 0x68, 0x6f, 0x75, 0x74, 0x20, 0x61, 0x6e, - 0x79, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72, 0x69, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, 0x2a, - 0x20, 0x63, 0x6f, 0x6d, 0x69, 0x6e, 0x67, 0x20, - 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, - 0x20, 0x75, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, - 0x74, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, - 0x65, 0x2e, 0x20, 0x20, 0x28, 0x54, 0x68, 0x65, - 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, - 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, - 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a, - 0x20, 0x2a, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72, - 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, - 0x64, 0x6f, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, - 0x20, 0x69, 0x6e, 0x20, 0x6f, 0x74, 0x68, 0x65, - 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x65, 0x63, - 0x74, 0x73, 0x3b, 0x20, 0x66, 0x6f, 0x72, 0x20, - 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2c, - 0x20, 0x74, 0x68, 0x65, 0x79, 0x20, 0x63, 0x6f, - 0x76, 0x65, 0x72, 0x0a, 0x20, 0x2a, 0x20, 0x6d, - 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x2c, - 0x20, 0x61, 0x6e, 0x64, 0x20, 0x64, 0x69, 0x73, - 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x6e, - 0x6f, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x6b, 0x65, - 0x64, 0x20, 0x69, 0x6e, 0x74, 0x6f, 0x0a, 0x20, - 0x2a, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6d, 0x62, - 0x69, 0x6e, 0x65, 0x64, 0x20, 0x65, 0x78, 0x65, - 0x63, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, - 0x29, 0x0a, 0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20, - 0x54, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, - 0x65, 0x20, 0x69, 0x73, 0x20, 0x64, 0x69, 0x73, - 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, - 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x68, 0x6f, 0x70, 0x65, 0x20, 0x74, 0x68, 0x61, - 0x74, 0x20, 0x69, 0x74, 0x20, 0x77, 0x69, 0x6c, - 0x6c, 0x20, 0x62, 0x65, 0x20, 0x75, 0x73, 0x65, - 0x66, 0x75, 0x6c, 0x2c, 0x20, 0x62, 0x75, 0x74, - 0x0a, 0x20, 0x2a, 0x20, 0x57, 0x49, 0x54, 0x48, - 0x4f, 0x55, 0x54, 0x20, 0x41, 0x4e, 0x59, 0x20, - 0x57, 0x41, 0x52, 0x52, 0x41, 0x4e, 0x54, 0x59, - 0x3b, 0x20, 0x77, 0x69, 0x74, 0x68, 0x6f, 0x75, - 0x74, 0x20, 0x65, 0x76, 0x65, 0x6e, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x69, - 0x65, 0x64, 0x20, 0x77, 0x61, 0x72, 0x72, 0x61, - 0x6e, 0x74, 0x79, 0x20, 0x6f, 0x66, 0x0a, 0x20, - 0x2a, 0x20, 0x4d, 0x45, 0x52, 0x43, 0x48, 0x41, - 0x4e, 0x54, 0x41, 0x42, 0x49, 0x4c, 0x49, 0x54, - 0x59, 0x20, 0x6f, 0x72, 0x20, 0x46, 0x49, 0x54, - 0x4e, 0x45, 0x53, 0x53, 0x20, 0x46, 0x4f, 0x52, - 0x20, 0x41, 0x20, 0x50, 0x41, 0x52, 0x54, 0x49, - 0x43, 0x55, 0x4c, 0x41, 0x52, 0x20, 0x50, 0x55, - 0x52, 0x50, 0x4f, 0x53, 0x45, 0x2e, 0x20, 0x20, - 0x53, 0x65, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x47, 0x4e, 0x55, 0x0a, 0x20, 0x2a, 0x20, 0x47, - 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x50, - 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69, - 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x66, 0x6f, - 0x72, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x64, - 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x2e, 0x0a, - 0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x59, 0x6f, - 0x75, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, - 0x20, 0x68, 0x61, 0x76, 0x65, 0x20, 0x72, 0x65, - 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x20, 0x61, - 0x20, 0x63, 0x6f, 0x70, 0x79, 0x20, 0x6f, 0x66, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55, - 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, - 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, - 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a, - 0x20, 0x2a, 0x20, 0x61, 0x6c, 0x6f, 0x6e, 0x67, - 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, - 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72, - 0x61, 0x6d, 0x3b, 0x20, 0x73, 0x65, 0x65, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, - 0x20, 0x43, 0x4f, 0x50, 0x59, 0x49, 0x4e, 0x47, - 0x2e, 0x20, 0x20, 0x49, 0x66, 0x20, 0x6e, 0x6f, - 0x74, 0x2c, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, - 0x20, 0x74, 0x6f, 0x0a, 0x20, 0x2a, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20, - 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x35, 0x31, 0x20, - 0x46, 0x72, 0x61, 0x6e, 0x6b, 0x6c, 0x69, 0x6e, - 0x20, 0x53, 0x74, 0x72, 0x65, 0x65, 0x74, 0x2c, - 0x20, 0x46, 0x69, 0x66, 0x74, 0x68, 0x20, 0x46, - 0x6c, 0x6f, 0x6f, 0x72, 0x2c, 0x0a, 0x20, 0x2a, - 0x20, 0x42, 0x6f, 0x73, 0x74, 0x6f, 0x6e, 0x2c, - 0x20, 0x4d, 0x41, 0x20, 0x30, 0x32, 0x31, 0x31, - 0x30, 0x2d, 0x31, 0x33, 0x30, 0x31, 0x2c, 0x20, - 0x55, 0x53, 0x41, 0x2e, 0x0a, 0x20, 0x2a, 0x2f, - 0x0a, -}; - -/* - * Sha1 IDS - */ -static char *commit_id = "3d7f8a6af076c8c3f20071a8935cdbe8228594d1"; -static char *tree_id = "dff2da90b254e1beb889d1f1f1288be1803782df"; -static char *tag_id = "09d373e1dfdc16b129ceec6dd649739911541e05"; -static char *zero_id = "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391"; -static char *one_id = "8b137891791fe96927ad78e64b0aad7bded08bdc"; -static char *two_id = "78981922613b2afb6025042ff6bd878ac1994e85"; -static char *some_id = "fd8430bc864cfcd5f10e5590f8a447e01b942bfe"; - -/* - * In memory objects - */ -static git_rawobj tree_obj = { - tree_data, - sizeof(tree_data), - GIT_OBJ_TREE -}; - -static git_rawobj tag_obj = { - tag_data, - sizeof(tag_data), - GIT_OBJ_TAG -}; - -static git_rawobj zero_obj = { - zero_data, - 0, - GIT_OBJ_BLOB -}; - -static git_rawobj one_obj = { - one_data, - sizeof(one_data), - GIT_OBJ_BLOB -}; - -static git_rawobj two_obj = { - two_data, - sizeof(two_data), - GIT_OBJ_BLOB -}; - -static git_rawobj commit_obj = { - commit_data, - sizeof(commit_data), - GIT_OBJ_COMMIT -}; - -static git_rawobj some_obj = { - some_data, - sizeof(some_data), - GIT_OBJ_BLOB -}; - -static git_rawobj junk_obj = { - NULL, - 0, - GIT_OBJ_BAD -}; - - diff --git a/vendor/libgit2/tests/t01-rawobj.c b/vendor/libgit2/tests/t01-rawobj.c deleted file mode 100644 index 255208532..000000000 --- a/vendor/libgit2/tests/t01-rawobj.c +++ /dev/null @@ -1,638 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "test_lib.h" - -#include "odb.h" -#include "hash.h" - -#include "t01-data.h" - -static int hash_object(git_oid *oid, git_rawobj *obj) -{ - return git_odb_hash(oid, obj->data, obj->len, obj->type); -} - -BEGIN_TEST(oid0, "validate size of oid objects") - git_oid out; - must_be_true(20 == GIT_OID_RAWSZ); - must_be_true(40 == GIT_OID_HEXSZ); - must_be_true(sizeof(out) == GIT_OID_RAWSZ); - must_be_true(sizeof(out.id) == GIT_OID_RAWSZ); -END_TEST - -BEGIN_TEST(oid1, "fail when parsing an empty string as oid") - git_oid out; - must_fail(git_oid_fromstr(&out, "")); -END_TEST - -BEGIN_TEST(oid2, "fail when parsing an invalid string as oid") - git_oid out; - must_fail(git_oid_fromstr(&out, "moo")); -END_TEST - -static int from_hex(unsigned int i) -{ - if (i >= '0' && i <= '9') - return i - '0'; - if (i >= 'a' && i <= 'f') - return 10 + (i - 'a'); - if (i >= 'A' && i <= 'F') - return 10 + (i - 'A'); - return -1; -} - -BEGIN_TEST(oid3, "find all invalid characters when parsing an oid") - git_oid out; - unsigned char exp[] = { - 0x16, 0xa6, 0x77, 0x70, 0xb7, - 0xd8, 0xd7, 0x23, 0x17, 0xc4, - 0xb7, 0x75, 0x21, 0x3c, 0x23, - 0xa8, 0xbd, 0x74, 0xf5, 0xe0, - }; - char in[41] = "16a67770b7d8d72317c4b775213c23a8bd74f5e0"; - unsigned int i; - - for (i = 0; i < 256; i++) { - in[38] = (char)i; - - if (from_hex(i) >= 0) { - exp[19] = (unsigned char)(from_hex(i) << 4); - must_pass(git_oid_fromstr(&out, in)); - must_be_true(memcmp(out.id, exp, sizeof(out.id)) == 0); - } else { - must_fail(git_oid_fromstr(&out, in)); - } - } -END_TEST - -BEGIN_TEST(oid4, "fail when parsing an invalid oid string") - git_oid out; - must_fail(git_oid_fromstr(&out, "16a67770b7d8d72317c4b775213c23a8bd74f5ez")); -END_TEST - -BEGIN_TEST(oid5, "succeed when parsing a valid oid string") - git_oid out; - unsigned char exp[] = { - 0x16, 0xa6, 0x77, 0x70, 0xb7, - 0xd8, 0xd7, 0x23, 0x17, 0xc4, - 0xb7, 0x75, 0x21, 0x3c, 0x23, - 0xa8, 0xbd, 0x74, 0xf5, 0xe0, - }; - - must_pass(git_oid_fromstr(&out, "16a67770b7d8d72317c4b775213c23a8bd74f5e0")); - must_pass(memcmp(out.id, exp, sizeof(out.id))); - - must_pass(git_oid_fromstr(&out, "16A67770B7D8D72317C4b775213C23A8BD74F5E0")); - must_pass(memcmp(out.id, exp, sizeof(out.id))); -END_TEST - -BEGIN_TEST(oid6, "build a valid oid from raw bytes") - git_oid out; - unsigned char exp[] = { - 0x16, 0xa6, 0x77, 0x70, 0xb7, - 0xd8, 0xd7, 0x23, 0x17, 0xc4, - 0xb7, 0x75, 0x21, 0x3c, 0x23, - 0xa8, 0xbd, 0x74, 0xf5, 0xe0, - }; - - git_oid_fromraw(&out, exp); - must_pass(memcmp(out.id, exp, sizeof(out.id))); -END_TEST - -BEGIN_TEST(oid7, "properly copy an oid to another") - git_oid a, b; - unsigned char exp[] = { - 0x16, 0xa6, 0x77, 0x70, 0xb7, - 0xd8, 0xd7, 0x23, 0x17, 0xc4, - 0xb7, 0x75, 0x21, 0x3c, 0x23, - 0xa8, 0xbd, 0x74, 0xf5, 0xe0, - }; - - memset(&b, 0, sizeof(b)); - git_oid_fromraw(&a, exp); - git_oid_cpy(&b, &a); - must_pass(memcmp(a.id, exp, sizeof(a.id))); -END_TEST - -BEGIN_TEST(oid8, "compare two oids (lesser than)") - git_oid a, b; - unsigned char a_in[] = { - 0x16, 0xa6, 0x77, 0x70, 0xb7, - 0xd8, 0xd7, 0x23, 0x17, 0xc4, - 0xb7, 0x75, 0x21, 0x3c, 0x23, - 0xa8, 0xbd, 0x74, 0xf5, 0xe0, - }; - unsigned char b_in[] = { - 0x16, 0xa6, 0x77, 0x70, 0xb7, - 0xd8, 0xd7, 0x23, 0x17, 0xc4, - 0xb7, 0x75, 0x21, 0x3c, 0x23, - 0xa8, 0xbd, 0x74, 0xf5, 0xf0, - }; - - git_oid_fromraw(&a, a_in); - git_oid_fromraw(&b, b_in); - must_be_true(git_oid_cmp(&a, &b) < 0); -END_TEST - -BEGIN_TEST(oid9, "compare two oids (equal)") - git_oid a, b; - unsigned char a_in[] = { - 0x16, 0xa6, 0x77, 0x70, 0xb7, - 0xd8, 0xd7, 0x23, 0x17, 0xc4, - 0xb7, 0x75, 0x21, 0x3c, 0x23, - 0xa8, 0xbd, 0x74, 0xf5, 0xe0, - }; - - git_oid_fromraw(&a, a_in); - git_oid_fromraw(&b, a_in); - must_be_true(git_oid_cmp(&a, &b) == 0); -END_TEST - -BEGIN_TEST(oid10, "compare two oids (greater than)") - git_oid a, b; - unsigned char a_in[] = { - 0x16, 0xa6, 0x77, 0x70, 0xb7, - 0xd8, 0xd7, 0x23, 0x17, 0xc4, - 0xb7, 0x75, 0x21, 0x3c, 0x23, - 0xa8, 0xbd, 0x74, 0xf5, 0xe0, - }; - unsigned char b_in[] = { - 0x16, 0xa6, 0x77, 0x70, 0xb7, - 0xd8, 0xd7, 0x23, 0x17, 0xc4, - 0xb7, 0x75, 0x21, 0x3c, 0x23, - 0xa8, 0xbd, 0x74, 0xf5, 0xd0, - }; - - git_oid_fromraw(&a, a_in); - git_oid_fromraw(&b, b_in); - must_be_true(git_oid_cmp(&a, &b) > 0); -END_TEST - -BEGIN_TEST(oid11, "compare formated oids") - const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0"; - git_oid in; - char out[GIT_OID_HEXSZ + 1]; - - must_pass(git_oid_fromstr(&in, exp)); - - /* Format doesn't touch the last byte */ - out[GIT_OID_HEXSZ] = 'Z'; - git_oid_fmt(out, &in); - must_be_true(out[GIT_OID_HEXSZ] == 'Z'); - - /* Format produced the right result */ - out[GIT_OID_HEXSZ] = '\0'; - must_be_true(strcmp(exp, out) == 0); -END_TEST - -BEGIN_TEST(oid12, "compare oids (allocate + format)") - const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0"; - git_oid in; - char *out; - - must_pass(git_oid_fromstr(&in, exp)); - - out = git_oid_allocfmt(&in); - must_be_true(out); - must_be_true(strcmp(exp, out) == 0); - free(out); -END_TEST - -BEGIN_TEST(oid13, "compare oids (path format)") - const char *exp1 = "16a0123456789abcdef4b775213c23a8bd74f5e0"; - const char *exp2 = "16/a0123456789abcdef4b775213c23a8bd74f5e0"; - git_oid in; - char out[GIT_OID_HEXSZ + 2]; - - must_pass(git_oid_fromstr(&in, exp1)); - - /* Format doesn't touch the last byte */ - out[GIT_OID_HEXSZ + 1] = 'Z'; - git_oid_pathfmt(out, &in); - must_be_true(out[GIT_OID_HEXSZ + 1] == 'Z'); - - /* Format produced the right result */ - out[GIT_OID_HEXSZ + 1] = '\0'; - must_be_true(strcmp(exp2, out) == 0); -END_TEST - -BEGIN_TEST(oid14, "convert raw oid to string") - const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0"; - git_oid in; - char out[GIT_OID_HEXSZ + 1]; - char *str; - int i; - - must_pass(git_oid_fromstr(&in, exp)); - - /* NULL buffer pointer, returns static empty string */ - str = git_oid_to_string(NULL, sizeof(out), &in); - must_be_true(str && *str == '\0' && str != out); - - /* zero buffer size, returns static empty string */ - str = git_oid_to_string(out, 0, &in); - must_be_true(str && *str == '\0' && str != out); - - /* NULL oid pointer, returns static empty string */ - str = git_oid_to_string(out, sizeof(out), NULL); - must_be_true(str && *str == '\0' && str != out); - - /* n == 1, returns out as an empty string */ - str = git_oid_to_string(out, 1, &in); - must_be_true(str && *str == '\0' && str == out); - - for (i = 1; i < GIT_OID_HEXSZ; i++) { - out[i+1] = 'Z'; - str = git_oid_to_string(out, i+1, &in); - /* returns out containing c-string */ - must_be_true(str && str == out); - /* must be '\0' terminated */ - must_be_true(*(str+i) == '\0'); - /* must not touch bytes past end of string */ - must_be_true(*(str+(i+1)) == 'Z'); - /* i == n-1 charaters of string */ - must_pass(strncmp(exp, out, i)); - } - - /* returns out as hex formatted c-string */ - str = git_oid_to_string(out, sizeof(out), &in); - must_be_true(str && str == out && *(str+GIT_OID_HEXSZ) == '\0'); - must_be_true(strcmp(exp, out) == 0); -END_TEST - -BEGIN_TEST(oid15, "convert raw oid to string (big)") - const char *exp = "16a0123456789abcdef4b775213c23a8bd74f5e0"; - git_oid in; - char big[GIT_OID_HEXSZ + 1 + 3]; /* note + 4 => big buffer */ - char *str; - - must_pass(git_oid_fromstr(&in, exp)); - - /* place some tail material */ - big[GIT_OID_HEXSZ+0] = 'W'; /* should be '\0' afterwards */ - big[GIT_OID_HEXSZ+1] = 'X'; /* should remain untouched */ - big[GIT_OID_HEXSZ+2] = 'Y'; /* ditto */ - big[GIT_OID_HEXSZ+3] = 'Z'; /* ditto */ - - /* returns big as hex formatted c-string */ - str = git_oid_to_string(big, sizeof(big), &in); - must_be_true(str && str == big && *(str+GIT_OID_HEXSZ) == '\0'); - must_be_true(strcmp(exp, big) == 0); - - /* check tail material is untouched */ - must_be_true(str && str == big && *(str+GIT_OID_HEXSZ+1) == 'X'); - must_be_true(str && str == big && *(str+GIT_OID_HEXSZ+2) == 'Y'); - must_be_true(str && str == big && *(str+GIT_OID_HEXSZ+3) == 'Z'); -END_TEST - - -BEGIN_TEST(oid16, "make sure the OID shortener doesn't choke on duplicate sha1s") - - git_oid_shorten *os; - int min_len; - - os = git_oid_shorten_new(0); - must_be_true(os != NULL); - - git_oid_shorten_add(os, "22596363b3de40b06f981fb85d82312e8c0ed511"); - git_oid_shorten_add(os, "ce08fe4884650f067bd5703b6a59a8b3b3c99a09"); - git_oid_shorten_add(os, "16a0123456789abcdef4b775213c23a8bd74f5e0"); - min_len = git_oid_shorten_add(os, "ce08fe4884650f067bd5703b6a59a8b3b3c99a09"); - - must_be_true(min_len == GIT_OID_HEXSZ + 1); - - git_oid_shorten_free(os); -END_TEST - -BEGIN_TEST(oid17, "stress test for the git_oid_shorten object") - -#define MAX_OIDS 1000 - - git_oid_shorten *os; - char *oids[MAX_OIDS]; - char number_buffer[16]; - git_oid oid; - size_t i, j; - - int min_len = 0, found_collision; - - os = git_oid_shorten_new(0); - must_be_true(os != NULL); - - /* - * Insert in the shortener 1000 unique SHA1 ids - */ - for (i = 0; i < MAX_OIDS; ++i) { - char *oid_text; - - sprintf(number_buffer, "%u", (unsigned int)i); - git_hash_buf(&oid, number_buffer, strlen(number_buffer)); - - oid_text = git__malloc(GIT_OID_HEXSZ + 1); - git_oid_fmt(oid_text, &oid); - oid_text[GIT_OID_HEXSZ] = 0; - - min_len = git_oid_shorten_add(os, oid_text); - must_be_true(min_len >= 0); - - oids[i] = oid_text; - } - - /* - * Compare the first `min_char - 1` characters of each - * SHA1 OID. If the minimizer worked, we should find at - * least one collision - */ - found_collision = 0; - for (i = 0; i < MAX_OIDS; ++i) { - for (j = 0; j < MAX_OIDS; ++j) { - if (i != j && memcmp(oids[i], oids[j], min_len - 1) == 0) - found_collision = 1; - } - } - must_be_true(found_collision == 1); - - /* - * Compare the first `min_char` characters of each - * SHA1 OID. If the minimizer worked, every single preffix - * should be unique. - */ - found_collision = 0; - for (i = 0; i < MAX_OIDS; ++i) { - for (j = 0; j < MAX_OIDS; ++j) { - if (i != j && memcmp(oids[i], oids[j], min_len) == 0) - found_collision = 1; - } - } - must_be_true(found_collision == 0); - - /* cleanup */ - for (i = 0; i < MAX_OIDS; ++i) - free(oids[i]); - - git_oid_shorten_free(os); - -#undef MAX_OIDS -END_TEST - -static char *hello_id = "22596363b3de40b06f981fb85d82312e8c0ed511"; -static char *hello_text = "hello world\n"; - -static char *bye_id = "ce08fe4884650f067bd5703b6a59a8b3b3c99a09"; -static char *bye_text = "bye world\n"; - -BEGIN_TEST(hash0, "normal hash by blocks") - git_hash_ctx *ctx; - git_oid id1, id2; - - must_be_true((ctx = git_hash_new_ctx()) != NULL); - - /* should already be init'd */ - git_hash_update(ctx, hello_text, strlen(hello_text)); - git_hash_final(&id2, ctx); - must_pass(git_oid_fromstr(&id1, hello_id)); - must_be_true(git_oid_cmp(&id1, &id2) == 0); - - /* reinit should permit reuse */ - git_hash_init(ctx); - git_hash_update(ctx, bye_text, strlen(bye_text)); - git_hash_final(&id2, ctx); - must_pass(git_oid_fromstr(&id1, bye_id)); - must_be_true(git_oid_cmp(&id1, &id2) == 0); - - git_hash_free_ctx(ctx); -END_TEST - -BEGIN_TEST(hash1, "hash whole buffer in a single call") - git_oid id1, id2; - - must_pass(git_oid_fromstr(&id1, hello_id)); - - git_hash_buf(&id2, hello_text, strlen(hello_text)); - - must_be_true(git_oid_cmp(&id1, &id2) == 0); -END_TEST - -BEGIN_TEST(hash2, "hash a vector") - git_oid id1, id2; - git_buf_vec vec[2]; - - must_pass(git_oid_fromstr(&id1, hello_id)); - - vec[0].data = hello_text; - vec[0].len = 4; - vec[1].data = hello_text+4; - vec[1].len = strlen(hello_text)-4; - - git_hash_vec(&id2, vec, 2); - - must_be_true(git_oid_cmp(&id1, &id2) == 0); -END_TEST - -BEGIN_TEST(objtype0, "convert type to string") - must_be_true(!strcmp(git_object_type2string(GIT_OBJ_BAD), "")); - must_be_true(!strcmp(git_object_type2string(GIT_OBJ__EXT1), "")); - must_be_true(!strcmp(git_object_type2string(GIT_OBJ_COMMIT), "commit")); - must_be_true(!strcmp(git_object_type2string(GIT_OBJ_TREE), "tree")); - must_be_true(!strcmp(git_object_type2string(GIT_OBJ_BLOB), "blob")); - must_be_true(!strcmp(git_object_type2string(GIT_OBJ_TAG), "tag")); - must_be_true(!strcmp(git_object_type2string(GIT_OBJ__EXT2), "")); - must_be_true(!strcmp(git_object_type2string(GIT_OBJ_OFS_DELTA), "OFS_DELTA")); - must_be_true(!strcmp(git_object_type2string(GIT_OBJ_REF_DELTA), "REF_DELTA")); - - must_be_true(!strcmp(git_object_type2string(-2), "")); - must_be_true(!strcmp(git_object_type2string(8), "")); - must_be_true(!strcmp(git_object_type2string(1234), "")); -END_TEST - -BEGIN_TEST(objtype1, "convert string to type") - must_be_true(git_object_string2type(NULL) == GIT_OBJ_BAD); - must_be_true(git_object_string2type("") == GIT_OBJ_BAD); - must_be_true(git_object_string2type("commit") == GIT_OBJ_COMMIT); - must_be_true(git_object_string2type("tree") == GIT_OBJ_TREE); - must_be_true(git_object_string2type("blob") == GIT_OBJ_BLOB); - must_be_true(git_object_string2type("tag") == GIT_OBJ_TAG); - must_be_true(git_object_string2type("OFS_DELTA") == GIT_OBJ_OFS_DELTA); - must_be_true(git_object_string2type("REF_DELTA") == GIT_OBJ_REF_DELTA); - - must_be_true(git_object_string2type("CoMmIt") == GIT_OBJ_BAD); - must_be_true(git_object_string2type("hohoho") == GIT_OBJ_BAD); -END_TEST - -BEGIN_TEST(objtype2, "check if an object type is loose") - must_be_true(git_object_typeisloose(GIT_OBJ_BAD) == 0); - must_be_true(git_object_typeisloose(GIT_OBJ__EXT1) == 0); - must_be_true(git_object_typeisloose(GIT_OBJ_COMMIT) == 1); - must_be_true(git_object_typeisloose(GIT_OBJ_TREE) == 1); - must_be_true(git_object_typeisloose(GIT_OBJ_BLOB) == 1); - must_be_true(git_object_typeisloose(GIT_OBJ_TAG) == 1); - must_be_true(git_object_typeisloose(GIT_OBJ__EXT2) == 0); - must_be_true(git_object_typeisloose(GIT_OBJ_OFS_DELTA) == 0); - must_be_true(git_object_typeisloose(GIT_OBJ_REF_DELTA) == 0); - - must_be_true(git_object_typeisloose(-2) == 0); - must_be_true(git_object_typeisloose(8) == 0); - must_be_true(git_object_typeisloose(1234) == 0); -END_TEST - -BEGIN_TEST(objhash0, "hash junk data") - git_oid id, id_zero; - - must_pass(git_oid_fromstr(&id_zero, zero_id)); - - /* invalid types: */ - junk_obj.data = some_data; - must_fail(hash_object(&id, &junk_obj)); - - junk_obj.type = GIT_OBJ__EXT1; - must_fail(hash_object(&id, &junk_obj)); - - junk_obj.type = GIT_OBJ__EXT2; - must_fail(hash_object(&id, &junk_obj)); - - junk_obj.type = GIT_OBJ_OFS_DELTA; - must_fail(hash_object(&id, &junk_obj)); - - junk_obj.type = GIT_OBJ_REF_DELTA; - must_fail(hash_object(&id, &junk_obj)); - - /* data can be NULL only if len is zero: */ - junk_obj.type = GIT_OBJ_BLOB; - junk_obj.data = NULL; - must_pass(hash_object(&id, &junk_obj)); - must_be_true(git_oid_cmp(&id, &id_zero) == 0); - - junk_obj.len = 1; - must_fail(hash_object(&id, &junk_obj)); -END_TEST - -BEGIN_TEST(objhash1, "hash a commit object") - git_oid id1, id2; - - must_pass(git_oid_fromstr(&id1, commit_id)); - - must_pass(hash_object(&id2, &commit_obj)); - - must_be_true(git_oid_cmp(&id1, &id2) == 0); -END_TEST - -BEGIN_TEST(objhash2, "hash a tree object") - git_oid id1, id2; - - must_pass(git_oid_fromstr(&id1, tree_id)); - - must_pass(hash_object(&id2, &tree_obj)); - - must_be_true(git_oid_cmp(&id1, &id2) == 0); -END_TEST - -BEGIN_TEST(objhash3, "hash a tag object") - git_oid id1, id2; - - must_pass(git_oid_fromstr(&id1, tag_id)); - - must_pass(hash_object(&id2, &tag_obj)); - - must_be_true(git_oid_cmp(&id1, &id2) == 0); -END_TEST - -BEGIN_TEST(objhash4, "hash a zero-length object") - git_oid id1, id2; - - must_pass(git_oid_fromstr(&id1, zero_id)); - - must_pass(hash_object(&id2, &zero_obj)); - - must_be_true(git_oid_cmp(&id1, &id2) == 0); -END_TEST - -BEGIN_TEST(objhash5, "hash an one-byte long object") - git_oid id1, id2; - - must_pass(git_oid_fromstr(&id1, one_id)); - - must_pass(hash_object(&id2, &one_obj)); - - must_be_true(git_oid_cmp(&id1, &id2) == 0); -END_TEST - -BEGIN_TEST(objhash6, "hash a two-byte long object") - git_oid id1, id2; - - must_pass(git_oid_fromstr(&id1, two_id)); - - must_pass(hash_object(&id2, &two_obj)); - - must_be_true(git_oid_cmp(&id1, &id2) == 0); -END_TEST - -BEGIN_TEST(objhash7, "hash an object several bytes long") - git_oid id1, id2; - - must_pass(git_oid_fromstr(&id1, some_id)); - - must_pass(hash_object(&id2, &some_obj)); - - must_be_true(git_oid_cmp(&id1, &id2) == 0); -END_TEST - -BEGIN_SUITE(rawobjects) - ADD_TEST(oid0); - ADD_TEST(oid1); - ADD_TEST(oid2); - ADD_TEST(oid3); - ADD_TEST(oid4); - ADD_TEST(oid5); - ADD_TEST(oid6); - ADD_TEST(oid7); - ADD_TEST(oid8); - ADD_TEST(oid9); - ADD_TEST(oid10); - ADD_TEST(oid11); - ADD_TEST(oid12); - ADD_TEST(oid13); - ADD_TEST(oid14); - ADD_TEST(oid15); - ADD_TEST(oid16); - ADD_TEST(oid17); - - ADD_TEST(hash0); - ADD_TEST(hash1); - ADD_TEST(hash2); - - ADD_TEST(objtype0); - ADD_TEST(objtype1); - ADD_TEST(objtype2); - - ADD_TEST(objhash0); - ADD_TEST(objhash1); - ADD_TEST(objhash2); - ADD_TEST(objhash3); - ADD_TEST(objhash4); - ADD_TEST(objhash5); - ADD_TEST(objhash6); - ADD_TEST(objhash7); -END_SUITE - diff --git a/vendor/libgit2/tests/t02-data.h b/vendor/libgit2/tests/t02-data.h deleted file mode 100644 index 705a2d7af..000000000 --- a/vendor/libgit2/tests/t02-data.h +++ /dev/null @@ -1,515 +0,0 @@ - -static char *odb_dir = "test-objects"; - -/* one == 8b137891791fe96927ad78e64b0aad7bded08bdc */ -static unsigned char one_bytes[] = { - 0x31, 0x78, 0x9c, 0xe3, 0x02, 0x00, 0x00, 0x0b, - 0x00, 0x0b, -}; - -static unsigned char one_data[] = { - 0x0a, -}; - -static object_data one = { - one_bytes, - sizeof(one_bytes), - "8b137891791fe96927ad78e64b0aad7bded08bdc", - "blob", - "test-objects/8b", - "test-objects/8b/137891791fe96927ad78e64b0aad7bded08bdc", - one_data, - sizeof(one_data), -}; - - -/* commit == 3d7f8a6af076c8c3f20071a8935cdbe8228594d1 */ -static unsigned char commit_bytes[] = { - 0x78, 0x01, 0x85, 0x50, 0xc1, 0x6a, 0xc3, 0x30, - 0x0c, 0xdd, 0xd9, 0x5f, 0xa1, 0xfb, 0x96, 0x12, - 0xbb, 0x29, 0x71, 0x46, 0x19, 0x2b, 0x3d, 0x97, - 0x1d, 0xd6, 0x7d, 0x80, 0x1d, 0xcb, 0x89, 0x21, - 0xb6, 0x82, 0xed, 0x40, 0xf3, 0xf7, 0xf3, 0x48, - 0x29, 0x3b, 0x6d, 0xd2, 0xe5, 0xbd, 0x27, 0xbd, - 0x27, 0x50, 0x4f, 0xde, 0xbb, 0x0c, 0xfb, 0x43, - 0xf3, 0x94, 0x23, 0x22, 0x18, 0x6b, 0x85, 0x51, - 0x5d, 0xad, 0xc5, 0xa1, 0x41, 0xae, 0x51, 0x4b, - 0xd9, 0x19, 0x6e, 0x4b, 0x0b, 0x29, 0x35, 0x72, - 0x59, 0xef, 0x5b, 0x29, 0x8c, 0x65, 0x6a, 0xc9, - 0x23, 0x45, 0x38, 0xc1, 0x17, 0x5c, 0x7f, 0xc0, - 0x71, 0x13, 0xde, 0xf1, 0xa6, 0xfc, 0x3c, 0xe1, - 0xae, 0x27, 0xff, 0x06, 0x5c, 0x88, 0x56, 0xf2, - 0x46, 0x74, 0x2d, 0x3c, 0xd7, 0xa5, 0x58, 0x51, - 0xcb, 0xb9, 0x8c, 0x11, 0xce, 0xf0, 0x01, 0x97, - 0x0d, 0x1e, 0x1f, 0xea, 0x3f, 0x6e, 0x76, 0x02, - 0x0a, 0x58, 0x4d, 0x2e, 0x20, 0x6c, 0x1e, 0x48, - 0x8b, 0xf7, 0x2a, 0xae, 0x8c, 0x5d, 0x47, 0x04, - 0x4d, 0x66, 0x05, 0xb2, 0x90, 0x0b, 0xbe, 0xcf, - 0x3d, 0xa6, 0xa4, 0x06, 0x7c, 0x29, 0x3c, 0x64, - 0xe5, 0x82, 0x0b, 0x03, 0xd8, 0x25, 0x96, 0x8d, - 0x08, 0x78, 0x9b, 0x27, 0x15, 0x54, 0x76, 0x14, - 0xd8, 0xdd, 0x35, 0x2f, 0x71, 0xa6, 0x84, 0x8f, - 0x90, 0x51, 0x85, 0x01, 0x13, 0xb8, 0x90, 0x23, - 0x99, 0xa5, 0x47, 0x03, 0x7a, 0xfd, 0x15, 0xbf, - 0x63, 0xec, 0xd3, 0x0d, 0x01, 0x4d, 0x45, 0xb6, - 0xd2, 0xeb, 0xeb, 0xdf, 0xef, 0x60, 0xdf, 0xef, - 0x1f, 0x78, 0x35, -}; - -static unsigned char commit_data[] = { - 0x74, 0x72, 0x65, 0x65, 0x20, 0x64, 0x66, 0x66, - 0x32, 0x64, 0x61, 0x39, 0x30, 0x62, 0x32, 0x35, - 0x34, 0x65, 0x31, 0x62, 0x65, 0x62, 0x38, 0x38, - 0x39, 0x64, 0x31, 0x66, 0x31, 0x66, 0x31, 0x32, - 0x38, 0x38, 0x62, 0x65, 0x31, 0x38, 0x30, 0x33, - 0x37, 0x38, 0x32, 0x64, 0x66, 0x0a, 0x61, 0x75, - 0x74, 0x68, 0x6f, 0x72, 0x20, 0x41, 0x20, 0x55, - 0x20, 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, - 0x75, 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, - 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, - 0x6d, 0x3e, 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, - 0x31, 0x34, 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, - 0x30, 0x30, 0x30, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, - 0x69, 0x74, 0x74, 0x65, 0x72, 0x20, 0x43, 0x20, - 0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72, - 0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, - 0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e, - 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34, - 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30, - 0x30, 0x0a, 0x0a, 0x41, 0x20, 0x6f, 0x6e, 0x65, - 0x2d, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x63, 0x6f, - 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x73, 0x75, 0x6d, - 0x6d, 0x61, 0x72, 0x79, 0x0a, 0x0a, 0x54, 0x68, - 0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x6f, - 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, - 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x6d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x2c, 0x20, 0x63, 0x6f, - 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67, - 0x20, 0x66, 0x75, 0x72, 0x74, 0x68, 0x65, 0x72, - 0x20, 0x65, 0x78, 0x70, 0x6c, 0x61, 0x6e, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x6f, 0x66, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x72, 0x70, - 0x6f, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x67, - 0x65, 0x73, 0x20, 0x69, 0x6e, 0x74, 0x72, 0x6f, - 0x64, 0x75, 0x63, 0x65, 0x64, 0x20, 0x62, 0x79, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6d, - 0x6d, 0x69, 0x74, 0x2e, 0x0a, 0x0a, 0x53, 0x69, - 0x67, 0x6e, 0x65, 0x64, 0x2d, 0x6f, 0x66, 0x2d, - 0x62, 0x79, 0x3a, 0x20, 0x41, 0x20, 0x55, 0x20, - 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, 0x75, - 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, 0x61, - 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, - 0x3e, 0x0a, -}; - -static object_data commit = { - commit_bytes, - sizeof(commit_bytes), - "3d7f8a6af076c8c3f20071a8935cdbe8228594d1", - "commit", - "test-objects/3d", - "test-objects/3d/7f8a6af076c8c3f20071a8935cdbe8228594d1", - commit_data, - sizeof(commit_data), -}; - -/* tree == dff2da90b254e1beb889d1f1f1288be1803782df */ -static unsigned char tree_bytes[] = { - 0x78, 0x01, 0x2b, 0x29, 0x4a, 0x4d, 0x55, 0x30, - 0x34, 0x32, 0x63, 0x30, 0x34, 0x30, 0x30, 0x33, - 0x31, 0x51, 0xc8, 0xcf, 0x4b, 0x65, 0xe8, 0x16, - 0xae, 0x98, 0x58, 0x29, 0xff, 0x32, 0x53, 0x7d, - 0x6d, 0xc5, 0x33, 0x6f, 0xae, 0xb5, 0xd5, 0xf7, - 0x2e, 0x74, 0xdf, 0x81, 0x4a, 0x17, 0xe7, 0xe7, - 0xa6, 0x32, 0xfc, 0x6d, 0x31, 0xd8, 0xd3, 0xe6, - 0xf3, 0xe7, 0xea, 0x47, 0xbe, 0xd0, 0x09, 0x3f, - 0x96, 0xb8, 0x3f, 0x90, 0x9e, 0xa2, 0xfd, 0x0f, - 0x2a, 0x5f, 0x52, 0x9e, 0xcf, 0x50, 0x31, 0x43, - 0x52, 0x29, 0xd1, 0x5a, 0xeb, 0x77, 0x82, 0x2a, - 0x8b, 0xfe, 0xb7, 0xbd, 0xed, 0x5d, 0x07, 0x67, - 0xfa, 0xb5, 0x42, 0xa5, 0xab, 0x52, 0x8b, 0xf2, - 0x19, 0x9e, 0xcd, 0x7d, 0x34, 0x7b, 0xd3, 0xc5, - 0x6b, 0xce, 0xde, 0xdd, 0x9a, 0xeb, 0xca, 0xa3, - 0x6e, 0x1c, 0x7a, 0xd2, 0x13, 0x3c, 0x11, 0x00, - 0xe2, 0xaa, 0x38, 0x57, -}; - -static unsigned char tree_data[] = { - 0x31, 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x6f, - 0x6e, 0x65, 0x00, 0x8b, 0x13, 0x78, 0x91, 0x79, - 0x1f, 0xe9, 0x69, 0x27, 0xad, 0x78, 0xe6, 0x4b, - 0x0a, 0xad, 0x7b, 0xde, 0xd0, 0x8b, 0xdc, 0x31, - 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x73, 0x6f, - 0x6d, 0x65, 0x00, 0xfd, 0x84, 0x30, 0xbc, 0x86, - 0x4c, 0xfc, 0xd5, 0xf1, 0x0e, 0x55, 0x90, 0xf8, - 0xa4, 0x47, 0xe0, 0x1b, 0x94, 0x2b, 0xfe, 0x31, - 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x74, 0x77, - 0x6f, 0x00, 0x78, 0x98, 0x19, 0x22, 0x61, 0x3b, - 0x2a, 0xfb, 0x60, 0x25, 0x04, 0x2f, 0xf6, 0xbd, - 0x87, 0x8a, 0xc1, 0x99, 0x4e, 0x85, 0x31, 0x30, - 0x30, 0x36, 0x34, 0x34, 0x20, 0x7a, 0x65, 0x72, - 0x6f, 0x00, 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, - 0xd6, 0x43, 0x4b, 0x8b, 0x29, 0xae, 0x77, 0x5a, - 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91, -}; - -static object_data tree = { - tree_bytes, - sizeof(tree_bytes), - "dff2da90b254e1beb889d1f1f1288be1803782df", - "tree", - "test-objects/df", - "test-objects/df/f2da90b254e1beb889d1f1f1288be1803782df", - tree_data, - sizeof(tree_data), -}; - -/* tag == 09d373e1dfdc16b129ceec6dd649739911541e05 */ -static unsigned char tag_bytes[] = { - 0x78, 0x01, 0x35, 0x4e, 0xcb, 0x0a, 0xc2, 0x40, - 0x10, 0xf3, 0xbc, 0x5f, 0x31, 0x77, 0xa1, 0xec, - 0xa3, 0xed, 0x6e, 0x41, 0x44, 0xf0, 0x2c, 0x5e, - 0xfc, 0x81, 0xe9, 0x76, 0xb6, 0xad, 0xb4, 0xb4, - 0x6c, 0x07, 0xd1, 0xbf, 0x77, 0x44, 0x0d, 0x39, - 0x84, 0x10, 0x92, 0x30, 0xf6, 0x60, 0xbc, 0xdb, - 0x2d, 0xed, 0x9d, 0x22, 0x83, 0xeb, 0x7c, 0x0a, - 0x58, 0x63, 0xd2, 0xbe, 0x8e, 0x21, 0xba, 0x64, - 0xb5, 0xf6, 0x06, 0x43, 0xe3, 0xaa, 0xd8, 0xb5, - 0x14, 0xac, 0x0d, 0x55, 0x53, 0x76, 0x46, 0xf1, - 0x6b, 0x25, 0x88, 0xcb, 0x3c, 0x8f, 0xac, 0x58, - 0x3a, 0x1e, 0xba, 0xd0, 0x85, 0xd8, 0xd8, 0xf7, - 0x94, 0xe1, 0x0c, 0x57, 0xb8, 0x8c, 0xcc, 0x22, - 0x0f, 0xdf, 0x90, 0xc8, 0x13, 0x3d, 0x71, 0x5e, - 0x27, 0x2a, 0xc4, 0x39, 0x82, 0xb1, 0xd6, 0x07, - 0x53, 0xda, 0xc6, 0xc3, 0x5e, 0x0b, 0x94, 0xba, - 0x0d, 0xe3, 0x06, 0x42, 0x1e, 0x08, 0x3e, 0x95, - 0xbf, 0x4b, 0x69, 0xc9, 0x90, 0x69, 0x22, 0xdc, - 0xe8, 0xbf, 0xf2, 0x06, 0x42, 0x9a, 0x36, 0xb1, -}; - -static unsigned char tag_data[] = { - 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x33, - 0x64, 0x37, 0x66, 0x38, 0x61, 0x36, 0x61, 0x66, - 0x30, 0x37, 0x36, 0x63, 0x38, 0x63, 0x33, 0x66, - 0x32, 0x30, 0x30, 0x37, 0x31, 0x61, 0x38, 0x39, - 0x33, 0x35, 0x63, 0x64, 0x62, 0x65, 0x38, 0x32, - 0x32, 0x38, 0x35, 0x39, 0x34, 0x64, 0x31, 0x0a, - 0x74, 0x79, 0x70, 0x65, 0x20, 0x63, 0x6f, 0x6d, - 0x6d, 0x69, 0x74, 0x0a, 0x74, 0x61, 0x67, 0x20, - 0x76, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0a, 0x74, - 0x61, 0x67, 0x67, 0x65, 0x72, 0x20, 0x43, 0x20, - 0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72, - 0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, - 0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e, - 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34, - 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30, - 0x30, 0x0a, 0x0a, 0x54, 0x68, 0x69, 0x73, 0x20, - 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, - 0x61, 0x67, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, - 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x72, 0x65, - 0x6c, 0x65, 0x61, 0x73, 0x65, 0x20, 0x76, 0x30, - 0x2e, 0x30, 0x2e, 0x31, 0x0a, -}; - -static object_data tag = { - tag_bytes, - sizeof(tag_bytes), - "09d373e1dfdc16b129ceec6dd649739911541e05", - "tag", - "test-objects/09", - "test-objects/09/d373e1dfdc16b129ceec6dd649739911541e05", - tag_data, - sizeof(tag_data), -}; - -/* zero == e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 */ -static unsigned char zero_bytes[] = { - 0x78, 0x01, 0x4b, 0xca, 0xc9, 0x4f, 0x52, 0x30, - 0x60, 0x00, 0x00, 0x09, 0xb0, 0x01, 0xf0, -}; - -static unsigned char zero_data[] = { - 0x00 /* dummy data */ -}; - -static object_data zero = { - zero_bytes, - sizeof(zero_bytes), - "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", - "blob", - "test-objects/e6", - "test-objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391", - zero_data, - 0, -}; - -/* two == 78981922613b2afb6025042ff6bd878ac1994e85 */ -static unsigned char two_bytes[] = { - 0x78, 0x01, 0x4b, 0xca, 0xc9, 0x4f, 0x52, 0x30, - 0x62, 0x48, 0xe4, 0x02, 0x00, 0x0e, 0x64, 0x02, - 0x5d, -}; - -static unsigned char two_data[] = { - 0x61, 0x0a, -}; - -static object_data two = { - two_bytes, - sizeof(two_bytes), - "78981922613b2afb6025042ff6bd878ac1994e85", - "blob", - "test-objects/78", - "test-objects/78/981922613b2afb6025042ff6bd878ac1994e85", - two_data, - sizeof(two_data), -}; - -/* some == fd8430bc864cfcd5f10e5590f8a447e01b942bfe */ -static unsigned char some_bytes[] = { - 0x78, 0x01, 0x7d, 0x54, 0xc1, 0x4e, 0xe3, 0x30, - 0x10, 0xdd, 0x33, 0x5f, 0x31, 0xc7, 0x5d, 0x94, - 0xa5, 0x84, 0xd5, 0x22, 0xad, 0x7a, 0x0a, 0x15, - 0x85, 0x48, 0xd0, 0x56, 0x49, 0x2a, 0xd4, 0xa3, - 0x13, 0x4f, 0x88, 0x85, 0x63, 0x47, 0xb6, 0x43, - 0xc9, 0xdf, 0xef, 0x8c, 0x69, 0x17, 0x56, 0x0b, - 0x7b, 0xaa, 0x62, 0x7b, 0xde, 0xbc, 0xf7, 0xe6, - 0x4d, 0x6b, 0x6d, 0x6b, 0x48, 0xd3, 0xcb, 0x5f, - 0x5f, 0x66, 0xa7, 0x27, 0x70, 0x0a, 0x55, 0xa7, - 0x3c, 0xb4, 0x4a, 0x23, 0xf0, 0xaf, 0x43, 0x04, - 0x6f, 0xdb, 0xb0, 0x17, 0x0e, 0xe7, 0x30, 0xd9, - 0x11, 0x1a, 0x61, 0xc0, 0xa1, 0x54, 0x3e, 0x38, - 0x55, 0x8f, 0x81, 0x9e, 0x05, 0x10, 0x46, 0xce, - 0xac, 0x83, 0xde, 0x4a, 0xd5, 0x4e, 0x0c, 0x42, - 0x67, 0xa3, 0x91, 0xe8, 0x20, 0x74, 0x08, 0x01, - 0x5d, 0xef, 0xc1, 0xb6, 0xf1, 0xe3, 0x66, 0xb5, - 0x85, 0x1b, 0x34, 0xe8, 0x84, 0x86, 0xcd, 0x58, - 0x6b, 0xd5, 0xc0, 0x9d, 0x6a, 0xd0, 0x78, 0x4c, - 0xe0, 0x19, 0x9d, 0x57, 0xd6, 0xc0, 0x45, 0xc2, - 0x18, 0xc2, 0xc3, 0xc0, 0x0f, 0x7c, 0x87, 0x12, - 0xea, 0x29, 0x56, 0x2f, 0x99, 0x4f, 0x79, 0xe0, - 0x03, 0x4b, 0x4b, 0x4d, 0x44, 0xa0, 0x92, 0x33, - 0x2a, 0xe0, 0x9a, 0xdc, 0x80, 0x90, 0x52, 0xf1, - 0x11, 0x04, 0x1b, 0x4b, 0x06, 0xea, 0xae, 0x3c, - 0xe3, 0x7a, 0x50, 0x74, 0x4a, 0x84, 0xfe, 0xc3, - 0x81, 0x41, 0xf8, 0x89, 0x18, 0x43, 0x67, 0x9d, - 0x87, 0x47, 0xf5, 0x8c, 0x51, 0xf6, 0x68, 0xb4, - 0xea, 0x55, 0x20, 0x2a, 0x6f, 0x80, 0xdc, 0x42, - 0x2b, 0xf3, 0x14, 0x2b, 0x1a, 0xdb, 0x0f, 0xe4, - 0x9a, 0x64, 0x84, 0xa3, 0x90, 0xa8, 0xf9, 0x8f, - 0x9d, 0x86, 0x9e, 0xd3, 0xab, 0x5a, 0x99, 0xc8, - 0xd9, 0xc3, 0x5e, 0x85, 0x0e, 0x2c, 0xb5, 0x73, - 0x30, 0x38, 0xfb, 0xe8, 0x44, 0xef, 0x5f, 0x95, - 0x1b, 0xc9, 0xd0, 0xef, 0x3c, 0x26, 0x32, 0x1e, - 0xff, 0x2d, 0xb6, 0x23, 0x7b, 0x3f, 0xd1, 0x3c, - 0x78, 0x1a, 0x0d, 0xcb, 0xe6, 0xf6, 0xd4, 0x44, - 0x99, 0x47, 0x1a, 0x9e, 0xed, 0x23, 0xb5, 0x91, - 0x6a, 0xdf, 0x53, 0x39, 0x03, 0xf8, 0x5a, 0xb1, - 0x0f, 0x1f, 0xce, 0x81, 0x11, 0xde, 0x01, 0x7a, - 0x90, 0x16, 0xc4, 0x30, 0xe8, 0x89, 0xed, 0x7b, - 0x65, 0x4b, 0xd7, 0x03, 0x36, 0xc1, 0xcf, 0xa1, - 0xa5, 0xb1, 0xe3, 0x8b, 0xe8, 0x07, 0x4d, 0xf3, - 0x23, 0x25, 0x13, 0x35, 0x27, 0xf5, 0x8c, 0x11, - 0xd3, 0xa0, 0x9a, 0xa8, 0xf5, 0x38, 0x7d, 0xce, - 0x55, 0xc2, 0x71, 0x79, 0x13, 0xc7, 0xa3, 0xda, - 0x77, 0x68, 0xc0, 0xd8, 0x10, 0xdd, 0x24, 0x8b, - 0x15, 0x59, 0xc5, 0x10, 0xe2, 0x20, 0x99, 0x8e, - 0xf0, 0x05, 0x9b, 0x31, 0x88, 0x5a, 0xe3, 0xd9, - 0x37, 0xba, 0xe2, 0xdb, 0xbf, 0x92, 0xfa, 0x66, - 0x16, 0x97, 0x47, 0xd9, 0x9d, 0x1d, 0x28, 0x7c, - 0x9d, 0x08, 0x1c, 0xc7, 0xbd, 0xd2, 0x1a, 0x6a, - 0x04, 0xf2, 0xa2, 0x1d, 0x75, 0x02, 0x14, 0x5d, - 0xc6, 0x78, 0xc8, 0xab, 0xdb, 0xf5, 0xb6, 0x82, - 0x6c, 0xb5, 0x83, 0x87, 0xac, 0x28, 0xb2, 0x55, - 0xb5, 0x9b, 0xc7, 0xc1, 0xb0, 0xb7, 0xf8, 0x4c, - 0xbc, 0x38, 0x0e, 0x8a, 0x04, 0x2a, 0x62, 0x41, - 0x6b, 0xe0, 0x84, 0x09, 0x13, 0xe9, 0xe1, 0xea, - 0xfb, 0xeb, 0x62, 0x71, 0x4b, 0x25, 0xd9, 0x55, - 0x7e, 0x97, 0x57, 0x3b, 0x20, 0x33, 0x96, 0x79, - 0xb5, 0xba, 0x2e, 0x4b, 0x58, 0xae, 0x0b, 0xc8, - 0x60, 0x93, 0x15, 0x55, 0xbe, 0xd8, 0xde, 0x65, - 0x05, 0x6c, 0xb6, 0xc5, 0x66, 0x5d, 0x5e, 0x93, - 0xf7, 0x25, 0x65, 0x98, 0x41, 0x29, 0x86, 0x0c, - 0xf2, 0xf1, 0x14, 0xa2, 0xb3, 0xbd, 0x75, 0x08, - 0x12, 0x83, 0x50, 0xda, 0x1f, 0x23, 0xbe, 0xa3, - 0x1d, 0xf4, 0x9d, 0x1d, 0xb5, 0x84, 0x4e, 0x50, - 0x38, 0x1d, 0x36, 0x48, 0x21, 0x95, 0xd1, 0xac, - 0x81, 0x99, 0x1d, 0xc1, 0x3f, 0x41, 0xe6, 0x9e, - 0x42, 0x5b, 0x0a, 0x48, 0xcc, 0x5f, 0xe0, 0x7d, - 0x3f, 0xc4, 0x6f, 0x0e, 0xfe, 0xc0, 0x2d, 0xfe, - 0x01, 0x2c, 0xd6, 0x9b, 0x5d, 0xbe, 0xba, 0x21, - 0xca, 0x79, 0xcb, 0xe3, 0x49, 0x60, 0xef, 0x68, - 0x05, 0x28, 0x9b, 0x8c, 0xc1, 0x12, 0x3e, 0xdb, - 0xc7, 0x04, 0x7e, 0xa6, 0x74, 0x29, 0xcc, 0x13, - 0xed, 0x07, 0x94, 0x81, 0xd6, 0x96, 0xaa, 0x97, - 0xaa, 0xa5, 0xc0, 0x2f, 0xb5, 0xb5, 0x2e, 0xe6, - 0xfc, 0xca, 0xfa, 0x60, 0x4d, 0x02, 0xf7, 0x19, - 0x9c, 0x5f, 0xa4, 0xe9, 0xf9, 0xf7, 0xf4, 0xc7, - 0x79, 0x9a, 0xc0, 0xb6, 0xcc, 0x58, 0xec, 0xec, - 0xe4, 0x37, 0x22, 0xfa, 0x8b, 0x53, -}; - -static unsigned char some_data[] = { - 0x2f, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x54, 0x68, - 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, - 0x69, 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, - 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x3b, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x63, 0x61, - 0x6e, 0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74, - 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x69, - 0x74, 0x20, 0x61, 0x6e, 0x64, 0x2f, 0x6f, 0x72, - 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x0a, - 0x20, 0x2a, 0x20, 0x69, 0x74, 0x20, 0x75, 0x6e, - 0x64, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x74, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x6f, 0x66, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55, - 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, - 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, - 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2c, - 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, - 0x20, 0x32, 0x2c, 0x0a, 0x20, 0x2a, 0x20, 0x61, - 0x73, 0x20, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, - 0x68, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20, - 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2e, 0x0a, 0x20, 0x2a, 0x0a, - 0x20, 0x2a, 0x20, 0x49, 0x6e, 0x20, 0x61, 0x64, - 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, - 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x65, - 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, - 0x73, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, - 0x20, 0x47, 0x4e, 0x55, 0x20, 0x47, 0x65, 0x6e, - 0x65, 0x72, 0x61, 0x6c, 0x20, 0x50, 0x75, 0x62, - 0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69, 0x63, 0x65, - 0x6e, 0x73, 0x65, 0x2c, 0x0a, 0x20, 0x2a, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x61, 0x75, 0x74, 0x68, - 0x6f, 0x72, 0x73, 0x20, 0x67, 0x69, 0x76, 0x65, - 0x20, 0x79, 0x6f, 0x75, 0x20, 0x75, 0x6e, 0x6c, - 0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x20, 0x70, - 0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, - 0x6e, 0x20, 0x74, 0x6f, 0x20, 0x6c, 0x69, 0x6e, - 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x0a, 0x20, - 0x2a, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, - 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69, - 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x69, - 0x6e, 0x74, 0x6f, 0x20, 0x63, 0x6f, 0x6d, 0x62, - 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, - 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x6f, 0x74, - 0x68, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x67, - 0x72, 0x61, 0x6d, 0x73, 0x2c, 0x0a, 0x20, 0x2a, - 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x6f, 0x20, - 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, - 0x74, 0x65, 0x20, 0x74, 0x68, 0x6f, 0x73, 0x65, - 0x20, 0x63, 0x6f, 0x6d, 0x62, 0x69, 0x6e, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69, - 0x74, 0x68, 0x6f, 0x75, 0x74, 0x20, 0x61, 0x6e, - 0x79, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72, 0x69, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, 0x2a, - 0x20, 0x63, 0x6f, 0x6d, 0x69, 0x6e, 0x67, 0x20, - 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, - 0x20, 0x75, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, - 0x74, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, - 0x65, 0x2e, 0x20, 0x20, 0x28, 0x54, 0x68, 0x65, - 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, - 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, - 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a, - 0x20, 0x2a, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72, - 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, - 0x64, 0x6f, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, - 0x20, 0x69, 0x6e, 0x20, 0x6f, 0x74, 0x68, 0x65, - 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x65, 0x63, - 0x74, 0x73, 0x3b, 0x20, 0x66, 0x6f, 0x72, 0x20, - 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2c, - 0x20, 0x74, 0x68, 0x65, 0x79, 0x20, 0x63, 0x6f, - 0x76, 0x65, 0x72, 0x0a, 0x20, 0x2a, 0x20, 0x6d, - 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x2c, - 0x20, 0x61, 0x6e, 0x64, 0x20, 0x64, 0x69, 0x73, - 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x6e, - 0x6f, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x6b, 0x65, - 0x64, 0x20, 0x69, 0x6e, 0x74, 0x6f, 0x0a, 0x20, - 0x2a, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6d, 0x62, - 0x69, 0x6e, 0x65, 0x64, 0x20, 0x65, 0x78, 0x65, - 0x63, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, - 0x29, 0x0a, 0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20, - 0x54, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, - 0x65, 0x20, 0x69, 0x73, 0x20, 0x64, 0x69, 0x73, - 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, - 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x68, 0x6f, 0x70, 0x65, 0x20, 0x74, 0x68, 0x61, - 0x74, 0x20, 0x69, 0x74, 0x20, 0x77, 0x69, 0x6c, - 0x6c, 0x20, 0x62, 0x65, 0x20, 0x75, 0x73, 0x65, - 0x66, 0x75, 0x6c, 0x2c, 0x20, 0x62, 0x75, 0x74, - 0x0a, 0x20, 0x2a, 0x20, 0x57, 0x49, 0x54, 0x48, - 0x4f, 0x55, 0x54, 0x20, 0x41, 0x4e, 0x59, 0x20, - 0x57, 0x41, 0x52, 0x52, 0x41, 0x4e, 0x54, 0x59, - 0x3b, 0x20, 0x77, 0x69, 0x74, 0x68, 0x6f, 0x75, - 0x74, 0x20, 0x65, 0x76, 0x65, 0x6e, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x69, - 0x65, 0x64, 0x20, 0x77, 0x61, 0x72, 0x72, 0x61, - 0x6e, 0x74, 0x79, 0x20, 0x6f, 0x66, 0x0a, 0x20, - 0x2a, 0x20, 0x4d, 0x45, 0x52, 0x43, 0x48, 0x41, - 0x4e, 0x54, 0x41, 0x42, 0x49, 0x4c, 0x49, 0x54, - 0x59, 0x20, 0x6f, 0x72, 0x20, 0x46, 0x49, 0x54, - 0x4e, 0x45, 0x53, 0x53, 0x20, 0x46, 0x4f, 0x52, - 0x20, 0x41, 0x20, 0x50, 0x41, 0x52, 0x54, 0x49, - 0x43, 0x55, 0x4c, 0x41, 0x52, 0x20, 0x50, 0x55, - 0x52, 0x50, 0x4f, 0x53, 0x45, 0x2e, 0x20, 0x20, - 0x53, 0x65, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x47, 0x4e, 0x55, 0x0a, 0x20, 0x2a, 0x20, 0x47, - 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x50, - 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69, - 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x66, 0x6f, - 0x72, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x64, - 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x2e, 0x0a, - 0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x59, 0x6f, - 0x75, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, - 0x20, 0x68, 0x61, 0x76, 0x65, 0x20, 0x72, 0x65, - 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x20, 0x61, - 0x20, 0x63, 0x6f, 0x70, 0x79, 0x20, 0x6f, 0x66, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55, - 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, - 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, - 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a, - 0x20, 0x2a, 0x20, 0x61, 0x6c, 0x6f, 0x6e, 0x67, - 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, - 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72, - 0x61, 0x6d, 0x3b, 0x20, 0x73, 0x65, 0x65, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, - 0x20, 0x43, 0x4f, 0x50, 0x59, 0x49, 0x4e, 0x47, - 0x2e, 0x20, 0x20, 0x49, 0x66, 0x20, 0x6e, 0x6f, - 0x74, 0x2c, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, - 0x20, 0x74, 0x6f, 0x0a, 0x20, 0x2a, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20, - 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x35, 0x31, 0x20, - 0x46, 0x72, 0x61, 0x6e, 0x6b, 0x6c, 0x69, 0x6e, - 0x20, 0x53, 0x74, 0x72, 0x65, 0x65, 0x74, 0x2c, - 0x20, 0x46, 0x69, 0x66, 0x74, 0x68, 0x20, 0x46, - 0x6c, 0x6f, 0x6f, 0x72, 0x2c, 0x0a, 0x20, 0x2a, - 0x20, 0x42, 0x6f, 0x73, 0x74, 0x6f, 0x6e, 0x2c, - 0x20, 0x4d, 0x41, 0x20, 0x30, 0x32, 0x31, 0x31, - 0x30, 0x2d, 0x31, 0x33, 0x30, 0x31, 0x2c, 0x20, - 0x55, 0x53, 0x41, 0x2e, 0x0a, 0x20, 0x2a, 0x2f, - 0x0a, -}; - -static object_data some = { - some_bytes, - sizeof(some_bytes), - "fd8430bc864cfcd5f10e5590f8a447e01b942bfe", - "blob", - "test-objects/fd", - "test-objects/fd/8430bc864cfcd5f10e5590f8a447e01b942bfe", - some_data, - sizeof(some_data), -}; - diff --git a/vendor/libgit2/tests/t02-objread.c b/vendor/libgit2/tests/t02-objread.c deleted file mode 100644 index 4bcff2742..000000000 --- a/vendor/libgit2/tests/t02-objread.c +++ /dev/null @@ -1,269 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "test_lib.h" -#include "test_helpers.h" -#include "odb.h" - -#include "t02-data.h" -#include "t02-oids.h" - - -BEGIN_TEST(existsloose0, "check if a loose object exists on the odb") - git_odb *db; - git_oid id, id2; - - must_pass(write_object_files(odb_dir, &one)); - must_pass(git_odb_open(&db, odb_dir)); - must_pass(git_oid_fromstr(&id, one.id)); - - must_be_true(git_odb_exists(db, &id)); - - /* Test for a non-existant object */ - must_pass(git_oid_fromstr(&id2, "8b137891791fe96927ad78e64b0aad7bded08baa")); - must_be_true(0 == git_odb_exists(db, &id2)); - - git_odb_close(db); - must_pass(remove_object_files(odb_dir, &one)); -END_TEST - -BEGIN_TEST(readloose0, "read a loose commit") - git_odb *db; - git_oid id; - git_odb_object *obj; - - must_pass(write_object_files(odb_dir, &commit)); - must_pass(git_odb_open(&db, odb_dir)); - must_pass(git_oid_fromstr(&id, commit.id)); - - must_pass(git_odb_read(&obj, db, &id)); - must_pass(cmp_objects((git_rawobj *)&obj->raw, &commit)); - - git_odb_object_close(obj); - git_odb_close(db); - must_pass(remove_object_files(odb_dir, &commit)); -END_TEST - -BEGIN_TEST(readloose1, "read a loose tree") - git_odb *db; - git_oid id; - git_odb_object *obj; - - must_pass(write_object_files(odb_dir, &tree)); - must_pass(git_odb_open(&db, odb_dir)); - must_pass(git_oid_fromstr(&id, tree.id)); - - must_pass(git_odb_read(&obj, db, &id)); - must_pass(cmp_objects((git_rawobj *)&obj->raw, &tree)); - - git_odb_object_close(obj); - git_odb_close(db); - must_pass(remove_object_files(odb_dir, &tree)); -END_TEST - -BEGIN_TEST(readloose2, "read a loose tag") - git_odb *db; - git_oid id; - git_odb_object *obj; - - must_pass(write_object_files(odb_dir, &tag)); - must_pass(git_odb_open(&db, odb_dir)); - must_pass(git_oid_fromstr(&id, tag.id)); - - must_pass(git_odb_read(&obj, db, &id)); - must_pass(cmp_objects((git_rawobj *)&obj->raw, &tag)); - - git_odb_object_close(obj); - git_odb_close(db); - must_pass(remove_object_files(odb_dir, &tag)); -END_TEST - -BEGIN_TEST(readloose3, "read a loose zero-bytes object") - git_odb *db; - git_oid id; - git_odb_object *obj; - - must_pass(write_object_files(odb_dir, &zero)); - must_pass(git_odb_open(&db, odb_dir)); - must_pass(git_oid_fromstr(&id, zero.id)); - - must_pass(git_odb_read(&obj, db, &id)); - must_pass(cmp_objects((git_rawobj *)&obj->raw, &zero)); - - git_odb_object_close(obj); - git_odb_close(db); - must_pass(remove_object_files(odb_dir, &zero)); -END_TEST - -BEGIN_TEST(readloose4, "read a one-byte long loose object") - git_odb *db; - git_oid id; - git_odb_object *obj; - - must_pass(write_object_files(odb_dir, &one)); - must_pass(git_odb_open(&db, odb_dir)); - must_pass(git_oid_fromstr(&id, one.id)); - - must_pass(git_odb_read(&obj, db, &id)); - must_pass(cmp_objects(&obj->raw, &one)); - - git_odb_object_close(obj); - git_odb_close(db); - must_pass(remove_object_files(odb_dir, &one)); -END_TEST - -BEGIN_TEST(readloose5, "read a two-bytes long loose object") - git_odb *db; - git_oid id; - git_odb_object *obj; - - must_pass(write_object_files(odb_dir, &two)); - must_pass(git_odb_open(&db, odb_dir)); - must_pass(git_oid_fromstr(&id, two.id)); - - must_pass(git_odb_read(&obj, db, &id)); - must_pass(cmp_objects(&obj->raw, &two)); - - git_odb_object_close(obj); - git_odb_close(db); - must_pass(remove_object_files(odb_dir, &two)); -END_TEST - -BEGIN_TEST(readloose6, "read a loose object which is several bytes long") - git_odb *db; - git_oid id; - git_odb_object *obj; - - must_pass(write_object_files(odb_dir, &some)); - must_pass(git_odb_open(&db, odb_dir)); - must_pass(git_oid_fromstr(&id, some.id)); - - must_pass(git_odb_read(&obj, db, &id)); - must_pass(cmp_objects(&obj->raw, &some)); - - git_odb_object_close(obj); - git_odb_close(db); - must_pass(remove_object_files(odb_dir, &some)); -END_TEST - -BEGIN_TEST(readpack0, "read several packed objects") - unsigned int i; - git_odb *db; - - must_pass(git_odb_open(&db, ODB_FOLDER)); - - for (i = 0; i < ARRAY_SIZE(packed_objects); ++i) { - git_oid id; - git_odb_object *obj; - - must_pass(git_oid_fromstr(&id, packed_objects[i])); - must_be_true(git_odb_exists(db, &id) == 1); - must_pass(git_odb_read(&obj, db, &id)); - - git_odb_object_close(obj); - } - - git_odb_close(db); -END_TEST - -BEGIN_TEST(readheader0, "read only the header of several packed objects") - unsigned int i; - git_odb *db; - - must_pass(git_odb_open(&db, ODB_FOLDER)); - - for (i = 0; i < ARRAY_SIZE(packed_objects); ++i) { - git_oid id; - git_odb_object *obj; - size_t len; - git_otype type; - - must_pass(git_oid_fromstr(&id, packed_objects[i])); - - must_pass(git_odb_read(&obj, db, &id)); - must_pass(git_odb_read_header(&len, &type, db, &id)); - - must_be_true(obj->raw.len == len); - must_be_true(obj->raw.type == type); - - git_odb_object_close(obj); - } - - git_odb_close(db); -END_TEST - -BEGIN_TEST(readheader1, "read only the header of several loose objects") - unsigned int i; - git_odb *db; - - must_pass(git_odb_open(&db, ODB_FOLDER)); - - for (i = 0; i < ARRAY_SIZE(loose_objects); ++i) { - git_oid id; - git_odb_object *obj; - size_t len; - git_otype type; - - must_pass(git_oid_fromstr(&id, loose_objects[i])); - - must_be_true(git_odb_exists(db, &id) == 1); - - must_pass(git_odb_read(&obj, db, &id)); - must_pass(git_odb_read_header(&len, &type, db, &id)); - - must_be_true(obj->raw.len == len); - must_be_true(obj->raw.type == type); - - git_odb_object_close(obj); - } - - git_odb_close(db); -END_TEST - -BEGIN_SUITE(objread) - ADD_TEST(existsloose0); - - ADD_TEST(readloose0); - ADD_TEST(readloose1); - ADD_TEST(readloose2); - ADD_TEST(readloose3); - ADD_TEST(readloose4); - ADD_TEST(readloose5); - ADD_TEST(readloose6); - -/* - ADD_TEST(readloose_enc0); - ADD_TEST(readloose_enc1); - ADD_TEST(readloose_enc2); - ADD_TEST(readloose_enc3); - ADD_TEST(readloose_enc4); - ADD_TEST(readloose_enc5); - ADD_TEST(readloose_enc6); -*/ - - ADD_TEST(readpack0); - - ADD_TEST(readheader0); - ADD_TEST(readheader1); -END_SUITE diff --git a/vendor/libgit2/tests/t02-oids.h b/vendor/libgit2/tests/t02-oids.h deleted file mode 100644 index 1a5ed5df0..000000000 --- a/vendor/libgit2/tests/t02-oids.h +++ /dev/null @@ -1,152 +0,0 @@ - -static const char *packed_objects[] = { - "0266163a49e280c4f5ed1e08facd36a2bd716bcf", - "53fc32d17276939fc79ed05badaef2db09990016", - "6336846bd5c88d32f93ae57d846683e61ab5c530", - "6dcf9bf7541ee10456529833502442f385010c3d", - "bed08a0b30b72a9d4aed7f1af8c8ca124e8d64b9", - "e90810b8df3e80c413d903f631643c716887138d", - "fc3c3a2083e9f6f89e6bd53e9420e70d1e357c9b", - "fc58168adf502d0c0ef614c3111a7038fc8c09c8", - "fd0ec0333948dfe23265ac46be0205a436a8c3a5", - "fd8430bc864cfcd5f10e5590f8a447e01b942bfe", - "fd899f45951c15c1c5f7c34b1c864e91bd6556c6", - "fda23b974899e7e1f938619099280bfda13bdca9", - "fdbec189efb657c8325962b494875987881a356b", - "fe1ca6bd22b5d8353ce6c2f3aba80805c438a7a5", - "fe3a6a42c87ff1239370c741a265f3997add87c1", - "deb106bfd2d36ecf9f0079224c12022201a39ad1", - "dec93efc79e60f2680de3e666755d335967eec30", - "def425bf8568b9c1e20879bf5be6f9c52b7361c4", - "df48000ac4f48570054e3a71a81916357997b680", - "dfae6ed8f6dd8acc3b40a31811ea316239223559", - "dff79e27d3d2cdc09790ded80fe2ea8ff5d61034", - "e00e46abe4c542e17c8bc83d72cf5be8018d7b0e", - "e01b107b4f77f8f98645adac0206a504f2d29d7c", - "e032d863f512c47b479bd984f8b6c8061f66b7d4", - "e044baa468a1c74f9f9da36805445f6888358b49", - "e04529998989ba8ae3419538dd57969af819b241", - "e0637ddfbea67c8d7f557c709e095af8906e9176", - "e0743ad4031231e71700abdc6fdbe94f189d20e5", - "cf33ac7a3d8b2b8f6bb266518aadbf59de397608", - "cf5f7235b9c9689b133f6ea12015720b411329bd", - "cf6cccf1297284833a9a03138a1f5738fa1c6c94", - "cf7992bde17ce7a79cab5f0c1fcbe8a0108721ed", - "cfe3a027ab12506d4144ee8a35669ae8fc4b7ab1", - "cfe96f31dfad7bab49977aa1df7302f7fafcb025", - "cff54d138945ef4de384e9d2759291d0c13ea90a", - "d01f7573ac34c2f502bd1cf18cde73480c741151", - "d03f567593f346a1ca96a57f8191def098d126e3", - "d047b47aadf88501238f36f5c17dd0a50dc62087", - "d0a0d63086fae3b0682af7261df21f7d0f7f066d", - "d0a44bd6ed0be21b725a96c0891bbc79bc1a540c", - "d0d7e736e536a41bcb885005f8bf258c61cad682", - "d0e7959d4b95ffec6198df6f5a7ae259b23a5f50", - "bf2fe2acca17d13356ce802ba9dc8343f710dfb7", - "bf55f407d6d9418e51f42ea7a3a6aadf17388349", - "bf92206f8b633b88a66dca4a911777630b06fbac", - "bfaf8c42eb8842abe206179fee864cfba87e3ca9", - "bfe05675d4e8f6b59d50932add8790f1a06b10ee", - "bff8618112330763327cfa6ce6e914db84f51ddf", - "bff873e9853ed99fed52c25f7ad29f78b27dcec2", - "c01c3fae7251098d7af1b459bcd0786e81d4616d", - "c0220fca67f48b8a5d4163d53b1486224be3a198", - "c02d0b160b82ee72469c269f13de4c26a7ea09cb", - "c059510ad1b45ab58390e042d7dee1ac46703854", - "c07204a1897aeeaa3c248d29dbfa9b033baf9755", - "c073337a4dd7276931b4b3fdbc3f0040e9441793", - "0fd7e4bfba5b3a82be88d1057757ca8b2c5e6d26", - "100746511cc45c9f1ad6721c4ef5be49222fee4d", - "1088490171d9b984d68b8b9be9ca003f4eafff59", - "1093c8ff4cb78fcf5f79dbbeedcb6e824bd4e253", - "10aa3fa72afab7ee31e116ae06442fe0f7b79df2", - "10b759e734e8299aa0dca08be935d95d886127b6", - "111d5ccf0bb010c4e8d7af3eedfa12ef4c5e265b", - "11261fbff21758444d426356ff6327ee01e90752", - "112998d425717bb922ce74e8f6f0f831d8dc4510", - "2ef4e5d838b6507bd61d457cf6466662b791c5c0", - "2ef4faa0f82efa00eeac6cae9e8b2abccc8566ee", - "2f06098183b0d7be350acbe39cdbaccff2df0c4a", - "2f1c5d509ac5bffb3c62f710a1c2c542e126dfd1", - "2f205b20fc16423c42b3ba51b2ea78d7b9ff3578", - "2f9b6b6e3d9250ba09360734aa47973a993b59d1", - "30c62a2d5a8d644f1311d4f7fe3f6a788e4c8188", - "31438e245492d85fd6da4d1406eba0fbde8332a4", - "3184a3abdfea231992254929ff4e275898e5bbf6", - "3188ffdbb3a3d52e0f78f30c484533899224436e", - "32581d0093429770d044a60eb0e9cc0462bedb13", - "32679a9544d83e5403202c4d5efb61ad02492847", - "4e7e9f60b7e2049b7f5697daf133161a18ef688f", - "4e8cda27ddc8be7db875ceb0f360c37734724c6d", - "4ea481c61c59ab55169b7cbaae536ad50b49d6f0", - "4f0adcd0e61eabe06fe32be66b16559537124b7a", - "4f1355c91100d12f9e7202f91b245df0c110867c", - "4f6eadeb08b9d0d1e8b1b3eac8a34940adf29a2d", - "4f9339df943c53117a5fc8e86e2f38716ff3a668", - "4fc3874b118752e40de556b1c3e7b4a9f1737d00", - "4ff1dd0992dd6baafdb5e166be6f9f23b59bdf87", - "5018a35e0b7e2eec7ce5050baf9c7343f3f74164", - "50298f44a45eda3a29dae82dbe911b5aa176ac07", - "502acd164fb115768d723144da2e7bb5a24891bb", - "50330c02bd4fd95c9db1fcf2f97f4218e42b7226", - "5052bf355d9f8c52446561a39733a8767bf31e37", - "6f2cd729ae42988c1dd43588d3a6661ba48ad7a0", - "6f4e2c42d9138bfbf3e0f908f1308828cc6f2178", - "6f6a17db05a83620cef4572761831c20a70ba9b9", - "6faad60901e36538634f0d8b8ff3f21f83503c71", - "6fc72e46de3df0c3842dab302bbacf697a63abab", - "6fdccd49f442a7204399ca9b418f017322dbded8", - "6fe7568fc3861c334cb008fd85d57d9647249ef5", - "700f55d91d7b55665594676a4bada1f1457a0598", - "702bd70595a7b19afc48a1f784a6505be68469d4", - "7033f9ee0e52b08cb5679cd49b7b7999eaf9eaf8", - "70957110ce446c4e250f865760fb3da513cdcc92", - "8ec696a4734f16479d091bc70574d23dd9fe7443", - "8ed341c55ed4d6f4cdc8bf4f0ca18a08c93f6962", - "8edc2805f1f11b63e44bf81f4557f8b473612b69", - "8ef9060a954118a698fc10e20acdc430566a100f", - "8f0c4b543f4bb6eb1518ecfc3d4699e43108d393", - "8fac94df3035405c2e60b3799153ce7c428af6b9", - "904c0ac12b23548de524adae712241b423d765a3", - "90bbaa9a809c3a768d873a9cc7d52b4f3bf3d1b9", - "90d4d2f0fc362beabbbf76b4ffda0828229c198d", - "90f9ff6755330b685feff6c3d81782ee3592ab04", - "91822c50ebe4f9bf5bbb8308ecf9f6557062775c", - "91d973263a55708fa8255867b3202d81ef9c2868", - "af292c99c6148d772af3315a1c74e83330e7ead7", - "af3b99d5be330dbbce0b9250c3a5fb05911908cc", - "af55d0cdeb280af2db8697e5afa506e081012719", - "af795e498d411142ddb073e8ca2c5447c3295a4c", - "afadc73a392f8cc8e2cc77dd62a7433dd3bafa8c", - "affd84ed8ec7ce67612fe3c12a80f8164b101f6a", - "b0941f9c70ffe67f0387a827b338e64ecf3190f0", - "b0a3077f9ef6e093f8d9869bdb0c07095bd722cb", - "b0a8568a7614806378a54db5706ee3b06ae58693", - "b0fb7372f242233d1d35ce7d8e74d3990cbc5841", - "b10489944b9ead17427551759d180d10203e06ba", - "b196a807b323f2748ffc6b1d42cd0812d04c9a40", - "b1bb1d888f0c5e19278536d49fa77db035fac7ae" -}; - -static const char *loose_objects[] = { - "45b983be36b73c0788dc9cbcb76cbb80fc7bb057", - "a8233120f6ad708f843d861ce2b7228ec4e3dec6", - "fd093bff70906175335656e6ce6ae05783708765", - "c47800c7266a2be04c571c04d5a6614691ea99bd", - "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd", - "8496071c1b46c854b31185ea97743be6a8774479", - "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", - "814889a078c031f61ed08ab5fa863aea9314344d", - "5b5b025afb0b4c913b4c338a42934a3863bf3644", - "1385f264afb75a56a5bec74243be9b367ba4ca08", - "f60079018b664e4e79329a7ef9559c8d9e0378d1", - "be3563ae3f795b2b4353bcce3a527ad0a4f7f644", - "75057dd4114e74cca1d750d0aee1647c903cb60a", - "fa49b077972391ad58037050f2a75f74e3671e92", - "9fd738e8f7967c078dceed8190330fc8648ee56a", - "1810dff58d8a660512d4832e740f692884338ccd", - "181037049a54a1eb5fab404658a3a250b44335d7", - "a4a7dce85cf63874e984719f4fdd239f5145052f", - "4a202b346bb0fb0db7eff3cffeb3c70babbd2045" -}; - diff --git a/vendor/libgit2/tests/t03-data.h b/vendor/libgit2/tests/t03-data.h deleted file mode 100644 index a4b73fec3..000000000 --- a/vendor/libgit2/tests/t03-data.h +++ /dev/null @@ -1,344 +0,0 @@ - -typedef struct object_data { - char *id; /* object id (sha1) */ - char *dir; /* object store (fan-out) directory name */ - char *file; /* object store filename */ -} object_data; - -static object_data commit = { - "3d7f8a6af076c8c3f20071a8935cdbe8228594d1", - "test-objects/3d", - "test-objects/3d/7f8a6af076c8c3f20071a8935cdbe8228594d1", -}; - -static unsigned char commit_data[] = { - 0x74, 0x72, 0x65, 0x65, 0x20, 0x64, 0x66, 0x66, - 0x32, 0x64, 0x61, 0x39, 0x30, 0x62, 0x32, 0x35, - 0x34, 0x65, 0x31, 0x62, 0x65, 0x62, 0x38, 0x38, - 0x39, 0x64, 0x31, 0x66, 0x31, 0x66, 0x31, 0x32, - 0x38, 0x38, 0x62, 0x65, 0x31, 0x38, 0x30, 0x33, - 0x37, 0x38, 0x32, 0x64, 0x66, 0x0a, 0x61, 0x75, - 0x74, 0x68, 0x6f, 0x72, 0x20, 0x41, 0x20, 0x55, - 0x20, 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, - 0x75, 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, - 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, - 0x6d, 0x3e, 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, - 0x31, 0x34, 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, - 0x30, 0x30, 0x30, 0x0a, 0x63, 0x6f, 0x6d, 0x6d, - 0x69, 0x74, 0x74, 0x65, 0x72, 0x20, 0x43, 0x20, - 0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72, - 0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, - 0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e, - 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34, - 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30, - 0x30, 0x0a, 0x0a, 0x41, 0x20, 0x6f, 0x6e, 0x65, - 0x2d, 0x6c, 0x69, 0x6e, 0x65, 0x20, 0x63, 0x6f, - 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x73, 0x75, 0x6d, - 0x6d, 0x61, 0x72, 0x79, 0x0a, 0x0a, 0x54, 0x68, - 0x65, 0x20, 0x62, 0x6f, 0x64, 0x79, 0x20, 0x6f, - 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, - 0x6d, 0x6d, 0x69, 0x74, 0x20, 0x6d, 0x65, 0x73, - 0x73, 0x61, 0x67, 0x65, 0x2c, 0x20, 0x63, 0x6f, - 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x69, 0x6e, 0x67, - 0x20, 0x66, 0x75, 0x72, 0x74, 0x68, 0x65, 0x72, - 0x20, 0x65, 0x78, 0x70, 0x6c, 0x61, 0x6e, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x6f, 0x66, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x70, 0x75, 0x72, 0x70, - 0x6f, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x63, 0x68, 0x61, 0x6e, 0x67, - 0x65, 0x73, 0x20, 0x69, 0x6e, 0x74, 0x72, 0x6f, - 0x64, 0x75, 0x63, 0x65, 0x64, 0x20, 0x62, 0x79, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, 0x6d, - 0x6d, 0x69, 0x74, 0x2e, 0x0a, 0x0a, 0x53, 0x69, - 0x67, 0x6e, 0x65, 0x64, 0x2d, 0x6f, 0x66, 0x2d, - 0x62, 0x79, 0x3a, 0x20, 0x41, 0x20, 0x55, 0x20, - 0x54, 0x68, 0x6f, 0x72, 0x20, 0x3c, 0x61, 0x75, - 0x74, 0x68, 0x6f, 0x72, 0x40, 0x65, 0x78, 0x61, - 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, - 0x3e, 0x0a, -}; - -static git_rawobj commit_obj = { - commit_data, - sizeof(commit_data), - GIT_OBJ_COMMIT -}; - -static object_data tree = { - "dff2da90b254e1beb889d1f1f1288be1803782df", - "test-objects/df", - "test-objects/df/f2da90b254e1beb889d1f1f1288be1803782df", -}; - -static unsigned char tree_data[] = { - 0x31, 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x6f, - 0x6e, 0x65, 0x00, 0x8b, 0x13, 0x78, 0x91, 0x79, - 0x1f, 0xe9, 0x69, 0x27, 0xad, 0x78, 0xe6, 0x4b, - 0x0a, 0xad, 0x7b, 0xde, 0xd0, 0x8b, 0xdc, 0x31, - 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x73, 0x6f, - 0x6d, 0x65, 0x00, 0xfd, 0x84, 0x30, 0xbc, 0x86, - 0x4c, 0xfc, 0xd5, 0xf1, 0x0e, 0x55, 0x90, 0xf8, - 0xa4, 0x47, 0xe0, 0x1b, 0x94, 0x2b, 0xfe, 0x31, - 0x30, 0x30, 0x36, 0x34, 0x34, 0x20, 0x74, 0x77, - 0x6f, 0x00, 0x78, 0x98, 0x19, 0x22, 0x61, 0x3b, - 0x2a, 0xfb, 0x60, 0x25, 0x04, 0x2f, 0xf6, 0xbd, - 0x87, 0x8a, 0xc1, 0x99, 0x4e, 0x85, 0x31, 0x30, - 0x30, 0x36, 0x34, 0x34, 0x20, 0x7a, 0x65, 0x72, - 0x6f, 0x00, 0xe6, 0x9d, 0xe2, 0x9b, 0xb2, 0xd1, - 0xd6, 0x43, 0x4b, 0x8b, 0x29, 0xae, 0x77, 0x5a, - 0xd8, 0xc2, 0xe4, 0x8c, 0x53, 0x91, -}; - -static git_rawobj tree_obj = { - tree_data, - sizeof(tree_data), - GIT_OBJ_TREE -}; - -static object_data tag = { - "09d373e1dfdc16b129ceec6dd649739911541e05", - "test-objects/09", - "test-objects/09/d373e1dfdc16b129ceec6dd649739911541e05", -}; - -static unsigned char tag_data[] = { - 0x6f, 0x62, 0x6a, 0x65, 0x63, 0x74, 0x20, 0x33, - 0x64, 0x37, 0x66, 0x38, 0x61, 0x36, 0x61, 0x66, - 0x30, 0x37, 0x36, 0x63, 0x38, 0x63, 0x33, 0x66, - 0x32, 0x30, 0x30, 0x37, 0x31, 0x61, 0x38, 0x39, - 0x33, 0x35, 0x63, 0x64, 0x62, 0x65, 0x38, 0x32, - 0x32, 0x38, 0x35, 0x39, 0x34, 0x64, 0x31, 0x0a, - 0x74, 0x79, 0x70, 0x65, 0x20, 0x63, 0x6f, 0x6d, - 0x6d, 0x69, 0x74, 0x0a, 0x74, 0x61, 0x67, 0x20, - 0x76, 0x30, 0x2e, 0x30, 0x2e, 0x31, 0x0a, 0x74, - 0x61, 0x67, 0x67, 0x65, 0x72, 0x20, 0x43, 0x20, - 0x4f, 0x20, 0x4d, 0x69, 0x74, 0x74, 0x65, 0x72, - 0x20, 0x3c, 0x63, 0x6f, 0x6d, 0x6d, 0x69, 0x74, - 0x74, 0x65, 0x72, 0x40, 0x65, 0x78, 0x61, 0x6d, - 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x3e, - 0x20, 0x31, 0x32, 0x32, 0x37, 0x38, 0x31, 0x34, - 0x32, 0x39, 0x37, 0x20, 0x2b, 0x30, 0x30, 0x30, - 0x30, 0x0a, 0x0a, 0x54, 0x68, 0x69, 0x73, 0x20, - 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20, 0x74, - 0x61, 0x67, 0x20, 0x6f, 0x62, 0x6a, 0x65, 0x63, - 0x74, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x72, 0x65, - 0x6c, 0x65, 0x61, 0x73, 0x65, 0x20, 0x76, 0x30, - 0x2e, 0x30, 0x2e, 0x31, 0x0a, -}; - -static git_rawobj tag_obj = { - tag_data, - sizeof(tag_data), - GIT_OBJ_TAG -}; - -static object_data zero = { - "e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", - "test-objects/e6", - "test-objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391", -}; - -static unsigned char zero_data[] = { - 0x00 /* dummy data */ -}; - -static git_rawobj zero_obj = { - zero_data, - 0, - GIT_OBJ_BLOB -}; - -static object_data one = { - "8b137891791fe96927ad78e64b0aad7bded08bdc", - "test-objects/8b", - "test-objects/8b/137891791fe96927ad78e64b0aad7bded08bdc", -}; - -static unsigned char one_data[] = { - 0x0a, -}; - -static git_rawobj one_obj = { - one_data, - sizeof(one_data), - GIT_OBJ_BLOB -}; - -static object_data two = { - "78981922613b2afb6025042ff6bd878ac1994e85", - "test-objects/78", - "test-objects/78/981922613b2afb6025042ff6bd878ac1994e85", -}; - -static unsigned char two_data[] = { - 0x61, 0x0a, -}; - -static git_rawobj two_obj = { - two_data, - sizeof(two_data), - GIT_OBJ_BLOB -}; - -static object_data some = { - "fd8430bc864cfcd5f10e5590f8a447e01b942bfe", - "test-objects/fd", - "test-objects/fd/8430bc864cfcd5f10e5590f8a447e01b942bfe", -}; - -static unsigned char some_data[] = { - 0x2f, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x54, 0x68, - 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, - 0x69, 0x73, 0x20, 0x66, 0x72, 0x65, 0x65, 0x20, - 0x73, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x3b, 0x20, 0x79, 0x6f, 0x75, 0x20, 0x63, 0x61, - 0x6e, 0x20, 0x72, 0x65, 0x64, 0x69, 0x73, 0x74, - 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x20, 0x69, - 0x74, 0x20, 0x61, 0x6e, 0x64, 0x2f, 0x6f, 0x72, - 0x20, 0x6d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x0a, - 0x20, 0x2a, 0x20, 0x69, 0x74, 0x20, 0x75, 0x6e, - 0x64, 0x65, 0x72, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x74, 0x65, 0x72, 0x6d, 0x73, 0x20, 0x6f, 0x66, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55, - 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, - 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, - 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x2c, - 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, - 0x20, 0x32, 0x2c, 0x0a, 0x20, 0x2a, 0x20, 0x61, - 0x73, 0x20, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, - 0x68, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20, - 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2e, 0x0a, 0x20, 0x2a, 0x0a, - 0x20, 0x2a, 0x20, 0x49, 0x6e, 0x20, 0x61, 0x64, - 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, - 0x6f, 0x20, 0x74, 0x68, 0x65, 0x20, 0x70, 0x65, - 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, 0x6e, - 0x73, 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, - 0x20, 0x47, 0x4e, 0x55, 0x20, 0x47, 0x65, 0x6e, - 0x65, 0x72, 0x61, 0x6c, 0x20, 0x50, 0x75, 0x62, - 0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69, 0x63, 0x65, - 0x6e, 0x73, 0x65, 0x2c, 0x0a, 0x20, 0x2a, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x61, 0x75, 0x74, 0x68, - 0x6f, 0x72, 0x73, 0x20, 0x67, 0x69, 0x76, 0x65, - 0x20, 0x79, 0x6f, 0x75, 0x20, 0x75, 0x6e, 0x6c, - 0x69, 0x6d, 0x69, 0x74, 0x65, 0x64, 0x20, 0x70, - 0x65, 0x72, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6f, - 0x6e, 0x20, 0x74, 0x6f, 0x20, 0x6c, 0x69, 0x6e, - 0x6b, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6f, - 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x64, 0x0a, 0x20, - 0x2a, 0x20, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, - 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x69, - 0x73, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x20, 0x69, - 0x6e, 0x74, 0x6f, 0x20, 0x63, 0x6f, 0x6d, 0x62, - 0x69, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, - 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x6f, 0x74, - 0x68, 0x65, 0x72, 0x20, 0x70, 0x72, 0x6f, 0x67, - 0x72, 0x61, 0x6d, 0x73, 0x2c, 0x0a, 0x20, 0x2a, - 0x20, 0x61, 0x6e, 0x64, 0x20, 0x74, 0x6f, 0x20, - 0x64, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, - 0x74, 0x65, 0x20, 0x74, 0x68, 0x6f, 0x73, 0x65, - 0x20, 0x63, 0x6f, 0x6d, 0x62, 0x69, 0x6e, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, 0x77, 0x69, - 0x74, 0x68, 0x6f, 0x75, 0x74, 0x20, 0x61, 0x6e, - 0x79, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72, 0x69, - 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x0a, 0x20, 0x2a, - 0x20, 0x63, 0x6f, 0x6d, 0x69, 0x6e, 0x67, 0x20, - 0x66, 0x72, 0x6f, 0x6d, 0x20, 0x74, 0x68, 0x65, - 0x20, 0x75, 0x73, 0x65, 0x20, 0x6f, 0x66, 0x20, - 0x74, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, - 0x65, 0x2e, 0x20, 0x20, 0x28, 0x54, 0x68, 0x65, - 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, - 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, - 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a, - 0x20, 0x2a, 0x20, 0x72, 0x65, 0x73, 0x74, 0x72, - 0x69, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x20, - 0x64, 0x6f, 0x20, 0x61, 0x70, 0x70, 0x6c, 0x79, - 0x20, 0x69, 0x6e, 0x20, 0x6f, 0x74, 0x68, 0x65, - 0x72, 0x20, 0x72, 0x65, 0x73, 0x70, 0x65, 0x63, - 0x74, 0x73, 0x3b, 0x20, 0x66, 0x6f, 0x72, 0x20, - 0x65, 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2c, - 0x20, 0x74, 0x68, 0x65, 0x79, 0x20, 0x63, 0x6f, - 0x76, 0x65, 0x72, 0x0a, 0x20, 0x2a, 0x20, 0x6d, - 0x6f, 0x64, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, 0x2c, - 0x20, 0x61, 0x6e, 0x64, 0x20, 0x64, 0x69, 0x73, - 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, - 0x6e, 0x20, 0x77, 0x68, 0x65, 0x6e, 0x20, 0x6e, - 0x6f, 0x74, 0x20, 0x6c, 0x69, 0x6e, 0x6b, 0x65, - 0x64, 0x20, 0x69, 0x6e, 0x74, 0x6f, 0x0a, 0x20, - 0x2a, 0x20, 0x61, 0x20, 0x63, 0x6f, 0x6d, 0x62, - 0x69, 0x6e, 0x65, 0x64, 0x20, 0x65, 0x78, 0x65, - 0x63, 0x75, 0x74, 0x61, 0x62, 0x6c, 0x65, 0x2e, - 0x29, 0x0a, 0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20, - 0x54, 0x68, 0x69, 0x73, 0x20, 0x66, 0x69, 0x6c, - 0x65, 0x20, 0x69, 0x73, 0x20, 0x64, 0x69, 0x73, - 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65, 0x64, - 0x20, 0x69, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x68, 0x6f, 0x70, 0x65, 0x20, 0x74, 0x68, 0x61, - 0x74, 0x20, 0x69, 0x74, 0x20, 0x77, 0x69, 0x6c, - 0x6c, 0x20, 0x62, 0x65, 0x20, 0x75, 0x73, 0x65, - 0x66, 0x75, 0x6c, 0x2c, 0x20, 0x62, 0x75, 0x74, - 0x0a, 0x20, 0x2a, 0x20, 0x57, 0x49, 0x54, 0x48, - 0x4f, 0x55, 0x54, 0x20, 0x41, 0x4e, 0x59, 0x20, - 0x57, 0x41, 0x52, 0x52, 0x41, 0x4e, 0x54, 0x59, - 0x3b, 0x20, 0x77, 0x69, 0x74, 0x68, 0x6f, 0x75, - 0x74, 0x20, 0x65, 0x76, 0x65, 0x6e, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x69, 0x6d, 0x70, 0x6c, 0x69, - 0x65, 0x64, 0x20, 0x77, 0x61, 0x72, 0x72, 0x61, - 0x6e, 0x74, 0x79, 0x20, 0x6f, 0x66, 0x0a, 0x20, - 0x2a, 0x20, 0x4d, 0x45, 0x52, 0x43, 0x48, 0x41, - 0x4e, 0x54, 0x41, 0x42, 0x49, 0x4c, 0x49, 0x54, - 0x59, 0x20, 0x6f, 0x72, 0x20, 0x46, 0x49, 0x54, - 0x4e, 0x45, 0x53, 0x53, 0x20, 0x46, 0x4f, 0x52, - 0x20, 0x41, 0x20, 0x50, 0x41, 0x52, 0x54, 0x49, - 0x43, 0x55, 0x4c, 0x41, 0x52, 0x20, 0x50, 0x55, - 0x52, 0x50, 0x4f, 0x53, 0x45, 0x2e, 0x20, 0x20, - 0x53, 0x65, 0x65, 0x20, 0x74, 0x68, 0x65, 0x20, - 0x47, 0x4e, 0x55, 0x0a, 0x20, 0x2a, 0x20, 0x47, - 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, 0x20, 0x50, - 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, 0x4c, 0x69, - 0x63, 0x65, 0x6e, 0x73, 0x65, 0x20, 0x66, 0x6f, - 0x72, 0x20, 0x6d, 0x6f, 0x72, 0x65, 0x20, 0x64, - 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x2e, 0x0a, - 0x20, 0x2a, 0x0a, 0x20, 0x2a, 0x20, 0x59, 0x6f, - 0x75, 0x20, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, - 0x20, 0x68, 0x61, 0x76, 0x65, 0x20, 0x72, 0x65, - 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x20, 0x61, - 0x20, 0x63, 0x6f, 0x70, 0x79, 0x20, 0x6f, 0x66, - 0x20, 0x74, 0x68, 0x65, 0x20, 0x47, 0x4e, 0x55, - 0x20, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x6c, - 0x20, 0x50, 0x75, 0x62, 0x6c, 0x69, 0x63, 0x20, - 0x4c, 0x69, 0x63, 0x65, 0x6e, 0x73, 0x65, 0x0a, - 0x20, 0x2a, 0x20, 0x61, 0x6c, 0x6f, 0x6e, 0x67, - 0x20, 0x77, 0x69, 0x74, 0x68, 0x20, 0x74, 0x68, - 0x69, 0x73, 0x20, 0x70, 0x72, 0x6f, 0x67, 0x72, - 0x61, 0x6d, 0x3b, 0x20, 0x73, 0x65, 0x65, 0x20, - 0x74, 0x68, 0x65, 0x20, 0x66, 0x69, 0x6c, 0x65, - 0x20, 0x43, 0x4f, 0x50, 0x59, 0x49, 0x4e, 0x47, - 0x2e, 0x20, 0x20, 0x49, 0x66, 0x20, 0x6e, 0x6f, - 0x74, 0x2c, 0x20, 0x77, 0x72, 0x69, 0x74, 0x65, - 0x20, 0x74, 0x6f, 0x0a, 0x20, 0x2a, 0x20, 0x74, - 0x68, 0x65, 0x20, 0x46, 0x72, 0x65, 0x65, 0x20, - 0x53, 0x6f, 0x66, 0x74, 0x77, 0x61, 0x72, 0x65, - 0x20, 0x46, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x2c, 0x20, 0x35, 0x31, 0x20, - 0x46, 0x72, 0x61, 0x6e, 0x6b, 0x6c, 0x69, 0x6e, - 0x20, 0x53, 0x74, 0x72, 0x65, 0x65, 0x74, 0x2c, - 0x20, 0x46, 0x69, 0x66, 0x74, 0x68, 0x20, 0x46, - 0x6c, 0x6f, 0x6f, 0x72, 0x2c, 0x0a, 0x20, 0x2a, - 0x20, 0x42, 0x6f, 0x73, 0x74, 0x6f, 0x6e, 0x2c, - 0x20, 0x4d, 0x41, 0x20, 0x30, 0x32, 0x31, 0x31, - 0x30, 0x2d, 0x31, 0x33, 0x30, 0x31, 0x2c, 0x20, - 0x55, 0x53, 0x41, 0x2e, 0x0a, 0x20, 0x2a, 0x2f, - 0x0a, -}; - -static git_rawobj some_obj = { - some_data, - sizeof(some_data), - GIT_OBJ_BLOB -}; diff --git a/vendor/libgit2/tests/t03-objwrite.c b/vendor/libgit2/tests/t03-objwrite.c deleted file mode 100644 index 31f611a5c..000000000 --- a/vendor/libgit2/tests/t03-objwrite.c +++ /dev/null @@ -1,255 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "test_lib.h" -#include "fileops.h" -#include "odb.h" - -static char *odb_dir = "test-objects"; -#include "t03-data.h" - -static int make_odb_dir(void) -{ - if (p_mkdir(odb_dir, 0755) < 0) { - int err = errno; - fprintf(stderr, "can't make directory \"%s\"", odb_dir); - if (err == EEXIST) - fprintf(stderr, " (already exists)"); - fprintf(stderr, "\n"); - return -1; - } - return 0; -} - -static int check_object_files(object_data *d) -{ - if (git_futils_exists(d->dir) < 0) - return -1; - if (git_futils_exists(d->file) < 0) - return -1; - return 0; -} - -static int cmp_objects(git_rawobj *o1, git_rawobj *o2) -{ - if (o1->type != o2->type) - return -1; - if (o1->len != o2->len) - return -1; - if ((o1->len > 0) && (memcmp(o1->data, o2->data, o1->len) != 0)) - return -1; - return 0; -} - -static int remove_object_files(object_data *d) -{ - if (p_unlink(d->file) < 0) { - fprintf(stderr, "can't delete object file \"%s\"\n", d->file); - return -1; - } - if ((p_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) { - fprintf(stderr, "can't remove directory \"%s\"\n", d->dir); - return -1; - } - - if (p_rmdir(odb_dir) < 0) { - fprintf(stderr, "can't remove directory \"%s\"\n", odb_dir); - return -1; - } - - return 0; -} - -static int streaming_write(git_oid *oid, git_odb *odb, git_rawobj *raw) -{ - git_odb_stream *stream; - int error; - - if ((error = git_odb_open_wstream(&stream, odb, raw->len, raw->type)) < GIT_SUCCESS) - return error; - - stream->write(stream, raw->data, raw->len); - - error = stream->finalize_write(oid, stream); - stream->free(stream); - - return error; -} - -BEGIN_TEST(write0, "write loose commit object") - git_odb *db; - git_oid id1, id2; - git_odb_object *obj; - - must_pass(make_odb_dir()); - must_pass(git_odb_open(&db, odb_dir)); - must_pass(git_oid_fromstr(&id1, commit.id)); - - must_pass(streaming_write(&id2, db, &commit_obj)); - must_be_true(git_oid_cmp(&id1, &id2) == 0); - must_pass(check_object_files(&commit)); - - must_pass(git_odb_read(&obj, db, &id1)); - must_pass(cmp_objects(&obj->raw, &commit_obj)); - - git_odb_object_close(obj); - git_odb_close(db); - must_pass(remove_object_files(&commit)); -END_TEST - -BEGIN_TEST(write1, "write loose tree object") - git_odb *db; - git_oid id1, id2; - git_odb_object *obj; - - must_pass(make_odb_dir()); - must_pass(git_odb_open(&db, odb_dir)); - must_pass(git_oid_fromstr(&id1, tree.id)); - - must_pass(streaming_write(&id2, db, &tree_obj)); - must_be_true(git_oid_cmp(&id1, &id2) == 0); - must_pass(check_object_files(&tree)); - - must_pass(git_odb_read(&obj, db, &id1)); - must_pass(cmp_objects(&obj->raw, &tree_obj)); - - git_odb_object_close(obj); - git_odb_close(db); - must_pass(remove_object_files(&tree)); -END_TEST - -BEGIN_TEST(write2, "write loose tag object") - git_odb *db; - git_oid id1, id2; - git_odb_object *obj; - - must_pass(make_odb_dir()); - must_pass(git_odb_open(&db, odb_dir)); - must_pass(git_oid_fromstr(&id1, tag.id)); - - must_pass(streaming_write(&id2, db, &tag_obj)); - must_be_true(git_oid_cmp(&id1, &id2) == 0); - must_pass(check_object_files(&tag)); - - must_pass(git_odb_read(&obj, db, &id1)); - must_pass(cmp_objects(&obj->raw, &tag_obj)); - - git_odb_object_close(obj); - git_odb_close(db); - must_pass(remove_object_files(&tag)); -END_TEST - -BEGIN_TEST(write3, "write zero-length object") - git_odb *db; - git_oid id1, id2; - git_odb_object *obj; - - must_pass(make_odb_dir()); - must_pass(git_odb_open(&db, odb_dir)); - must_pass(git_oid_fromstr(&id1, zero.id)); - - must_pass(streaming_write(&id2, db, &zero_obj)); - must_be_true(git_oid_cmp(&id1, &id2) == 0); - must_pass(check_object_files(&zero)); - - must_pass(git_odb_read(&obj, db, &id1)); - must_pass(cmp_objects(&obj->raw, &zero_obj)); - - git_odb_object_close(obj); - git_odb_close(db); - must_pass(remove_object_files(&zero)); -END_TEST - -BEGIN_TEST(write4, "write one-byte long object") - git_odb *db; - git_oid id1, id2; - git_odb_object *obj; - - must_pass(make_odb_dir()); - must_pass(git_odb_open(&db, odb_dir)); - must_pass(git_oid_fromstr(&id1, one.id)); - - must_pass(streaming_write(&id2, db, &one_obj)); - must_be_true(git_oid_cmp(&id1, &id2) == 0); - must_pass(check_object_files(&one)); - - must_pass(git_odb_read(&obj, db, &id1)); - must_pass(cmp_objects(&obj->raw, &one_obj)); - - git_odb_object_close(obj); - git_odb_close(db); - must_pass(remove_object_files(&one)); -END_TEST - -BEGIN_TEST(write5, "write two-byte long object") - git_odb *db; - git_oid id1, id2; - git_odb_object *obj; - - must_pass(make_odb_dir()); - must_pass(git_odb_open(&db, odb_dir)); - must_pass(git_oid_fromstr(&id1, two.id)); - - must_pass(streaming_write(&id2, db, &two_obj)); - must_be_true(git_oid_cmp(&id1, &id2) == 0); - must_pass(check_object_files(&two)); - - must_pass(git_odb_read(&obj, db, &id1)); - must_pass(cmp_objects(&obj->raw, &two_obj)); - - git_odb_object_close(obj); - git_odb_close(db); - must_pass(remove_object_files(&two)); -END_TEST - -BEGIN_TEST(write6, "write an object which is several bytes long") - git_odb *db; - git_oid id1, id2; - git_odb_object *obj; - - must_pass(make_odb_dir()); - must_pass(git_odb_open(&db, odb_dir)); - must_pass(git_oid_fromstr(&id1, some.id)); - - must_pass(streaming_write(&id2, db, &some_obj)); - must_be_true(git_oid_cmp(&id1, &id2) == 0); - must_pass(check_object_files(&some)); - - must_pass(git_odb_read(&obj, db, &id1)); - must_pass(cmp_objects(&obj->raw, &some_obj)); - - git_odb_object_close(obj); - git_odb_close(db); - must_pass(remove_object_files(&some)); -END_TEST - -BEGIN_SUITE(objwrite) - ADD_TEST(write0); - ADD_TEST(write1); - ADD_TEST(write2); - ADD_TEST(write3); - ADD_TEST(write4); - ADD_TEST(write5); - ADD_TEST(write6); -END_SUITE diff --git a/vendor/libgit2/tests/t04-commit.c b/vendor/libgit2/tests/t04-commit.c deleted file mode 100644 index a8617ed6a..000000000 --- a/vendor/libgit2/tests/t04-commit.c +++ /dev/null @@ -1,775 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "test_lib.h" -#include "test_helpers.h" - -#include "commit.h" -#include "signature.h" - -static char *test_commits_broken[] = { - -/* empty commit */ -"", - -/* random garbage */ -"asd97sa9du902e9a0jdsuusad09as9du098709aweu8987sd\n", - -/* broken endlines 1 */ -"tree f6c0dad3c7b3481caa9d73db21f91964894a945b\r\n\ -parent 05452d6349abcd67aa396dfb28660d765d8b2a36\r\n\ -author Vicent Marti 1273848544 +0200\r\n\ -committer Vicent Marti 1273848544 +0200\r\n\ -\r\n\ -a test commit with broken endlines\r\n", - -/* broken endlines 2 */ -"tree f6c0dad3c7b3481caa9d73db21f91964894a945b\ -parent 05452d6349abcd67aa396dfb28660d765d8b2a36\ -author Vicent Marti 1273848544 +0200\ -committer Vicent Marti 1273848544 +0200\ -\ -another test commit with broken endlines", - -/* starting endlines */ -"\ntree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\ -parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n\ -author Vicent Marti 1273848544 +0200\n\ -committer Vicent Marti 1273848544 +0200\n\ -\n\ -a test commit with a starting endline\n", - -/* corrupted commit 1 */ -"tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\ -parent 05452d6349abcd67aa396df", - -/* corrupted commit 2 */ -"tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\ -parent ", - -/* corrupted commit 3 */ -"tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\ -parent ", - -/* corrupted commit 4 */ -"tree f6c0dad3c7b3481caa9d73db21f91964894a945b\n\ -par", - -}; - - -static char *test_commits_working[] = { -/* simple commit with no message */ -"tree 1810dff58d8a660512d4832e740f692884338ccd\n\ -author Vicent Marti 1273848544 +0200\n\ -committer Vicent Marti 1273848544 +0200\n\ -\n", - -/* simple commit, no parent */ -"tree 1810dff58d8a660512d4832e740f692884338ccd\n\ -author Vicent Marti 1273848544 +0200\n\ -committer Vicent Marti 1273848544 +0200\n\ -\n\ -a simple commit which works\n", - -/* simple commit, no parent, no newline in message */ -"tree 1810dff58d8a660512d4832e740f692884338ccd\n\ -author Vicent Marti 1273848544 +0200\n\ -committer Vicent Marti 1273848544 +0200\n\ -\n\ -a simple commit which works", - -/* simple commit, 1 parent */ -"tree 1810dff58d8a660512d4832e740f692884338ccd\n\ -parent e90810b8df3e80c413d903f631643c716887138d\n\ -author Vicent Marti 1273848544 +0200\n\ -committer Vicent Marti 1273848544 +0200\n\ -\n\ -a simple commit which works\n", -}; - -BEGIN_TEST(parse0, "parse the OID line in a commit") - - git_oid oid; - -#define TEST_OID_PASS(string, header) { \ - const char *ptr = string;\ - const char *ptr_original = ptr;\ - size_t len = strlen(ptr);\ - must_pass(git_oid__parse(&oid, &ptr, ptr + len, header));\ - must_be_true(ptr == ptr_original + len);\ -} - -#define TEST_OID_FAIL(string, header) { \ - const char *ptr = string;\ - size_t len = strlen(ptr);\ - must_fail(git_oid__parse(&oid, &ptr, ptr + len, header));\ -} - - TEST_OID_PASS("parent 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "parent "); - TEST_OID_PASS("tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree "); - TEST_OID_PASS("random_heading 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "random_heading "); - TEST_OID_PASS("stuck_heading05452d6349abcd67aa396dfb28660d765d8b2a36\n", "stuck_heading"); - TEST_OID_PASS("tree 5F4BEFFC0759261D015AA63A3A85613FF2F235DE\n", "tree "); - TEST_OID_PASS("tree 1A669B8AB81B5EB7D9DB69562D34952A38A9B504\n", "tree "); - TEST_OID_PASS("tree 5B20DCC6110FCC75D31C6CEDEBD7F43ECA65B503\n", "tree "); - TEST_OID_PASS("tree 173E7BF00EA5C33447E99E6C1255954A13026BE4\n", "tree "); - - TEST_OID_FAIL("parent 05452d6349abcd67aa396dfb28660d765d8b2a36", "parent "); - TEST_OID_FAIL("05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree "); - TEST_OID_FAIL("parent05452d6349abcd67aa396dfb28660d765d8b2a6a\n", "parent "); - TEST_OID_FAIL("parent 05452d6349abcd67aa396dfb280d765d8b2a6\n", "parent "); - TEST_OID_FAIL("tree 05452d6349abcd67aa396dfb28660d765d8b2a36\n", "tree "); - TEST_OID_FAIL("parent 0545xd6349abcd67aa396dfb28660d765d8b2a36\n", "parent "); - TEST_OID_FAIL("parent 0545xd6349abcd67aa396dfb28660d765d8b2a36FF\n", "parent "); - TEST_OID_FAIL("", "tree "); - TEST_OID_FAIL("", ""); - -#undef TEST_OID_PASS -#undef TEST_OID_FAIL - -END_TEST - -BEGIN_TEST(parse1, "parse the signature line in a commit") - -#define TEST_SIGNATURE_PASS(_string, _header, _name, _email, _time, _offset) { \ - const char *ptr = _string; \ - size_t len = strlen(_string);\ - git_signature person = {NULL, NULL, {0, 0}}; \ - must_pass(git_signature__parse(&person, &ptr, ptr + len, _header, '\n'));\ - must_be_true(strcmp(_name, person.name) == 0);\ - must_be_true(strcmp(_email, person.email) == 0);\ - must_be_true(_time == person.when.time);\ - must_be_true(_offset == person.when.offset);\ - free(person.name); free(person.email);\ -} - -#define TEST_SIGNATURE_FAIL(_string, _header) { \ - const char *ptr = _string; \ - size_t len = strlen(_string);\ - git_signature person = {NULL, NULL, {0, 0}}; \ - must_fail(git_signature__parse(&person, &ptr, ptr + len, _header, '\n'));\ - free(person.name); free(person.email);\ -} - - TEST_SIGNATURE_PASS( - "author Vicent Marti 12345 \n", - "author ", - "Vicent Marti", - "tanoku@gmail.com", - 12345, - 0); - - TEST_SIGNATURE_PASS( - "author Vicent Marti <> 12345 \n", - "author ", - "Vicent Marti", - "", - 12345, - 0); - - TEST_SIGNATURE_PASS( - "author Vicent Marti 231301 +1020\n", - "author ", - "Vicent Marti", - "tanoku@gmail.com", - 231301, - 620); - - TEST_SIGNATURE_PASS( - "author Vicent Marti with an outrageously long name \ - which will probably overflow the buffer 12345 \n", - "author ", - "Vicent Marti with an outrageously long name \ - which will probably overflow the buffer", - "tanoku@gmail.com", - 12345, - 0); - - TEST_SIGNATURE_PASS( - "author Vicent Marti 12345 \n", - "author ", - "Vicent Marti", - "tanokuwithaveryveryverylongemail\ - whichwillprobablyvoverflowtheemailbuffer@gmail.com", - 12345, - 0); - - TEST_SIGNATURE_PASS( - "committer Vicent Marti 123456 +0000 \n", - "committer ", - "Vicent Marti", - "tanoku@gmail.com", - 123456, - 0); - - TEST_SIGNATURE_PASS( - "committer Vicent Marti 123456 +0100 \n", - "committer ", - "Vicent Marti", - "tanoku@gmail.com", - 123456, - 60); - - TEST_SIGNATURE_PASS( - "committer Vicent Marti 123456 -0100 \n", - "committer ", - "Vicent Marti", - "tanoku@gmail.com", - 123456, - -60); - - /* Parse a signature without an author field */ - TEST_SIGNATURE_PASS( - "committer 123456 -0100 \n", - "committer ", - "", - "tanoku@gmail.com", - 123456, - -60); - - /* Parse a signature without an author field */ - TEST_SIGNATURE_PASS( - "committer 123456 -0100 \n", - "committer ", - "", - "tanoku@gmail.com", - 123456, - -60); - - /* Parse a signature with an empty author field */ - TEST_SIGNATURE_PASS( - "committer 123456 -0100 \n", - "committer ", - "", - "tanoku@gmail.com", - 123456, - -60); - - /* Parse a signature with an empty email field */ - TEST_SIGNATURE_PASS( - "committer Vicent Marti <> 123456 -0100 \n", - "committer ", - "Vicent Marti", - "", - 123456, - -60); - - /* Parse a signature with an empty email field */ - TEST_SIGNATURE_PASS( - "committer Vicent Marti < > 123456 -0100 \n", - "committer ", - "Vicent Marti", - "", - 123456, - -60); - - /* Parse a signature with empty name and email */ - TEST_SIGNATURE_PASS( - "committer <> 123456 -0100 \n", - "committer ", - "", - "", - 123456, - -60); - - /* Parse a signature with empty name and email */ - TEST_SIGNATURE_PASS( - "committer <> 123456 -0100 \n", - "committer ", - "", - "", - 123456, - -60); - - /* Parse a signature with empty name and email */ - TEST_SIGNATURE_PASS( - "committer < > 123456 -0100 \n", - "committer ", - "", - "", - 123456, - -60); - - /* Parse an obviously invalid signature */ - TEST_SIGNATURE_PASS( - "committer foo<@bar> 123456 -0100 \n", - "committer ", - "foo", - "@bar", - 123456, - -60); - - /* Parse an obviously invalid signature */ - TEST_SIGNATURE_PASS( - "committer foo<@bar>123456 -0100 \n", - "committer ", - "foo", - "@bar", - 123456, - -60); - - /* Parse an obviously invalid signature */ - TEST_SIGNATURE_PASS( - "committer <>\n", - "committer ", - "", - "", - 0, - 0); - - TEST_SIGNATURE_PASS( - "committer Vicent Marti 123456 -1500 \n", - "committer ", - "Vicent Marti", - "tanoku@gmail.com", - 0, - 0); - - TEST_SIGNATURE_PASS( - "committer Vicent Marti 123456 +0163 \n", - "committer ", - "Vicent Marti", - "tanoku@gmail.com", - 0, - 0); - - TEST_SIGNATURE_PASS( - "author Vicent Marti notime \n", - "author ", - "Vicent Marti", - "tanoku@gmail.com", - 0, - 0); - - TEST_SIGNATURE_PASS( - "author Vicent Marti 123456 notimezone \n", - "author ", - "Vicent Marti", - "tanoku@gmail.com", - 0, - 0); - - TEST_SIGNATURE_PASS( - "author Vicent Marti notime +0100\n", - "author ", - "Vicent Marti", - "tanoku@gmail.com", - 0, - 0); - - TEST_SIGNATURE_PASS( - "author Vicent Marti \n", - "author ", - "Vicent Marti", - "tanoku@gmail.com", - 0, - 0); - - TEST_SIGNATURE_PASS( - "author A U Thor , C O. Miter 1234567890 -0700\n", - "author ", - "A U Thor", - "author@example.com", - 1234567890, - -420); - - TEST_SIGNATURE_PASS( - "author A U Thor and others 1234567890 -0700\n", - "author ", - "A U Thor", - "author@example.com", - 1234567890, - -420); - - TEST_SIGNATURE_PASS( - "author A U Thor and others 1234567890\n", - "author ", - "A U Thor", - "author@example.com", - 1234567890, - 0); - - TEST_SIGNATURE_FAIL( - "committer Vicent Marti tanoku@gmail.com> 123456 -0100 \n", - "committer "); - - TEST_SIGNATURE_FAIL( - "author Vicent Marti 12345 \n", - "author "); - - TEST_SIGNATURE_FAIL( - "author Vicent Marti 12345 \n", - "committer "); - - TEST_SIGNATURE_FAIL( - "author Vicent Marti 12345 \n", - "author "); - - TEST_SIGNATURE_FAIL( - "author Vicent Marti <\n", - "committer "); - - TEST_SIGNATURE_FAIL( - "author ", - "author "); - -#undef TEST_SIGNATURE_PASS -#undef TEST_SIGNATURE_FAIL - -END_TEST - -static int try_build_signature(const char *name, const char *email, git_time_t time, int offset) -{ - git_signature *sign; - int error = GIT_SUCCESS; - - if ((error = git_signature_new(&sign, name, email, time, offset)) < GIT_SUCCESS) - return error; - - git_signature_free((git_signature *)sign); - - return error; -} - -BEGIN_TEST(signature0, "creating a signature trims leading and trailing spaces") - git_signature *sign; - must_pass(git_signature_new(&sign, " nulltoken ", " emeric.fermas@gmail.com ", 1234567890, 60)); - must_be_true(strcmp(sign->name, "nulltoken") == 0); - must_be_true(strcmp(sign->email, "emeric.fermas@gmail.com") == 0); - git_signature_free((git_signature *)sign); -END_TEST - -BEGIN_TEST(signature1, "can not create a signature with empty name or email") - must_pass(try_build_signature("nulltoken", "emeric.fermas@gmail.com", 1234567890, 60)); - - must_fail(try_build_signature("", "emeric.fermas@gmail.com", 1234567890, 60)); - must_fail(try_build_signature(" ", "emeric.fermas@gmail.com", 1234567890, 60)); - must_fail(try_build_signature("nulltoken", "", 1234567890, 60)); - must_fail(try_build_signature("nulltoken", " ", 1234567890, 60)); -END_TEST - -BEGIN_TEST(signature2, "creating a one character signature") - git_signature *sign; - must_pass(git_signature_new(&sign, "x", "foo@bar.baz", 1234567890, 60)); - must_be_true(strcmp(sign->name, "x") == 0); - must_be_true(strcmp(sign->email, "foo@bar.baz") == 0); - git_signature_free((git_signature *)sign); -END_TEST - -BEGIN_TEST(signature3, "creating a two character signature") - git_signature *sign; - must_pass(git_signature_new(&sign, "xx", "x@y.z", 1234567890, 60)); - must_be_true(strcmp(sign->name, "xx") == 0); - must_be_true(strcmp(sign->email, "x@y.z") == 0); - git_signature_free((git_signature *)sign); -END_TEST - -BEGIN_TEST(signature4, "creating a zero character signature") - git_signature *sign; - must_fail(git_signature_new(&sign, "", "x@y.z", 1234567890, 60)); - must_be_true(sign == NULL); -END_TEST - - -/* External declaration for testing the buffer parsing method */ -int commit_parse_buffer(git_commit *commit, void *data, size_t len); - -BEGIN_TEST(parse2, "parse a whole commit buffer") - const int broken_commit_count = sizeof(test_commits_broken) / sizeof(*test_commits_broken); - const int working_commit_count = sizeof(test_commits_working) / sizeof(*test_commits_working); - - int i; - git_repository *repo; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - for (i = 0; i < broken_commit_count; ++i) { - git_commit *commit; - commit = git__malloc(sizeof(git_commit)); - memset(commit, 0x0, sizeof(git_commit)); - commit->object.repo = repo; - - must_fail(commit_parse_buffer( - commit, - test_commits_broken[i], - strlen(test_commits_broken[i])) - ); - - git_commit__free(commit); - } - - for (i = 0; i < working_commit_count; ++i) { - git_commit *commit; - - commit = git__malloc(sizeof(git_commit)); - memset(commit, 0x0, sizeof(git_commit)); - commit->object.repo = repo; - - must_pass(commit_parse_buffer( - commit, - test_commits_working[i], - strlen(test_commits_working[i])) - ); - - git_commit__free(commit); - - commit = git__malloc(sizeof(git_commit)); - memset(commit, 0x0, sizeof(git_commit)); - commit->object.repo = repo; - - must_pass(commit_parse_buffer( - commit, - test_commits_working[i], - strlen(test_commits_working[i])) - ); - - git_commit__free(commit); - } - - git_repository_free(repo); -END_TEST - -static const char *commit_ids[] = { - "a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */ - "9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */ - "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", /* 2 */ - "c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */ - "8496071c1b46c854b31185ea97743be6a8774479", /* 4 */ - "5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */ -}; - -BEGIN_TEST(details0, "query the details on a parsed commit") - const size_t commit_count = sizeof(commit_ids) / sizeof(const char *); - - unsigned int i; - git_repository *repo; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - for (i = 0; i < commit_count; ++i) { - git_oid id; - git_commit *commit; - - const git_signature *author, *committer; - const char *message; - git_time_t commit_time; - unsigned int parents, p; - git_commit *parent = NULL, *old_parent = NULL; - - git_oid_fromstr(&id, commit_ids[i]); - - must_pass(git_commit_lookup(&commit, repo, &id)); - - message = git_commit_message(commit); - author = git_commit_author(commit); - committer = git_commit_committer(commit); - commit_time = git_commit_time(commit); - parents = git_commit_parentcount(commit); - - must_be_true(strcmp(author->name, "Scott Chacon") == 0); - must_be_true(strcmp(author->email, "schacon@gmail.com") == 0); - must_be_true(strcmp(committer->name, "Scott Chacon") == 0); - must_be_true(strcmp(committer->email, "schacon@gmail.com") == 0); - must_be_true(strchr(message, '\n') != NULL); - must_be_true(commit_time > 0); - must_be_true(parents <= 2); - for (p = 0;p < parents;p++) { - if (old_parent != NULL) - git_commit_close(old_parent); - - old_parent = parent; - must_pass(git_commit_parent(&parent, commit, p)); - must_be_true(parent != NULL); - must_be_true(git_commit_author(parent) != NULL); // is it really a commit? - } - git_commit_close(old_parent); - git_commit_close(parent); - - must_fail(git_commit_parent(&parent, commit, parents)); - git_commit_close(commit); - } - - git_repository_free(repo); -END_TEST - -#define COMMITTER_NAME "Vicent Marti" -#define COMMITTER_EMAIL "vicent@github.com" -#define COMMIT_MESSAGE "This commit has been created in memory\n\ -This is a commit created in memory and it will be written back to disk\n" - -static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd"; - -BEGIN_TEST(write0, "write a new commit object from memory to disk") - git_repository *repo; - git_commit *commit; - git_oid tree_id, parent_id, commit_id; - git_signature *author, *committer; - const git_signature *author1, *committer1; - git_commit *parent; - git_tree *tree; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - git_oid_fromstr(&tree_id, tree_oid); - must_pass(git_tree_lookup(&tree, repo, &tree_id)); - - git_oid_fromstr(&parent_id, commit_ids[4]); - must_pass(git_commit_lookup(&parent, repo, &parent_id)); - - /* create signatures */ - must_pass(git_signature_new(&committer, COMMITTER_NAME, COMMITTER_EMAIL, 123456789, 60)); - must_pass(git_signature_new(&author, COMMITTER_NAME, COMMITTER_EMAIL, 987654321, 90)); - - must_pass(git_commit_create_v( - &commit_id, /* out id */ - repo, - NULL, /* do not update the HEAD */ - author, - committer, - NULL, - COMMIT_MESSAGE, - tree, - 1, parent)); - - git_object_close((git_object *)parent); - git_object_close((git_object *)tree); - - git_signature_free(committer); - git_signature_free(author); - - must_pass(git_commit_lookup(&commit, repo, &commit_id)); - - /* Check attributes were set correctly */ - author1 = git_commit_author(commit); - must_be_true(author1 != NULL); - must_be_true(strcmp(author1->name, COMMITTER_NAME) == 0); - must_be_true(strcmp(author1->email, COMMITTER_EMAIL) == 0); - must_be_true(author1->when.time == 987654321); - must_be_true(author1->when.offset == 90); - - committer1 = git_commit_committer(commit); - must_be_true(committer1 != NULL); - must_be_true(strcmp(committer1->name, COMMITTER_NAME) == 0); - must_be_true(strcmp(committer1->email, COMMITTER_EMAIL) == 0); - must_be_true(committer1->when.time == 123456789); - must_be_true(committer1->when.offset == 60); - - must_be_true(strcmp(git_commit_message(commit), COMMIT_MESSAGE) == 0); - - must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit)); - - git_commit_close(commit); - git_repository_free(repo); -END_TEST - -#define ROOT_COMMIT_MESSAGE "This is a root commit\n\ -This is a root commit and should be the only one in this branch\n" - -BEGIN_TEST(root0, "create a root commit") - git_repository *repo; - git_commit *commit; - git_oid tree_id, commit_id; - const git_oid *branch_oid; - git_signature *author, *committer; - const char *branch_name = "refs/heads/root-commit-branch"; - git_reference *head, *branch; - char *head_old; - git_tree *tree; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - git_oid_fromstr(&tree_id, tree_oid); - must_pass(git_tree_lookup(&tree, repo, &tree_id)); - - /* create signatures */ - must_pass(git_signature_new(&committer, COMMITTER_NAME, COMMITTER_EMAIL, 123456789, 60)); - must_pass(git_signature_new(&author, COMMITTER_NAME, COMMITTER_EMAIL, 987654321, 90)); - - /* First we need to update HEAD so it points to our non-existant branch */ - must_pass(git_reference_lookup(&head, repo, "HEAD")); - must_be_true(git_reference_type(head) == GIT_REF_SYMBOLIC); - head_old = git__strdup(git_reference_target(head)); - must_be_true(head_old != NULL); - - must_pass(git_reference_set_target(head, branch_name)); - - must_pass(git_commit_create_v( - &commit_id, /* out id */ - repo, - "HEAD", - author, - committer, - NULL, - ROOT_COMMIT_MESSAGE, - tree, - 0)); - - git_object_close((git_object *)tree); - git_signature_free(committer); - git_signature_free(author); - - /* - * The fact that creating a commit works has already been - * tested. Here we just make sure it's our commit and that it was - * written as a root commit. - */ - must_pass(git_commit_lookup(&commit, repo, &commit_id)); - must_be_true(git_commit_parentcount(commit) == 0); - must_pass(git_reference_lookup(&branch, repo, branch_name)); - branch_oid = git_reference_oid(branch); - must_pass(git_oid_cmp(branch_oid, &commit_id)); - must_be_true(!strcmp(git_commit_message(commit), ROOT_COMMIT_MESSAGE)); - - /* Remove the data we just added to the repo */ - must_pass(git_reference_lookup(&head, repo, "HEAD")); - must_pass(git_reference_set_target(head, head_old)); - must_pass(git_reference_delete(branch)); - must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)commit)); - free(head_old); - git_commit_close(commit); - git_repository_free(repo); -END_TEST - -BEGIN_SUITE(commit) - ADD_TEST(parse0); - ADD_TEST(parse1); - ADD_TEST(parse2); - ADD_TEST(details0); - - ADD_TEST(write0); - - ADD_TEST(root0); - - ADD_TEST(signature0); - ADD_TEST(signature1); - ADD_TEST(signature2); - ADD_TEST(signature3); - ADD_TEST(signature4); -END_SUITE diff --git a/vendor/libgit2/tests/t05-revwalk.c b/vendor/libgit2/tests/t05-revwalk.c deleted file mode 100644 index ab509ab94..000000000 --- a/vendor/libgit2/tests/t05-revwalk.c +++ /dev/null @@ -1,140 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "test_lib.h" -#include "test_helpers.h" - -/* - $ git log --oneline --graph --decorate - * a4a7dce (HEAD, br2) Merge branch 'master' into br2 - |\ - | * 9fd738e (master) a fourth commit - | * 4a202b3 a third commit - * | c47800c branch commit one - |/ - * 5b5b025 another commit - * 8496071 testing -*/ -static const char *commit_head = "a4a7dce85cf63874e984719f4fdd239f5145052f"; - -static const char *commit_ids[] = { - "a4a7dce85cf63874e984719f4fdd239f5145052f", /* 0 */ - "9fd738e8f7967c078dceed8190330fc8648ee56a", /* 1 */ - "4a202b346bb0fb0db7eff3cffeb3c70babbd2045", /* 2 */ - "c47800c7266a2be04c571c04d5a6614691ea99bd", /* 3 */ - "8496071c1b46c854b31185ea97743be6a8774479", /* 4 */ - "5b5b025afb0b4c913b4c338a42934a3863bf3644", /* 5 */ -}; - -/* Careful: there are two possible topological sorts */ -static const int commit_sorting_topo[][6] = { - {0, 1, 2, 3, 5, 4}, {0, 3, 1, 2, 5, 4} -}; - -static const int commit_sorting_time[][6] = { - {0, 3, 1, 2, 5, 4} -}; - -static const int commit_sorting_topo_reverse[][6] = { - {4, 5, 3, 2, 1, 0}, {4, 5, 2, 1, 3, 0} -}; - -static const int commit_sorting_time_reverse[][6] = { - {4, 5, 2, 1, 3, 0} -}; - -#define commit_count 6 -static const int result_bytes = 24; - - -static int get_commit_index(git_oid *raw_oid) -{ - int i; - char oid[40]; - - git_oid_fmt(oid, raw_oid); - - for (i = 0; i < commit_count; ++i) - if (memcmp(oid, commit_ids[i], 40) == 0) - return i; - - return -1; -} - -static int test_walk(git_revwalk *walk, const git_oid *root, - int flags, const int possible_results[][6], int results_count) -{ - git_oid oid; - - int i; - int result_array[commit_count]; - - git_revwalk_sorting(walk, flags); - git_revwalk_push(walk, root); - - for (i = 0; i < commit_count; ++i) - result_array[i] = -1; - - i = 0; - - while (git_revwalk_next(&oid, walk) == GIT_SUCCESS) { - result_array[i++] = get_commit_index(&oid); - /*{ - char str[41]; - git_oid_fmt(str, &oid); - str[40] = 0; - printf(" %d) %s\n", i, str); - }*/ - } - - for (i = 0; i < results_count; ++i) - if (memcmp(possible_results[i], - result_array, result_bytes) == 0) - return GIT_SUCCESS; - - return GIT_ERROR; -} - -BEGIN_TEST(walk0, "do a simple walk on a repo with different sorting modes") - git_oid id; - git_repository *repo; - git_revwalk *walk; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(git_revwalk_new(&walk, repo)); - - git_oid_fromstr(&id, commit_head); - - must_pass(test_walk(walk, &id, GIT_SORT_TIME, commit_sorting_time, 1)); - must_pass(test_walk(walk, &id, GIT_SORT_TOPOLOGICAL, commit_sorting_topo, 2)); - must_pass(test_walk(walk, &id, GIT_SORT_TIME | GIT_SORT_REVERSE, commit_sorting_time_reverse, 1)); - must_pass(test_walk(walk, &id, GIT_SORT_TOPOLOGICAL | GIT_SORT_REVERSE, commit_sorting_topo_reverse, 2)); - - git_revwalk_free(walk); - git_repository_free(repo); -END_TEST - -BEGIN_SUITE(revwalk) - ADD_TEST(walk0); -END_SUITE diff --git a/vendor/libgit2/tests/t06-index.c b/vendor/libgit2/tests/t06-index.c deleted file mode 100644 index 621e742b3..000000000 --- a/vendor/libgit2/tests/t06-index.c +++ /dev/null @@ -1,219 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "test_lib.h" -#include "test_helpers.h" - -#include "index.h" - -#define TEST_INDEX_ENTRY_COUNT 109 -#define TEST_INDEX2_ENTRY_COUNT 1437 - -struct test_entry { - unsigned int index; - char path[128]; - git_off_t file_size; - git_time_t mtime; -}; - -struct test_entry TEST_ENTRIES[] = { - {4, "Makefile", 5064, 0x4C3F7F33}, - {62, "tests/Makefile", 2631, 0x4C3F7F33}, - {36, "src/index.c", 10014, 0x4C43368D}, - {6, "git.git-authors", 2709, 0x4C3F7F33}, - {48, "src/revobject.h", 1448, 0x4C3F7FE2} -}; - -BEGIN_TEST(read0, "load an empty index") - git_index *index; - - must_pass(git_index_open(&index, "in-memory-index")); - must_be_true(index->on_disk == 0); - - must_be_true(git_index_entrycount(index) == 0); - must_be_true(index->entries.sorted); - - git_index_free(index); -END_TEST - -BEGIN_TEST(read1, "load a standard index (default test index)") - git_index *index; - unsigned int i; - git_index_entry **entries; - - must_pass(git_index_open(&index, TEST_INDEX_PATH)); - must_be_true(index->on_disk); - - must_be_true(git_index_entrycount(index) == TEST_INDEX_ENTRY_COUNT); - must_be_true(index->entries.sorted); - - entries = (git_index_entry **)index->entries.contents; - - for (i = 0; i < ARRAY_SIZE(TEST_ENTRIES); ++i) { - git_index_entry *e = entries[TEST_ENTRIES[i].index]; - - must_be_true(strcmp(e->path, TEST_ENTRIES[i].path) == 0); - must_be_true(e->mtime.seconds == TEST_ENTRIES[i].mtime); - must_be_true(e->file_size == TEST_ENTRIES[i].file_size); - } - - git_index_free(index); -END_TEST - -BEGIN_TEST(read2, "load a standard index (git.git index)") - git_index *index; - - must_pass(git_index_open(&index, TEST_INDEX2_PATH)); - must_be_true(index->on_disk); - - must_be_true(git_index_entrycount(index) == TEST_INDEX2_ENTRY_COUNT); - must_be_true(index->entries.sorted); - must_be_true(index->tree != NULL); - - git_index_free(index); -END_TEST - -BEGIN_TEST(find0, "find an entry on an index") - git_index *index; - unsigned int i; - - must_pass(git_index_open(&index, TEST_INDEX_PATH)); - - for (i = 0; i < ARRAY_SIZE(TEST_ENTRIES); ++i) { - int idx = git_index_find(index, TEST_ENTRIES[i].path); - must_be_true((unsigned int)idx == TEST_ENTRIES[i].index); - } - - git_index_free(index); -END_TEST - -BEGIN_TEST(find1, "find an entry in an empty index") - git_index *index; - unsigned int i; - - must_pass(git_index_open(&index, "fake-index")); - - for (i = 0; i < ARRAY_SIZE(TEST_ENTRIES); ++i) { - int idx = git_index_find(index, TEST_ENTRIES[i].path); - must_be_true(idx == GIT_ENOTFOUND); - } - - git_index_free(index); -END_TEST - -BEGIN_TEST(write0, "write an index back to disk") - git_index *index; - - must_pass(copy_file(TEST_INDEXBIG_PATH, "index_rewrite")); - - must_pass(git_index_open(&index, "index_rewrite")); - must_be_true(index->on_disk); - - must_pass(git_index_write(index)); - must_pass(cmp_files(TEST_INDEXBIG_PATH, "index_rewrite")); - - git_index_free(index); - - p_unlink("index_rewrite"); -END_TEST - -BEGIN_TEST(sort0, "sort the entires in an index") - /* - * TODO: This no longer applies: - * index sorting in Git uses some specific changes to the way - * directories are sorted. - * - * We need to specificially check for this by creating a new - * index, adding entries in random order and then - * checking for consistency - */ -END_TEST - -BEGIN_TEST(sort1, "sort the entires in an empty index") - git_index *index; - - must_pass(git_index_open(&index, "fake-index")); - - /* FIXME: this test is slightly dumb */ - must_be_true(index->entries.sorted); - - git_index_free(index); -END_TEST - -BEGIN_TEST(add0, "add a new file to the index") - git_index *index; - git_filebuf file; - git_repository *repo; - git_index_entry *entry; - git_oid id1; - - /* Intialize a new repository */ - must_pass(git_repository_init(&repo, TEMP_REPO_FOLDER "myrepo", 0)); - - /* Ensure we're the only guy in the room */ - must_pass(git_repository_index(&index, repo)); - must_pass(git_index_entrycount(index) == 0); - - /* Create a new file in the working directory */ - must_pass(git_futils_mkpath2file(TEMP_REPO_FOLDER "myrepo/test.txt")); - must_pass(git_filebuf_open(&file, TEMP_REPO_FOLDER "myrepo/test.txt", 0)); - must_pass(git_filebuf_write(&file, "hey there\n", 10)); - must_pass(git_filebuf_commit(&file)); - - /* Store the expected hash of the file/blob - * This has been generated by executing the following - * $ echo "hey there" | git hash-object --stdin - */ - must_pass(git_oid_fromstr(&id1, "a8233120f6ad708f843d861ce2b7228ec4e3dec6")); - - /* Add the new file to the index */ - must_pass(git_index_add(index, "test.txt", 0)); - - /* Wow... it worked! */ - must_pass(git_index_entrycount(index) == 1); - entry = git_index_get(index, 0); - - /* And the built-in hashing mechanism worked as expected */ - must_be_true(git_oid_cmp(&id1, &entry->oid) == 0); - - git_index_free(index); - git_repository_free(repo); - must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1)); -END_TEST - -BEGIN_SUITE(index) - ADD_TEST(read0); - ADD_TEST(read1); - ADD_TEST(read2); - - ADD_TEST(find0); - ADD_TEST(find1); - - ADD_TEST(write0); - - ADD_TEST(sort0); - ADD_TEST(sort1); - - ADD_TEST(add0); -END_SUITE diff --git a/vendor/libgit2/tests/t07-hashtable.c b/vendor/libgit2/tests/t07-hashtable.c deleted file mode 100644 index 7313f2cc9..000000000 --- a/vendor/libgit2/tests/t07-hashtable.c +++ /dev/null @@ -1,192 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "test_lib.h" -#include "test_helpers.h" - -#include "hashtable.h" -#include "hash.h" - -typedef struct _aux_object { - int __bulk; - git_oid id; - int visited; -} table_item; - -uint32_t hash_func(const void *key, int hash_id) -{ - uint32_t r; - const git_oid *id = key; - - memcpy(&r, id->id + (hash_id * sizeof(uint32_t)), sizeof(r)); - return r; -} - -int hash_cmpkey(const void *a, const void *b) -{ - return git_oid_cmp(a, b); -} - -BEGIN_TEST(table0, "create a new hashtable") - - git_hashtable *table = NULL; - - table = git_hashtable_alloc(55, hash_func, hash_cmpkey); - must_be_true(table != NULL); - must_be_true(table->size_mask + 1 == 64); - - git_hashtable_free(table); - -END_TEST - -BEGIN_TEST(table1, "fill the hashtable with random entries") - - const int objects_n = 32; - int i; - - table_item *objects; - git_hashtable *table = NULL; - - table = git_hashtable_alloc(objects_n * 2, hash_func, hash_cmpkey); - must_be_true(table != NULL); - - objects = git__malloc(objects_n * sizeof(table_item)); - memset(objects, 0x0, objects_n * sizeof(table_item)); - - /* populate the hash table */ - for (i = 0; i < objects_n; ++i) { - git_hash_buf(&(objects[i].id), &i, sizeof(int)); - must_pass(git_hashtable_insert(table, &(objects[i].id), &(objects[i]))); - } - - /* make sure all the inserted objects can be found */ - for (i = 0; i < objects_n; ++i) { - git_oid id; - table_item *ob; - - git_hash_buf(&id, &i, sizeof(int)); - ob = (table_item *)git_hashtable_lookup(table, &id); - - must_be_true(ob != NULL); - must_be_true(ob == &(objects[i])); - } - - /* make sure we cannot find inexisting objects */ - for (i = 0; i < 50; ++i) { - int hash_id; - git_oid id; - - hash_id = (rand() % 50000) + objects_n; - git_hash_buf(&id, &hash_id, sizeof(int)); - must_be_true(git_hashtable_lookup(table, &id) == NULL); - } - - git_hashtable_free(table); - free(objects); - -END_TEST - - -BEGIN_TEST(table2, "make sure the table resizes automatically") - - const int objects_n = 64; - int i; - unsigned int old_size; - table_item *objects; - git_hashtable *table = NULL; - - table = git_hashtable_alloc(objects_n, hash_func, hash_cmpkey); - must_be_true(table != NULL); - - objects = git__malloc(objects_n * sizeof(table_item)); - memset(objects, 0x0, objects_n * sizeof(table_item)); - - old_size = table->size_mask + 1; - - /* populate the hash table -- should be automatically resized */ - for (i = 0; i < objects_n; ++i) { - git_hash_buf(&(objects[i].id), &i, sizeof(int)); - must_pass(git_hashtable_insert(table, &(objects[i].id), &(objects[i]))); - } - - must_be_true(table->size_mask > old_size); - - /* make sure all the inserted objects can be found */ - for (i = 0; i < objects_n; ++i) { - git_oid id; - table_item *ob; - - git_hash_buf(&id, &i, sizeof(int)); - ob = (table_item *)git_hashtable_lookup(table, &id); - - must_be_true(ob != NULL); - must_be_true(ob == &(objects[i])); - } - - git_hashtable_free(table); - free(objects); - -END_TEST - -BEGIN_TEST(tableit0, "iterate through all the contents of the table") - - const int objects_n = 32; - int i; - table_item *objects, *ob; - const void *GIT_UNUSED(_unused); - - git_hashtable *table = NULL; - - table = git_hashtable_alloc(objects_n * 2, hash_func, hash_cmpkey); - must_be_true(table != NULL); - - objects = git__malloc(objects_n * sizeof(table_item)); - memset(objects, 0x0, objects_n * sizeof(table_item)); - - /* populate the hash table */ - for (i = 0; i < objects_n; ++i) { - git_hash_buf(&(objects[i].id), &i, sizeof(int)); - must_pass(git_hashtable_insert(table, &(objects[i].id), &(objects[i]))); - } - - GIT_HASHTABLE_FOREACH(table, _unused, ob, - ob->visited = 1; - ); - - /* make sure all nodes have been visited */ - for (i = 0; i < objects_n; ++i) - must_be_true(objects[i].visited); - - git_hashtable_free(table); - free(objects); -END_TEST - - -BEGIN_SUITE(hashtable) - ADD_TEST(table0); - ADD_TEST(table1); - ADD_TEST(table2); - ADD_TEST(tableit0); -END_SUITE - diff --git a/vendor/libgit2/tests/t08-tag.c b/vendor/libgit2/tests/t08-tag.c deleted file mode 100644 index b0d4af87b..000000000 --- a/vendor/libgit2/tests/t08-tag.c +++ /dev/null @@ -1,316 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "test_lib.h" -#include "test_helpers.h" - -#include "tag.h" - -static const char *tag1_id = "b25fa35b38051e4ae45d4222e795f9df2e43f1d1"; -static const char *tag2_id = "7b4384978d2493e851f9cca7858815fac9b10980"; -static const char *tagged_commit = "e90810b8df3e80c413d903f631643c716887138d"; - -BEGIN_TEST(read0, "read and parse a tag from the repository") - git_repository *repo; - git_tag *tag1, *tag2; - git_commit *commit; - git_oid id1, id2, id_commit; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - git_oid_fromstr(&id1, tag1_id); - git_oid_fromstr(&id2, tag2_id); - git_oid_fromstr(&id_commit, tagged_commit); - - must_pass(git_tag_lookup(&tag1, repo, &id1)); - - must_be_true(strcmp(git_tag_name(tag1), "test") == 0); - must_be_true(git_tag_type(tag1) == GIT_OBJ_TAG); - - must_pass(git_tag_target((git_object **)&tag2, tag1)); - must_be_true(tag2 != NULL); - - must_be_true(git_oid_cmp(&id2, git_tag_id(tag2)) == 0); - - must_pass(git_tag_target((git_object **)&commit, tag2)); - must_be_true(commit != NULL); - - must_be_true(git_oid_cmp(&id_commit, git_commit_id(commit)) == 0); - - git_tag_close(tag1); - git_tag_close(tag2); - git_commit_close(commit); - git_repository_free(repo); -END_TEST - -BEGIN_TEST(read1, "list all tag names from the repository") - git_repository *repo; - git_strarray tag_list; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(git_tag_list(&tag_list, repo)); - - must_be_true(tag_list.count == 3); - - git_strarray_free(&tag_list); - git_repository_free(repo); -END_TEST - -static int ensure_tag_pattern_match(git_repository *repo, const char *pattern, const size_t expected_matches) -{ - git_strarray tag_list; - int error = GIT_SUCCESS; - - if ((error = git_tag_list_match(&tag_list, pattern, repo)) < GIT_SUCCESS) - goto exit; - - if (tag_list.count != expected_matches) - error = GIT_ERROR; - -exit: - git_strarray_free(&tag_list); - return error; -} - -BEGIN_TEST(read2, "list all tag names from the repository matching a specified pattern") - git_repository *repo; - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(ensure_tag_pattern_match(repo, "", 3)); - must_pass(ensure_tag_pattern_match(repo, "*", 3)); - must_pass(ensure_tag_pattern_match(repo, "t*", 1)); - must_pass(ensure_tag_pattern_match(repo, "*b", 2)); - must_pass(ensure_tag_pattern_match(repo, "e", 0)); - must_pass(ensure_tag_pattern_match(repo, "e90810b", 1)); - must_pass(ensure_tag_pattern_match(repo, "e90810[ab]", 1)); - git_repository_free(repo); -END_TEST - - -#define TAGGER_NAME "Vicent Marti" -#define TAGGER_EMAIL "vicent@github.com" -#define TAGGER_MESSAGE "This is my tag.\n\nThere are many tags, but this one is mine\n" - -BEGIN_TEST(write0, "write a tag to the repository and read it again") - git_repository *repo; - git_tag *tag; - git_oid target_id, tag_id; - git_signature *tagger; - const git_signature *tagger1; - git_reference *ref_tag; - git_object *target; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - git_oid_fromstr(&target_id, tagged_commit); - must_pass(git_object_lookup(&target, repo, &target_id, GIT_OBJ_COMMIT)); - - /* create signature */ - must_pass(git_signature_new(&tagger, TAGGER_NAME, TAGGER_EMAIL, 123456789, 60)); - - must_pass(git_tag_create( - &tag_id, /* out id */ - repo, - "the-tag", - target, - tagger, - TAGGER_MESSAGE, - 0)); - - git_object_close(target); - git_signature_free(tagger); - - must_pass(git_tag_lookup(&tag, repo, &tag_id)); - must_be_true(git_oid_cmp(git_tag_target_oid(tag), &target_id) == 0); - - /* Check attributes were set correctly */ - tagger1 = git_tag_tagger(tag); - must_be_true(tagger1 != NULL); - must_be_true(strcmp(tagger1->name, TAGGER_NAME) == 0); - must_be_true(strcmp(tagger1->email, TAGGER_EMAIL) == 0); - must_be_true(tagger1->when.time == 123456789); - must_be_true(tagger1->when.offset == 60); - - must_be_true(strcmp(git_tag_message(tag), TAGGER_MESSAGE) == 0); - - must_pass(git_reference_lookup(&ref_tag, repo, "refs/tags/the-tag")); - must_be_true(git_oid_cmp(git_reference_oid(ref_tag), &tag_id) == 0); - must_pass(git_reference_delete(ref_tag)); - - must_pass(remove_loose_object(REPOSITORY_FOLDER, (git_object *)tag)); - - git_tag_close(tag); - git_repository_free(repo); - -END_TEST - -BEGIN_TEST(write2, "Attempt to write a tag bearing the same name than an already existing tag") - git_repository *repo; - git_oid target_id, tag_id; - git_signature *tagger; - git_object *target; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - git_oid_fromstr(&target_id, tagged_commit); - must_pass(git_object_lookup(&target, repo, &target_id, GIT_OBJ_COMMIT)); - - /* create signature */ - must_pass(git_signature_new(&tagger, TAGGER_NAME, TAGGER_EMAIL, 123456789, 60)); - - must_fail(git_tag_create( - &tag_id, /* out id */ - repo, - "e90810b", - target, - tagger, - TAGGER_MESSAGE, - 0)); - - git_object_close(target); - git_signature_free(tagger); - - git_repository_free(repo); - -END_TEST - -BEGIN_TEST(write3, "Replace an already existing tag") - git_repository *repo; - git_oid target_id, tag_id, old_tag_id; - git_signature *tagger; - git_reference *ref_tag; - git_object *target; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - git_oid_fromstr(&target_id, tagged_commit); - must_pass(git_object_lookup(&target, repo, &target_id, GIT_OBJ_COMMIT)); - - must_pass(git_reference_lookup(&ref_tag, repo, "refs/tags/e90810b")); - git_oid_cpy(&old_tag_id, git_reference_oid(ref_tag)); - - /* create signature */ - must_pass(git_signature_new(&tagger, TAGGER_NAME, TAGGER_EMAIL, 123456789, 60)); - - must_pass(git_tag_create( - &tag_id, /* out id */ - repo, - "e90810b", - target, - tagger, - TAGGER_MESSAGE, - 1)); - - git_object_close(target); - git_signature_free(tagger); - - must_pass(git_reference_lookup(&ref_tag, repo, "refs/tags/e90810b")); - must_be_true(git_oid_cmp(git_reference_oid(ref_tag), &tag_id) == 0); - must_be_true(git_oid_cmp(git_reference_oid(ref_tag), &old_tag_id) != 0); - - close_temp_repo(repo); - -END_TEST - -BEGIN_TEST(write4, "write a lightweight tag to the repository and read it again") - git_repository *repo; - git_oid target_id, object_id; - git_reference *ref_tag; - git_object *target; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - git_oid_fromstr(&target_id, tagged_commit); - must_pass(git_object_lookup(&target, repo, &target_id, GIT_OBJ_COMMIT)); - - must_pass(git_tag_create_lightweight( - &object_id, - repo, - "light-tag", - target, - 0)); - - git_object_close(target); - - must_be_true(git_oid_cmp(&object_id, &target_id) == 0); - - must_pass(git_reference_lookup(&ref_tag, repo, "refs/tags/light-tag")); - must_be_true(git_oid_cmp(git_reference_oid(ref_tag), &target_id) == 0); - - must_pass(git_tag_delete(repo, "light-tag")); - - git_repository_free(repo); -END_TEST - -BEGIN_TEST(write5, "Attempt to write a lightweight tag bearing the same name than an already existing tag") - git_repository *repo; - git_oid target_id, object_id, existing_object_id; - git_object *target; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - git_oid_fromstr(&target_id, tagged_commit); - must_pass(git_object_lookup(&target, repo, &target_id, GIT_OBJ_COMMIT)); - - must_fail(git_tag_create_lightweight( - &object_id, - repo, - "e90810b", - target, - 0)); - - git_oid_fromstr(&existing_object_id, tag2_id); - must_be_true(git_oid_cmp(&object_id, &existing_object_id) == 0); - - git_object_close(target); - - git_repository_free(repo); -END_TEST - -BEGIN_TEST(delete0, "Delete an already existing tag") - git_repository *repo; - git_reference *ref_tag; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - must_pass(git_tag_delete(repo, "e90810b")); - - must_fail(git_reference_lookup(&ref_tag, repo, "refs/tags/e90810b")); - - close_temp_repo(repo); -END_TEST - -BEGIN_SUITE(tag) - ADD_TEST(read0); - ADD_TEST(read1); - ADD_TEST(read2); - - ADD_TEST(write0); - ADD_TEST(write2); - ADD_TEST(write3); - ADD_TEST(write4); - ADD_TEST(write5); - - ADD_TEST(delete0); - -END_SUITE diff --git a/vendor/libgit2/tests/t09-tree.c b/vendor/libgit2/tests/t09-tree.c deleted file mode 100644 index 543aea8d4..000000000 --- a/vendor/libgit2/tests/t09-tree.c +++ /dev/null @@ -1,218 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "test_lib.h" -#include "test_helpers.h" - -#include "tree.h" - -static const char *tree_oid = "1810dff58d8a660512d4832e740f692884338ccd"; - -static const char *blob_oid = "fa49b077972391ad58037050f2a75f74e3671e92"; -static const char *first_tree = "181037049a54a1eb5fab404658a3a250b44335d7"; -static const char *second_tree = "f60079018b664e4e79329a7ef9559c8d9e0378d1"; -static const char *third_tree = "eb86d8b81d6adbd5290a935d6c9976882de98488"; - -#if 0 -static int print_tree(git_repository *repo, const git_oid *tree_oid, int depth) -{ - static const char *indent = " "; - git_tree *tree; - unsigned int i; - - if (git_tree_lookup(&tree, repo, tree_oid) < GIT_SUCCESS) - return GIT_ERROR; - - for (i = 0; i < git_tree_entrycount(tree); ++i) { - const git_tree_entry *entry = git_tree_entry_byindex(tree, i); - char entry_oid[40]; - - git_oid_fmt(entry_oid, &entry->oid); - printf("%.*s%o [%.*s] %s\n", depth*2, indent, entry->attr, 40, entry_oid, entry->filename); - - if (entry->attr == S_IFDIR) { - if (print_tree(repo, &entry->oid, depth + 1) < GIT_SUCCESS) { - git_tree_close(tree); - return GIT_ERROR; - } - } - } - - git_tree_close(tree); - return GIT_SUCCESS; -} -#endif - -BEGIN_TEST(read0, "acces randomly the entries on a loaded tree") - git_oid id; - git_repository *repo; - git_tree *tree; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - git_oid_fromstr(&id, tree_oid); - - must_pass(git_tree_lookup(&tree, repo, &id)); - - must_be_true(git_tree_entry_byname(tree, "README") != NULL); - must_be_true(git_tree_entry_byname(tree, "NOTEXISTS") == NULL); - must_be_true(git_tree_entry_byname(tree, "") == NULL); - must_be_true(git_tree_entry_byindex(tree, 0) != NULL); - must_be_true(git_tree_entry_byindex(tree, 2) != NULL); - must_be_true(git_tree_entry_byindex(tree, 3) == NULL); - must_be_true(git_tree_entry_byindex(tree, (unsigned int)-1) == NULL); - - git_tree_close(tree); - git_repository_free(repo); -END_TEST - -BEGIN_TEST(read1, "read a tree from the repository") - git_oid id; - git_repository *repo; - git_tree *tree; - const git_tree_entry *entry; - git_object *obj; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - git_oid_fromstr(&id, tree_oid); - - must_pass(git_tree_lookup(&tree, repo, &id)); - - must_be_true(git_tree_entrycount(tree) == 3); - - /* GH-86: git_object_lookup() should also check the type if the object comes from the cache */ - must_be_true(git_object_lookup(&obj, repo, &id, GIT_OBJ_TREE) == 0); - must_be_true(obj != NULL); - git_object_close(obj); - obj = NULL; - must_be_true(git_object_lookup(&obj, repo, &id, GIT_OBJ_BLOB) == GIT_EINVALIDTYPE); - must_be_true(obj == NULL); - - entry = git_tree_entry_byname(tree, "README"); - must_be_true(entry != NULL); - - must_be_true(strcmp(git_tree_entry_name(entry), "README") == 0); - - must_pass(git_tree_entry_2object(&obj, repo, entry)); - must_be_true(obj != NULL); - - git_object_close(obj); - git_tree_close(tree); - git_repository_free(repo); -END_TEST - -#if 0 -BEGIN_TEST(write0, "write a tree from an index") - git_repository *repo; - git_index *index; - git_oid tree_oid; - - must_pass(git_repository_open(&repo, "/tmp/redtmp/.git")); - must_pass(git_repository_index(&index, repo)); - - must_pass(git_tree_create_fromindex(&tree_oid, index)); - must_pass(print_tree(repo, &tree_oid, 0)); - - git_repository_free(repo); -END_TEST -#endif - -BEGIN_TEST(write2, "write a tree from a memory") - git_repository *repo; - git_treebuilder *builder; - git_tree *tree; - git_oid id, bid, rid, id2; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - git_oid_fromstr(&id, first_tree); - git_oid_fromstr(&id2, second_tree); - git_oid_fromstr(&bid, blob_oid); - - //create a second tree from first tree using `git_treebuilder_insert` on REPOSITORY_FOLDER. - must_pass(git_tree_lookup(&tree, repo, &id)); - must_pass(git_treebuilder_create(&builder, tree)); - - must_fail(git_treebuilder_insert(NULL, builder, "", &bid, 0100644)); - must_fail(git_treebuilder_insert(NULL, builder, "/", &bid, 0100644)); - must_fail(git_treebuilder_insert(NULL, builder, "folder/new.txt", &bid, 0100644)); - - must_pass(git_treebuilder_insert(NULL,builder,"new.txt",&bid,0100644)); - must_pass(git_treebuilder_write(&rid,repo,builder)); - - must_be_true(git_oid_cmp(&rid, &id2) == 0); - - git_treebuilder_free(builder); - git_tree_close(tree); - close_temp_repo(repo); -END_TEST - -BEGIN_TEST(write3, "write a hierarchical tree from a memory") - git_repository *repo; - git_treebuilder *builder; - git_tree *tree; - git_oid id, bid, subtree_id, id2, id3; - git_oid id_hiearar; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - git_oid_fromstr(&id, first_tree); - git_oid_fromstr(&id2, second_tree); - git_oid_fromstr(&id3, third_tree); - git_oid_fromstr(&bid, blob_oid); - - //create subtree - must_pass(git_treebuilder_create(&builder, NULL)); - must_pass(git_treebuilder_insert(NULL,builder,"new.txt",&bid,0100644)); - must_pass(git_treebuilder_write(&subtree_id,repo,builder)); - git_treebuilder_free(builder); - - // create parent tree - must_pass(git_tree_lookup(&tree, repo, &id)); - must_pass(git_treebuilder_create(&builder, tree)); - must_pass(git_treebuilder_insert(NULL,builder,"new",&subtree_id,040000)); - must_pass(git_treebuilder_write(&id_hiearar,repo,builder)); - git_treebuilder_free(builder); - git_tree_close(tree); - - must_be_true(git_oid_cmp(&id_hiearar, &id3) == 0); - - // check data is correct - must_pass(git_tree_lookup(&tree, repo, &id_hiearar)); - must_be_true(2 == git_tree_entrycount(tree)); - git_tree_close(tree); - - close_temp_repo(repo); - -END_TEST - -BEGIN_SUITE(tree) - //ADD_TEST(print0); - ADD_TEST(read0); - ADD_TEST(read1); - //ADD_TEST(write0); - //ADD_TEST(write1); - ADD_TEST(write2); - ADD_TEST(write3); -END_SUITE - diff --git a/vendor/libgit2/tests/t10-refs.c b/vendor/libgit2/tests/t10-refs.c deleted file mode 100644 index 65fbdd69f..000000000 --- a/vendor/libgit2/tests/t10-refs.c +++ /dev/null @@ -1,1152 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "test_lib.h" -#include "test_helpers.h" - -#include "repository.h" - -#include "git2/reflog.h" -#include "reflog.h" - -static const char *loose_tag_ref_name = "refs/tags/e90810b"; -static const char *non_existing_tag_ref_name = "refs/tags/i-do-not-exist"; - -BEGIN_TEST(readtag0, "lookup a loose tag reference") - git_repository *repo; - git_reference *reference; - git_object *object; - char ref_name_from_tag_name[GIT_REFNAME_MAX]; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - must_pass(git_reference_lookup(&reference, repo, loose_tag_ref_name)); - must_be_true(reference->type & GIT_REF_OID); - must_be_true((reference->type & GIT_REF_PACKED) == 0); - must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0); - - must_pass(git_object_lookup(&object, repo, git_reference_oid(reference), GIT_OBJ_ANY)); - must_be_true(object != NULL); - must_be_true(git_object_type(object) == GIT_OBJ_TAG); - - /* Ensure the name of the tag matches the name of the reference */ - git_path_join(ref_name_from_tag_name, GIT_REFS_TAGS_DIR, git_tag_name((git_tag *)object)); - must_be_true(strcmp(ref_name_from_tag_name, loose_tag_ref_name) == 0); - - git_object_close(object); - git_repository_free(repo); -END_TEST - -BEGIN_TEST(readtag1, "lookup a loose tag reference that doesn't exist") - git_repository *repo; - git_reference *reference; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_fail(git_reference_lookup(&reference, repo, non_existing_tag_ref_name)); - - git_repository_free(repo); -END_TEST - -static const char *head_tracker_sym_ref_name = "head-tracker"; -static const char *current_head_target = "refs/heads/master"; -static const char *current_master_tip = "be3563ae3f795b2b4353bcce3a527ad0a4f7f644"; - -BEGIN_TEST(readsym0, "lookup a symbolic reference") - git_repository *repo; - git_reference *reference, *resolved_ref; - git_object *object; - git_oid id; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - must_pass(git_reference_lookup(&reference, repo, GIT_HEAD_FILE)); - must_be_true(reference->type & GIT_REF_SYMBOLIC); - must_be_true((reference->type & GIT_REF_PACKED) == 0); - must_be_true(strcmp(reference->name, GIT_HEAD_FILE) == 0); - - must_pass(git_reference_resolve(&resolved_ref, reference)); - must_be_true(resolved_ref->type == GIT_REF_OID); - - must_pass(git_object_lookup(&object, repo, git_reference_oid(resolved_ref), GIT_OBJ_ANY)); - must_be_true(object != NULL); - must_be_true(git_object_type(object) == GIT_OBJ_COMMIT); - - git_oid_fromstr(&id, current_master_tip); - must_be_true(git_oid_cmp(&id, git_object_id(object)) == 0); - - git_object_close(object); - git_repository_free(repo); -END_TEST - -BEGIN_TEST(readsym1, "lookup a nested symbolic reference") - git_repository *repo; - git_reference *reference, *resolved_ref; - git_object *object; - git_oid id; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - must_pass(git_reference_lookup(&reference, repo, head_tracker_sym_ref_name)); - must_be_true(reference->type & GIT_REF_SYMBOLIC); - must_be_true((reference->type & GIT_REF_PACKED) == 0); - must_be_true(strcmp(reference->name, head_tracker_sym_ref_name) == 0); - - must_pass(git_reference_resolve(&resolved_ref, reference)); - must_be_true(resolved_ref->type == GIT_REF_OID); - - must_pass(git_object_lookup(&object, repo, git_reference_oid(resolved_ref), GIT_OBJ_ANY)); - must_be_true(object != NULL); - must_be_true(git_object_type(object) == GIT_OBJ_COMMIT); - - git_oid_fromstr(&id, current_master_tip); - must_be_true(git_oid_cmp(&id, git_object_id(object)) == 0); - - git_object_close(object); - git_repository_free(repo); -END_TEST - -BEGIN_TEST(readsym2, "lookup the HEAD and resolve the master branch") - git_repository *repo; - git_reference *reference, *resolved_ref, *comp_base_ref; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - must_pass(git_reference_lookup(&reference, repo, head_tracker_sym_ref_name)); - must_pass(git_reference_resolve(&resolved_ref, reference)); - comp_base_ref = resolved_ref; - - must_pass(git_reference_lookup(&reference, repo, GIT_HEAD_FILE)); - must_pass(git_reference_resolve(&resolved_ref, reference)); - must_pass(git_oid_cmp(git_reference_oid(comp_base_ref), git_reference_oid(resolved_ref))); - - must_pass(git_reference_lookup(&reference, repo, current_head_target)); - must_pass(git_reference_resolve(&resolved_ref, reference)); - must_pass(git_oid_cmp(git_reference_oid(comp_base_ref), git_reference_oid(resolved_ref))); - - git_repository_free(repo); -END_TEST - -BEGIN_TEST(readsym3, "lookup the master branch and then the HEAD") - git_repository *repo; - git_reference *reference, *master_ref, *resolved_ref; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - must_pass(git_reference_lookup(&master_ref, repo, current_head_target)); - must_pass(git_reference_lookup(&reference, repo, GIT_HEAD_FILE)); - - must_pass(git_reference_resolve(&resolved_ref, reference)); - must_pass(git_oid_cmp(git_reference_oid(master_ref), git_reference_oid(resolved_ref))); - - git_repository_free(repo); -END_TEST - -static const char *packed_head_name = "refs/heads/packed"; -static const char *packed_test_head_name = "refs/heads/packed-test"; - -BEGIN_TEST(readpacked0, "lookup a packed reference") - git_repository *repo; - git_reference *reference; - git_object *object; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - must_pass(git_reference_lookup(&reference, repo, packed_head_name)); - must_be_true(reference->type & GIT_REF_OID); - must_be_true((reference->type & GIT_REF_PACKED) != 0); - must_be_true(strcmp(reference->name, packed_head_name) == 0); - - must_pass(git_object_lookup(&object, repo, git_reference_oid(reference), GIT_OBJ_ANY)); - must_be_true(object != NULL); - must_be_true(git_object_type(object) == GIT_OBJ_COMMIT); - - git_object_close(object); - git_repository_free(repo); -END_TEST - -BEGIN_TEST(readpacked1, "assure that a loose reference is looked up before a packed reference") - git_repository *repo; - git_reference *reference; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(git_reference_lookup(&reference, repo, packed_head_name)); - must_pass(git_reference_lookup(&reference, repo, packed_test_head_name)); - must_be_true(reference->type & GIT_REF_OID); - must_be_true((reference->type & GIT_REF_PACKED) == 0); - must_be_true(strcmp(reference->name, packed_test_head_name) == 0); - - git_repository_free(repo); -END_TEST - -BEGIN_TEST(create0, "create a new symbolic reference") - git_reference *new_reference, *looked_up_ref, *resolved_ref; - git_repository *repo, *repo2; - git_oid id; - char ref_path[GIT_PATH_MAX]; - - const char *new_head_tracker = "another-head-tracker"; - - git_oid_fromstr(&id, current_master_tip); - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - /* Retrieve the physical path to the symbolic ref for further cleaning */ - git_path_join(ref_path, repo->path_repository, new_head_tracker); - - /* Create and write the new symbolic reference */ - must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target, 0)); - - /* Ensure the reference can be looked-up... */ - must_pass(git_reference_lookup(&looked_up_ref, repo, new_head_tracker)); - must_be_true(looked_up_ref->type & GIT_REF_SYMBOLIC); - must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0); - must_be_true(strcmp(looked_up_ref->name, new_head_tracker) == 0); - - /* ...peeled.. */ - must_pass(git_reference_resolve(&resolved_ref, looked_up_ref)); - must_be_true(resolved_ref->type == GIT_REF_OID); - - /* ...and that it points to the current master tip */ - must_be_true(git_oid_cmp(&id, git_reference_oid(resolved_ref)) == 0); - - git_repository_free(repo); - - /* Similar test with a fresh new repository */ - must_pass(git_repository_open(&repo2, TEMP_REPO_FOLDER)); - - must_pass(git_reference_lookup(&looked_up_ref, repo2, new_head_tracker)); - must_pass(git_reference_resolve(&resolved_ref, looked_up_ref)); - must_be_true(git_oid_cmp(&id, git_reference_oid(resolved_ref)) == 0); - - close_temp_repo(repo2); -END_TEST - -BEGIN_TEST(create1, "create a deep symbolic reference") - git_reference *new_reference, *looked_up_ref, *resolved_ref; - git_repository *repo; - git_oid id; - char ref_path[GIT_PATH_MAX]; - - const char *new_head_tracker = "deep/rooted/tracker"; - - git_oid_fromstr(&id, current_master_tip); - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - git_path_join(ref_path, repo->path_repository, new_head_tracker); - must_pass(git_reference_create_symbolic(&new_reference, repo, new_head_tracker, current_head_target, 0)); - must_pass(git_reference_lookup(&looked_up_ref, repo, new_head_tracker)); - must_pass(git_reference_resolve(&resolved_ref, looked_up_ref)); - must_be_true(git_oid_cmp(&id, git_reference_oid(resolved_ref)) == 0); - - close_temp_repo(repo); -END_TEST - -BEGIN_TEST(create2, "create a new OID reference") - git_reference *new_reference, *looked_up_ref; - git_repository *repo, *repo2; - git_oid id; - char ref_path[GIT_PATH_MAX]; - - const char *new_head = "refs/heads/new-head"; - - git_oid_fromstr(&id, current_master_tip); - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - /* Retrieve the physical path to the symbolic ref for further cleaning */ - git_path_join(ref_path, repo->path_repository, new_head); - - /* Create and write the new object id reference */ - must_pass(git_reference_create_oid(&new_reference, repo, new_head, &id, 0)); - - /* Ensure the reference can be looked-up... */ - must_pass(git_reference_lookup(&looked_up_ref, repo, new_head)); - must_be_true(looked_up_ref->type & GIT_REF_OID); - must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0); - must_be_true(strcmp(looked_up_ref->name, new_head) == 0); - - /* ...and that it points to the current master tip */ - must_be_true(git_oid_cmp(&id, git_reference_oid(looked_up_ref)) == 0); - - git_repository_free(repo); - - /* Similar test with a fresh new repository */ - must_pass(git_repository_open(&repo2, TEMP_REPO_FOLDER)); - - must_pass(git_reference_lookup(&looked_up_ref, repo2, new_head)); - must_be_true(git_oid_cmp(&id, git_reference_oid(looked_up_ref)) == 0); - - close_temp_repo(repo2); -END_TEST - -BEGIN_TEST(create3, "Can not create a new OID reference which targets at an unknown id") - git_reference *new_reference, *looked_up_ref; - git_repository *repo; - git_oid id; - - const char *new_head = "refs/heads/new-head"; - - git_oid_fromstr(&id, "deadbeef3f795b2b4353bcce3a527ad0a4f7f644"); - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - /* Create and write the new object id reference */ - must_fail(git_reference_create_oid(&new_reference, repo, new_head, &id, 0)); - - /* Ensure the reference can't be looked-up... */ - must_fail(git_reference_lookup(&looked_up_ref, repo, new_head)); - - git_repository_free(repo); -END_TEST - -static const char *ref_name = "refs/heads/other"; -static const char *ref_master_name = "refs/heads/master"; -static const char *ref_branch_name = "refs/heads/branch"; -static const char *ref_test_name = "refs/heads/test"; -BEGIN_TEST(overwrite0, "Overwrite an existing symbolic reference") - git_reference *ref, *branch_ref; - git_repository *repo; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - /* The target needds to exist and we need to check the name has changed */ - must_pass(git_reference_create_symbolic(&branch_ref, repo, ref_branch_name, ref_master_name, 0)); - must_pass(git_reference_create_symbolic(&ref, repo, ref_name, ref_branch_name, 0)); - /* Ensure it points to the right place*/ - must_pass(git_reference_lookup(&ref, repo, ref_name)); - must_be_true(git_reference_type(ref) & GIT_REF_SYMBOLIC); - must_be_true(!strcmp(git_reference_target(ref), ref_branch_name)); - - /* Ensure we can't create it unless we force it to */ - must_fail(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name, 0)); - must_pass(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name, 1)); - - /* Ensure it points to the right place */ - must_pass(git_reference_lookup(&ref, repo, ref_name)); - must_be_true(git_reference_type(ref) & GIT_REF_SYMBOLIC); - must_be_true(!strcmp(git_reference_target(ref), ref_master_name)); - - close_temp_repo(repo); -END_TEST - -BEGIN_TEST(overwrite1, "Overwrite an existing object id reference") - git_reference *ref; - git_repository *repo; - git_oid id; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - must_pass(git_reference_lookup(&ref, repo, ref_master_name)); - must_be_true(ref->type & GIT_REF_OID); - git_oid_cpy(&id, git_reference_oid(ref)); - - /* Create it */ - must_pass(git_reference_create_oid(&ref, repo, ref_name, &id, 0)); - - must_pass(git_reference_lookup(&ref, repo, ref_test_name)); - must_be_true(ref->type & GIT_REF_OID); - git_oid_cpy(&id, git_reference_oid(ref)); - - /* Ensure we can't overwrite unless we force it */ - must_fail(git_reference_create_oid(&ref, repo, ref_name, &id, 0)); - must_pass(git_reference_create_oid(&ref, repo, ref_name, &id, 1)); - - /* Ensure it has been overwritten */ - must_pass(git_reference_lookup(&ref, repo, ref_name)); - must_be_true(!git_oid_cmp(&id, git_reference_oid(ref))); - - close_temp_repo(repo); -END_TEST - -BEGIN_TEST(overwrite2, "Overwrite an existing object id reference with a symbolic one") - git_reference *ref; - git_repository *repo; - git_oid id; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - must_pass(git_reference_lookup(&ref, repo, ref_master_name)); - must_be_true(ref->type & GIT_REF_OID); - git_oid_cpy(&id, git_reference_oid(ref)); - - must_pass(git_reference_create_oid(&ref, repo, ref_name, &id, 0)); - must_fail(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name, 0)); - must_pass(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name, 1)); - - /* Ensure it points to the right place */ - must_pass(git_reference_lookup(&ref, repo, ref_name)); - must_be_true(git_reference_type(ref) & GIT_REF_SYMBOLIC); - must_be_true(!strcmp(git_reference_target(ref), ref_master_name)); - - close_temp_repo(repo); -END_TEST - -BEGIN_TEST(overwrite3, "Overwrite an existing symbolic reference with an object id one") - git_reference *ref; - git_repository *repo; - git_oid id; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - must_pass(git_reference_lookup(&ref, repo, ref_master_name)); - must_be_true(ref->type & GIT_REF_OID); - git_oid_cpy(&id, git_reference_oid(ref)); - - /* Create the symbolic ref */ - must_pass(git_reference_create_symbolic(&ref, repo, ref_name, ref_master_name, 0)); - /* It shouldn't overwrite unless we tell it to */ - must_fail(git_reference_create_oid(&ref, repo, ref_name, &id, 0)); - must_pass(git_reference_create_oid(&ref, repo, ref_name, &id, 1)); - - /* Ensure it points to the right place */ - must_pass(git_reference_lookup(&ref, repo, ref_name)); - must_be_true(git_reference_type(ref) & GIT_REF_OID); - must_be_true(!git_oid_cmp(git_reference_oid(ref), &id)); - - close_temp_repo(repo); -END_TEST - -BEGIN_TEST(pack0, "create a packfile for an empty folder") - git_repository *repo; - char temp_path[GIT_PATH_MAX]; - const int mode = 0755; /* or 0777 ? */ - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - git_path_join_n(temp_path, 3, repo->path_repository, GIT_REFS_HEADS_DIR, "empty_dir"); - must_pass(git_futils_mkdir_r(temp_path, mode)); - - must_pass(git_reference_packall(repo)); - - close_temp_repo(repo); -END_TEST - -BEGIN_TEST(pack1, "create a packfile from all the loose rn a repo") - git_repository *repo; - git_reference *reference; - char temp_path[GIT_PATH_MAX]; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - /* Ensure a known loose ref can be looked up */ - must_pass(git_reference_lookup(&reference, repo, loose_tag_ref_name)); - must_be_true((reference->type & GIT_REF_PACKED) == 0); - must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0); - - /* - * We are now trying to pack also a loose reference - * called `points_to_blob`, to make sure we can properly - * pack weak tags - */ - must_pass(git_reference_packall(repo)); - - /* Ensure the packed-refs file exists */ - git_path_join(temp_path, repo->path_repository, GIT_PACKEDREFS_FILE); - must_pass(git_futils_exists(temp_path)); - - /* Ensure the known ref can still be looked up but is now packed */ - must_pass(git_reference_lookup(&reference, repo, loose_tag_ref_name)); - must_be_true((reference->type & GIT_REF_PACKED) != 0); - must_be_true(strcmp(reference->name, loose_tag_ref_name) == 0); - - /* Ensure the known ref has been removed from the loose folder structure */ - git_path_join(temp_path, repo->path_repository, loose_tag_ref_name); - must_pass(!git_futils_exists(temp_path)); - - close_temp_repo(repo); -END_TEST - -BEGIN_TEST(rename0, "rename a loose reference") - git_reference *looked_up_ref, *another_looked_up_ref; - git_repository *repo; - char temp_path[GIT_PATH_MAX]; - const char *new_name = "refs/tags/Nemo/knows/refs.kung-fu"; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - /* Ensure the ref doesn't exist on the file system */ - git_path_join(temp_path, repo->path_repository, new_name); - must_pass(!git_futils_exists(temp_path)); - - /* Retrieval of the reference to rename */ - must_pass(git_reference_lookup(&looked_up_ref, repo, loose_tag_ref_name)); - - /* ... which is indeed loose */ - must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0); - - /* Now that the reference is renamed... */ - must_pass(git_reference_rename(looked_up_ref, new_name, 0)); - must_be_true(!strcmp(looked_up_ref->name, new_name)); - - /* ...It can't be looked-up with the old name... */ - must_fail(git_reference_lookup(&another_looked_up_ref, repo, loose_tag_ref_name)); - - /* ...but the new name works ok... */ - must_pass(git_reference_lookup(&another_looked_up_ref, repo, new_name)); - must_be_true(!strcmp(another_looked_up_ref->name, new_name)); - - /* .. the ref is still loose... */ - must_be_true((another_looked_up_ref->type & GIT_REF_PACKED) == 0); - must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0); - - /* ...and the ref can be found in the file system */ - git_path_join(temp_path, repo->path_repository, new_name); - must_pass(git_futils_exists(temp_path)); - - close_temp_repo(repo); -END_TEST - -BEGIN_TEST(rename1, "rename a packed reference (should make it loose)") - git_reference *looked_up_ref, *another_looked_up_ref; - git_repository *repo; - char temp_path[GIT_PATH_MAX]; - const char *brand_new_name = "refs/heads/brand_new_name"; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - /* Ensure the ref doesn't exist on the file system */ - git_path_join(temp_path, repo->path_repository, packed_head_name); - must_pass(!git_futils_exists(temp_path)); - - /* The reference can however be looked-up... */ - must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name)); - - /* .. and it's packed */ - must_be_true((looked_up_ref->type & GIT_REF_PACKED) != 0); - - /* Now that the reference is renamed... */ - must_pass(git_reference_rename(looked_up_ref, brand_new_name, 0)); - must_be_true(!strcmp(looked_up_ref->name, brand_new_name)); - - /* ...It can't be looked-up with the old name... */ - must_fail(git_reference_lookup(&another_looked_up_ref, repo, packed_head_name)); - - /* ...but the new name works ok... */ - must_pass(git_reference_lookup(&another_looked_up_ref, repo, brand_new_name)); - must_be_true(!strcmp(another_looked_up_ref->name, brand_new_name)); - - /* .. the ref is no longer packed... */ - must_be_true((another_looked_up_ref->type & GIT_REF_PACKED) == 0); - must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0); - - /* ...and the ref now happily lives in the file system */ - git_path_join(temp_path, repo->path_repository, brand_new_name); - must_pass(git_futils_exists(temp_path)); - - close_temp_repo(repo); -END_TEST - -BEGIN_TEST(rename2, "renaming a packed reference does not pack another reference which happens to be in both loose and pack state") - git_reference *looked_up_ref, *another_looked_up_ref; - git_repository *repo; - char temp_path[GIT_PATH_MAX]; - const char *brand_new_name = "refs/heads/brand_new_name"; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - /* Ensure the other reference exists on the file system */ - git_path_join(temp_path, repo->path_repository, packed_test_head_name); - must_pass(git_futils_exists(temp_path)); - - /* Lookup the other reference */ - must_pass(git_reference_lookup(&another_looked_up_ref, repo, packed_test_head_name)); - - /* Ensure it's loose */ - must_be_true((another_looked_up_ref->type & GIT_REF_PACKED) == 0); - - /* Lookup the reference to rename */ - must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name)); - - /* Ensure it's packed */ - must_be_true((looked_up_ref->type & GIT_REF_PACKED) != 0); - - /* Now that the reference is renamed... */ - must_pass(git_reference_rename(looked_up_ref, brand_new_name, 0)); - - /* Lookup the other reference */ - must_pass(git_reference_lookup(&another_looked_up_ref, repo, packed_test_head_name)); - - /* Ensure it's loose */ - must_be_true((another_looked_up_ref->type & GIT_REF_PACKED) == 0); - - /* Ensure the other ref still exists on the file system */ - must_pass(git_futils_exists(temp_path)); - - close_temp_repo(repo); -END_TEST - -BEGIN_TEST(rename3, "can not rename a reference with the name of an existing reference") - git_reference *looked_up_ref; - git_repository *repo; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - /* An existing reference... */ - must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name)); - - /* Can not be renamed to the name of another existing reference. */ - must_fail(git_reference_rename(looked_up_ref, packed_test_head_name, 0)); - - /* Failure to rename it hasn't corrupted its state */ - must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name)); - must_be_true(!strcmp(looked_up_ref->name, packed_head_name)); - - close_temp_repo(repo); -END_TEST - -BEGIN_TEST(rename4, "can not rename a reference with an invalid name") - git_reference *looked_up_ref; - git_repository *repo; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - /* An existing oid reference... */ - must_pass(git_reference_lookup(&looked_up_ref, repo, packed_test_head_name)); - - /* Can not be renamed with an invalid name. */ - must_fail(git_reference_rename(looked_up_ref, "Hello! I'm a very invalid name.", 0)); - - /* Can not be renamed outside of the refs hierarchy. */ - must_fail(git_reference_rename(looked_up_ref, "i-will-sudo-you", 0)); - - /* Failure to rename it hasn't corrupted its state */ - must_pass(git_reference_lookup(&looked_up_ref, repo, packed_test_head_name)); - must_be_true(!strcmp(looked_up_ref->name, packed_test_head_name)); - - close_temp_repo(repo); -END_TEST - -BEGIN_TEST(rename5, "can force-rename a packed reference with the name of an existing loose and packed reference") - git_reference *looked_up_ref; - git_repository *repo; - git_oid oid; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - /* An existing reference... */ - must_pass(git_reference_lookup(&looked_up_ref, repo, packed_head_name)); - git_oid_cpy(&oid, git_reference_oid(looked_up_ref)); - - /* Can be force-renamed to the name of another existing reference. */ - must_pass(git_reference_rename(looked_up_ref, packed_test_head_name, 1)); - - /* Check we actually renamed it */ - must_pass(git_reference_lookup(&looked_up_ref, repo, packed_test_head_name)); - must_be_true(!strcmp(looked_up_ref->name, packed_test_head_name)); - must_be_true(!git_oid_cmp(&oid, git_reference_oid(looked_up_ref))); - - /* And that the previous one doesn't exist any longer */ - must_fail(git_reference_lookup(&looked_up_ref, repo, packed_head_name)); - - close_temp_repo(repo); -END_TEST - -BEGIN_TEST(rename6, "can force-rename a loose reference with the name of an existing loose reference") - git_reference *looked_up_ref; - git_repository *repo; - git_oid oid; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - /* An existing reference... */ - must_pass(git_reference_lookup(&looked_up_ref, repo, "refs/heads/br2")); - git_oid_cpy(&oid, git_reference_oid(looked_up_ref)); - - /* Can be force-renamed to the name of another existing reference. */ - must_pass(git_reference_rename(looked_up_ref, "refs/heads/test", 1)); - - /* Check we actually renamed it */ - must_pass(git_reference_lookup(&looked_up_ref, repo, "refs/heads/test")); - must_be_true(!strcmp(looked_up_ref->name, "refs/heads/test")); - must_be_true(!git_oid_cmp(&oid, git_reference_oid(looked_up_ref))); - - /* And that the previous one doesn't exist any longer */ - must_fail(git_reference_lookup(&looked_up_ref, repo, "refs/heads/br2")); - - close_temp_repo(repo); -END_TEST - -static const char *ref_one_name = "refs/heads/one/branch"; -static const char *ref_one_name_new = "refs/heads/two/branch"; -static const char *ref_two_name = "refs/heads/two"; - -BEGIN_TEST(rename7, "can not overwrite name of existing reference") - git_reference *ref, *ref_one, *ref_one_new, *ref_two; - git_repository *repo; - git_oid id; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - must_pass(git_reference_lookup(&ref, repo, ref_master_name)); - must_be_true(ref->type & GIT_REF_OID); - - git_oid_cpy(&id, git_reference_oid(ref)); - - /* Create loose references */ - must_pass(git_reference_create_oid(&ref_one, repo, ref_one_name, &id, 0)); - must_pass(git_reference_create_oid(&ref_two, repo, ref_two_name, &id, 0)); - - /* Pack everything */ - must_pass(git_reference_packall(repo)); - - /* Attempt to create illegal reference */ - must_fail(git_reference_create_oid(&ref_one_new, repo, ref_one_name_new, &id, 0)); - - /* Illegal reference couldn't be created so this is supposed to fail */ - must_fail(git_reference_lookup(&ref_one_new, repo, ref_one_name_new)); - - close_temp_repo(repo); -END_TEST - -static const char *ref_two_name_new = "refs/heads/two/two"; - -BEGIN_TEST(rename8, "can be renamed to a new name prefixed with the old name") - git_reference *ref, *ref_two, *looked_up_ref; - git_repository *repo; - git_oid id; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - must_pass(git_reference_lookup(&ref, repo, ref_master_name)); - must_be_true(ref->type & GIT_REF_OID); - - git_oid_cpy(&id, git_reference_oid(ref)); - - /* Create loose references */ - must_pass(git_reference_create_oid(&ref_two, repo, ref_two_name, &id, 0)); - - /* An existing reference... */ - must_pass(git_reference_lookup(&looked_up_ref, repo, ref_two_name)); - - /* Can be rename to a new name starting with the old name. */ - must_pass(git_reference_rename(looked_up_ref, ref_two_name_new, 0)); - - /* Check we actually renamed it */ - must_pass(git_reference_lookup(&looked_up_ref, repo, ref_two_name_new)); - must_be_true(!strcmp(looked_up_ref->name, ref_two_name_new)); - must_fail(git_reference_lookup(&looked_up_ref, repo, ref_two_name)); - - close_temp_repo(repo); -END_TEST - -BEGIN_TEST(delete0, "deleting a ref which is both packed and loose should remove both tracks in the filesystem") - git_reference *looked_up_ref, *another_looked_up_ref; - git_repository *repo; - char temp_path[GIT_PATH_MAX]; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - /* Ensure the loose reference exists on the file system */ - git_path_join(temp_path, repo->path_repository, packed_test_head_name); - must_pass(git_futils_exists(temp_path)); - - /* Lookup the reference */ - must_pass(git_reference_lookup(&looked_up_ref, repo, packed_test_head_name)); - - /* Ensure it's the loose version that has been found */ - must_be_true((looked_up_ref->type & GIT_REF_PACKED) == 0); - - /* Now that the reference is deleted... */ - must_pass(git_reference_delete(looked_up_ref)); - - /* Looking up the reference once again should not retrieve it */ - must_fail(git_reference_lookup(&another_looked_up_ref, repo, packed_test_head_name)); - - /* Ensure the loose reference doesn't exist any longer on the file system */ - must_pass(!git_futils_exists(temp_path)); - - close_temp_repo(repo); -END_TEST - -static int ensure_refname_normalized(int is_oid_ref, const char *input_refname, const char *expected_refname) -{ - int error = GIT_SUCCESS; - char buffer_out[GIT_REFNAME_MAX]; - - if (is_oid_ref) - error = git_reference__normalize_name_oid(buffer_out, sizeof(buffer_out), input_refname); - else - error = git_reference__normalize_name(buffer_out, sizeof(buffer_out), input_refname); - - if (error < GIT_SUCCESS) - return error; - - if (expected_refname == NULL) - return error; - - if (strcmp(buffer_out, expected_refname)) - error = GIT_ERROR; - - return error; -} - -#define OID_REF 1 -#define SYM_REF 0 - -BEGIN_TEST(normalize0, "normalize a direct (OID) reference name") - must_fail(ensure_refname_normalized(OID_REF, "a", NULL)); - must_fail(ensure_refname_normalized(OID_REF, "", NULL)); - must_fail(ensure_refname_normalized(OID_REF, "refs/heads/a/", NULL)); - must_fail(ensure_refname_normalized(OID_REF, "refs/heads/a.", NULL)); - must_fail(ensure_refname_normalized(OID_REF, "refs/heads/a.lock", NULL)); - must_pass(ensure_refname_normalized(OID_REF, "refs/dummy/a", NULL)); - must_pass(ensure_refname_normalized(OID_REF, "refs/stash", NULL)); - must_pass(ensure_refname_normalized(OID_REF, "refs/tags/a", "refs/tags/a")); - must_pass(ensure_refname_normalized(OID_REF, "refs/heads/a/b", "refs/heads/a/b")); - must_pass(ensure_refname_normalized(OID_REF, "refs/heads/a./b", "refs/heads/a./b")); - must_fail(ensure_refname_normalized(OID_REF, "refs/heads/foo?bar", NULL)); - must_fail(ensure_refname_normalized(OID_REF, "refs/heads\foo", NULL)); - must_pass(ensure_refname_normalized(OID_REF, "refs/heads/v@ation", "refs/heads/v@ation")); - must_pass(ensure_refname_normalized(OID_REF, "refs///heads///a", "refs/heads/a")); - must_fail(ensure_refname_normalized(OID_REF, "refs/heads/.a/b", NULL)); - must_fail(ensure_refname_normalized(OID_REF, "refs/heads/foo/../bar", NULL)); - must_fail(ensure_refname_normalized(OID_REF, "refs/heads/foo..bar", NULL)); - must_fail(ensure_refname_normalized(OID_REF, "refs/heads/./foo", NULL)); - must_fail(ensure_refname_normalized(OID_REF, "refs/heads/v@{ation", NULL)); -END_TEST - -BEGIN_TEST(normalize1, "normalize a symbolic reference name") - must_pass(ensure_refname_normalized(SYM_REF, "a", "a")); - must_pass(ensure_refname_normalized(SYM_REF, "a/b", "a/b")); - must_pass(ensure_refname_normalized(SYM_REF, "refs///heads///a", "refs/heads/a")); - must_fail(ensure_refname_normalized(SYM_REF, "", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "heads\foo", NULL)); -END_TEST - -/* Ported from JGit, BSD licence. - * See https://github.com/spearce/JGit/commit/e4bf8f6957bbb29362575d641d1e77a02d906739 */ -BEGIN_TEST(normalize2, "tests borrowed from JGit") - -/* EmptyString */ - must_fail(ensure_refname_normalized(SYM_REF, "", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "/", NULL)); - -/* MustHaveTwoComponents */ - must_fail(ensure_refname_normalized(OID_REF, "master", NULL)); - must_pass(ensure_refname_normalized(SYM_REF, "heads/master", "heads/master")); - -/* ValidHead */ - - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/master", "refs/heads/master")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/pu", "refs/heads/pu")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/z", "refs/heads/z")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/FoO", "refs/heads/FoO")); - -/* ValidTag */ - must_pass(ensure_refname_normalized(SYM_REF, "refs/tags/v1.0", "refs/tags/v1.0")); - -/* NoLockSuffix */ - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master.lock", NULL)); - -/* NoDirectorySuffix */ - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master/", NULL)); - -/* NoSpace */ - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/i haz space", NULL)); - -/* NoAsciiControlCharacters */ - { - char c; - char buffer[GIT_REFNAME_MAX]; - for (c = '\1'; c < ' '; c++) { - strncpy(buffer, "refs/heads/mast", 15); - strncpy(buffer + 15, (const char *)&c, 1); - strncpy(buffer + 16, "er", 2); - buffer[18 - 1] = '\0'; - must_fail(ensure_refname_normalized(SYM_REF, buffer, NULL)); - } - } - -/* NoBareDot */ - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/.", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/..", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/./master", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/../master", NULL)); - -/* NoLeadingOrTrailingDot */ - must_fail(ensure_refname_normalized(SYM_REF, ".", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/.bar", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/..bar", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/bar.", NULL)); - -/* ContainsDot */ - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/m.a.s.t.e.r", "refs/heads/m.a.s.t.e.r")); - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master..pu", NULL)); - -/* NoMagicRefCharacters */ - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master^", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/^master", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "^refs/heads/master", NULL)); - - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master~", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/~master", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "~refs/heads/master", NULL)); - - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master:", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/:master", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, ":refs/heads/master", NULL)); - -/* ShellGlob */ - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master?", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/?master", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "?refs/heads/master", NULL)); - - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master[", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/[master", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "[refs/heads/master", NULL)); - - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master*", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/*master", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "*refs/heads/master", NULL)); - -/* ValidSpecialCharacters */ - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/!", "refs/heads/!")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/\"", "refs/heads/\"")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/#", "refs/heads/#")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/$", "refs/heads/$")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/%", "refs/heads/%")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/&", "refs/heads/&")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/'", "refs/heads/'")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/(", "refs/heads/(")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/)", "refs/heads/)")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/+", "refs/heads/+")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/,", "refs/heads/,")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/-", "refs/heads/-")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/;", "refs/heads/;")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/<", "refs/heads/<")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/=", "refs/heads/=")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/>", "refs/heads/>")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/@", "refs/heads/@")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/]", "refs/heads/]")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/_", "refs/heads/_")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/`", "refs/heads/`")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/{", "refs/heads/{")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/|", "refs/heads/|")); - must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/}", "refs/heads/}")); - - // This is valid on UNIX, but not on Windows - // hence we make in invalid due to non-portability - // - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/\\", NULL)); - -/* UnicodeNames */ - /* - * Currently this fails. - * must_pass(ensure_refname_normalized(SYM_REF, "refs/heads/\u00e5ngstr\u00f6m", "refs/heads/\u00e5ngstr\u00f6m")); - */ - -/* RefLogQueryIsValidRef */ - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master@{1}", NULL)); - must_fail(ensure_refname_normalized(SYM_REF, "refs/heads/master@{1.hour.ago}", NULL)); -END_TEST - -BEGIN_TEST(list0, "try to list all the references in our test repo") - git_repository *repo; - git_strarray ref_list; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(git_reference_listall(&ref_list, repo, GIT_REF_LISTALL)); - - /*{ - unsigned short i; - for (i = 0; i < ref_list.count; ++i) - printf("# %s\n", ref_list.strings[i]); - }*/ - - /* We have exactly 8 refs in total if we include the packed ones: - * there is a reference that exists both in the packfile and as - * loose, but we only list it once */ - must_be_true(ref_list.count == 8); - - git_strarray_free(&ref_list); - git_repository_free(repo); -END_TEST - -BEGIN_TEST(list1, "try to list only the symbolic references") - git_repository *repo; - git_strarray ref_list; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(git_reference_listall(&ref_list, repo, GIT_REF_SYMBOLIC)); - must_be_true(ref_list.count == 0); /* no symrefs in the test repo */ - - git_strarray_free(&ref_list); - git_repository_free(repo); -END_TEST - -static const char *new_ref = "refs/heads/test-reflog"; -#define commit_msg "commit: bla bla" - -static int assert_signature(git_signature *expected, git_signature *actual) -{ - if (actual == NULL) - return GIT_ERROR; - - if (strcmp(expected->name, actual->name) != 0) - return GIT_ERROR; - - if (strcmp(expected->email, actual->email) != 0) - return GIT_ERROR; - - if (expected->when.offset != actual->when.offset) - return GIT_ERROR; - - if (expected->when.time != actual->when.time) - return GIT_ERROR; - - return GIT_SUCCESS; -} - -BEGIN_TEST(reflog0, "write a reflog for a given reference and ensure it can be read back") - git_repository *repo, *repo2; - git_reference *ref, *lookedup_ref; - git_oid oid; - git_signature *committer; - git_reflog *reflog; - git_reflog_entry *entry; - char oid_str[GIT_OID_HEXSZ+1]; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - /* Create a new branch pointing at the HEAD */ - git_oid_fromstr(&oid, current_master_tip); - must_pass(git_reference_create_oid(&ref, repo, new_ref, &oid, 0)); - must_pass(git_reference_lookup(&ref, repo, new_ref)); - - must_pass(git_signature_now(&committer, "foo", "foo@bar")); - - must_pass(git_reflog_write(ref, NULL, committer, NULL)); - must_fail(git_reflog_write(ref, NULL, committer, "no ancestor NULL for an existing reflog")); - must_fail(git_reflog_write(ref, NULL, committer, "no\nnewline")); - must_pass(git_reflog_write(ref, &oid, committer, commit_msg)); - - git_repository_free(repo); - - /* Reopen a new instance of the repository */ - must_pass(git_repository_open(&repo2, TEMP_REPO_FOLDER)); - - /* Lookup the preivously created branch */ - must_pass(git_reference_lookup(&lookedup_ref, repo2, new_ref)); - - /* Read and parse the reflog for this branch */ - must_pass(git_reflog_read(&reflog, lookedup_ref)); - must_be_true(reflog->entries.length == 2); - - entry = (git_reflog_entry *)git_vector_get(&reflog->entries, 0); - must_pass(assert_signature(committer, entry->committer)); - git_oid_to_string(oid_str, GIT_OID_HEXSZ+1, &entry->oid_old); - must_be_true(strcmp("0000000000000000000000000000000000000000", oid_str) == 0); - git_oid_to_string(oid_str, GIT_OID_HEXSZ+1, &entry->oid_cur); - must_be_true(strcmp(current_master_tip, oid_str) == 0); - must_be_true(entry->msg == NULL); - - entry = (git_reflog_entry *)git_vector_get(&reflog->entries, 1); - must_pass(assert_signature(committer, entry->committer)); - git_oid_to_string(oid_str, GIT_OID_HEXSZ+1, &entry->oid_old); - must_be_true(strcmp(current_master_tip, oid_str) == 0); - git_oid_to_string(oid_str, GIT_OID_HEXSZ+1, &entry->oid_cur); - must_be_true(strcmp(current_master_tip, oid_str) == 0); - must_be_true(strcmp(commit_msg, entry->msg) == 0); - - git_signature_free(committer); - git_reflog_free(reflog); - close_temp_repo(repo2); -END_TEST - -BEGIN_TEST(reflog1, "avoid writing an obviously wrong reflog") - git_repository *repo; - git_reference *ref; - git_oid oid; - git_signature *committer; - - must_pass(open_temp_repo(&repo, REPOSITORY_FOLDER)); - - /* Create a new branch pointing at the HEAD */ - git_oid_fromstr(&oid, current_master_tip); - must_pass(git_reference_create_oid(&ref, repo, new_ref, &oid, 0)); - must_pass(git_reference_lookup(&ref, repo, new_ref)); - - must_pass(git_signature_now(&committer, "foo", "foo@bar")); - - /* Write the reflog for the new branch */ - must_pass(git_reflog_write(ref, NULL, committer, NULL)); - - /* Try to update the reflog with wrong information: - * It's no new reference, so the ancestor OID cannot - * be NULL. */ - must_fail(git_reflog_write(ref, NULL, committer, NULL)); - - git_signature_free(committer); - - close_temp_repo(repo); -END_TEST - -BEGIN_SUITE(refs) - ADD_TEST(readtag0); - ADD_TEST(readtag1); - - ADD_TEST(readsym0); - ADD_TEST(readsym1); - ADD_TEST(readsym2); - ADD_TEST(readsym3); - - ADD_TEST(readpacked0); - ADD_TEST(readpacked1); - - ADD_TEST(create0); - ADD_TEST(create1); - ADD_TEST(create2); - ADD_TEST(create3); - - ADD_TEST(overwrite0); - ADD_TEST(overwrite1); - ADD_TEST(overwrite2); - ADD_TEST(overwrite3); - - ADD_TEST(normalize0); - ADD_TEST(normalize1); - ADD_TEST(normalize2); - - ADD_TEST(pack0); - ADD_TEST(pack1); - - ADD_TEST(rename0); - ADD_TEST(rename1); - ADD_TEST(rename2); - ADD_TEST(rename3); - ADD_TEST(rename4); - ADD_TEST(rename5); - ADD_TEST(rename6); - ADD_TEST(rename7); - ADD_TEST(rename8); - - ADD_TEST(delete0); - - ADD_TEST(list0); - ADD_TEST(list1); - - ADD_TEST(reflog0); - ADD_TEST(reflog1); -END_SUITE diff --git a/vendor/libgit2/tests/t11-sqlite.c b/vendor/libgit2/tests/t11-sqlite.c deleted file mode 100644 index 61ecf98ac..000000000 --- a/vendor/libgit2/tests/t11-sqlite.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "test_lib.h" -#include "odb.h" - -#ifdef GIT2_SQLITE_BACKEND -#include "t03-data.h" -#include "fileops.h" -#include "git2/odb_backend.h" - - -static int cmp_objects(git_odb_object *odb_obj, git_rawobj *raw) -{ - if (raw->type != git_odb_object_type(odb_obj)) - return -1; - - if (raw->len != git_odb_object_size(odb_obj)) - return -1; - - if ((raw->len > 0) && (memcmp(raw->data, git_odb_object_data(odb_obj), raw->len) != 0)) - return -1; - - return 0; -} - -static git_odb *open_sqlite_odb(void) -{ - git_odb *odb; - git_odb_backend *sqlite; - - if (git_odb_new(&odb) < GIT_SUCCESS) - return NULL; - - if (git_odb_backend_sqlite(&sqlite, ":memory") < GIT_SUCCESS) - return NULL; - - if (git_odb_add_backend(odb, sqlite, 0) < GIT_SUCCESS) - return NULL; - - return odb; -} - -#define TEST_WRITE(PTR) {\ - git_odb *db; \ - git_oid id1, id2; \ - git_odb_object *obj; \ - db = open_sqlite_odb(); \ - must_be_true(db != NULL); \ - must_pass(git_oid_mkstr(&id1, PTR.id)); \ - must_pass(git_odb_write(&id2, db, PTR##_obj.data, PTR##_obj.len, PTR##_obj.type)); \ - must_be_true(git_oid_cmp(&id1, &id2) == 0); \ - must_pass(git_odb_read(&obj, db, &id1)); \ - must_pass(cmp_objects(obj, &PTR##_obj)); \ - git_odb_object_close(obj); \ - git_odb_close(db); \ -} - -BEGIN_TEST(sqlite0, "write a commit, read it back (sqlite backend)") - TEST_WRITE(commit); -END_TEST - -BEGIN_TEST(sqlite1, "write a tree, read it back (sqlite backend)") - TEST_WRITE(tree); -END_TEST - -BEGIN_TEST(sqlite2, "write a tag, read it back (sqlite backend)") - TEST_WRITE(tag); -END_TEST - -BEGIN_TEST(sqlite3, "write a zero-byte entry, read it back (sqlite backend)") - TEST_WRITE(zero); -END_TEST - -BEGIN_TEST(sqlite4, "write a one-byte entry, read it back (sqlite backend)") - TEST_WRITE(one); -END_TEST - -BEGIN_TEST(sqlite5, "write a two-byte entry, read it back (sqlite backend)") - TEST_WRITE(two); -END_TEST - -BEGIN_TEST(sqlite6, "write some bytes in an entry, read it back (sqlite backend)") - TEST_WRITE(some); -END_TEST - - -BEGIN_SUITE(sqlite) - ADD_TEST(sqlite0); - ADD_TEST(sqlite1); - ADD_TEST(sqlite2); - ADD_TEST(sqlite3); - ADD_TEST(sqlite4); - ADD_TEST(sqlite5); - ADD_TEST(sqlite6); -END_SUITE - -#else /* no sqlite builtin */ -BEGIN_SUITE(sqlite) - /* empty */ -END_SUITE -#endif - - - diff --git a/vendor/libgit2/tests/t12-repo.c b/vendor/libgit2/tests/t12-repo.c deleted file mode 100644 index cc8942f40..000000000 --- a/vendor/libgit2/tests/t12-repo.c +++ /dev/null @@ -1,463 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "test_lib.h" -#include "test_helpers.h" - -#include "odb.h" -#include "git2/odb_backend.h" -#include "repository.h" - -typedef struct { - git_odb_backend base; - int position; -} fake_backend; - -git_odb_backend *new_backend(int position) -{ - fake_backend *b; - - b = git__malloc(sizeof(fake_backend)); - if (b == NULL) - return NULL; - - memset(b, 0x0, sizeof(fake_backend)); - b->position = position; - return (git_odb_backend *)b; -} - -int test_backend_sorting(git_odb *odb) -{ - unsigned int i; - - for (i = 0; i < odb->backends.length; ++i) { - fake_backend *internal = *((fake_backend **)git_vector_get(&odb->backends, i)); - - if (internal == NULL) - return GIT_ERROR; - - if (internal->position != (int)i) - return GIT_ERROR; - } - - return GIT_SUCCESS; -} - -BEGIN_TEST(odb0, "assure that ODB backends are properly sorted") - git_odb *odb; - must_pass(git_odb_new(&odb)); - must_pass(git_odb_add_backend(odb, new_backend(0), 5)); - must_pass(git_odb_add_backend(odb, new_backend(2), 3)); - must_pass(git_odb_add_backend(odb, new_backend(1), 4)); - must_pass(git_odb_add_backend(odb, new_backend(3), 1)); - must_pass(test_backend_sorting(odb)); - git_odb_close(odb); -END_TEST - -BEGIN_TEST(odb1, "assure that alternate backends are properly sorted") - git_odb *odb; - must_pass(git_odb_new(&odb)); - must_pass(git_odb_add_backend(odb, new_backend(0), 5)); - must_pass(git_odb_add_backend(odb, new_backend(2), 3)); - must_pass(git_odb_add_backend(odb, new_backend(1), 4)); - must_pass(git_odb_add_backend(odb, new_backend(3), 1)); - must_pass(git_odb_add_alternate(odb, new_backend(4), 5)); - must_pass(git_odb_add_alternate(odb, new_backend(6), 3)); - must_pass(git_odb_add_alternate(odb, new_backend(5), 4)); - must_pass(git_odb_add_alternate(odb, new_backend(7), 1)); - must_pass(test_backend_sorting(odb)); - git_odb_close(odb); -END_TEST - - -#define STANDARD_REPOSITORY 0 -#define BARE_REPOSITORY 1 - -static int ensure_repository_init( - const char *working_directory, - int repository_kind, - const char *expected_path_index, - const char *expected_path_repository, - const char *expected_working_directory) -{ - char path_odb[GIT_PATH_MAX]; - git_repository *repo; - - if (git_futils_isdir(working_directory) == GIT_SUCCESS) - return GIT_ERROR; - - git_path_join(path_odb, expected_path_repository, GIT_OBJECTS_DIR); - - if (git_repository_init(&repo, working_directory, repository_kind) < GIT_SUCCESS) - return GIT_ERROR; - - if (repo->path_workdir != NULL || expected_working_directory != NULL) { - if (git__suffixcmp(repo->path_workdir, expected_working_directory) != 0) - goto cleanup; - } - - if (git__suffixcmp(repo->path_odb, path_odb) != 0) - goto cleanup; - - if (git__suffixcmp(repo->path_repository, expected_path_repository) != 0) - goto cleanup; - - if (repo->path_index != NULL || expected_path_index != NULL) { - if (git__suffixcmp(repo->path_index, expected_path_index) != 0) - goto cleanup; - -#ifdef GIT_WIN32 - if ((GetFileAttributes(repo->path_repository) & FILE_ATTRIBUTE_HIDDEN) == 0) - goto cleanup; -#endif - - if (git_repository_is_bare(repo) == 1) - goto cleanup; - } else if (git_repository_is_bare(repo) == 0) - goto cleanup; - - if (git_repository_is_empty(repo) == 0) - goto cleanup; - - git_repository_free(repo); - git_futils_rmdir_r(working_directory, 1); - - return GIT_SUCCESS; - -cleanup: - git_repository_free(repo); - git_futils_rmdir_r(working_directory, 1); - return GIT_ERROR; -} - -BEGIN_TEST(init0, "initialize a standard repo") - char path_index[GIT_PATH_MAX], path_repository[GIT_PATH_MAX]; - - git_path_join(path_repository, TEMP_REPO_FOLDER, GIT_DIR); - git_path_join(path_index, path_repository, GIT_INDEX_FILE); - - must_pass(ensure_repository_init(TEMP_REPO_FOLDER, STANDARD_REPOSITORY, path_index, path_repository, TEMP_REPO_FOLDER)); - must_pass(ensure_repository_init(TEMP_REPO_FOLDER_NS, STANDARD_REPOSITORY, path_index, path_repository, TEMP_REPO_FOLDER)); -END_TEST - -BEGIN_TEST(init1, "initialize a bare repo") - char path_repository[GIT_PATH_MAX]; - - git_path_join(path_repository, TEMP_REPO_FOLDER, ""); - - must_pass(ensure_repository_init(TEMP_REPO_FOLDER, BARE_REPOSITORY, NULL, path_repository, NULL)); - must_pass(ensure_repository_init(TEMP_REPO_FOLDER_NS, BARE_REPOSITORY, NULL, path_repository, NULL)); -END_TEST - -BEGIN_TEST(init2, "Initialize and open a bare repo with a relative path escaping out of the current working directory") - char path_repository[GIT_PATH_MAX]; - char current_workdir[GIT_PATH_MAX]; - const int mode = 0755; /* or 0777 ? */ - git_repository* repo; - - must_pass(p_getcwd(current_workdir, sizeof(current_workdir))); - - git_path_join(path_repository, TEMP_REPO_FOLDER, "a/b/c/"); - must_pass(git_futils_mkdir_r(path_repository, mode)); - - must_pass(chdir(path_repository)); - - must_pass(git_repository_init(&repo, "../d/e.git", 1)); - must_pass(git__suffixcmp(repo->path_repository, "/a/b/d/e.git/")); - - git_repository_free(repo); - - must_pass(git_repository_open(&repo, "../d/e.git")); - - git_repository_free(repo); - - must_pass(chdir(current_workdir)); - must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1)); -END_TEST - -#define EMPTY_BARE_REPOSITORY_FOLDER TEST_RESOURCES "/empty_bare.git/" - -BEGIN_TEST(open0, "Open a bare repository that has just been initialized by git") - git_repository *repo; - - must_pass(copydir_recurs(EMPTY_BARE_REPOSITORY_FOLDER, TEMP_REPO_FOLDER)); - must_pass(remove_placeholders(TEMP_REPO_FOLDER, "dummy-marker.txt")); - - must_pass(git_repository_open(&repo, TEMP_REPO_FOLDER)); - must_be_true(git_repository_path(repo, GIT_REPO_PATH) != NULL); - must_be_true(git_repository_path(repo, GIT_REPO_PATH_WORKDIR) == NULL); - - git_repository_free(repo); - must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1)); -END_TEST - -#define EMPTY_REPOSITORY_FOLDER TEST_RESOURCES "/empty_standard_repo/.gitted/" - -BEGIN_TEST(open1, "Open a standard repository that has just been initialized by git") - git_repository *repo; - - must_pass(copydir_recurs(EMPTY_REPOSITORY_FOLDER, TEST_STD_REPO_FOLDER)); - must_pass(remove_placeholders(TEST_STD_REPO_FOLDER, "dummy-marker.txt")); - - must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); - must_be_true(git_repository_path(repo, GIT_REPO_PATH) != NULL); - must_be_true(git_repository_path(repo, GIT_REPO_PATH_WORKDIR) != NULL); - - git_repository_free(repo); - must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1)); -END_TEST - - -BEGIN_TEST(open2, "Open a bare repository with a relative path escaping out of the current working directory") - char new_current_workdir[GIT_PATH_MAX]; - char current_workdir[GIT_PATH_MAX]; - char path_repository[GIT_PATH_MAX]; - - const int mode = 0755; /* or 0777 ? */ - git_repository* repo; - - /* Setup the repository to open */ - must_pass(p_getcwd(current_workdir, sizeof(current_workdir))); - strcpy(path_repository, current_workdir); - git_path_join_n(path_repository, 3, path_repository, TEMP_REPO_FOLDER, "a/d/e.git"); - must_pass(copydir_recurs(REPOSITORY_FOLDER, path_repository)); - - /* Change the current working directory */ - git_path_join(new_current_workdir, TEMP_REPO_FOLDER, "a/b/c/"); - must_pass(git_futils_mkdir_r(new_current_workdir, mode)); - must_pass(chdir(new_current_workdir)); - - must_pass(git_repository_open(&repo, "../../d/e.git")); - - git_repository_free(repo); - - must_pass(chdir(current_workdir)); - must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1)); -END_TEST - -BEGIN_TEST(empty0, "test if a repository is empty or not") - - git_repository *repo_empty, *repo_normal; - - must_pass(git_repository_open(&repo_normal, REPOSITORY_FOLDER)); - must_be_true(git_repository_is_empty(repo_normal) == 0); - git_repository_free(repo_normal); - - must_pass(git_repository_open(&repo_empty, EMPTY_BARE_REPOSITORY_FOLDER)); - must_be_true(git_repository_is_empty(repo_empty) == 1); - git_repository_free(repo_empty); -END_TEST - -BEGIN_TEST(detached0, "test if HEAD is detached") - git_repository *repo; - git_reference *ref; - git_oid oid; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - must_be_true(git_repository_head_detached(repo) == 0); - - /* detach the HEAD */ - git_oid_fromstr(&oid, "c47800c7266a2be04c571c04d5a6614691ea99bd"); - must_pass(git_reference_create_oid(&ref, repo, "HEAD", &oid, 1)); - must_be_true(git_repository_head_detached(repo) == 1); - - /* take the reop back to it's original state */ - must_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1)); - must_be_true(git_repository_head_detached(repo) == 0); - - git_repository_free(repo); -END_TEST - -BEGIN_TEST(orphan0, "test if HEAD is orphan") - git_repository *repo; - git_reference *ref; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - - must_be_true(git_repository_head_orphan(repo) == 0); - - /* orphan HEAD */ - must_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/orphan", 1)); - must_be_true(git_repository_head_orphan(repo) == 1); - - /* take the reop back to it's original state */ - must_pass(git_reference_create_symbolic(&ref, repo, "HEAD", "refs/heads/master", 1)); - must_be_true(git_repository_head_orphan(repo) == 0); - - git_repository_free(repo); -END_TEST - -#define DISCOVER_FOLDER TEMP_REPO_FOLDER "discover.git" - -#define SUB_REPOSITORY_FOLDER_NAME "sub_repo" -#define SUB_REPOSITORY_FOLDER DISCOVER_FOLDER "/" SUB_REPOSITORY_FOLDER_NAME -#define SUB_REPOSITORY_FOLDER_SUB SUB_REPOSITORY_FOLDER "/sub" -#define SUB_REPOSITORY_FOLDER_SUB_SUB SUB_REPOSITORY_FOLDER_SUB "/subsub" -#define SUB_REPOSITORY_FOLDER_SUB_SUB_SUB SUB_REPOSITORY_FOLDER_SUB_SUB "/subsubsub" - -#define REPOSITORY_ALTERNATE_FOLDER DISCOVER_FOLDER "/alternate_sub_repo" -#define REPOSITORY_ALTERNATE_FOLDER_SUB REPOSITORY_ALTERNATE_FOLDER "/sub" -#define REPOSITORY_ALTERNATE_FOLDER_SUB_SUB REPOSITORY_ALTERNATE_FOLDER_SUB "/subsub" -#define REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB REPOSITORY_ALTERNATE_FOLDER_SUB_SUB "/subsubsub" - -#define ALTERNATE_MALFORMED_FOLDER1 DISCOVER_FOLDER "/alternate_malformed_repo1" -#define ALTERNATE_MALFORMED_FOLDER2 DISCOVER_FOLDER "/alternate_malformed_repo2" -#define ALTERNATE_MALFORMED_FOLDER3 DISCOVER_FOLDER "/alternate_malformed_repo3" -#define ALTERNATE_NOT_FOUND_FOLDER DISCOVER_FOLDER "/alternate_not_found_repo" - -static int ensure_repository_discover(const char *start_path, const char *ceiling_dirs, const char *expected_path) -{ - int error; - char found_path[GIT_PATH_MAX]; - - error = git_repository_discover(found_path, sizeof(found_path), start_path, 0, ceiling_dirs); - //across_fs is always 0 as we can't automate the filesystem change tests - - if (error < GIT_SUCCESS) - return error; - - return strcmp(found_path, expected_path) ? GIT_ERROR : GIT_SUCCESS; -} - -static int write_file(const char *path, const char *content) -{ - int error; - git_file file; - - if (git_futils_exists(path) == GIT_SUCCESS) { - error = p_unlink(path); - - if (error < GIT_SUCCESS) - return error; - } - - file = git_futils_creat_withpath(path, 0644); - if (file < GIT_SUCCESS) - return file; - - error = p_write(file, content, strlen(content) * sizeof(char)); - - p_close(file); - - return error; -} - -//no check is performed on ceiling_dirs length, so be sure it's long enough -static int append_ceiling_dir(char *ceiling_dirs, const char *path) -{ - int len = strlen(ceiling_dirs); - int error; - - error = git_path_prettify_dir(ceiling_dirs + len + (len ? 1 : 0), path, NULL); - if (error < GIT_SUCCESS) - return git__rethrow(error, "Failed to append ceiling directory."); - - if (len) - ceiling_dirs[len] = GIT_PATH_LIST_SEPARATOR; - - return GIT_SUCCESS; -} - -BEGIN_TEST(discover0, "test discover") - git_repository *repo; - char ceiling_dirs[GIT_PATH_MAX * 2] = ""; - char repository_path[GIT_PATH_MAX]; - char sub_repository_path[GIT_PATH_MAX]; - char found_path[GIT_PATH_MAX]; - int mode = 0755; - - git_futils_mkdir_r(DISCOVER_FOLDER, mode); - must_pass(append_ceiling_dir(ceiling_dirs, TEMP_REPO_FOLDER)); - - must_be_true(git_repository_discover(repository_path, sizeof(repository_path), DISCOVER_FOLDER, 0, ceiling_dirs) == GIT_ENOTAREPO); - - must_pass(git_repository_init(&repo, DISCOVER_FOLDER, 1)); - must_pass(git_repository_discover(repository_path, sizeof(repository_path), DISCOVER_FOLDER, 0, ceiling_dirs)); - git_repository_free(repo); - - must_pass(git_repository_init(&repo, SUB_REPOSITORY_FOLDER, 0)); - must_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode)); - must_pass(git_repository_discover(sub_repository_path, sizeof(sub_repository_path), SUB_REPOSITORY_FOLDER, 0, ceiling_dirs)); - - must_pass(git_futils_mkdir_r(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, mode)); - must_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB, ceiling_dirs, sub_repository_path)); - must_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path)); - must_pass(ensure_repository_discover(SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, ceiling_dirs, sub_repository_path)); - - must_pass(git_futils_mkdir_r(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, mode)); - must_pass(write_file(REPOSITORY_ALTERNATE_FOLDER "/" DOT_GIT, "gitdir: ../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT)); - must_pass(write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB "/" DOT_GIT, "gitdir: ../../../" SUB_REPOSITORY_FOLDER_NAME "/" DOT_GIT)); - must_pass(write_file(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB "/" DOT_GIT, "gitdir: ../../../../")); - must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER, ceiling_dirs, sub_repository_path)); - must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB, ceiling_dirs, sub_repository_path)); - must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path)); - must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, repository_path)); - - must_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER1, mode)); - must_pass(write_file(ALTERNATE_MALFORMED_FOLDER1 "/" DOT_GIT, "Anything but not gitdir:")); - must_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER2, mode)); - must_pass(write_file(ALTERNATE_MALFORMED_FOLDER2 "/" DOT_GIT, "gitdir:")); - must_pass(git_futils_mkdir_r(ALTERNATE_MALFORMED_FOLDER3, mode)); - must_pass(write_file(ALTERNATE_MALFORMED_FOLDER3 "/" DOT_GIT, "gitdir: \n\n\n")); - must_pass(git_futils_mkdir_r(ALTERNATE_NOT_FOUND_FOLDER, mode)); - must_pass(write_file(ALTERNATE_NOT_FOUND_FOLDER "/" DOT_GIT, "gitdir: a_repository_that_surely_does_not_exist")); - must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER1, 0, ceiling_dirs)); - must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER2, 0, ceiling_dirs)); - must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_MALFORMED_FOLDER3, 0, ceiling_dirs)); - must_fail(git_repository_discover(found_path, sizeof(found_path), ALTERNATE_NOT_FOUND_FOLDER, 0, ceiling_dirs)); - - must_pass(append_ceiling_dir(ceiling_dirs, SUB_REPOSITORY_FOLDER)); - //this must pass as ceiling_directories cannot predent the current - //working directory to be checked - must_pass(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER, 0, ceiling_dirs)); - must_fail(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB, 0, ceiling_dirs)); - must_fail(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB_SUB, 0, ceiling_dirs)); - must_fail(git_repository_discover(found_path, sizeof(found_path), SUB_REPOSITORY_FOLDER_SUB_SUB_SUB, 0, ceiling_dirs)); - - //.gitfile redirection should not be affected by ceiling directories - must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER, ceiling_dirs, sub_repository_path)); - must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB, ceiling_dirs, sub_repository_path)); - must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB, ceiling_dirs, sub_repository_path)); - must_pass(ensure_repository_discover(REPOSITORY_ALTERNATE_FOLDER_SUB_SUB_SUB, ceiling_dirs, repository_path)); - - must_pass(git_futils_rmdir_r(TEMP_REPO_FOLDER, 1)); - git_repository_free(repo); -END_TEST - -BEGIN_SUITE(repository) - ADD_TEST(odb0); - ADD_TEST(odb1); - ADD_TEST(init0); - ADD_TEST(init1); - ADD_TEST(init2); - ADD_TEST(open0); - ADD_TEST(open1); - ADD_TEST(open2); - ADD_TEST(empty0); - ADD_TEST(detached0); - ADD_TEST(orphan0); - ADD_TEST(discover0); -END_SUITE - diff --git a/vendor/libgit2/tests/t13-threads.c b/vendor/libgit2/tests/t13-threads.c deleted file mode 100644 index 3888b70ce..000000000 --- a/vendor/libgit2/tests/t13-threads.c +++ /dev/null @@ -1,41 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "test_lib.h" -#include "test_helpers.h" -#include "cache.h" - - -typedef struct { - git_cached_obj cached; - unsigned int __dummy; -} ttest_obj; - -BEGIN_TEST(cache0, "run several threads polling the cache at the same time") - -END_TEST - -BEGIN_SUITE(threads) - ADD_TEST(cache0); -END_SUITE diff --git a/vendor/libgit2/tests/t14-hiredis.c b/vendor/libgit2/tests/t14-hiredis.c deleted file mode 100644 index c743f7d48..000000000 --- a/vendor/libgit2/tests/t14-hiredis.c +++ /dev/null @@ -1,123 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "test_lib.h" -#include "odb.h" - -#ifdef GIT2_HIREDIS_BACKEND -#include "t03-data.h" -#include "fileops.h" -#include "git2/odb_backend.h" - - -static int cmp_objects(git_odb_object *odb_obj, git_rawobj *raw) -{ - if (raw->type != git_odb_object_type(odb_obj)) - return -1; - - if (raw->len != git_odb_object_size(odb_obj)) - return -1; - - if ((raw->len > 0) && (memcmp(raw->data, git_odb_object_data(odb_obj), raw->len) != 0)) - return -1; - - return 0; -} - -static git_odb *open_hiredis_odb(void) -{ - git_odb *odb; - git_odb_backend *hiredis; - - if (git_odb_new(&odb) < GIT_SUCCESS) - return NULL; - - if (git_odb_backend_hiredis(&hiredis, "127.0.0.1", 6379) < GIT_SUCCESS) - return NULL; - - if (git_odb_add_backend(odb, hiredis, 0) < GIT_SUCCESS) - return NULL; - - return odb; -} - -#define TEST_WRITE(PTR) {\ - git_odb *db; \ - git_oid id1, id2; \ - git_odb_object *obj; \ - db = open_hiredis_odb(); \ - must_be_true(db != NULL); \ - must_pass(git_oid_mkstr(&id1, PTR.id)); \ - must_pass(git_odb_write(&id2, db, PTR##_obj.data, PTR##_obj.len, PTR##_obj.type)); \ - must_be_true(git_oid_cmp(&id1, &id2) == 0); \ - must_pass(git_odb_read(&obj, db, &id1)); \ - must_pass(cmp_objects(obj, &PTR##_obj)); \ - git_odb_object_close(obj); \ - git_odb_close(db); \ -} - -BEGIN_TEST(hiredis0, "write a commit, read it back (hiredis backend)") - TEST_WRITE(commit); -END_TEST - -BEGIN_TEST(hiredis1, "write a tree, read it back (hiredis backend)") - TEST_WRITE(tree); -END_TEST - -BEGIN_TEST(hiredis2, "write a tag, read it back (hiredis backend)") - TEST_WRITE(tag); -END_TEST - -BEGIN_TEST(hiredis3, "write a zero-byte entry, read it back (hiredis backend)") - TEST_WRITE(zero); -END_TEST - -BEGIN_TEST(hiredis4, "write a one-byte entry, read it back (hiredis backend)") - TEST_WRITE(one); -END_TEST - -BEGIN_TEST(hiredis5, "write a two-byte entry, read it back (hiredis backend)") - TEST_WRITE(two); -END_TEST - -BEGIN_TEST(hiredis6, "write some bytes in an entry, read it back (hiredis backend)") - TEST_WRITE(some); -END_TEST - - -BEGIN_SUITE(hiredis) - ADD_TEST(hiredis0); - ADD_TEST(hiredis1); - ADD_TEST(hiredis2); - ADD_TEST(hiredis3); - ADD_TEST(hiredis4); - ADD_TEST(hiredis5); - ADD_TEST(hiredis6); -END_SUITE - -#else /* no hiredis builtin */ -BEGIN_SUITE(hiredis) - /* empty */ -END_SUITE -#endif diff --git a/vendor/libgit2/tests/t15-config.c b/vendor/libgit2/tests/t15-config.c deleted file mode 100644 index 05de25f8c..000000000 --- a/vendor/libgit2/tests/t15-config.c +++ /dev/null @@ -1,325 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "test_lib.h" -#include "test_helpers.h" - -#include -#include "filebuf.h" - -#define CONFIG_BASE TEST_RESOURCES "/config" - -/* - * This one is so we know the code isn't completely broken - */ -BEGIN_TEST(config0, "read a simple configuration") - git_config *cfg; - int i; - - must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config0")); - must_pass(git_config_get_int(cfg, "core.repositoryformatversion", &i)); - must_be_true(i == 0); - must_pass(git_config_get_bool(cfg, "core.filemode", &i)); - must_be_true(i == 1); - must_pass(git_config_get_bool(cfg, "core.bare", &i)); - must_be_true(i == 0); - must_pass(git_config_get_bool(cfg, "core.logallrefupdates", &i)); - must_be_true(i == 1); - - git_config_free(cfg); -END_TEST - -/* - * [this "that"] and [this "That] are different namespaces. Make sure - * each returns the correct one. - */ -BEGIN_TEST(config1, "case sensitivity") - git_config *cfg; - int i; - const char *str; - - must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config1")); - - must_pass(git_config_get_string(cfg, "this.that.other", &str)); - must_be_true(!strcmp(str, "true")); - must_pass(git_config_get_string(cfg, "this.That.other", &str)); - must_be_true(!strcmp(str, "yes")); - - must_pass(git_config_get_bool(cfg, "this.that.other", &i)); - must_be_true(i == 1); - must_pass(git_config_get_bool(cfg, "this.That.other", &i)); - must_be_true(i == 1); - - /* This one doesn't exist */ - must_fail(git_config_get_bool(cfg, "this.thaT.other", &i)); - - git_config_free(cfg); -END_TEST - -/* - * If \ is the last non-space character on the line, we read the next - * one, separating each line with SP. - */ -BEGIN_TEST(config2, "parse a multiline value") - git_config *cfg; - const char *str; - - must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config2")); - - must_pass(git_config_get_string(cfg, "this.That.and", &str)); - must_be_true(!strcmp(str, "one one one two two three three")); - - git_config_free(cfg); -END_TEST - -/* - * This kind of subsection declaration is case-insensitive - */ -BEGIN_TEST(config3, "parse a [section.subsection] header") - git_config *cfg; - const char *str; - - must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config3")); - - must_pass(git_config_get_string(cfg, "section.subsection.var", &str)); - must_be_true(!strcmp(str, "hello")); - - /* Avoid a false positive */ - str = "nohello"; - must_pass(git_config_get_string(cfg, "section.subSectIon.var", &str)); - must_be_true(!strcmp(str, "hello")); - - git_config_free(cfg); -END_TEST - -BEGIN_TEST(config4, "a variable name on its own is valid") - git_config *cfg; -const char *str; -int i; - - must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config4")); - - must_pass(git_config_get_string(cfg, "some.section.variable", &str)); - must_be_true(str == NULL); - - must_pass(git_config_get_bool(cfg, "some.section.variable", &i)); - must_be_true(i == 1); - - - git_config_free(cfg); -END_TEST - -BEGIN_TEST(config5, "test number suffixes") - git_config *cfg; - long int i; - - must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config5")); - - must_pass(git_config_get_long(cfg, "number.simple", &i)); - must_be_true(i == 1); - - must_pass(git_config_get_long(cfg, "number.k", &i)); - must_be_true(i == 1 * 1024); - - must_pass(git_config_get_long(cfg, "number.kk", &i)); - must_be_true(i == 1 * 1024); - - must_pass(git_config_get_long(cfg, "number.m", &i)); - must_be_true(i == 1 * 1024 * 1024); - - must_pass(git_config_get_long(cfg, "number.mm", &i)); - must_be_true(i == 1 * 1024 * 1024); - - must_pass(git_config_get_long(cfg, "number.g", &i)); - must_be_true(i == 1 * 1024 * 1024 * 1024); - - must_pass(git_config_get_long(cfg, "number.gg", &i)); - must_be_true(i == 1 * 1024 * 1024 * 1024); - - git_config_free(cfg); -END_TEST - -BEGIN_TEST(config6, "test blank lines") - git_config *cfg; - int i; - - must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config6")); - - must_pass(git_config_get_bool(cfg, "valid.subsection.something", &i)); - must_be_true(i == 1); - - must_pass(git_config_get_bool(cfg, "something.else.something", &i)); - must_be_true(i == 0); - - git_config_free(cfg); -END_TEST - -BEGIN_TEST(config7, "test for invalid ext headers") - git_config *cfg; - - must_fail(git_config_open_ondisk(&cfg, CONFIG_BASE "/config7")); - -END_TEST - -BEGIN_TEST(config8, "don't fail on empty files") - git_config *cfg; - - must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config8")); - - git_config_free(cfg); -END_TEST - -BEGIN_TEST(config9, "replace a value") - git_config *cfg; - int i; - - /* By freeing the config, we make sure we flush the values */ - must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config9")); - must_pass(git_config_set_int(cfg, "core.dummy", 5)); - git_config_free(cfg); - - must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config9")); - must_pass(git_config_get_int(cfg, "core.dummy", &i)); - must_be_true(i == 5); - git_config_free(cfg); - - must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config9")); - must_pass(git_config_set_int(cfg, "core.dummy", 1)); - git_config_free(cfg); - -END_TEST - -BEGIN_TEST(config10, "a repo's config overrides the global config") - git_repository *repo; - git_config *cfg; - int version; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(git_repository_config(&cfg, repo, CONFIG_BASE "/.gitconfig", NULL)); - must_pass(git_config_get_int(cfg, "core.repositoryformatversion", &version)); - must_be_true(version == 0); - git_config_free(cfg); - git_repository_free(repo); -END_TEST - -BEGIN_TEST(config11, "fall back to the global config") - git_repository *repo; - git_config *cfg; - int num; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(git_repository_config(&cfg, repo, CONFIG_BASE "/.gitconfig", NULL)); - must_pass(git_config_get_int(cfg, "core.something", &num)); - must_be_true(num == 2); - git_config_free(cfg); - git_repository_free(repo); -END_TEST - -BEGIN_TEST(config12, "delete a value") - git_config *cfg; - int i; - - /* By freeing the config, we make sure we flush the values */ - must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config9")); - must_pass(git_config_set_int(cfg, "core.dummy", 5)); - git_config_free(cfg); - - must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config9")); - must_pass(git_config_delete(cfg, "core.dummy")); - git_config_free(cfg); - - must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config9")); - must_be_true(git_config_get_int(cfg, "core.dummy", &i) == GIT_ENOTFOUND); - must_pass(git_config_set_int(cfg, "core.dummy", 1)); - git_config_free(cfg); -END_TEST - -BEGIN_TEST(config13, "can't delete a non-existent value") - git_config *cfg; - - /* By freeing the config, we make sure we flush the values */ - must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config9")); - must_be_true(git_config_delete(cfg, "core.imaginary") == GIT_ENOTFOUND); - git_config_free(cfg); -END_TEST - -BEGIN_TEST(config14, "don't fail horribly if a section header is in the last line") - git_config *cfg; - - /* By freeing the config, we make sure we flush the values */ - must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config10")); - git_config_free(cfg); -END_TEST - -BEGIN_TEST(config15, "add a variable in an existing section") - git_config *cfg; - int i; - - /* By freeing the config, we make sure we flush the values */ - must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config10")); - must_pass(git_config_set_int(cfg, "empty.tmp", 5)); - must_pass(git_config_get_int(cfg, "empty.tmp", &i)); - must_be_true(i == 5); - must_pass(git_config_delete(cfg, "empty.tmp")); - git_config_free(cfg); -END_TEST - -BEGIN_TEST(config16, "add a variable in a new section") - git_config *cfg; - int i; - git_filebuf buf; - - /* By freeing the config, we make sure we flush the values */ - must_pass(git_config_open_ondisk(&cfg, CONFIG_BASE "/config10")); - must_pass(git_config_set_int(cfg, "section.tmp", 5)); - must_pass(git_config_get_int(cfg, "section.tmp", &i)); - must_be_true(i == 5); - must_pass(git_config_delete(cfg, "section.tmp")); - git_config_free(cfg); - - /* As the section wasn't removed, owerwrite the file */ - must_pass(git_filebuf_open(&buf, CONFIG_BASE "/config10", 0)); - must_pass(git_filebuf_write(&buf, "[empty]\n", strlen("[empty]\n"))); - must_pass(git_filebuf_commit(&buf)); -END_TEST - -BEGIN_SUITE(config) - ADD_TEST(config0); - ADD_TEST(config1); - ADD_TEST(config2); - ADD_TEST(config3); - ADD_TEST(config4); - ADD_TEST(config5); - ADD_TEST(config6); - ADD_TEST(config7); - ADD_TEST(config8); - ADD_TEST(config9); - ADD_TEST(config10); - ADD_TEST(config11); - ADD_TEST(config12); - ADD_TEST(config13); - ADD_TEST(config14); - ADD_TEST(config15); - ADD_TEST(config16); -END_SUITE diff --git a/vendor/libgit2/tests/t16-remotes.c b/vendor/libgit2/tests/t16-remotes.c deleted file mode 100644 index 4bc2f55d7..000000000 --- a/vendor/libgit2/tests/t16-remotes.c +++ /dev/null @@ -1,106 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "test_lib.h" -#include "test_helpers.h" - -#include - -BEGIN_TEST(remotes0, "remote parsing works") - git_remote *remote; - git_repository *repo; - git_config *cfg; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(git_repository_config(&cfg, repo, NULL, NULL)); - must_pass(git_remote_get(&remote, cfg, "test")); - must_be_true(!strcmp(git_remote_name(remote), "test")); - must_be_true(!strcmp(git_remote_url(remote), "git://github.com/libgit2/libgit2")); - - git_remote_free(remote); - git_config_free(cfg); - git_repository_free(repo); -END_TEST - -BEGIN_TEST(refspec0, "remote with refspec works") - git_remote *remote; - git_repository *repo; - git_config *cfg; - const git_refspec *refspec = NULL; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(git_repository_config(&cfg, repo, NULL, NULL)); - must_pass(git_remote_get(&remote, cfg, "test")); - refspec = git_remote_fetchspec(remote); - must_be_true(refspec != NULL); - must_be_true(!strcmp(git_refspec_src(refspec), "refs/heads/*")); - must_be_true(!strcmp(git_refspec_dst(refspec), "refs/remotes/test/*")); - git_remote_free(remote); - git_config_free(cfg); - git_repository_free(repo); -END_TEST - -BEGIN_TEST(refspec1, "remote fnmatch works as expected") - git_remote *remote; - git_repository *repo; - git_config *cfg; - const git_refspec *refspec = NULL; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(git_repository_config(&cfg, repo, NULL, NULL)); - must_pass(git_remote_get(&remote, cfg, "test")); - refspec = git_remote_fetchspec(remote); - must_be_true(refspec != NULL); - must_pass(git_refspec_src_match(refspec, "refs/heads/master")); - must_pass(git_refspec_src_match(refspec, "refs/heads/multi/level/branch")); - git_remote_free(remote); - git_config_free(cfg); - git_repository_free(repo); -END_TEST - -BEGIN_TEST(refspec2, "refspec transform") - git_remote *remote; - git_repository *repo; - git_config *cfg; - const git_refspec *refspec = NULL; - char ref[1024] = {0}; - - must_pass(git_repository_open(&repo, REPOSITORY_FOLDER)); - must_pass(git_repository_config(&cfg, repo, NULL, NULL)); - must_pass(git_remote_get(&remote, cfg, "test")); - refspec = git_remote_fetchspec(remote); - must_be_true(refspec != NULL); - must_pass(git_refspec_transform(ref, sizeof(ref), refspec, "refs/heads/master")); - must_be_true(!strcmp(ref, "refs/remotes/test/master")); - git_remote_free(remote); - git_config_free(cfg); - git_repository_free(repo); -END_TEST - -BEGIN_SUITE(remotes) - ADD_TEST(remotes0) - ADD_TEST(refspec0) - ADD_TEST(refspec1) - ADD_TEST(refspec2) -END_SUITE diff --git a/vendor/libgit2/tests/t17-bufs.c b/vendor/libgit2/tests/t17-bufs.c deleted file mode 100644 index 2cbd8c87a..000000000 --- a/vendor/libgit2/tests/t17-bufs.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ -#include "test_lib.h" -#include "test_helpers.h" - -#include -#include "buffer.h" - -const char *test_string = "Have you seen that? Have you seeeen that??"; - -BEGIN_TEST(buf0, "check that resizing works properly") - git_buf buf = GIT_BUF_INIT; - git_buf_puts(&buf, test_string); - - must_be_true(git_buf_oom(&buf) == 0); - must_be_true(strcmp(git_buf_cstr(&buf), test_string) == 0); - - git_buf_puts(&buf, test_string); - must_be_true(strlen(git_buf_cstr(&buf)) == strlen(test_string) * 2); - git_buf_free(&buf); -END_TEST - -BEGIN_TEST(buf1, "check that printf works properly") - git_buf buf = GIT_BUF_INIT; - - git_buf_printf(&buf, "%s %s %d ", "shoop", "da", 23); - must_be_true(git_buf_oom(&buf) == 0); - must_be_true(strcmp(git_buf_cstr(&buf), "shoop da 23 ") == 0); - - git_buf_printf(&buf, "%s %d", "woop", 42); - must_be_true(git_buf_oom(&buf) == 0); - must_be_true(strcmp(git_buf_cstr(&buf), "shoop da 23 woop 42") == 0); - git_buf_free(&buf); -END_TEST - -BEGIN_SUITE(buffers) - ADD_TEST(buf0) - ADD_TEST(buf1) -END_SUITE diff --git a/vendor/libgit2/tests/t18-status.c b/vendor/libgit2/tests/t18-status.c deleted file mode 100644 index c30c541df..000000000 --- a/vendor/libgit2/tests/t18-status.c +++ /dev/null @@ -1,184 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "test_lib.h" -#include "test_helpers.h" -#include "fileops.h" -#include "git2/status.h" - -static const char *test_blob_oid = "d4fa8600b4f37d7516bef4816ae2c64dbf029e3a"; - -#define STATUS_WORKDIR_FOLDER TEST_RESOURCES "/status/" -#define STATUS_REPOSITORY_TEMP_FOLDER TEMP_REPO_FOLDER ".gitted/" - -BEGIN_TEST(file0, "test retrieving OID from a file apart from the ODB") - git_oid expected_id, actual_id; - char filename[] = "new_file"; - int fd; - - fd = p_creat(filename, 0644); - must_pass(fd); - must_pass(p_write(fd, "new_file\n", 9)); - must_pass(p_close(fd)); - - must_pass(git_odb_hashfile(&actual_id, filename, GIT_OBJ_BLOB)); - - must_pass(git_oid_fromstr(&expected_id, test_blob_oid)); - must_be_true(git_oid_cmp(&expected_id, &actual_id) == 0); - - must_pass(p_unlink(filename)); -END_TEST - -static const char *entry_paths[] = { - "current_file", - "file_deleted", - "modified_file", - "new_file", - "staged_changes", - "staged_changes_file_deleted", - "staged_changes_modified_file", - "staged_delete_file_deleted", - "staged_delete_modified_file", - "staged_new_file", - "staged_new_file_deleted_file", - "staged_new_file_modified_file", - - "subdir/current_file", - "subdir/deleted_file", - "subdir/modified_file", - "subdir/new_file", -}; -static const unsigned int entry_statuses[] = { - GIT_STATUS_CURRENT, - GIT_STATUS_WT_DELETED, - GIT_STATUS_WT_MODIFIED, - GIT_STATUS_WT_NEW, - GIT_STATUS_INDEX_MODIFIED, - GIT_STATUS_INDEX_MODIFIED | GIT_STATUS_WT_DELETED, - GIT_STATUS_INDEX_MODIFIED | GIT_STATUS_WT_MODIFIED, - GIT_STATUS_INDEX_DELETED, - GIT_STATUS_INDEX_DELETED | GIT_STATUS_WT_NEW, - GIT_STATUS_INDEX_NEW, - GIT_STATUS_INDEX_NEW | GIT_STATUS_WT_DELETED, - GIT_STATUS_INDEX_NEW | GIT_STATUS_WT_MODIFIED, - - GIT_STATUS_CURRENT, - GIT_STATUS_WT_DELETED, - GIT_STATUS_WT_MODIFIED, - GIT_STATUS_WT_NEW, -}; -#define ENTRY_COUNT 16 - -static unsigned int get_expected_entry_status(const char *path) -{ - int i; - - for (i = 0; i < ENTRY_COUNT; ++i) - if (!strcmp(path, entry_paths[i])) - return entry_statuses[i]; - - return (unsigned int)-1; -} - -struct status_entry_counts { - int wrong_status_flags_count; - int entry_count; -}; - -static int status_cb(const char *path, unsigned int status_flags, void *payload) -{ - unsigned int expected_status_flags = get_expected_entry_status(path); - struct status_entry_counts *counts = (struct status_entry_counts *)payload; - - counts->entry_count++; - if (status_flags != expected_status_flags) - counts->wrong_status_flags_count++; - - return GIT_SUCCESS; -} - -BEGIN_TEST(statuscb0, "test retrieving status for worktree of repository") - git_repository *repo; - struct status_entry_counts counts; - - must_pass(copydir_recurs(STATUS_WORKDIR_FOLDER, TEMP_REPO_FOLDER)); - must_pass(git_futils_mv_atomic(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); - must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); - - memset(&counts, 0x0, sizeof(struct status_entry_counts)); - git_status_foreach(repo, status_cb, &counts); - must_be_true(counts.entry_count == ENTRY_COUNT); - must_be_true(counts.wrong_status_flags_count == 0); - - git_repository_free(repo); - - git_futils_rmdir_r(TEMP_REPO_FOLDER, 1); -END_TEST - -BEGIN_TEST(singlestatus0, "test retrieving status for single file") - git_repository *repo; - unsigned int status_flags; - int i; - - must_pass(copydir_recurs(STATUS_WORKDIR_FOLDER, TEMP_REPO_FOLDER)); - must_pass(git_futils_mv_atomic(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); - must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); - - for (i = 0; i < ENTRY_COUNT; ++i) { - must_pass(git_status_file(&status_flags, repo, entry_paths[i])); - must_be_true(status_flags == entry_statuses[i]); - } - - git_repository_free(repo); - - git_futils_rmdir_r(TEMP_REPO_FOLDER, 1); -END_TEST - -BEGIN_TEST(singlestatus1, "test retrieving status for nonexistent file") - git_repository *repo; - unsigned int status_flags; - int error; - - must_pass(copydir_recurs(STATUS_WORKDIR_FOLDER, TEMP_REPO_FOLDER)); - must_pass(git_futils_mv_atomic(STATUS_REPOSITORY_TEMP_FOLDER, TEST_STD_REPO_FOLDER)); - must_pass(git_repository_open(&repo, TEST_STD_REPO_FOLDER)); - - // "nonexistent" does not exist in HEAD, Index or the worktree - error = git_status_file(&status_flags, repo, "nonexistent"); - must_be_true(error == GIT_ENOTFOUND); - - git_repository_free(repo); - - git_futils_rmdir_r(TEMP_REPO_FOLDER, 1); -END_TEST - -BEGIN_SUITE(status) - ADD_TEST(file0); - - ADD_TEST(statuscb0); - - ADD_TEST(singlestatus0); - ADD_TEST(singlestatus1); -END_SUITE \ No newline at end of file diff --git a/vendor/libgit2/tests/test_helpers.c b/vendor/libgit2/tests/test_helpers.c deleted file mode 100644 index 0900430e1..000000000 --- a/vendor/libgit2/tests/test_helpers.c +++ /dev/null @@ -1,263 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include "common.h" -#include "test_helpers.h" -#include "fileops.h" - -int write_object_data(char *file, void *data, size_t len) -{ - git_file fd; - int ret; - - if ((fd = p_creat(file, S_IREAD | S_IWRITE)) < 0) - return -1; - ret = p_write(fd, data, len); - p_close(fd); - - return ret; -} - -int write_object_files(const char *odb_dir, object_data *d) -{ - if (p_mkdir(odb_dir, 0755) < 0) { - int err = errno; - fprintf(stderr, "can't make directory \"%s\"", odb_dir); - if (err == EEXIST) - fprintf(stderr, " (already exists)"); - fprintf(stderr, "\n"); - return -1; - } - - if ((p_mkdir(d->dir, 0755) < 0) && (errno != EEXIST)) { - fprintf(stderr, "can't make object directory \"%s\"\n", d->dir); - return -1; - } - if (write_object_data(d->file, d->bytes, d->blen) < 0) { - fprintf(stderr, "can't write object file \"%s\"\n", d->file); - return -1; - } - - return 0; -} - -int remove_object_files(const char *odb_dir, object_data *d) -{ - if (p_unlink(d->file) < 0) { - fprintf(stderr, "can't delete object file \"%s\"\n", d->file); - return -1; - } - if ((p_rmdir(d->dir) < 0) && (errno != ENOTEMPTY)) { - fprintf(stderr, "can't remove object directory \"%s\"\n", d->dir); - return -1; - } - - if (p_rmdir(odb_dir) < 0) { - fprintf(stderr, "can't remove directory \"%s\"\n", odb_dir); - return -1; - } - - return 0; -} - -int remove_loose_object(const char *repository_folder, git_object *object) -{ - static const char *objects_folder = "objects/"; - - char *ptr, *full_path, *top_folder; - int path_length, objects_length; - - assert(repository_folder && object); - - objects_length = strlen(objects_folder); - path_length = strlen(repository_folder); - ptr = full_path = git__malloc(path_length + objects_length + GIT_OID_HEXSZ + 3); - - strcpy(ptr, repository_folder); - strcpy(ptr + path_length, objects_folder); - - ptr = top_folder = ptr + path_length + objects_length; - *ptr++ = '/'; - git_oid_pathfmt(ptr, git_object_id(object)); - ptr += GIT_OID_HEXSZ + 1; - *ptr = 0; - - if (p_unlink(full_path) < 0) { - fprintf(stderr, "can't delete object file \"%s\"\n", full_path); - return -1; - } - - *top_folder = 0; - - if ((p_rmdir(full_path) < 0) && (errno != ENOTEMPTY)) { - fprintf(stderr, "can't remove object directory \"%s\"\n", full_path); - return -1; - } - - free(full_path); - - return GIT_SUCCESS; -} - -int cmp_objects(git_rawobj *o, object_data *d) -{ - if (o->type != git_object_string2type(d->type)) - return -1; - if (o->len != d->dlen) - return -1; - if ((o->len > 0) && (memcmp(o->data, d->data, o->len) != 0)) - return -1; - return 0; -} - -int copy_file(const char *src, const char *dst) -{ - git_fbuffer source_buf; - git_file dst_fd; - int error = GIT_ERROR; - - if (git_futils_readbuffer(&source_buf, src) < GIT_SUCCESS) - return GIT_ENOTFOUND; - - dst_fd = git_futils_creat_withpath(dst, 0644); - if (dst_fd < 0) - goto cleanup; - - error = p_write(dst_fd, source_buf.data, source_buf.len); - -cleanup: - git_futils_freebuffer(&source_buf); - p_close(dst_fd); - - return error; -} - -int cmp_files(const char *a, const char *b) -{ - git_fbuffer buf_a, buf_b; - int error = GIT_ERROR; - - if (git_futils_readbuffer(&buf_a, a) < GIT_SUCCESS) - return GIT_ERROR; - - if (git_futils_readbuffer(&buf_b, b) < GIT_SUCCESS) { - git_futils_freebuffer(&buf_a); - return GIT_ERROR; - } - - if (buf_a.len == buf_b.len && !memcmp(buf_a.data, buf_b.data, buf_a.len)) - error = GIT_SUCCESS; - - git_futils_freebuffer(&buf_a); - git_futils_freebuffer(&buf_b); - - return error; -} - -typedef struct { - size_t src_len, dst_len; - char *dst; -} copydir_data; - -static int copy_filesystem_element_recurs(void *_data, char *source) -{ - copydir_data *data = (copydir_data *)_data; - - data->dst[data->dst_len] = 0; - git_path_join(data->dst, data->dst, source + data->src_len); - - if (git_futils_isdir(source) == GIT_SUCCESS) - return git_futils_direach(source, GIT_PATH_MAX, copy_filesystem_element_recurs, _data); - - return copy_file(source, data->dst); -} - -int copydir_recurs(const char *source_directory_path, const char *destination_directory_path) -{ - char source_buffer[GIT_PATH_MAX]; - char dest_buffer[GIT_PATH_MAX]; - copydir_data data; - - /* Source has to exist, Destination hast to _not_ exist */ - if (git_futils_isdir(source_directory_path) != GIT_SUCCESS || - git_futils_isdir(destination_directory_path) == GIT_SUCCESS) - return GIT_EINVALIDPATH; - - git_path_join(source_buffer, source_directory_path, ""); - data.src_len = strlen(source_buffer); - - git_path_join(dest_buffer, destination_directory_path, ""); - data.dst = dest_buffer; - data.dst_len = strlen(dest_buffer); - - return copy_filesystem_element_recurs(&data, source_buffer); -} - -int open_temp_repo(git_repository **repo, const char *path) -{ - if (copydir_recurs(path, TEMP_REPO_FOLDER) < GIT_SUCCESS) { - printf("\nFailed to create temporary folder. Aborting test suite.\n"); - exit(-1); - } - - return git_repository_open(repo, TEMP_REPO_FOLDER); -} - -void close_temp_repo(git_repository *repo) -{ - git_repository_free(repo); - if (git_futils_rmdir_r(TEMP_REPO_FOLDER, 1) < GIT_SUCCESS) { - printf("\nFailed to remove temporary folder. Aborting test suite.\n"); - exit(-1); - } -} - -static int remove_placeholders_recurs(void *filename, char *path) -{ - char passed_filename[GIT_PATH_MAX]; - char *data = (char *)filename; - - if (!git_futils_isdir(path)) - return git_futils_direach(path, GIT_PATH_MAX, remove_placeholders_recurs, data); - - if (git_path_basename_r(passed_filename, sizeof(passed_filename), path) < GIT_SUCCESS) - return GIT_EINVALIDPATH; - - if (!strcmp(data, passed_filename)) - return p_unlink(path); - - return GIT_SUCCESS; -} - -int remove_placeholders(char *directory_path, char *filename) -{ - char buffer[GIT_PATH_MAX]; - - if (git_futils_isdir(directory_path)) - return GIT_EINVALIDPATH; - - strcpy(buffer, directory_path); - return remove_placeholders_recurs(filename, buffer); -} diff --git a/vendor/libgit2/tests/test_helpers.h b/vendor/libgit2/tests/test_helpers.h deleted file mode 100644 index 75027dd6f..000000000 --- a/vendor/libgit2/tests/test_helpers.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#ifndef INCLUDE_test_helpers_h__ -#define INCLUDE_test_helpers_h__ - -#include "test_lib.h" -#include - -#include "odb.h" - -#define TEST_REPOSITORY_NAME "testrepo.git" -#define REPOSITORY_FOLDER TEST_RESOURCES "/" TEST_REPOSITORY_NAME "/" -#define ODB_FOLDER (REPOSITORY_FOLDER "objects/") -#define TEST_INDEX_PATH (REPOSITORY_FOLDER "index") -#define TEST_INDEX2_PATH (TEST_RESOURCES "/gitgit.index") -#define TEST_INDEXBIG_PATH (TEST_RESOURCES "/big.index") - -#define TEMP_FOLDER "" -#define TEMP_REPO_FOLDER TEMP_FOLDER TEST_REPOSITORY_NAME "/" -#define TEMP_REPO_FOLDER_NS TEMP_FOLDER TEST_REPOSITORY_NAME -#define TEST_STD_REPO_FOLDER TEMP_REPO_FOLDER ".git/" - -typedef struct object_data { - unsigned char *bytes; /* (compressed) bytes stored in object store */ - size_t blen; /* length of data in object store */ - char *id; /* object id (sha1) */ - char *type; /* object type */ - char *dir; /* object store (fan-out) directory name */ - char *file; /* object store filename */ - unsigned char *data; /* (uncompressed) object data */ - size_t dlen; /* length of (uncompressed) object data */ -} object_data; - -extern int write_object_data(char *file, void *data, size_t len); - -extern int write_object_files(const char *odb_dir, object_data *d); - -extern int remove_object_files(const char *odb_dir, object_data *d); - -extern int cmp_objects(git_rawobj *o, object_data *d); - -extern int remove_loose_object(const char *odb_dir, git_object *object); - -extern int cmp_files(const char *a, const char *b); -extern int copy_file(const char *source, const char *dest); -extern int rmdir_recurs(const char *directory_path); -extern int copydir_recurs(const char *source_directory_path, const char *destination_directory_path); -extern int remove_placeholders(char *directory_path, char *filename); - -extern int open_temp_repo(git_repository **repo, const char *path); -extern void close_temp_repo(git_repository *repo); - -#endif -/* INCLUDE_test_helpers_h__ */ diff --git a/vendor/libgit2/tests/test_lib.c b/vendor/libgit2/tests/test_lib.c deleted file mode 100755 index a4c39dfde..000000000 --- a/vendor/libgit2/tests/test_lib.c +++ /dev/null @@ -1,198 +0,0 @@ -#include -#include -#include -#include -#include -#include - -#include "test_lib.h" - -#define DO_ALLOC(TYPE) ((TYPE*) malloc(sizeof(TYPE))) -#define GIT_MAX_TEST_CASES 64 - -struct git_test { - char *name; - char *message; - char *failed_pos; - char *description; - char *error_message; - - git_testfunc function; - unsigned failed:1, ran:1; - jmp_buf *jump; -}; - -struct git_testsuite { - char *name; - int count, fail_count; - git_test *list[GIT_MAX_TEST_CASES]; -}; - -static void test_free(git_test *t) -{ - if (t) { - free(t->name); - free(t->description); - free(t->failed_pos); - free(t->message); - free(t->error_message); - free(t); - } -} - -static void test_run(git_test *tc) -{ - jmp_buf buf; - tc->jump = &buf; - - if (setjmp(buf) == 0) { - tc->ran = 1; - (tc->function)(tc); - } - - tc->jump = 0; -} - -static git_test *create_test(git_testfunc function) -{ - git_test *t = DO_ALLOC(git_test); - - memset(t, 0x0, sizeof(git_test)); - t->function = function; - - return t; -} - -void git_test__init(git_test *t, const char *name, const char *description) -{ - t->name = strdup(name); - t->description = strdup(description); -} - - -/*-------------------------------------------------------------------------* - * Public assert methods - *-------------------------------------------------------------------------*/ - -static void fail_test(git_test *tc, const char *file, int line, const char *message) -{ - char buf[1024]; - const char *last_error = git_lasterror(); - - snprintf(buf, 1024, "%s:%d", file, line); - - tc->failed = 1; - tc->message = strdup(message); - tc->failed_pos = strdup(buf); - - if (last_error) - tc->error_message = strdup(last_error); - - if (tc->jump != 0) - longjmp(*(tc->jump), 0); -} - -void git_test__fail(git_test *tc, const char *file, int line, const char *message) -{ - fail_test(tc, file, line, message); -} - -void git_test__assert(git_test *tc, const char *file, int line, const char *message, int condition) -{ - if (condition == 0) - fail_test(tc, file, line, message); -} - -void git_test__assert_pass(git_test *tc, const char *file, int line, const char *message, int ret_value) -{ - if (ret_value < 0) - fail_test(tc, file, line, message); -} - -/*-------------------------------------------------------------------------* - * Test Suite - *-------------------------------------------------------------------------*/ - -static void testsuite_init(git_testsuite *ts) -{ - ts->count = 0; - ts->fail_count = 0; - memset(ts->list, 0, sizeof(ts->list)); -} - -git_testsuite *git_testsuite_new(const char *name) -{ - git_testsuite *ts = DO_ALLOC(git_testsuite); - testsuite_init(ts); - ts->name = strdup(name); - return ts; -} - -static void free_suite(git_testsuite *ts) -{ - unsigned int n; - - for (n = 0; n < GIT_MAX_TEST_CASES; n++) - if (ts->list[n]) - test_free(ts->list[n]); - - free(ts->name); - free(ts); -} - -void git_testsuite_add(git_testsuite *ts, git_testfunc test) -{ - assert(ts->count < GIT_MAX_TEST_CASES); - ts->list[ts->count++] = create_test(test); -} - -static void print_details(git_testsuite *ts) -{ - int i; - int failCount = 0; - - if (ts->fail_count == 0) { - const char *testWord = ts->count == 1 ? "test" : "tests"; - printf("OK (%d %s)\n", ts->count, testWord); - } else { - printf("Failed (%d failures):\n", ts->fail_count); - - for (i = 0 ; i < ts->count ; ++i) { - git_test *tc = ts->list[i]; - if (tc->failed) { - failCount++; - printf(" %d) \"%s\" [test %s @ %s]\n\t%s\n", - failCount, tc->description, tc->name, tc->failed_pos, tc->message); - if (tc->error_message) - printf("\tError: %s\n", tc->error_message); - } - } - } -} - -int git_testsuite_run(git_testsuite *ts) -{ - int i, fail_count; - - printf("Suite \"%s\": ", ts->name); - - for (i = 0 ; i < ts->count ; ++i) { - git_test *tc = ts->list[i]; - - test_run(tc); - if (tc->failed) { - ts->fail_count++; - putchar('F'); - } else - putchar('.'); - - fflush(stdout); - } - printf("\n "); - print_details(ts); - fail_count = ts->fail_count; - - free_suite(ts); - return fail_count; -} - diff --git a/vendor/libgit2/tests/test_lib.h b/vendor/libgit2/tests/test_lib.h deleted file mode 100755 index fc75ed771..000000000 --- a/vendor/libgit2/tests/test_lib.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef __LIBGIT2_TEST_H__ -#define __LIBGIT2_TEST_H__ - -#include -#include -#include -#include - -#include "common.h" -#include - -#define DECLARE_SUITE(SNAME) extern git_testsuite *libgit2_suite_##SNAME(void) -#define SUITE_NAME(SNAME) libgit2_suite_##SNAME - -#define BEGIN_SUITE(SNAME) \ - git_testsuite *libgit2_suite_##SNAME(void) {\ - git_testsuite *_gitsuite = git_testsuite_new(#SNAME); - -#define ADD_TEST(TNAME) \ - git_testsuite_add(_gitsuite, _gittest__##TNAME); - -#define END_SUITE \ - return _gitsuite;\ - } - -#define BEGIN_TEST(TNAME, DESC) \ - static void _gittest__##TNAME(git_test *_gittest) { \ - git_test__init(_gittest, #TNAME, DESC); \ - git_clearerror();\ - {\ - -#define END_TEST }} - -typedef struct git_test git_test; -typedef struct git_testsuite git_testsuite; -typedef void (*git_testfunc)(git_test *); -typedef git_testsuite *(*libgit2_suite)(void); - -void git_test__init(git_test *t, const char *name, const char *description); -void git_test__fail(git_test *tc, const char *file, int line, const char *message); -void git_test__assert(git_test *tc, const char *file, int line, const char *message, int condition); -void git_test__assert_pass(git_test *tc, const char *file, int line, const char *message, int ret_value); - -#define must_pass(expr) git_test__assert_pass(_gittest, __FILE__, __LINE__, "Method failed: " #expr, (expr)) -#define must_fail(expr) git_test__assert(_gittest, __FILE__, __LINE__, "Expected method to fail: " #expr, (expr) < 0) -#define must_be_true(expr) git_test__assert(_gittest, __FILE__, __LINE__, "Expression is not true: " #expr, !!(expr)) - -git_testsuite *git_testsuite_new(const char *name); -void git_testsuite_add(git_testsuite *ts, git_testfunc test); -int git_testsuite_run(git_testsuite *ts); - -#endif - diff --git a/vendor/libgit2/tests/test_main.c b/vendor/libgit2/tests/test_main.c deleted file mode 100644 index c9f8da3a4..000000000 --- a/vendor/libgit2/tests/test_main.c +++ /dev/null @@ -1,91 +0,0 @@ -/* - * This file is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License, version 2, - * as published by the Free Software Foundation. - * - * In addition to the permissions in the GNU General Public License, - * the authors give you unlimited permission to link the compiled - * version of this file into combinations with other programs, - * and to distribute those combinations without any restriction - * coming from the use of this file. (The General Public License - * restrictions do apply in other respects; for example, they cover - * modification of the file, and distribution when not linked into - * a combined executable.) - * - * This file is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 51 Franklin Street, Fifth Floor, - * Boston, MA 02110-1301, USA. - */ - -#include -#include - -#include "test_lib.h" -#include "test_helpers.h" - -DECLARE_SUITE(core); -DECLARE_SUITE(rawobjects); -DECLARE_SUITE(objread); -DECLARE_SUITE(objwrite); -DECLARE_SUITE(commit); -DECLARE_SUITE(revwalk); -DECLARE_SUITE(index); -DECLARE_SUITE(hashtable); -DECLARE_SUITE(tag); -DECLARE_SUITE(tree); -DECLARE_SUITE(refs); -DECLARE_SUITE(repository); -DECLARE_SUITE(threads); -DECLARE_SUITE(config); -DECLARE_SUITE(remotes); -DECLARE_SUITE(buffers); -DECLARE_SUITE(status); - -static libgit2_suite suite_methods[]= { - SUITE_NAME(core), - SUITE_NAME(rawobjects), - SUITE_NAME(objread), - SUITE_NAME(objwrite), - SUITE_NAME(commit), - SUITE_NAME(revwalk), - SUITE_NAME(index), - SUITE_NAME(hashtable), - SUITE_NAME(tag), - SUITE_NAME(tree), - SUITE_NAME(refs), - SUITE_NAME(repository), - SUITE_NAME(threads), - SUITE_NAME(config), - SUITE_NAME(remotes), - SUITE_NAME(buffers), - SUITE_NAME(status), -}; - -#define GIT_SUITE_COUNT (ARRAY_SIZE(suite_methods)) - -#ifdef GIT_WIN32 -int __cdecl -#else -int -#endif -main(int GIT_UNUSED(argc), char *GIT_UNUSED(argv[])) -{ - unsigned int i, failures; - - GIT_UNUSED_ARG(argc); - GIT_UNUSED_ARG(argv); - - failures = 0; - - for (i = 0; i < GIT_SUITE_COUNT; ++i) - failures += git_testsuite_run(suite_methods[i]()); - - return failures ? -1 : 0; -} - diff --git a/vendor/libgit2/tests/tests.supp b/vendor/libgit2/tests/tests.supp deleted file mode 100644 index fe9d965dc..000000000 --- a/vendor/libgit2/tests/tests.supp +++ /dev/null @@ -1,6 +0,0 @@ -{ - ignore-zlib-cond - Memcheck:Cond - obj:*libz.so* -} - diff --git a/vendor/libgit2/waf b/vendor/libgit2/waf deleted file mode 100755 index 18b9aa3e4..000000000 Binary files a/vendor/libgit2/waf and /dev/null differ diff --git a/vendor/libgit2/wscript b/vendor/libgit2/wscript deleted file mode 100644 index f4f8da989..000000000 --- a/vendor/libgit2/wscript +++ /dev/null @@ -1,284 +0,0 @@ -from __future__ import with_statement -from waflib.Context import Context -from waflib.Build import BuildContext, CleanContext, \ - InstallContext, UninstallContext - -# Unix flags -CFLAGS_UNIX = ["-O2", "-Wall", "-Wextra", "-fPIC"] -CFLAGS_UNIX_DBG = ['-g', '-O0'] - -# Windows MSVC flags -CFLAGS_WIN32_COMMON = ['/TC', '/W4', '/WX', '/nologo', '/Zi'] -CFLAGS_WIN32_RELEASE = ['/O2', '/MD'] - -# Note: /RTC* cannot be used with optimization on. -CFLAGS_WIN32_DBG = ['/Od', '/RTC1', '/RTCc', '/DEBUG', '/MDd'] -CFLAGS_WIN32_L = ['/RELEASE'] # used for /both/ debug and release builds. - # sets the module's checksum in the header. -CFLAGS_WIN32_L_DBG = ['/DEBUG'] - -ALL_LIBS = ['crypto', 'pthread', 'sqlite3', 'hiredis'] - -def options(opt): - opt.load('compiler_c') - opt.add_option('--sha1', action='store', default='builtin', - help="Use the builtin SHA1 routines (builtin), the \ -PPC optimized version (ppc) or the SHA1 functions from OpenSSL (openssl)") - opt.add_option('--debug', action='store_true', default=False, - help='Compile with debug symbols') - opt.add_option('--msvc', action='store', default=None, - help='Force a specific MSVC++ version (7.1, 8.0, 9.0, 10.0), if more than one is installed') - opt.add_option('--arch', action='store', default='x86', - help='Select target architecture (ia64, x64, x86, x86_amd64, x86_ia64)') - opt.add_option('--with-sqlite', action='store_true', default=False, - dest='use_sqlite', help='Enable sqlite support') - opt.add_option('--with-hiredis', action='store_true', default=False, - dest='use_hiredis', help='Enable redis support using hiredis') - opt.add_option('--threadsafe', action='store_true', default=False, - help='Make libgit2 thread-safe (requires pthreads)') - -def configure(conf): - - # load the MSVC configuration flags - if conf.options.msvc: - conf.env['MSVC_VERSIONS'] = ['msvc ' + conf.options.msvc] - - conf.env['MSVC_TARGETS'] = [conf.options.arch] - - # default configuration for C programs - conf.load('compiler_c') - - dbg = conf.options.debug - - conf.env.CFLAGS = CFLAGS_UNIX + (CFLAGS_UNIX_DBG if dbg else []) - - if conf.env.DEST_OS == 'win32': - conf.env.PLATFORM = 'win32' - - if conf.env.CC_NAME == 'msvc': - conf.env.CFLAGS = CFLAGS_WIN32_COMMON + \ - (CFLAGS_WIN32_DBG if dbg else CFLAGS_WIN32_RELEASE) - conf.env.LINKFLAGS += CFLAGS_WIN32_L + \ - (CFLAGS_WIN32_L_DBG if dbg else []) - conf.env.DEFINES += ['WIN32', '_DEBUG', '_LIB'] - - else: - conf.env.PLATFORM = 'unix' - - if conf.env.DEST_OS == 'sunos': - conf.env.DEFINES += ['NO_VIZ'] - - if conf.options.threadsafe: - if conf.env.PLATFORM == 'unix': - conf.check_cc(lib='pthread', uselib_store='pthread') - conf.env.DEFINES += ['GIT_THREADS'] - - # check for sqlite3 - if conf.options.use_sqlite and conf.check_cc( - lib='sqlite3', uselib_store='sqlite3', install_path=None, mandatory=False): - conf.env.DEFINES += ['GIT2_SQLITE_BACKEND'] - - # check for hiredis - if conf.options.use_hiredis and conf.check_cc( - lib='hiredis', uselib_store='hiredis', install_path=None, mandatory=False): - conf.env.DEFINES += ['GIT2_HIREDIS_BACKEND'] - - - if conf.options.sha1 not in ['openssl', 'ppc', 'builtin']: - conf.fatal('Invalid SHA1 option') - - # check for libcrypto (openssl) if we are using its SHA1 functions - if conf.options.sha1 == 'openssl': - conf.check_cfg(package='libcrypto', args=['--cflags', '--libs'], uselib_store='crypto') - conf.env.DEFINES += ['OPENSSL_SHA1'] - - elif conf.options.sha1 == 'ppc': - conf.env.DEFINES += ['PPC_SHA1'] - - conf.env.sha1 = conf.options.sha1 - -def build(bld): - - # command '[build|clean|install|uninstall]-static' - if bld.variant == 'static': - build_library(bld, 'static') - - # command '[build|clean|install|uninstall]-shared' - elif bld.variant == 'shared': - build_library(bld, 'shared') - - # command '[build|clean]-tests' - elif bld.variant == 'test': - build_library(bld, 'objects') - build_test(bld) - - # command 'build|clean|install|uninstall': by default, run - # the same command for both the static and the shared lib - else: - from waflib import Options - Options.commands = [bld.cmd + '-shared', bld.cmd + '-static'] + Options.commands - -def get_libgit2_version(git2_h): - import re - line = None - - with open(git2_h) as f: - line = re.search(r'^#define LIBGIT2_VERSION "(\d+\.\d+\.\d+)"$', f.read(), re.MULTILINE) - - if line is None: - raise Exception("Failed to detect libgit2 version") - - return line.group(1) - - -def build_library(bld, build_type): - - BUILD = { - 'shared' : bld.shlib, - 'static' : bld.stlib, - 'objects' : bld.objects - } - - directory = bld.path - sources = directory.ant_glob('src/*.c') - - # Find the version of the library, from our header file - version = get_libgit2_version(directory.find_node("include/git2.h").abspath()) - - # Compile platform-dependant code - # E.g. src/unix/*.c - # src/win32/*.c - sources = sources + directory.ant_glob('src/%s/*.c' % bld.env.PLATFORM) - sources = sources + directory.ant_glob('src/backends/*.c') - sources = sources + directory.ant_glob('deps/zlib/*.c') - - # SHA1 methods source - if bld.env.sha1 == "ppc": - sources.append('src/ppc/sha1.c') - else: - sources.append('src/block-sha1/sha1.c') - #------------------------------ - # Build the main library - #------------------------------ - - # either as static or shared; - BUILD[build_type]( - source=sources, - target='git2', - includes=['src', 'include', 'deps/zlib'], - install_path='${LIBDIR}', - use=ALL_LIBS, - vnum=version, - ) - - # On Unix systems, build the Pkg-config entry file - if bld.env.PLATFORM == 'unix' and bld.is_install: - bld(rule="""sed -e 's#@prefix@#${PREFIX}#' -e 's#@libdir@#${LIBDIR}#' -e 's#@version@#%s#' < ${SRC} > ${TGT}""" % version, - source='libgit2.pc.in', - target='libgit2.pc', - install_path='${LIBDIR}/pkgconfig', - ) - - # Install headers - bld.install_files('${PREFIX}/include', directory.find_node('include/git2.h')) - bld.install_files('${PREFIX}/include/git2', directory.ant_glob('include/git2/*.h')) - - # On Unix systems, let them know about installation - if bld.env.PLATFORM == 'unix' and bld.cmd == 'install-shared': - bld.add_post_fun(call_ldconfig) - -def call_ldconfig(bld): - import distutils.spawn as s - ldconf = s.find_executable('ldconfig') - if ldconf: - bld.exec_command(ldconf) - -def build_test(bld): - directory = bld.path - resources_path = directory.find_node('tests/resources/').abspath().replace('\\', '/') - - sources = ['tests/test_lib.c', 'tests/test_helpers.c', 'tests/test_main.c'] - sources = sources + directory.ant_glob('tests/t??-*.c') - - bld.program( - source=sources, - target='libgit2_test', - includes=['src', 'tests', 'include'], - defines=['TEST_RESOURCES="%s"' % resources_path], - use=['git2'] + ALL_LIBS - ) - -class _test(BuildContext): - cmd = 'test' - fun = 'test' - -def test(bld): - from waflib import Options - Options.commands = ['build-test', 'run-test'] + Options.commands - -class _build_doc(Context): - cmd = 'doxygen' - fun = 'build_docs' - -def build_docs(ctx): - ctx.exec_command("doxygen api.doxygen") - ctx.exec_command("git stash") - ctx.exec_command("git checkout gh-pages") - ctx.exec_command("cp -Rf apidocs/html/* .") - ctx.exec_command("git add .") - ctx.exec_command("git commit -am 'generated docs'") - ctx.exec_command("git push origin gh-pages") - ctx.exec_command("git checkout master") - -class _run_test(Context): - cmd = 'run-test' - fun = 'run_test' - -def run_test(ctx): - import shutil, tempfile, sys - - failed = False - - test_path = 'build/test/libgit2_test' - if sys.platform == 'win32': - test_path += '.exe' - - test_folder = tempfile.mkdtemp() - test = ctx.path.find_node(test_path) - - if not test or ctx.exec_command(test.abspath(), cwd=test_folder) != 0: - failed = True - - shutil.rmtree(test_folder) - - if failed: - ctx.fatal('Test run failed') - - -CONTEXTS = { - 'build' : BuildContext, - 'clean' : CleanContext, - 'install' : InstallContext, - 'uninstall' : UninstallContext -} - -def build_command(command): - ctx, var = command.split('-') - class _gen_command(CONTEXTS[ctx]): - cmd = command - variant = var - -build_command('build-static') -build_command('build-shared') -build_command('build-test') - -build_command('clean-static') -build_command('clean-shared') -build_command('clean-test') - -build_command('install-static') -build_command('install-shared') - -build_command('uninstall-static') -build_command('uninstall-shared') - diff --git a/vendor/libv8-convert/cvv8/ClassCreator.hpp b/vendor/libv8-convert/cvv8/ClassCreator.hpp new file mode 100644 index 000000000..4a8b6d7d9 --- /dev/null +++ b/vendor/libv8-convert/cvv8/ClassCreator.hpp @@ -0,0 +1,1286 @@ +#if !defined(CODE_GOOGLE_COM_P_V8_CONVERT_CLASS_CREATOR_HPP_INCLUDED) +#define CODE_GOOGLE_COM_P_V8_CONVERT_CLASS_CREATOR_HPP_INCLUDED 1 +/** LICENSE + + This software's source code, including accompanying documentation and + demonstration applications, are licensed under the following + conditions... + + The author (Stephan G. Beal [http://wanderinghorse.net/home/stephan/]) + explicitly disclaims copyright in all jurisdictions which recognize + such a disclaimer. In such jurisdictions, this software is released + into the Public Domain. + + In jurisdictions which do not recognize Public Domain property + (e.g. Germany as of 2011), this software is Copyright (c) 2011 + by Stephan G. Beal, and is released under the terms of the MIT License + (see below). + + In jurisdictions which recognize Public Domain property, the user of + this software may choose to accept it either as 1) Public Domain, 2) + under the conditions of the MIT License (see below), or 3) under the + terms of dual Public Domain/MIT License conditions described here, as + they choose. + + The MIT License is about as close to Public Domain as a license can + get, and is described in clear, concise terms at: + + http://en.wikipedia.org/wiki/MIT_License + + The full text of the MIT License follows: + + -- + Copyright (c) 2011 Stephan G. Beal (http://wanderinghorse.net/home/stephan/) + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following + conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. + + --END OF MIT LICENSE-- + + For purposes of the above license, the term "Software" includes + documentation and demonstration source code which accompanies + this software. ("Accompanies" = is contained in the Software's + primary public source code repository.) + +*/ + +#include +#include +#include "convert.hpp" +//#include // only for debuggering +#include "NativeToJSMap.hpp" +namespace cvv8 { + + /** + Policy template used by ClassCreator for + instantiating T objects. + */ + template + class ClassCreator_Factory + { + public: + typedef T * ReturnType; + /** + Must instantiate a new T object based on the given + arguments. On error it should throw an exception (which the + binding framework will convert to a JS-side exception). It + may also return NULL on error, but the error message + probably won't be as clear for the user. + + Ownership of the object is passed to the caller (the + binding API internals), and eventually given to v8. + + jsSelf will be the newly-created JS-side 'this' object. It + is not normally required by this function but it is + sometimes useful when we need to bind supplementary + properties in the ctor, especially when binding a "pure + C++" class which has no native place to store such + properties. + + At the time this is called, jsSelf is not connected to the + native (because it hasn't yet been created). + Implementations must not perform the actual binding of the + returned native to jsSelf - ClassCreator will do that + immediately after Create() returns the new object. + + The default implementation simply return (new T). + */ + static ReturnType Create( v8::Persistent & jsSelf, v8::Arguments const & argv ) + { + return new T; + } + + /** + Must destroy obj using a mechanism complementary to its + construction via a prior call to Create(). + + The default implementation simply calls (delete obj). + */ + static void Delete( T * obj ) + { + delete obj; + } + }; + + /** + Base class for static ClassCreator options. + */ + template + struct Opt_ConstVal + { + typedef ValT Type; + const static Type Value = Val; + }; + + /** + Base class for static integer ClassCreator options. + */ + template + struct Opt_Int : Opt_ConstVal + {}; + + /** + Base class for static boolean ClassCreator options. + */ + template + struct Opt_Bool : Opt_ConstVal + {}; + + /** + A ClassCreator policy/option class responsible specifying whether + or not a ClassCreator-bound class should allow "Foo()" and "new + Foo()" to behave the same or not. If the Value member is false + (the default) then "Foo()" is not allowed to behave as a + constructor call (it will generate an error), otherwise it will + be treated exactly as if "new Foo()" had been called. + */ + template + struct ClassCreator_AllowCtorWithoutNew : Opt_Bool + {}; + + /** + ClassCreator policy which determines whether lookups for native + types in JS objects should walk through the prototype + chain. This can decrease the speed of JS-to-this operations and + is necessary only if bound types will be subclassed (either from + other bound native types or from JS classes). + + The default value is true for the sake of usability. If JS-side + subclassing will never be used, you can potentially optimize out a + few lookup operations by creating the specialization by subclassing + Opt_Bool. + */ + template + struct ClassCreator_SearchPrototypeForThis : Opt_Bool + {}; + + /** + ClassCreator policy type which defines a "type ID" value + for a type wrapped using ClassCreator. This is used + together with JSToNative_ObjectWithInternalFieldsTypeSafe + (type THAT 10 times fast) to provide a lightweight + (but highly effective) type check when extracting + natives from v8 (as void pointers). The default + implementation is fine for all cases i can think of, but i can + concieve of one or two uses for specializations (e.g. storing the + JS-side name of the class as the type ID). + + The type id must be unique per type except that subtypes may + (depending on various other binding options) may need use the same + value as the parent type. If multiple types share the same type ID, + the type-safety check can be bypassed, _potentially_ leading to an + illegal static_cast() and subsequent mis-use of the pointer. i + stress the word "potentially" because to get that condition one + would have to (A) abuse the object via the C++ API (which doesn't + happen via the binding process, and you're probably also not going + to do it) or (B) write some script code to confuse two bound native + types about who is really who when a particular member is called. + + In the case of subclassed bound types, the + ClassCreator_TypeID impl should subclass + ClassCreator_TypeID. Whether or not this is _required_ + for proper functionality depends at least in part on whether + (ClassCreator_InternalFields::TypeIDIndex>=0). If it is + negative, subclasses do not need to explicitly define this policy + because the type ID won't be used for purposes of validating a JS-held + pointer's native type. + + TODO: see if we can consolidate this type with TypeName<>. The problem + at the moment is that JSToNative_ObjectWithInternalFieldsTypeSafe + takes a (void const * &) and TypeName::Value is a (char const *), which + won't convert to (void const *) in the context of template parameters. + */ + template + struct ClassCreator_TypeID + { + const static void * Value; + }; + template + const void * ClassCreator_TypeID::Value = TypeName::Value; + + /** + Convenience base type for ClassCreator_InternalFields + implementations. + + See the member documentation for the meaning of + HowMany and Index. + + If any of the following conditions are met then + a compile-time assertion is triggered: + + - (ObjectIndex<0) + + - (ObjectIndex>=HowMany) + + - (TypeIndex>=HowMany). + + - (TypeIndex == ObjectIndex) + + TypeIndex may be negative, which indicates to ClassCreator that the + binding should not store type ID information. However, if it is + negative then T must not be used together with + JSToNative_ObjectWithInternalFieldsTypeSafe - doing so will trigger + a compile-time assertion. + */ + template + struct ClassCreator_InternalFields_Base + { + /** + Total number of internal fields assigned to JS-side T + objects. + */ + static const int Count = HowMany; + + /** + The internal field index at which ClassCreator policies should + expect the native object to be found in any given JS object. + It must be 0 or greater, and must be less than Value. + */ + static const int NativeIndex = ObjectIndex; + + /** + The internal field index at which ClassCreator policies + should expect a type identifier tag to be stored. + This can be used in conjunction with + JSToNative_ObjectWithInternalFieldsTypeSafe (or similar) + to provide an extra level of type safety at JS runtime. + + */ + static const int TypeIDIndex = TypeIndex; + private: + typedef char AssertFields[ + (HowMany > TypeIndex) + && (HowMany > ObjectIndex) + && (TypeIndex != ObjectIndex) + && (ObjectIndex >= 0) + ? 1 : -1]; + }; + + /** + The ClassCreator policy which sets the number of internal + fields reserved for JS objects and the internal field index + (0-based) at which the native object is stored . The Count + value must be greater than 0 and greater than the NativeIndex + member. Failing to meet these prerequisites will cause a + compile-time assertion to be triggered. + + ACHTUNG SUBCLASSERS: + + When using a heirarchy of native types, more than one of which + is compatible with CastFromJS(), conversions from subtype to + base type will fail unless all subtypes use the same internal + field placement as the parent type. If this code can detect a + mismatch then it will fail gracefully (e.g. a JS-side + exception), and if not then it might mis-cast an object and + cause Undefined Behaviour. + + If a given parent type uses a custom ClassCreator_InternalFields + specialization then to ensure that subclasses always have the + same placement, they "should" define their own policy like + this: + + @code + template <> + struct ClassCreator_InternalFields< SubType > + : ClassCreator_InternalFields< ParentType > + {}; + @endcode + + That prohibits special internal field handling in the subtypes, + but experience hasn't shown that subclasses need their own + internal fields. Normaly a single internal field is all we need + when binding native data. And when i say "normally", i mean + "almost always." + + This must-match requirement is partially a side-effect of the library + internally using the field count as a santiy check before trying to + extract data from internal fields. It also exists so that the + optional (but recommended) type-safety-check support (added in late + June 2011: see JSToNative_ObjectWithInternalFieldsTypeSafe) will + treat the subclasses as instances of the base class. + */ + template + struct ClassCreator_InternalFields : ClassCreator_InternalFields_Base + { + }; + + + /** + This policy is used by ClassCreator::SetupBindings() as the generic + interface for plugging in a bound class. Clients are not required to + specialise this, but see this class' Initialize() for what might + happen if they don't. + */ + template + struct ClassCreator_SetupBindings + { + /** + Specializations should perform any class/function-related binding + here, adding their functionality to the given object (which is + normally the logical global object but need not be). (Note that the + handle refererence is const but that object itself can be modified. + + The default implementation throws an exception deriving from + std::exception, so it must be specialized to be useful. A default + specialization exists because there are probably a few cases + out there which don't really need this. But most (if not all) + need a setup function, and this is the official one for + ClassCreator-wrapped types. Implementations may of course simply + forward the call to another, client-provided function. + + On error the binding should throw a NATIVE exception (ideally + deriving from std::exception because (A) it's portable practice + and (B) parts of the cvv8 API handles those explicitly). + + Several years of experience have shown that this function (or + similar implementations) should take some care to make sure + not to set up their bindings twice. We can do that by using the + following pattern: + + @code + typedef ClassCreator CC; + CC & cc( CC::Instance() ); + if( cc.IsSealed() ) { + cc.AddClassTo( "T", dest ); + return; + } + + // ... do your bindings here... + + // As the final step: + cc.AddClassTo( "T", dest ); + return; + @endcode + + If you do not actually want to add the class to the dest object, + you should call Seal() instead of AddClassTo() (or pass a different + destination object to AddClassTo(). + */ + static void Initialize( v8::Handle const & target ) + { + throw std::runtime_error("ClassCreator_SetupBindings MUST be specialized " + "in order to be useful!"); + } + }; + + /** + A concrete ClassCreator_SetupBindings implementation which forwards + the call to a user-defined function. + */ + template const &) > + struct ClassCreator_SetupBindings_ClientFunc + { + /** + Calls Func(target). + */ + static void Initialize( v8::Handle const & target ) + { + Func(target); + } + }; + + /** + The ClassCreator policy class responsible for doing optional + class-specific binding-related work as part of the JS/Native + object construction process. + + The default specialization does nothing (which is okay for the + general case) but defines the interface which specializations + must implement. + + Reminder to self: we could arguably benefit by splitting this policy + into 3 classes, but experience has shown that the metadata used by + the 3 functions are typically shared amongst the 3 implementations + (or 2 of them in most cases). + */ + template + struct ClassCreator_WeakWrap + { + typedef typename TypeInfo::NativeHandle NativeHandle; + + /** + Similar to Wrap(), but this is called before the native constructor is called. + It is rarely needed, but is necessary if one needs to manipulate the JS + "this" object before the native object is constructed, so that the native ctor + can access information stored in the JS-side internal fields. + + If this throws a native exception, construction of the + object will fail and Unwrap() is called, passed + (jsSelf,NULL), to clean up any data which this function might have + stored in jsSelf. + + The argv object is the arguments passed to the constructor. + + The default implementation does nothing. + */ + static void PreWrap( v8::Persistent const &, v8::Arguments const & ) + { + return; + } + + + /** + This operation is called one time from ClassCreator for each + new object, directly after the native has been connected to + a Persistent handle. + + Note that the ClassCreator code which calls this has already + taken care of connecting nativeSelf to jsSelf. Client + specializations of this policy may opt to add their own + binding mechanisms, e.g. to allow CastToJS() to work. + + Clients should do any bindings-related cleanup in + Factory::Destruct() or Unwrap(), as appropriate for their + case. + + Ownership of the objects is unchanged by calling this. + + On error, this function may throw a native exception. If + that happens, ClassCreator will call + Unwrap(jsSelf,nativeHandle) and + Factory::Destruct(nativeSelf) to clean up, and will then + propagate the exception. + + The default implementation does nothing. + */ + static void Wrap( v8::Persistent const &, NativeHandle ) + { + return; + } + + /** + This is called from the ClassCreator-generated destructor, + just before the native destructor is called. If nativeSelf + is NULL then it means that native construction failed, + but implementations must (if necessary) clean up any data + stored in jsSelf by the PreWrap() function. + + Specializations may use this to clean up data stored in + other internal fields of the object (_not_ the field used + to hold the native itself - that is removed by the + framework). Optionally, such cleanup may be done in the + corresponding Factory::Destruct() routine, and must be done + there if the dtor will need access to such data. + + Note that when this is called, jsSelf and nativeSelf are + about to be destroyed, so do not do anything crazy with the + contents of jsSelf and DO NOT destroy nativeSelf (that is + the job of the ClassCreator_Factory policy). + + Ownership of the objects is unchanged by calling this. + + Unwrap() is called during destruction or when construction + fails (via a native exception), so any cleanup required for + the jsSelf object can be delegated to this function, as + opposed to being performed (and possibly duplicated) in + PreWrap() and/or Wrap(). + + The default implementation does nothing. + */ + static void Unwrap( v8::Handle const &, NativeHandle ) + { + return; + } + }; + + +#if 0 + namespace Detail + { + template + struct SharedType : public Context + { + private: + SharedType(){} + public: + static SharedType & Instance() + { + static SharedType bob; + return bob; + } + }; + } +#endif + /** + A basic Native-to-JS class binding mechanism. This class does + not aim to be a monster framework, just something simple, + mainly for purposes of showing (and testing) what the core + cvv8 can do. + + The framework must know how to convert JS objects to T objects, + and for this to work client code must define a JSToNative + specialization in this manner: + + @code + template <> + struct JSToNative + : JSToNative_ClassCreator + {}; + @endcode + + If the internal field configuration must be customized then the + client must define the number of fields by + specializing/customizing the ClassCreator_InternalFields + policy class. Additionally, if the client does NOT use the + above JSToNative implementation then he should create his + implementation by subclassing + JSToNative_ObjectWithInternalFields, where (N,M) are the + number of internals fields and the index of the field where the + native object is to be stored. See JSToNative_ClassCreator + for an example. + + TODOs: + + - Certain operations may not work properly when inheriting + bound classes from JS space, and possibly not even when + inheriting bound natives from one another. That depends on + several factors too complex to summarize here. + + - See how much of the v8::juice::cw::ClassWrap + inheritance-related code we can salvage for re-use here. + + - There are known problems when trying to bind inherited methods + when the parent class has no bound them to JS. i'm not sure how + i can fix the templates to get this working. + */ + template + class ClassCreator + { + private: + typedef ClassCreator_InternalFields InternalFields; + typedef ClassCreator_WeakWrap WeakWrap; + typedef ClassCreator_TypeID TypeID; + v8::Persistent ctorTmpl; + v8::Handle protoTmpl; + bool isSealed; + typedef ClassCreator_Factory Factory; + + + /** + A utility function primarily intended to support various + ClassCreator policy implementations. + + This function tries to extract a native handle from jo by + looking in the internal field defined by + ClassCreator_InternalFields::NativeIndex. If a native is + found in that field and it is the same as nh, then jo is + returned. If none is found, jo's prototype object is searched, + recursively, until either nh is found in the prototype chain or + the end of the chain is reached. If a match is found, the JS + object in which the native was found is returned. This does no + casting - it only compares by address. + + If nh is not found anywhere in the chain, an empty handle is + returned. + + Note that T must be non-cv qualified, so it is generally + undesirable to allow the compiler to deduce its type from the + parameter. Thus the T template parameter should not be omitted + from calls to this function. + */ + static v8::Handle FindHolder( v8::Handle const & jo, + T const * nh ) + { + if( !nh || jo.IsEmpty() ) return v8::Handle(); + v8::Handle proto(jo); + void const * ext = NULL; + typedef ClassCreator_SearchPrototypeForThis SPFT; + while( !ext && !proto.IsEmpty() && proto->IsObject() ) + { + v8::Local const & obj( v8::Object::Cast( *proto ) ); + ext = (obj->InternalFieldCount() != InternalFields::Count) + ? NULL + : obj->GetPointerFromInternalField( InternalFields::NativeIndex ); + // FIXME: if InternalFields::TypeIDIndex>=0 then also do a check on that one. + /* + If !ext, there is no bound pointer. If (ext && + (ext!=nh)) then there is one, but it's not the droid + we're looking for. In either case, (possibly) check the + prototype... + */ + if( ext == nh ) return obj; + else if( !SPFT::Value ) break; + else proto = obj->GetPrototype(); + } + return v8::Handle(); + } + + static void weak_dtor( v8::Persistent< v8::Value > pv, void *nobj ) + { + using namespace v8; + //std::cerr << "Entering weak_dtor<>(native="<<(void const *)nobj<<")\n"; + Local jobj( Object::Cast(*pv) ); + typedef typename JSToNative::ResultType NT; + NT native = CastFromJS( pv ); + if( !native ) + { + /* see: http://code.google.com/p/v8-juice/issues/detail?id=27 + + When i call pv.Dispose(), this function is getting called twice, + and the second time won't work. i'm going to igore (return w/o + side-effects) this for now for the sake of avoiding a crash + which i'm seeing only on 64-bit platforms. + + However, even if i return here, v8 is crashing with a + !NEAR_DEATH assertion right after the second call is made. + + The extra pair of Dispose()/Clear() calls seems to eliminate that + crash, but the fact that this code block is hit AT ALL is a + sign of a problem - the dtor shouldn't be called twice! + */ + pv.Dispose(); + pv.Clear(); +#if 1 /* i believe this problem was fixed. If you are reading this b/c + you followed an assert() message, please report this as a bug. + */ + assert( 0 && "weak_dtor() got no native object!"); +#endif + return; + } + else + { + /** + Reminder: the FindHolder() bits are here to + assist when the bound native exists somewhere in the + prototype chain other than jobj itself. In that case, + jobj is valid but we cannot clear out the native handle + internal field on it because it has no internal fields + (or none that belong to us). + + To fix this properly we have to be able to know + _exactly_ which JS object in the prototype chain nh is + bound to. + */ + v8::Handle nholder = FindHolder( jobj, native ); +#if 1 /* reminder: i've never actually seen this error happen, i'm just pedantic about checking... */ + assert( ! nholder.IsEmpty() ); + WeakWrap::Unwrap( nholder /*jobj? subtle difference!*/, native ); + if( nholder.IsEmpty() || (nholder->InternalFieldCount() != InternalFields::Count) ) + { + StringBuffer msg; + msg << "SERIOUS INTERNAL ERROR:\n" + << "ClassCreator::weak_dtor() " + << "validated that the JS/Native belong together, but " + << "FindHolder() returned an " + << (nholder.IsEmpty() ? "empty" : "invalid") + << " handle!\n" + << "From JS=@"<<(void const *)nobj + << ", Converted to Native=@"<<(void const *)native + << ", nholder field count="<InternalFieldCount() + << ", jobj field count="<InternalFieldCount() + << "\nTHIS MAY LEAD TO A CRASH IF THIS JS HANDLE IS USED AGAIN!!!\n" + ; + Factory::Delete(native); + pv.Dispose(); pv.Clear(); /* see comments below!*/ + v8::ThrowException(msg.toError()); + return; + } + else + { + nholder->SetInternalField( InternalFields::NativeIndex, Null() ); + if( 0 <= InternalFields::TypeIDIndex ) + { + nholder->SetInternalField( InternalFields::TypeIDIndex, Null() ); + } + Factory::Delete(native); + } +#else + WeakWrap::Unwrap( nholder, native ); + nholder->SetInternalField( InternalFields::NativeIndex, Null() ); + if( 0 <= InternalFields::TypeIDIndex ) + { + nholder->SetInternalField( InternalFields::TypeIDIndex, Null() ); + } + Factory::Delete(native); +#endif + } + /* + According to the v8 gurus i need to call pv.Dispose() + instead of pv.Clear(), but if i do then this dtor is + being called twice. If i don't call it, v8 is crashing + sometime after this function with a !NEAR_DEATH + assertion. + */ + pv.Dispose(); + pv.Clear(); + } + + /** + Gets installed as the NewInstance() handler for T. + */ + static v8::Handle ctor_proxy( v8::Arguments const & argv ) + { + using namespace v8; + if(ClassCreator_AllowCtorWithoutNew::Value) + { + /** + Allow construction without 'new' by forcing this + function to be called in a ctor context... + */ + if (!argv.IsConstructCall()) + { + const int argc = argv.Length(); + Handle ctor( Function::Cast(*argv.Callee())); + std::vector< Handle > av(static_cast(argc),Undefined()); + for( int i = 0; i < argc; ++i ) av[i] = argv[i]; + return ctor->NewInstance( argc, &av[0] ); + } + } + else + { + /** + Why have this limitation? If we don't, v8 pukes + when the ctor is called, with + "v8::Object::SetInternalField() Writing internal + field out of bounds". + */ + if (!argv.IsConstructCall()) + { + return Toss("This constructor cannot be called as function!"); + } + } + Local const & jobj( argv.This() + /*CastToJS(*nobj) + + We are not yet far enough + along in the binding that + CastToJS() can work. And it + can't work for the generic + case, anyway. + */); + if( jobj.IsEmpty() ) return jobj /* assume exception*/; + Persistent self( Persistent::New(jobj) ); + T * nobj = NULL; + try + { + WeakWrap::PreWrap( self, argv ); + nobj = Factory::Create( self, argv ); + if( ! nobj ) + { + return CastToJS(std::runtime_error("Native constructor failed.")); + } + WeakWrap::Wrap( self, nobj ); + self.MakeWeak( nobj, weak_dtor ); + if( 0 <= InternalFields::TypeIDIndex ) + { + self->SetPointerInInternalField( InternalFields::TypeIDIndex, (void *)TypeID::Value ); + } + self->SetPointerInInternalField( InternalFields::NativeIndex, nobj ) + /* We do this after the call to Wrap() just in case the Wrap() impl + accidentally writes to this field. In that case we end up + losing the data they stored there. So this is just as evil as + adding the internal field before Wrap(), but only when the + client mis-uses the internal fields. + */ + ; + } + catch(std::exception const &ex) + { + WeakWrap::Unwrap( self, nobj ); + if( nobj ) Factory::Delete( nobj ); + self.Clear(); + return Toss(CastToJS(ex)); + } + catch(...) + { + WeakWrap::Unwrap( self, nobj ); + if( nobj ) Factory::Delete( nobj ); + self.Clear(); + return Toss("Native constructor threw an unknown exception!"); + } + return self; + } + + ClassCreator() + : ctorTmpl(v8::Persistent::New( v8::FunctionTemplate::New(ctor_proxy) )), + protoTmpl(v8::Persistent::New( ctorTmpl->PrototypeTemplate() )), + isSealed(false) + { + ctorTmpl->InstanceTemplate()->SetInternalFieldCount(InternalFields::Count); + } + public: + /** + The native type being bound to JS. + */ + typedef typename tmp::PlainType::Type Type; + + /** + Returns the shared instance of this class. + */ + static ClassCreator & Instance() + { + static ClassCreator bob; + return bob; + } + + /** + Returns this class' prototype object. + */ + inline v8::Handle Prototype() + { + return this->protoTmpl; + } + + /** + Returns this class' constructor template object. + */ + inline v8::Handle CtorTemplate() + { + return this->ctorTmpl; + } + + /** + Returns this class' constructor template. + + ACHTUNG: after this is called, changes made to the Prototype() + object might not have any effect. Thus this should only be + called after the prototype object has been fully set up. + (i have no idea why v8 behaves this way.) + + After calling this, IsSealed() will return true. + */ + inline v8::Handle CtorFunction() + { + // In my experience, if GetFunction() is called BEFORE setting up + // the Prototype object, v8 gets very unhappy (class member lookups don't work?). + this->isSealed = true; + return this->ctorTmpl->GetFunction(); + } + + /** + Returns true if CtorFunction() has been called. See that + function for why. + */ + inline bool IsSealed() const + { + return this->isSealed; + } + + /** + Creates a new instanced of the object via the JS API. It calls + ClassCreator_Factory::Create(), passing it argv, to + instantiate the object. On success a JS handle to the object is + returned (it is owned by v8), and the caller can get the native + pointer with: + + @code + T * t = CastFromJS(theHandle); + @endcode + */ + inline v8::Handle NewInstance( int argc, v8::Handle argv[] ) + { + return this->CtorFunction()->NewInstance(argc, argv); + } + + /** + A convenience form of NewInstance() which returns the JS version + of the object and assigns tgt to the native pointer (which will + be NULL on error). + + If tgt is NULL when this function returns, or + returnedObj.IsEmpty(), then we assume that a v8 exception is + propagating, and the caller should return to v8 as soon as + possible so the exception can be triggered JS-side (it is not + actually triggered until we return to v8). + + The returned object is owned by v8. + */ + v8::Handle NewInstance( int argc, v8::Handle argv[], T * & tgt ) + { + v8::Handle const & obj( this->CtorFunction()->NewInstance(argc, argv) ); + if( obj.IsEmpty() ) return obj /* assume exception is propagating. */; + else + { + tgt = CastFromJS(obj); + if( !tgt ) { + Toss(StringBuffer()<<"Internal error: NewInstance() returned a non-empty " + << "Handle but CastFromJS<"<::Value<<">() failed. " + << "This is either a serious cvv8 bug or the JSToNative specialization " + << "is not working properly."); + return v8::Handle(); + } + else return obj; + } + } + + /** + Convenience method to add the given property to the + prototype. Returns this object, for call chaining. + + CastToJS(val) must be valid or a compile-time + error will be triggered. + */ + template + inline ClassCreator & Set( char const * name, ValueT val ) + { + this->protoTmpl->Set(v8::String::New(name), CastToJS(val)); + return *this; + } + //! Not quite sure why i need this overload, but i do. + inline ClassCreator & Set( char const * name, v8::InvocationCallback val ) + { + this->protoTmpl->Set(v8::String::New(name), CastToJS(val)); + return *this; + } + /** + Equivalent to Set(). + */ + template + inline ClassCreator & operator()( char const * name, ValueT val ) + { + return this->Set(name, val); + } + /** + Overload to avoid an ambiguity. + */ + inline ClassCreator & operator()( char const * name, v8::InvocationCallback val ) + { + return this->Set(name, val); + } + + /** + Adds CtorFunction() to dest using the given property name. + This implicitly "seals" the class (see CtorFunction() for + details). + */ + inline void AddClassTo( char const * thisClassName, v8::Handle const & dest ) + { + dest->Set(v8::String::New(thisClassName), + this->CtorFunction()); + } + + /** + Destroys the given object by disconnecting its associated + native object and calling the native destructor function + for it. + + If jo cannot be converted to a T then false is + returned. Otherwise the true is returned and the native + object referenced by jo is no longer valid (it should not + be used by JS code). + + Native functions bound to that object should take care to + bail out with an exception once the native pointer is gone, + as opposed to blindly stepping on its null/dangling pointer + (which _might_ have been re-allocated to a different + object, even of a different type, in the mean time). + */ + static bool DestroyObject( v8::Handle const & jo ) + { + T * t = CastFromJS(jo); + if( ! t ) return false; + else + { + v8::Persistent p( v8::Persistent::New( jo ) ); + p.ClearWeak(); // avoid a second call to weak_dtor() via gc! + weak_dtor( p, t ); + return true; + } + } + /** + If jv is empty or !jv->IsObject() then false is returned, + otherwise it returns the result of + DestroyObject(Handle). + */ + static bool DestroyObject( v8::Handle const & jv ) + { + return (jv.IsEmpty() || !jv->IsObject()) + ? false + : DestroyObject( v8::Handle( v8::Object::Cast(*jv) ) ); + } + + /** + A v8::InvocationCallback implementation which calls + DestroyObject( argv.This() ). + + It is intended to be used as a "manual destructor" for + classes which need it. The canonical examples are + Stream.close() and Database.close(). + + This function is not called DestroyObject to avoid name + collisions during binding using Set(...,DestroyObjectCallback). + */ + static v8::Handle DestroyObjectCallback( v8::Arguments const & argv ) + { + return DestroyObject(argv.This()) ? v8::True() : v8::False(); + } + + /** + Tells v8 that this bound type inherits ParentType. + ParentType _must_ be a class wrapped by ClassCreator. + This function throws if + ClassCreator::Instance().IsSealed() returns + false). We require that the parent class be sealed to + avoid accidental mis-use caused by registering a + subclass of a class which has not yet been bound (and may + may never be bound). + */ + template + void Inherit() + { + typedef ClassCreator PT; + PT & p(PT::Instance()); + if( ! p.IsSealed() ) + { + throw std::runtime_error("ClassCreator has not been sealed yet!"); + } + this->CtorTemplate()->Inherit( p.CtorTemplate() ); + } + + /** + Simply runs ClassCreator_SetupBindings::Initialize( target ). + It is provided here to simplify the client-side interface. + */ + static void SetupBindings( v8::Handle const & target ) + { + ClassCreator_SetupBindings::Initialize( target ); + } + + }; + + /** + Intended to be the base class for JSToNative specializations + when T is JS-bound using ClassCreator. + + This particular implementation must be defined _after_ + any of the following policies are customized for T: + + - ClassCreator_InternalFields + - ClassCreator_SearchPrototypeForThis + - ClassCreator_TypeID (only if TypeSafe is true!) + + If the client will not specialize those types type then the order is + irrelevant, but when specializing any of them, they must come before + this JSToNative implementation is instantiated. + + If TypeSafe is true then this type is a proxy for + JSToNative_ObjectWithInternalFieldsTypeSafe, else it is a proxy for + JSToNative_ObjectWithInternalFields. Note that ClassCreator is + hard-wired to implant/deplant type id information if + ClassCreator_InternalFields::TypeIDIndex is not negative, with the + _hope_ that JSToNative will use it, but it does not enforce that + the type ID is used. For types where the internal fields' TypeIDIndex + is negative, ClassCreator will not set up bits for the type check, + which means a slightly smaller runtime memory footprint. + */ + template ::TypeIDIndex >= 0 > + struct JSToNative_ClassCreator : + tmp::IfElse< TypeSafe, + JSToNative_ObjectWithInternalFieldsTypeSafe::Value, + ClassCreator_InternalFields::Count, + ClassCreator_InternalFields::TypeIDIndex, + ClassCreator_InternalFields::NativeIndex, + ClassCreator_SearchPrototypeForThis::Value + >, + JSToNative_ObjectWithInternalFields::Count, + ClassCreator_InternalFields::NativeIndex, + ClassCreator_SearchPrototypeForThis::Value + > + >::Type + { + }; + +#if 0 + //! Experimental. + template + struct JSToNative_ClassCreator_Subclass + { + typedef typename TypeInfo::NativeHandle ResultType; + ResultType operator()( v8::Handle const & h ) const + { + typedef typename TypeInfo::NativeHandle PTP; + PTP typeCheck; typeCheck = (ResultType)NULL + /* If compiler errors led you here then SubT probably does not + publicly subclass ParentT. */ + ; + PTP p = CastFromJS(h); + //std::cerr << "dyncast="<(p)<<"\n"; + return p ? dynamic_cast(p) : NULL; + } + }; +#endif + +#if !defined(DOXYGEN) + namespace Detail + { + /** + A base class for ClassCreator_Factory_CtorArityDispatcher. + We don't really need this level of indirection, i think. + */ + template + struct Factory_CtorForwarder_Base + { + typedef typename TypeInfo::Type Type; + typedef typename TypeInfo::NativeHandle NativeHandle; + static void Delete( NativeHandle nself ) + { + delete nself; + } + protected: + /** + If argv.Length() >= Arity then this function ignores errmsg and + returns true, otherwise it writes a descriptive error message + to errmsg and return false. + */ + static bool argv_check( v8::Arguments const & argv, int Arity ) + { + if( argv.Length() >= Arity ) return true; + else + { + StringBuffer msg; + msg << "constructor requires " << Arity << " arguments!"; + throw std::range_error(msg.Content().c_str()); + return false; + } + } + }; + } +#endif // !DOXYGEN + + /** + Can be used as a concrete ClassCreator_Factor + specialization to forward JS ctor calls directly to native + ctors. + + T must be the ClassCreator'd type to construct. CtorProxy must + be a type having this interface: + + @code + TypeInfo::NativeHandle Call( v8::Arguments const & ); + @endcode + + Normally CtorProxy would be CtorForwarder or CtorArityDispatcher, + but any interface-compatible type will do. + + It must return a new object instance on success. On error it + may return NULL and "should" throw a native exception explaining + the problem. The exception will be caught by ClassCreator and + transformed into a JS-side exception. + + If CtorProxy::Call() succeeds (returns non-NULL and does not throw) + then NativeToJSMap is used to create a native-to-JS mapping. + To make use of this, the client should do the following: + + @code + // in the cvv8 namespace: + template <> + struct NativeToJS : NativeToJSMap::NativeToJSImpl {}; + @endcode + + After that, CastToJS( theNativeObject ) can work. + + The mapping is cleaned up when (if!) the object is sent through + the JS garbage collector or the client somehow triggers its + JS-aware destruction (e.g. via ClassCreator::DestroyObject(), + assuming the type was wrapped using ClassCreator). + */ + template + struct ClassCreator_Factory_NativeToJSMap : Detail::Factory_CtorForwarder_Base + { + public: + typedef NativeToJSMap N2JMap; + typedef typename TypeInfo::Type Type; + typedef typename TypeInfo::NativeHandle NativeHandle; + + /** + If CtorProxy::Call(argv) succeeds, N2JMap::Insert(jself, theNative) + is called. The result of CtorProxy::Call() is returned. + */ + static NativeHandle Create( v8::Persistent jself, v8::Arguments const & argv ) + { + NativeHandle n = CtorProxy::Call( argv ); + if( n ) N2JMap::Insert( jself, n ); + return n; + } + /** + Calls N2JMap::Remove( nself ) then (delete nself). + */ + static void Delete( NativeHandle nself ) + { + N2JMap::Remove( nself ); + delete nself; + } + }; + + /** @deprecated Use ClassCreator_Factory_Dispatcher instead (same interface). + */ + template + struct ClassCreator_Factory_CtorArityDispatcher : Detail::Factory_CtorForwarder_Base + { + public: + typedef typename TypeInfo::Type Type; + typedef typename TypeInfo::NativeHandle NativeHandle; + static NativeHandle Create( v8::Persistent , v8::Arguments const & argv ) + { + typedef CtorArityDispatcher Proxy; + return Proxy::Call( argv ); + } + }; + + /** + A ClassCreator_Factory implementation which forwards its Create() + member to CtorT::Call() (the interface used by CtorForwarder and friends). + + T must (or is assumed to) be a ClassCreator-wrapped class. + CtorForwarderList must be a Signature typelist of CtorForwarder + types and its "return type" must be T (optionally pointer-qualified). + + Example: + + @code + typedef CtorForwarder C0; + typedef CtorForwarder C1; + typedef CtorForwarder C2; + typedef Signature< CFT (C0, C1, C2) > CtorList; + + // Then create Factory specialization based on those: + template <> + struct ClassCreator_Factory : + ClassCreator_Factory_Dispatcher > {}; + @endcode + + Or: + + @code + template <> + struct ClassCreator_Factory : + ClassCreator_Factory_Dispatcher< MyType, CtorForwarder > + {}; + @endcode + */ + template + struct ClassCreator_Factory_Dispatcher : Detail::Factory_CtorForwarder_Base + { + public: + typedef typename TypeInfo::Type Type; + typedef typename TypeInfo::NativeHandle NativeHandle; + static NativeHandle Create( v8::Persistent jself, v8::Arguments const & argv ) + { + return CtorT::Call( argv ); + } + }; + + +}// namespaces + +#endif /* CODE_GOOGLE_COM_P_V8_CONVERT_CLASS_CREATOR_HPP_INCLUDED */ diff --git a/vendor/libv8-convert/cvv8/Makefile b/vendor/libv8-convert/cvv8/Makefile new file mode 100644 index 000000000..552c1ebd4 --- /dev/null +++ b/vendor/libv8-convert/cvv8/Makefile @@ -0,0 +1,8 @@ +all: + +EXAMPLE_DIR := ../../examples +ifneq (,$(wildcard $(EXAMPLE_DIR)/Makefile)) +$(sort all $(MAKECMDGOALS)): + $(MAKE) -C ../../examples $@ +endif + diff --git a/vendor/libv8-convert/cvv8/NativeToJSMap.hpp b/vendor/libv8-convert/cvv8/NativeToJSMap.hpp new file mode 100644 index 000000000..1e09da7bd --- /dev/null +++ b/vendor/libv8-convert/cvv8/NativeToJSMap.hpp @@ -0,0 +1,183 @@ +#if ! defined(V8_CONVERT_NATIVE_JS_MAPPER_HPP_INCLUDED) +#define V8_CONVERT_NATIVE_JS_MAPPER_HPP_INCLUDED + +#include "detail/convert_core.hpp" +namespace cvv8 { + /** + A helper class to assist in the "two-way-binding" of + natives to JS objects. This class holds native-to-JS + binding information. + + In the general case, a native-to-JS conversion is only + needed at the framework-level if bound/converted + functions/methods will _return_ bound native + pointers/references. If they only return "core" types (numbers + and strings, basically), or explicitly return v8-supported + types (e.g. v8::Handle) then no native-to-JS + conversion is typically needed. + + Known limitations: + + This type does not fully support subclass conversions. + e.g. the following function binding: + + @code + virtual MyType * (MyType::*)(); + @endcode + + _should_ be able to return a MySubType from derived implementations + but it currently cannot. Handling this requires that a parent class + be told each of its subclasses, and that we add internal handlers + which try lookups on those classes if a conversion to MyType fails. + + Reminder to self: the v8::juice tree has an example of that which we + can probably plunder. + */ + template + struct NativeToJSMap + { + private: + typedef TypeInfo TI; + typedef typename TI::Type Type; + /** + The native type to bind to. + */ + typedef typename TI::NativeHandle NativeHandle; + /** The type for holding the JS 'this' object. */ + typedef v8::Persistent JSObjHandle; + //typedef v8::Handle JSObjHandle; // Hmmm. + typedef std::pair ObjBindT; + typedef std::map OneOfUsT; + /** Maps (void const *) to ObjBindT. + + Reminder to self: we might need to make this map a static + non-function member to work around linking problems (at + least on Windows) which lead to multiple instances of + the returned map being created when the types being + bound are loaded from multiple DLLs. The out-of-class + initialization of the member is going to require a really + ugly set of template parameters, though. + */ + static OneOfUsT & Map() + { + static OneOfUsT bob; + return bob; + } + public: + /** Maps obj as a lookup key for jself. Returns false if !obj, + else true. */ + static bool Insert( JSObjHandle const & jself, + NativeHandle obj ) + { + return obj + ? (Map().insert( std::make_pair( obj, std::make_pair( obj, jself ) ) ),true) + : 0; + } + + /** + Removes any mapping of the given key. Returns the + mapped native, or 0 if none is found. + */ + static NativeHandle Remove( void const * key ) + { + typedef typename OneOfUsT::iterator Iterator; + OneOfUsT & map( Map() ); + Iterator it = map.find( key ); + if( map.end() == it ) + { + return 0; + } + else + { + NativeHandle victim = (*it).second.first; + map.erase(it); + return victim; + } + } + + /** + Returns the native associated (via Insert()) + with key, or 0 if none is found. + */ + static NativeHandle GetNative( void const * key ) + { + if( ! key ) return 0; + else + { + typename OneOfUsT::iterator it = Map().find(key); + return (Map().end() == it) + ? 0 + : (*it).second.first; + } + } + + /** + Returns the JS object associated with key, or + an empty handle if !key or no object is found. + */ + static v8::Handle GetJSObject( void const * key ) + { + if( ! key ) return v8::Handle(); + typename OneOfUsT::const_iterator it = Map().find(key); + if( Map().end() == it ) return v8::Handle(); + else return (*it).second.second; + } + + /** + A base NativeToJS implementation for classes which use NativeToJSMap + to hold their native-to-JS bindings. To be used like this: + + @code + // must be in the v8::convert namespace! + template <> + struct NativeToJS : NativeToJSMap::NativeToJSImpl {}; + @endcode + */ + struct NativeToJSImpl + { + v8::Handle operator()( Type const * n ) const + { + typedef NativeToJSMap BM; + v8::Handle const & rc( BM::GetJSObject(n) ); + if( rc.IsEmpty() ) return v8::Null(); + else return rc; + } + v8::Handle operator()( Type const & n ) const + { + return this->operator()( &n ); + } + }; + +#if 0 + //! Experimental + template + struct NativeToJSImpl_Subclass + { + v8::Handle operator()( Type const * n ) const + { + typedef NativeToJSMap BM; + v8::Handle const & rc( BM::GetJSObject(n) ); + if( rc.IsEmpty() ) + { + typedef typename NativeToJSMap::NativeToJSImpl PI; + return PI()(n); +#if 0 + typedef typename TypeInfo::NativeHandle PH; + rc = CastToJS(n); + if( rc.IsEmpty() ) return v8::Null(); + else return rc; +#endif + } + else return rc; + } + v8::Handle operator()( Type const & n ) const + { + return this->operator()( &n ); + } + }; +#endif + }; + +} // namespaces + +#endif /* include guard */ diff --git a/vendor/libv8-convert/cvv8/V8Shell.hpp b/vendor/libv8-convert/cvv8/V8Shell.hpp new file mode 100644 index 000000000..ecfb9aa3a --- /dev/null +++ b/vendor/libv8-convert/cvv8/V8Shell.hpp @@ -0,0 +1,650 @@ +#if !defined(V8_CONVERT_V8Shell_HPP_INCLUDED) +#define V8_CONVERT_V8Shell_HPP_INCLUDED +/** @file V8Shell.hpp + + This file contains the v8::convert::V8Shell class, a convenience + wrapper for bootstrapping integration of v8 into arbitrary + client applications. + + Dependencies: v8 and the STL. + + License: released into the Public Domain by its author, + Stephan Beal (http://wanderinghorse.net/home/stephan/). +*/ +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +namespace cvv8 { + namespace Detail { + template + struct V8MaybeLocker + { + private: + v8::Locker lock; + public: + V8MaybeLocker() : lock() {} + }; + template <> + struct V8MaybeLocker + { + }; + } + /** + This class implements a very basic shell for v8. + + + These objects are basically thin wrappers around the + bootstrap code necessary for getting v8 running in an + application. They are intended to be stack-created in main() + (or equivalent) and used as a front-end for passing JS code + into v8 for execution. + + Because library-level JS code activated via this class + _might_ use v8::Unlocker to unlock the VM while C-level + routines are running, each instance of this class includes a + v8::Locker instance if UseLocker is true. (If it did not, + clients would be required to add one or accept crashes when + called code uses v8::Unlocker.) Only set UseLocker to false + if you _know_ that _no_ JS code run through this API will + end up trying to unlock v8. (If you're using this class + together with the v8::convert function binding API then you + are almost certainly using v8::Unlocker without realizing it.) + + Maintenance reminder: keep this class free of dependencies + on other library-level code so that we can re-use it + in arbitrary v8 clients. + + FIXME: the way this class uses v8::TryCatch is "all wrong", and any + functions using it need to be revisited. + */ + template + class V8Shell + { + public: + /** + A callback function signature for reporing JS-side + exception messages to the native world. + + TODO: consider passing a v8::Handle argument + instead of a (char const *) and possibly a (void *) State + handle for use by the client. + */ + typedef void (*ErrorMessageReporter)( char const * msg ); + private: + // The declaration order of the v8-related objects is important! + Detail::V8MaybeLocker locker; + v8::HandleScope hscope; + //v8::Handle globt; + v8::Handle context; + v8::Context::Scope cxscope; + v8::Handle global; + /** + tryCatch is only here until i can track down a post-main() + v8 assertion which happens when V8Shell-executed JS code + exits with an exception. It is just a workaround. + */ + v8::TryCatch tryCatch; + ErrorMessageReporter reporter; + static void DefaultErrorMessageReporter( char const * msg ) + { + if( msg && *msg ) std::cerr + //<< "[V8Shell default exception reporter says:]\n" + << msg << std::endl; + } + + /** + An v8::InvocationCallback implementation which implements a + JS-conventional print() routine. OS must be a pointer to + an ostream, e.g. std::cout or std::cerr. + + Each argument is converted to a string (using + v8::String::Utf8Value) and is output, separated by a + space. For compatibility with other toolkits' print() + implementations (some of which only accept one + argument), it is recommended that client script code + only rely on the first argument being output. + + Always returns v8::Undefined(). + + It is a little-known fact that one can replace the output + buffer used by std::cout (and other std::ostreams) with a + custom one, such that calling print() from JS code will + redirect the output to a different destination. This can + be used, e.g., to redirect std::cout to a libcurses window. + */ + template + static v8::Handle PrintToStdOstream( v8::Arguments const & argv ) + { + v8::HandleScope hscope; + int const argc = argv.Length(); + const char * cstr = NULL; + for (int i = 0; i < argc; i++) + { + if( 0 != i ) *OS << ' '; + v8::String::Utf8Value const str(argv[i]); + cstr = *str; + if( cstr ) *OS << cstr; + } + *OS << '\n'; + OS->flush(); + return v8::Undefined(); + } + + void init( char const * globalObjectName, + int argc, char const * const * argv, + unsigned short argOffset ) + { + if( globalObjectName && *globalObjectName ) + { + this->global->Set( v8::String::New(globalObjectName), this->global ); + } + if( (0 < argc) && (NULL != argv) ) + { + this->ProcessMainArgv( argc, argv, argOffset ); + } + } + + static void SetupTryCatch( v8::TryCatch & tc ) + { + tc.SetVerbose(true); + tc.SetCaptureMessage(true); + } + public: + /** + Initialize a v8 context and global object belonging to this object. + + If globalObjectName is not null and not empty then the global object + is given a refernce to itself using the given name, such that client + JS code can then refer to it. + + If argc is greater than 0 and argv is not NULL then argv is + assumed to be an arguments list in the format conventional + for main() and ProcessMainArgv(argc,argv,argOffset) is called. + */ + V8Shell( char const * globalObjectName = NULL, + int argc = 0, char const * const * argv = NULL, + unsigned short argOffset = 1 ) : + locker(), + hscope(), + //globt( v8::ObjectTemplate::New() ), + context( v8::Context::New(NULL, v8::ObjectTemplate::New()) ), + cxscope(context), + global( context->Global() ), + reporter( DefaultErrorMessageReporter ) + { + this->init( globalObjectName, argc, argv, argOffset ); + } + + /** + Destructs all v8 resources used by this object, e.g. the JS context. + */ + ~V8Shell() + { + if( ! v8::V8::IsDead() ) { + tryCatch.Reset(); + } + } + + /** + Sets the error reporter function used by + ExecuteString(). Passing 0 will disable exception + reporting. The default reporter sends its output to + std::cerr. + */ + void SetExecuteErrorReporter( ErrorMessageReporter r ) + { + this->reporter = r; + } + + /** + Outputs an exception message using the current + error reporter function. + + If try_catch or the current error reporter are + null then nothing is done. + + @see SetExecuteErrorReporter(). + */ + + void ReportException(v8::TryCatch* try_catch) + { + if( !try_catch || ! this->reporter ) return; + v8::HandleScope hsc; + v8::String::Utf8Value const excUtf(try_catch->Exception()); +#define TOCSTR(X) (*X ? *X : "") + const char* excCstr = TOCSTR(excUtf); + v8::Handle const & message( try_catch->Message() ); + std::ostringstream os; + os << "V8Shell Exception Reporter: "; + if (message.IsEmpty()) + { + // V8 didn't provide any extra information about this error; just + // print the exception. + os << excCstr << '\n'; + } + else + { + // output (filename):(line number): (message)... + int linenum = message->GetLineNumber(); + os << *v8::String::Utf8Value(message->GetScriptResourceName()) << ':' + << std::dec << linenum << ": " + << excCstr << '\n'; + // output source code line... + os << *v8::String::AsciiValue(message->GetSourceLine()) << '\n'; + // output decoration pointing to error location... + int start = message->GetStartColumn(); + for (int i = 0; i < start; i++) { + os << '-'; + } + int end = message->GetEndColumn(); + for (int i = start; i < end; i++) { + os << '^'; + } + os << '\n'; + } + std::string const & str( os.str() ); + this->reporter( str.c_str() ); +#undef TOCSTR + } + + /** + Adds the given function to the global object. + + Returns this object. + */ + V8Shell & operator()( char const * name, v8::Handle const & f ) + { + this->global->Set( v8::String::New(name), f ); + return *this; + } + + /** + Adds the given function to the global object. + + Returns this object. + */ + V8Shell & operator()( char const * name, v8::Handle const & f ) + { + return this->operator()( name, f->GetFunction() ); + } + + /** + Adds the given function to the global object. + + Returns this object. + */ + V8Shell & operator()( char const * name, v8::InvocationCallback const f ) + { + return this->operator()( name, v8::FunctionTemplate::New(f) ); + } + + /** + Returns the global object for this shell. + */ + v8::Handle Global() + { + return this->global; + } + + /** + Returns the context object for this shell. + */ + v8::Handle Context() + { + return this->context; + } + +#if 0 // changes made to global ObjectTemplate have no effect after cx is set up. + v8::Handle GlobalTemplate() + { + return this->globt; + } +#endif + + /** + Intended to be called from main() and passed the argc/argv + which are passed to main. offset is the number of arguments + to skip, and defaults to one to skip the argv[0] argument, + which is conventionally the application name. + + It skips all arguments up to "--". For each argument after + "--", it adds the argument to a list. At the end of the + list, the global object is assigned a property named + "arguments" which contains that list. + + If the argument list has no arguments after a "--" entry + then the "arguments" global value will be an empty array, + as opposed to null or undefined. + + This function does no interpretation of the arguments. + */ + V8Shell & ProcessMainArgv( int argc, char const * const * _argv, unsigned short offset = 1 ) + { + if( (argc<1) || !_argv ) return *this; + char const * endofargs = "--"; + v8::Handle argv( v8::Array::New() ); + int i = (int)offset; + for( ; i < argc; ++i ) + { + if( 0 == strcmp(_argv[i],endofargs) ) + { + ++i; + break; + } + } + int ndx = 0; + for( ; i < argc; ++i ) + { + char const * arg = _argv[i]; + if( arg ) + { // String::New() calls strlen(), which hates NULL + argv->Set( ndx++, v8::String::New(arg) ); + } + } + this->global->Set( v8::String::New("arguments"), argv ); + return *this; + } + + /** + Executes the given source string in the current + context. + + If the script throws an exception then a TryCatch object is used + to build an error string, which is passed to this object's error + reporter function. The default sends the output to std::cerr. + + If resultGoesTo is not null and the result a valid handle, then + the result is converted to a string and sent to that stream. + + Returns the result of the last expression evaluated in the script, + or an empty handle on error. + */ + v8::Handle ExecuteString(v8::Handle const & source, + v8::Handle name, + std::ostream * out = NULL ) + { + //this->executeThrew = false; + v8::HandleScope scope; + v8::TryCatch tc; + SetupTryCatch(tc); + v8::Handle script = v8::Script::Compile(source, name); + if( script.IsEmpty())//tc.HasCaught()) + { + // Report errors that happened during compilation. + //this->executeThrew = true; + this->ReportException(&tc); + return scope.Close(tc.ReThrow()); + //return v8::Handle(); + } + else + { + v8::Handle const & result( script->Run() ); + if( tc.HasCaught())//(result.IsEmpty()) + { + //this->executeThrew = true; + this->ReportException(&tc); + //return v8::Handle(); + return scope.Close(tc.ReThrow()); + } + else + { + if (out && !result.IsEmpty()) + { + (*out) << *v8::String::Utf8Value(result) << '\n'; + } + return scope.Close(result); + } + } + } + +#if 0 + bool ExecThrewException() const + { + return this->executeThrew; + } +#endif + + /** + Convenience form of ExecuteString(source,"some default name", reportExceptions, 0). + */ + v8::Handle ExecuteString(std::string const & source, + std::string const & name, + std::ostream * resultGoesTo ) + { + v8::HandleScope scope; + v8::Local const & s( v8::String::New( source.c_str(), static_cast(source.size()) ) ); + v8::Local const & n( v8::String::New( name.c_str(), static_cast(name.size()) ) ); + return scope.Close(this->ExecuteString( s, n, resultGoesTo )); + } + + /** + Convenience overload taking input from a native string. + */ + v8::Handle ExecuteString(std::string const & source ) + { + return this->ExecuteString(source, "ExecuteString()", 0); + } + + /** + Convenience form of ExecuteString(source,"some default name", 0, reportExceptions). + */ + v8::Handle ExecuteString(v8::Handle source ) + { + return this->ExecuteString(source, v8::String::New("ExecuteString()"), 0); + } + + /** + Convenience form of ExecuteString() reading from an opened input stream. + + Throws a std::exception if reading fails or the input is empty. + + An empty input is not necessarily an error. Todo: re-think this decision. + */ + v8::Handle ExecuteStream( std::istream & is, std::string const & name, + std::ostream * resultGoesTo = NULL ) + { + std::ostringstream os; + is >> std::noskipws; + std::copy( std::istream_iterator(is), std::istream_iterator(), std::ostream_iterator(os) ); + std::string const & str( os.str() ); + if( str.empty() ) + { + std::ostringstream msg; + msg << "Input stream ["<ExecuteString( str, name, resultGoesTo ); + } + + /** + Convenience form of ExecuteString() reading from a local file. + */ + v8::Handle ExecuteFile( char const * filename, + std::ostream * resultGoesTo = NULL ) + { + if( ! filename || !*filename ) + { + throw std::runtime_error("filename argument must not be NULL/empty."); + } + std::ifstream inf(filename); + if( ! inf.good() ) + { + // FIXME: throw a v8 exception and report it via our reporter. + // Nevermind: the result is useless b/c the exception has no proper vm stack/state info here... + std::ostringstream msg; + msg << "Could not open file ["<ExecuteStream( inf, filename, resultGoesTo ); + } + + /** + An v8::InvocationCallback implementation which implements + a JS-conventional print() routine, sending its output to + std::cout. See PrintToStdOstream() for the exact semantics + argument/return. + */ + static v8::Handle PrintToCout( v8::Arguments const & argv ) + { + return PrintToStdOstream<&std::cout>( argv ); + } + + /** + Identical to PrintToCout(), but sends its output to + std::cerr instead. + */ + static v8::Handle PrintToCerr( v8::Arguments const & argv ) + { + return PrintToStdOstream<&std::cerr>( argv ); + } + + private: + static v8::Handle Include( v8::Arguments const & argv ) + { + int const argc = argv.Length(); + if( argc < 1 ) return v8::Undefined(); + v8::HandleScope hsc; + v8::Local const jvself(argv.Data()); + if( jvself.IsEmpty() || !jvself->IsExternal() ) + { + return v8::ThrowException(v8::Exception::Error(v8::String::New("Include() callback is missing its native V8Shell object."))); + } + V8Shell * self = static_cast( v8::External::Cast(*jvself)->Value() ); + v8::String::Utf8Value fn(argv[0]); + try + { + return hsc.Close(self->ExecuteFile( *fn )); + } + catch( std::exception const & ex ) + { + char const * msg = ex.what(); + return v8::ThrowException(v8::Exception::Error(v8::String::New(msg ? msg : "Unspecified native exception."))); + } + } + + public: + /** + Returns a Function object implementing conventional + include(filename) functionality (called load() in some JS + shells). This function must be created dynamically + because the generated function internally refers back to + this object (so that we can re-use ExecuteString() for the + implementation). + + The return value of the Function is the value of the last + expression evaluated in the given JS code. + + Results are undefined, and almost certainly fatal, if + the generated function is ever called after this native + object has been destructed. For best results, to avoid + potential lifetime issues, never install the returned + function in any object other than this object's Global(). + */ + v8::Handle CreateIncludeFunction() + { + return v8::FunctionTemplate::New(Include, v8::External::New(this))->GetFunction(); + } + + /** + Implements the v8::InvocationCallback interface and has the + following JS interface: + + @code + Array getStracktrace([unsigned int limit = some reasonable default]) + @endcode + + Each element in the returned array represents a stack frame and + is a plain object with the following properties: + + column = 1-based column number (note that this is + different from most editors, but this is how v8 returns + this value). + + line = 1-based line number + + scriptName = name of the script + + functionName = name of the function + + isConstructor = true if this is a constructor call + + isEval = true if this is part of an eval() + + TODO: + + - Add a toString() member to the returned array which creates a + conventional-looking stacktrace string. + */ + static v8::Handle GetStackTrace( v8::Arguments const & argv ) + { + using namespace v8; + int32_t limitSigned = (argv.Length() > 0) ? argv[0]->Int32Value() : 0; + if( limitSigned <= 0 ) limitSigned = 8; + else if( limitSigned > 100 ) limitSigned = 100; + uint32_t limit = static_cast(limitSigned); + HandleScope hsc; + Local const st = StackTrace::CurrentStackTrace( limit, StackTrace::kDetailed ); + int const fcountI = st->GetFrameCount(); + // Who the hell designed the StackTrace API to return an int in GetFrameCount() but take + // an unsigned int in GetFrame()??? + uint32_t const fcount = static_cast(fcountI); + Local jst = Array::New(fcount); +#define STR(X) v8::String::New(X) + for( uint32_t i = 0; (i < fcount) && (i const & sf( st->GetFrame(i) ); + Local jsf = Object::New(); + jsf->Set(STR("column"), v8::Integer::New(sf->GetColumn())); + jsf->Set(STR("functionName"), sf->GetFunctionName()); + jsf->Set(STR("line"), v8::Integer::New(sf->GetLineNumber())); + jsf->Set(STR("scriptName"), sf->GetScriptName()); + jsf->Set(STR("isConstructor"), sf->IsConstructor() ? v8::True() : v8::False() ); + jsf->Set(STR("isEval"), sf->IsEval() ? v8::True() : v8::False() ); + jst->Set(i,jsf); + } + return hsc.Close(jst); +#undef STR + } + + /** + Can optionally be called to include the following functionality + in this shell's Global() object: + + JS Functions: + + print(...) (see PrintToCout()) + + getStacktrace([int limit]) (see GetStackTrace()) + + load(filename) (see CreateIncludeFunction()) + + Returns this object, for use in chaining. + */ + V8Shell & SetupDefaultBindings() + { + (*this)( "print", PrintToCout ) + ("getStacktrace", GetStackTrace) + ("load", this->CreateIncludeFunction()) + ; + return *this; + } + }; + + /** + Convenience typedef for V8Shell<>. + */ + typedef V8Shell<> Shell; + +} +#endif /* V8_CONVERT_V8Shell_HPP_INCLUDED */ diff --git a/vendor/libv8-convert/cvv8/XTo.hpp b/vendor/libv8-convert/cvv8/XTo.hpp new file mode 100644 index 000000000..f3502063e --- /dev/null +++ b/vendor/libv8-convert/cvv8/XTo.hpp @@ -0,0 +1,281 @@ +#if !defined (CVV8_TO_X_HPP_INCLUDED) +#define CVV8_TO_X_HPP_INCLUDED +#include "invocable.hpp" +#include "properties.hpp" +/** @file XTo.hpp + + This file provides an alternate approach to the function + conversion API. It covers: + + - Converting functions and methods to to v8::InvocationCallback, + v8::AccessorGetter, and v8::AccessorSetter. + + - Converting variables to v8::AccessorGetter and v8::AccessorSetter. + + All conversions of a given category, e.g. FunctionToXYZ or MethodToXYZ + have a common template, e.g. FunctionTo or MethodTo. The first type + passed to that template is a "tag" type which tells us what conversion + to perform. e.g. a function can be used as an v8::InvocationCallback, + v8::AccessorGetter, or v8::AccessorSetter. + + An example probably explains it best: + + @code + int aBoundInt = 3; + void test_to_bindings() + { + v8::InvocationCallback cb; + v8::AccessorGetter g; + v8::AccessorSetter s; + + using namespace cvv8; + + typedef FunctionTo< InCa, int(char const *), ::puts> FPuts; + typedef FunctionTo< Getter, int(void), ::getchar> GetChar; + typedef FunctionTo< Setter, int(int), ::putchar> SetChar; + cb = FPuts::Call; + g = GetChar::Get; + s = SetChar::Set; + + typedef VarTo< Getter, int, &aBoundInt > VarGet; + typedef VarTo< Setter, int, &aBoundInt > VarSet; + g = VarGet::Get; + s = VarSet::Set; + typedef VarTo< Accessors, int, &aBoundInt > VarGetSet; + g = VarGetSet::Get; + s = VarGetSet::Set; + + typedef BoundNative T; + typedef MethodTo< InCa, const T, int (), &T::getInt > MemInCa; + typedef MethodTo< Getter, const T, int (), &T::getInt > MemGet; + typedef MethodTo< Setter, T, void (int), &T::setInt > MemSet; + cb = MemInCa::Call; + g = MemGet::Get; + s = MemSet::Set; + } + @endcode + + This unconventional, but nonetheless interesting and arguably + very readable/writable approach was first proposed by Coen + Campman. +*/ + + +namespace cvv8 { + + /** + Base (unimplemented) FunctionTo interface. + + Specializations act as proxies for FunctionToInCa, + FunctionToGetter and FunctionToSetter. Tag must be one of + (InCa, InCaVoid, Getter, Setter). The other args are as + documented for the aforementioned proxied types. + + See FunctionToInCa for more information about the parameters. + */ + template ::FunctionType Func, + bool UnlockV8 = SignatureIsUnlockable< FunctionSignature >::Value > + struct FunctionTo DOXYGEN_FWD_DECL_KLUDGE; + + //! Behaves like FunctionToInCa. + template ::FunctionType Func, bool UnlockV8> + struct FunctionTo< InCa, Sig, Func, UnlockV8 > : FunctionToInCa + {}; + + //! Behaves like FunctionToInCaVoid. + template ::FunctionType Func, bool UnlockV8> + struct FunctionTo< InCaVoid, Sig, Func, UnlockV8 > : FunctionToInCaVoid + {}; + + //! Behaves like FunctionToGetter. + template ::FunctionType Func, bool UnlockV8> + struct FunctionTo< Getter, Sig, Func, UnlockV8 > : FunctionToGetter + {}; + + //! Behaves like FunctionToSetter. + template ::FunctionType Func, bool UnlockV8> + struct FunctionTo< Setter, Sig, Func, UnlockV8 > : FunctionToSetter + {}; + + /** @class VarTo + + Base (unimplemented) VarTo interface. + + Acts as a proxy for VarToGetter and VarToSetter. Tag must be + one of (Getter, Setter, Accessors). The other args are as + documented for VarToGetter and VarToSetter. + */ + template + struct VarTo DOXYGEN_FWD_DECL_KLUDGE; + + //! Behaves like VarToGetter. + template + struct VarTo< Getter, PropertyType,SharedVar> : VarToGetter + {}; + + //! Behaves like VarToSetter. + template + struct VarTo< Setter, PropertyType,SharedVar> : VarToSetter + {}; + + //! Behaves like VarToAccessors. + template + struct VarTo< Accessors, PropertyType,SharedVar> : VarToAccessors + {}; + + /** + Base (unimplemented) type for MemberTo-xxx conversions. + + Acts as a proxy for MemberToGetter, MemberToSetter and + MemberToAccessors. Tag must be one of (Getter, Setter, Accessors). + The other args are as documented for MemberToGetter and + MemberToSetter. + */ + template + struct MemberTo DOXYGEN_FWD_DECL_KLUDGE; + + //! Behaves like MemberToGetter. + template + struct MemberTo : MemberToGetter< T, PropertyType, MemVar > {}; + + //! Behaves like MemberToSetter. + template + struct MemberTo : MemberToSetter< T, PropertyType, MemVar > {}; + + //! Behaves like MemberToAccessors. + template + struct MemberTo : MemberToAccessors< T, PropertyType, MemVar > {}; + + /** + Base (unimplemented) MethodTo interface. + + Acts as a proxy for MethodToInCa, MethodToGetter and + MethodToSetter (or their const cousins if T is + const-qualified). Tag must be one of (InCa, InCaVoid, + Getter, Setter). The other args are as documented for the + aforementioned proxied types. + + See MethodToInCa for more information about the parameters. + */ + template ::FunctionType Func, + bool UnlockV8 = SignatureIsUnlockable< MethodSignature >::Value> + struct MethodTo DOXYGEN_FWD_DECL_KLUDGE; + + //! Behaves like MethodToInCa. For const methods, const-qualify T. + template ::FunctionType Func, bool UnlockV8> + struct MethodTo< InCa, T, Sig, Func, UnlockV8 > : MethodToInCa + {}; + + //! Behaves like MethodToInCaVoid. For const methods, const-qualify T. + template ::FunctionType Func, bool UnlockV8> + struct MethodTo< InCaVoid, T, Sig, Func, UnlockV8 > : MethodToInCaVoid + {}; + + //! Behaves like MethodToGetter. For const methods, const-qualify T. + template ::FunctionType Func, bool UnlockV8> + struct MethodTo< Getter, T, Sig, Func, UnlockV8 > : MethodToGetter + {}; + + //! Behaves like MethodToSetter. For const methods, const-qualify T. + template ::FunctionType Func, bool UnlockV8> + struct MethodTo< Setter, T, Sig, Func, UnlockV8 > : MethodToSetter + {}; + + /** + Base (unimplemented) FunctorTo interface. + + Behaves like one of the following, depending on the Tag type: + + FunctorToInCa (Tag=InCa), FunctorToInCaVoid (Tag=InCaVoid), + FunctorToGetter (Tag=Getter), FunctorToSetter (Tag=Setter) + + See FunctorToInCa for more information about the parameters. + */ + template >::Value + > + struct FunctorTo DOXYGEN_FWD_DECL_KLUDGE; + + //! Behaves like FunctorToInCa. + template + struct FunctorTo< InCa, FtorT, Sig, UnlockV8 > : FunctorToInCa + {}; + + //! Behaves like FunctorToInCaVoid. + template + struct FunctorTo< InCaVoid, FtorT, Sig, UnlockV8 > : FunctorToInCaVoid + {}; + + //! Behaves like FunctorToGetter. + template + struct FunctorTo< Getter, FtorT, Sig, UnlockV8 > : FunctorToGetter + {}; + + //! Behaves like FunctorToSetter. + template + struct FunctorTo< Setter, FtorT, Sig, UnlockV8 > : FunctorToSetter + {}; +} +/** LICENSE + + This software's source code, including accompanying documentation and + demonstration applications, are licensed under the following + conditions... + + The author (Stephan G. Beal [http://wanderinghorse.net/home/stephan/]) + explicitly disclaims copyright in all jurisdictions which recognize + such a disclaimer. In such jurisdictions, this software is released + into the Public Domain. + + In jurisdictions which do not recognize Public Domain property + (e.g. Germany as of 2011), this software is Copyright (c) 2011 + by Stephan G. Beal, and is released under the terms of the MIT License + (see below). + + In jurisdictions which recognize Public Domain property, the user of + this software may choose to accept it either as 1) Public Domain, 2) + under the conditions of the MIT License (see below), or 3) under the + terms of dual Public Domain/MIT License conditions described here, as + they choose. + + The MIT License is about as close to Public Domain as a license can + get, and is described in clear, concise terms at: + + http://en.wikipedia.org/wiki/MIT_License + + The full text of the MIT License follows: + + -- + Copyright (c) 2011 Stephan G. Beal (http://wanderinghorse.net/home/stephan/) + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following + conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. + + --END OF MIT LICENSE-- + + For purposes of the above license, the term "Software" includes + documentation and demonstration source code which accompanies + this software. ("Accompanies" = is contained in the Software's + primary public source code repository.) + +*/ + +#endif /* CVV8_TO_X_HPP_INCLUDED */ diff --git a/vendor/libv8-convert/cvv8/arguments.hpp b/vendor/libv8-convert/cvv8/arguments.hpp new file mode 100644 index 000000000..307db2cae --- /dev/null +++ b/vendor/libv8-convert/cvv8/arguments.hpp @@ -0,0 +1,817 @@ +#if !defined(V8_CONVERT_ARGUMENTS_HPP_INCLUDED) +#define V8_CONVERT_ARGUMENTS_HPP_INCLUDED +#include "convert.hpp" +#include + +namespace cvv8 { + + /** + A functor which fetches an argument by index. + + I = the argument index to fetch. + + The class is intended mainly to be invoked via code paths + selected by template metaprograms, thus the hard-coding of + the argument parameter index at compile-time. + */ + template + struct ArgAt + { + typedef char AssertIndex[ (I>=0) ? 1 : -1]; + /** + Returns argv[I] if argv.Length() is <= I, else v8::Undefined() + is returned. + */ + inline v8::Handle operator()( v8::Arguments const & argv ) const + { + return (argv.Length() > I) ? argv[I] : v8::Undefined(); + } + }; + + /** + Functor to fetch an argument and return its result + as a native value. + + I = the argument index to fetch. + + T = the native type to convert to. CastFromJS() must be legal. + */ + template + struct ArgAtCast + { + typedef JSToNative J2N; + typedef typename J2N::ReturnType ReturnType; + typedef char AssertIndex[ (I>=0) ? 1 : -1]; + /** + Returns CastFromJS( ArtAt(argv) ). + */ + inline ReturnType operator()( v8::Arguments const & argv ) const + { + typedef ArgAt Proxy; + return CastFromJS( Proxy()(argv) ); + } + }; + + /** + Marker class, for documentation purposes. + */ + struct ValuePredicate + { + /** + Must evaluate the handle and return true or false. + The framework cannot guaranty that h.IsEmpty() is false, + so implementations should be in the habit of checking it. + */ + bool operator()( v8::Handle const & h ) const; + }; + + /** + A functor interface for determining if a JS value + "is-a" value of a particular native type. The default + implementation is useable for any type for which the + following is legal: + + @code + T const * t = CastFromJS( aV8Handle ); + @endcode + + Specializations are used for most data types, but this + one is fine for client-bound types conformant with + CastFromJS(). + + Note that the default specializations treat T as a plain type, + discarding const/pointer/reference qualifiers. Certain types may + require that ValIs (and similar) be specialized in order + to behave properly. + */ + template + struct ValIs : ValuePredicate + { + typedef T Type; + /** + Returns true if v appears to contain a (T*). + */ + inline bool operator()( v8::Handle const & v ) const + { + return NULL != CastFromJS(v); + } + }; + + //! Specialization to treat (T const) as T. + template struct ValIs : ValIs {}; + //! Specialization to treat (T const &) as T. + template struct ValIs : ValIs {}; + //! Specialization to treat (T *) as T. + template struct ValIs : ValIs {}; + //! Specialization to treat (T const *) as T. + template struct ValIs : ValIs {}; + + /** + Specialization which treats void as the v8::Undefined() value. + */ + template <> + struct ValIs + { + typedef void Type; + /** + Returns true only if h is not empty and h->IsUndefined(). Note + that an empty handle evaluates to false in this context because + Undefined is a legal value whereas an empty handle is not. + (Though Undefined might not be _semantically_ legal in any given + use case, it is legal to dereference such a handle.) + */ + inline bool operator()( v8::Handle const & h ) const + { + return h.IsEmpty() ? false : h->IsUndefined(); + } + }; + +#if !defined(DOXYGEN) + namespace Detail { + /** + ValuePredicate impl which returns retrue if + Getter returns true for the given value. + + Getter must be a pointer to one of the v8::Value::IsXXX() + functions. This functor returns true if the passed-in handle is + not empty and its IsXXX() function returns true. + */ + template + struct ValIs_X : ValuePredicate + { + inline bool operator()( v8::Handle const & v ) const + { + return v.IsEmpty() ? false : ((*v)->*Getter)(); + } + }; + + /** + A ValuePredicate impl which returns true only if + the given handle is-a number and the number is in the + inclusive range (std::numeric_limits::min .. + max()). + */ + template + struct ValIs_NumberStrictRange : ValuePredicate + { + typedef NumT Type; + inline bool operator()( v8::Handle const & h ) const + { + if( h.IsEmpty() || ! h->IsNumber() ) return false; + else + { + double const dv( h->NumberValue() ); + return (dv >= std::numeric_limits::min()) + && (dv <= std::numeric_limits::max()); + } + } + }; + /** Special-case specialization which returns true if the given + handle is-a Number (without checking the range, which is + not necessary for this specific type in this context). + */ + template <> + struct ValIs_NumberStrictRange : ValuePredicate + { + typedef double Type; + inline bool operator()( v8::Handle const & h ) const + { + return !h.IsEmpty() && h->IsNumber(); + } + }; + } +#endif // DOXYGEN + + /** A Value predicate which returns true if its argument is-a Array. */ + struct ValIs_Array : Detail::ValIs_X<&v8::Value::IsArray> {}; + /** A Value predicate which returns true if its argument is-a Object. */ + struct ValIs_Object : Detail::ValIs_X<&v8::Value::IsObject> {}; + /** A Value predicate which returns true if its argument is-a Boolean. */ + struct ValIs_Boolean : Detail::ValIs_X<&v8::Value::IsBoolean> {}; + /** A Value predicate which returns true if its argument is-a Date. */ + struct ValIs_Date : Detail::ValIs_X<&v8::Value::IsDate> {}; + /** A Value predicate which returns true if its argument is-a External. */ + struct ValIs_External : Detail::ValIs_X<&v8::Value::IsExternal> {}; + /** A Value predicate which returns true if its argument has a false value. */ + struct ValIs_False : Detail::ValIs_X<&v8::Value::IsFalse> {}; + /** A Value predicate which returns true if its argument is-a Function. */ + struct ValIs_Function : Detail::ValIs_X<&v8::Value::IsFunction> {}; + /** A Value predicate which returns true if its argument is-a In32. */ + struct ValIs_Int32 : Detail::ValIs_X<&v8::Value::IsInt32> {}; + /** A Value predicate which returns true if its argument is-a UInt32. */ + struct ValIs_UInt32 : Detail::ValIs_X<&v8::Value::IsUint32 /* Note the "UInt" vs "Uint" descrepancy. i consider Uint to be wrong.*/ > {}; + /** A Value predicate which returns true if its argument is Null (JS null, not C++ NULL). */ + struct ValIs_Null : Detail::ValIs_X<&v8::Value::IsNull> {}; + /** A Value predicate which returns true if its argument has the special Undefined value. */ + struct ValIs_Undefined : Detail::ValIs_X<&v8::Value::IsUndefined> {}; + /** A Value predicate which returns true if its argument is-a Number. */ + struct ValIs_Number : Detail::ValIs_X<&v8::Value::IsNumber> {}; + /** A Value predicate which returns true if its argument is-a RegExp. */ + struct ValIs_RegExp : Detail::ValIs_X<&v8::Value::IsRegExp> {}; + /** A Value predicate which returns true if its argument is-a String. */ + struct ValIs_String : Detail::ValIs_X<&v8::Value::IsString> {}; + /** A Value predicate which returns true if its argument has a true value. */ + struct ValIs_True : Detail::ValIs_X<&v8::Value::IsTrue> {}; + + // FIXME: reverse the parent relationships between e.g. ValIs and ValIs_Array. + /** A Value predicate which returns true if its argument is a number capable + of fitting in an int8_t. */ + template <> struct ValIs : Detail::ValIs_NumberStrictRange {}; + /** A Value predicate which returns true if its argument is a number capable + of fitting in an uint8_t. */ + template <> struct ValIs : Detail::ValIs_NumberStrictRange {}; + /** A Value predicate which returns true if its argument is a number capable + of fitting in an int16_t. */ + template <> struct ValIs : Detail::ValIs_NumberStrictRange {}; + /** A Value predicate which returns true if its argument is a number capable + of fitting in an uint16_t. */ + template <> struct ValIs : Detail::ValIs_NumberStrictRange {}; + /** A Value predicate which returns true if its argument is a number capable + of fitting in an int32_t. */ + template <> struct ValIs : Detail::ValIs_NumberStrictRange {}; + /** A Value predicate which returns true if its argument is a number capable + of fitting in an uint32_t. */ + template <> struct ValIs : Detail::ValIs_NumberStrictRange {}; + /** A Value predicate which returns true if its argument is a number capable + of fitting in an int64_t. */ + template <> struct ValIs : Detail::ValIs_NumberStrictRange {}; + /** A Value predicate which returns true if its argument is a number capable + of fitting in an uint64_t. */ + template <> struct ValIs : Detail::ValIs_NumberStrictRange {}; + /** A Value predicate which returns true if its argument is-a Number value. */ + template <> struct ValIs : ValIs_Number {}; + //! Special-case specialization to treat C strings as JS strings. + template <> struct ValIs : ValIs_String {}; + //! Special-case specialization to treat v8 strings as JS strings. + template <> struct ValIs : ValIs_String {}; + //! A Value predicate which returns true if its argument is-a Array. */ + template <> struct ValIs : ValIs_Array {}; + //! A Value predicate which returns true if its argument is-a Object. */ + template <> struct ValIs : ValIs_Object {}; + //! A Value predicate which returns true if its argument is-a Boolean. */ + template <> struct ValIs : ValIs_Boolean {}; + //! A Value predicate which returns true if its argument is-a Date. */ + template <> struct ValIs : ValIs_Date {}; + //! A Value predicate which returns true if its argument is-a External. */ + template <> struct ValIs : ValIs_External {}; + //! A Value predicate which returns true if its argument is-a Function. */ + template <> struct ValIs : ValIs_Function {}; + //! A Value predicate which returns true if its argument is-a Int32. */ + template <> struct ValIs : ValIs_Int32 {}; + //! A Value predicate which returns true if its argument is-a UInt32. */ + template <> struct ValIs : ValIs_UInt32 {}; + //! A Value predicate which returns true if its argument is-a Number. */ + template <> struct ValIs : ValIs_Number {}; + //! A Value predicate which returns true if its argument is-a RegExp. */ + template <> struct ValIs : ValIs_RegExp {}; + //! A Value predicate which returns true if its argument is-a String. */ + template <> struct ValIs : ValIs_String {}; + //! Specialization to treat Handle as T. */ + template struct ValIs< v8::Handle > : ValIs< T > {}; + //! Specialization to treat Local as T. */ + template struct ValIs< v8::Local > : ValIs< T > {}; + //! Specialization to treat Persistent as T. */ + template struct ValIs< v8::Persistent > : ValIs< T > {}; + + /** + Marker class, mainly for documentation purposes. + + Classes matching this concept "evaluate" a v8::Arguments + object for validity without actually performing any + "application logic." These are intended to be used as + functors, primarily triggered via code paths selected by + template metaprograms. + + They must be default-construcable and should have no + private state. Their public API consists of only operator(). + + This Concept's operator() is intended only to be used for + decision-making purposes ("are there enough arguments?" or + "are the arguments of the proper types?"), and not + higher-level application logic. + */ + struct ArgumentsPredicate + { + /** + Must "evaluate" the arguments and return true or false. + */ + bool operator()( v8::Arguments const & ) const; + }; + + /** + Functor to evaluate whether an Arguments list + has a certain range of argument count. + + Min is the minimum number. Max is the maximum. The range is + inclusive. Use (Max + struct Argv_Length : ArgumentsPredicate + { + private: + typedef char AssertMinIsPositive[ (Min_>=0) ? 1 : -1 ]; + enum { Min = Min_, Max = Max_ }; + public: + /** + Returns true if av meets the argument count + requirements defined by the Min and Max + values. + */ + bool operator()( v8::Arguments const & av ) const + { + + int const argc = av.Length(); + return (Max < Min) + ? argc >= Min + : (argc>=Min) && (argc<=Max); + } + }; + + /** + Arguments predicate functor. + + Index = arg index to check. + + ValIsType must match the ValuePredicate interface. + */ + template + struct ArgAt_Is : ArgumentsPredicate + { + /** + Returns true if ValType()( av[Index] ) is true. + */ + inline bool operator()( v8::Arguments const & av ) const + { + return (Index >= av.Length()) + ? false + : ValIsType()( av[Index] ); + } + }; + + /** + Arguments predicate functor. + + Index = arg index to check. + + T is a type for which ValIs is legal. The functor + returns true if ValIs returns true the argument + at the given index. + */ + template + struct ArgAt_IsA : ArgAt_Is< Index, ValIs > {}; + + namespace Detail { + /** + Functor which proxies the v8::Value "is-a" functions. + + Index is the argument index to check. Getter is the + member to be used to perform the is-a evaluation. + */ + template + struct ArgAt_IsX : ArgumentsPredicate + { + /** + Returns true only if (Index < av.Length()) + and av->Getter() returns true. + */ + inline bool operator()( v8::Arguments const & av ) const + { + return ( av.Length() <= Index ) + ? false + : ((*av[Index])->*Getter)(); + } + }; + } + + //! ArgumentsPredicate which returns true if the argument at Index is-a Array. */ + template + struct ArgAt_IsArray : Detail::ArgAt_IsX {}; + + //! ArgumentsPredicate which returns true if the argument at Index is-a Object. */ + template + struct ArgAt_IsObject : Detail::ArgAt_IsX {}; + + //! ArgumentsPredicate which returns true if the argument at Index is-a Boolean. */ + template + struct ArgAt_IsBoolean : Detail::ArgAt_IsX {}; + + //! ArgumentsPredicate which returns true if the argument at Index is-a Date. */ + template + struct ArgAt_IsDate : Detail::ArgAt_IsX {}; + + //! ArgumentsPredicate which returns true if the argument at Index is-a External. */ + template + struct ArgAt_IsExternal : Detail::ArgAt_IsX {}; + + //! ArgumentsPredicate which returns true if the argument at Index has a false value. */ + template + struct ArgAt_IsFalse : Detail::ArgAt_IsX {}; + + //! ArgumentsPredicate which returns true if the argument at Index is-a Function. */ + template + struct ArgAt_IsFunction : Detail::ArgAt_IsX {}; + + //! ArgumentsPredicate which returns true if the argument at Index is-a Int32Boolean. */ + template + struct ArgAt_IsInt32 : Detail::ArgAt_IsX {}; + + //! ArgumentsPredicate which returns true if the argument at Index is-a UInt32. */ + template + struct ArgAt_IsUInt32 : Detail::ArgAt_IsX {}; + + //! ArgumentsPredicate which returns true if the argument at Index has the special Null value. */ + template + struct ArgAt_IsNull : Detail::ArgAt_IsX {}; + + //! ArgumentsPredicate which returns true if the argument at Index has the special Undefined value. */ + template + struct ArgAt_IsUndefined : Detail::ArgAt_IsX {}; + + //! ArgumentsPredicate which returns true if the argument at Index is-a Number. */ + template + struct ArgAt_IsNumber : Detail::ArgAt_IsX {}; + + //! ArgumentsPredicate which returns true if the argument at Index is-a RegExp. */ + template + struct ArgAt_IsRegExp : Detail::ArgAt_IsX {}; + + //! ArgumentsPredicate which returns true if the argument at Index is-a String. */ + template + struct ArgAt_IsString : Detail::ArgAt_IsX {}; + + //! ArgumentsPredicate which returns true if the argument at Index has a True value. */ + template + struct ArgAt_IsTrue : Detail::ArgAt_IsX {}; + + + /** + ArgumentsPredicate functor which always returns true. + + This currently has only one obscure use: as the predicate given to a + PredicatedInCa in conjunction with an N-arity callback, used as a + catch-all fallback as the last item in a list of PredicatedInCas + passed to PredicatedInCaDispatcher. (Got that?) + */ + struct Argv_True : ArgumentsPredicate + { + inline bool operator()( v8::Arguments const & ) const + { + return true; + } + }; + /** ArgumentsPredicate which always returns false. + + This predicate has only one known, rather obscure use in combination + with type lists. + */ + struct Argv_False : ArgumentsPredicate + { + inline bool operator()( v8::Arguments const & ) const + { + return false; + } + }; + + /** + An ArgumentsPredicate implementation which takes + two ArgumentsPredicate functors as template parameters + and combines them using an AND operation. + + See Argv_AndN if you just want to combine more than two functors. + (Argv_AndN can also be used for two functors but is more verbose + than this form for that case.) + */ + template + struct Argv_And : ArgumentsPredicate + { + /** + Returns true only if ArgPred1()(args) and + ArgPred2()(args) both return true. + */ + inline bool operator()( v8::Arguments const & args ) const + { + return ArgPred1()( args ) && ArgPred2()( args ); + } + }; + + /** + The "or" equivalent of Argv_And. + + Use Argv_OrN for chaining more than two predicates. + */ + template + struct Argv_Or : ArgumentsPredicate + { + /** + Returns true only if one of ArgPred1()(args) or + ArgPred2()(args) return true. + */ + inline bool operator()( v8::Arguments const & args ) const + { + return ArgPred1()( args ) || ArgPred2()( args ); + } + }; + + /** + This ArgumentsPredicate implementation combines a list of + other ArgumentsPredicates using an AND operation on the combined + results of each functor. + + PredList must be a type-list containing ArgumentsPredicate types. + This functor is a predicate which performs an AND operation on all + of the predicates in the type list. + + Note that an empty typelist evaluates to True in this context, for + deeply arcane reasons. + + See Argv_And if you just want to combine two functors + (it is more succinct for that case). + + Example: + + @code + // Predicate matching (function, ANYTHING, function) signature: + typedef Argv_AndN< CVV8_TYPELIST(( + Argv_Length<3>, + ArgAt_IsFunction<0>, + ArgAt_IsFunction<2> + )) > PredFuncXFunc; + @endcode + */ + template + struct Argv_AndN : ArgumentsPredicate + { + /** + Returns true only if all predicates in PredList + return true when passed the args object. + */ + inline bool operator()( v8::Arguments const & args ) const + { + typedef typename PredList::Head Head; + typedef typename tmp::IfElse< tmp::SameType::Value, + Argv_True, + Head>::Type P1; + typedef typename PredList::Tail Tail; + typedef Argv_AndN P2; + return P1()( args ) && P2()(args); + } + }; + + //! End-of-list specialization. + template <> + struct Argv_AndN : Argv_True {}; + + /** + The "or" equivalent of Argv_AndN. + + When chaining only two predicates Argv_Or offers + a more succinct equivalent to this type. + + Note that an empty typelist evaluates to False in this context, for + deeply arcane reasons. + */ + template + struct Argv_OrN : ArgumentsPredicate + { + /** + Returns true only if one of the predicates in PredList + returns true when passed the args object. + */ + inline bool operator()( v8::Arguments const & args ) const + { + typedef typename PredList::Head P1; + typedef typename PredList::Tail Tail; + typedef Argv_OrN P2; + return P1()( args ) || P2()(args); + } + }; + + //! End-of-list specialization. + template <> + struct Argv_OrN : ArgumentsPredicate + { + /** + Always returns false. + */ + inline bool operator()( v8::Arguments const & ) const + { + return false; + } + }; + + /** + Intended as a base class for a couple other + PredicatedXyz types. + + This type combines ArgumentsPredicate ArgPred and + CallT::Call() into one type, for template-based dispatching + purposes. + + ArgPred must be-a ArgumentsPredicate. CallT must + be a type having a static Call() function taking one + (v8::Arguments const &) and returning any type. + + This type uses subclassing instead of composition + to avoid having to specify the CallT::Call() return + type as an additional template parameter. i don't seem to + be able to template-calculate it from here. We can't use + CallT::ReturnType because for most bindings that value + is different from its Call() return type. We will possibly + eventually run into a problem with the lack of a way + to get Call()'s return type. + + @see PredicatedInCaDispatcher + */ + template + struct PredicatedInCaLike : ArgPred, CallT {}; + + /** + PredicatedInCa combines an ArgumentsPredicate functor + (ArgPred) with an InCa type, such that we can create lists + of functor/callback pairs for use in dispatching callbacks + based on the results of ArgumentPredicates. + + InCaT must implement the InCa interface. + + This type is primarily intended to be used together with + PredicatedInCaDispatcher. + + @see PredicatedInCaLike + + Reminder to self: this class is only in arguments.hpp, as opposed to + invocable_core.hpp, because i want (for pedantic + documentation-related reasons) this class to inherit + ArgumentsPredicate, which invocable*.hpp does not know about. + We might want to move ArgumentsPredicate and + ValuePredicate into convert_core.hpp and move this class back + into invocable_core.hpp. + + @see PredicatedInCaDispatcher + */ + template + struct PredicatedInCa : PredicatedInCaLike {}; + + /** + This class creates an InvocationCallback which dispatches to one of an + arbitrarily large set of other InvocationCallbacks, as determined by + predicate rules. + + PredList must be a type-list (e.g. Signature) of PredicatedInCa + implementations. See Call() for more details. + + Basic example: + + @code + // Overloads for 1-3 arguments: + typedef PredicatedInCa< Argv_Length<1>, ToInCa<...> > Cb1; + typedef PredicatedInCa< Argv_Length<2>, ToInCa<...> > Cb2; + typedef PredicatedInCa< Argv_Length<3>, ToInCa<...> > Cb3; + // Fallback impl for 0 or 4+ args: + typedef PredicatedInCa< Argv_True, InCaToInCa > CbN; + // Side note: this ^^^^^^^^^^^^^^ is the only known use for the + // Argv_True predicate. + + // Combine them into one InvocationCallback: + typedef PredicatedInCaDispatcher< CVV8_TYPELIST(( + Cb1, Cb2, Cb3, CbN + ))> AllOverloads; + v8::InvocationCallback cb = AllOverloads::Call; + @endcode + */ + template + struct PredicatedInCaDispatcher + : InCa + { + /** + For each PredicatedInCa (P) in PredList, if P()(argv) + returns true then P::Call(argv) is returned, else the next + predicate in the list is tried. + + If no predicates match then a JS-side exception will be triggered. + */ + static inline v8::Handle Call( v8::Arguments const & argv ) + { + typedef typename PredList::Head Head; + typedef typename tmp::IfElse< tmp::SameType::Value, + Argv_False, + Head>::Type Ftor; + typedef typename PredList::Tail Tail; + typedef char AssertEndOfListCheck[ tmp::SameType::Value + ? (tmp::SameType::Value ? 1 : -1) + : 1 + /* ensures that the Argv_False kludge does not call + any specialization other than the NilType one. + */ + ]; + return ( Ftor()( argv ) ) + ? Detail::OverloadCallHelper::Call( argv ) + : PredicatedInCaDispatcher::Call(argv); + } + }; + + //! End-of-list specialization. + template <> + struct PredicatedInCaDispatcher< tmp::NilType > : InCa + { + /** + Triggers a JS-side exception explaining (in English text) that no + overloads could be matched to the given arguments. + */ + static inline v8::Handle Call( v8::Arguments const & argv ) + { + return Toss(StringBuffer()<<"No predicates in the " + << "argument dispatcher matched the given " + << "arguments (arg count="< + struct PredicatedCtorForwarder + : PredicatedInCaLike {}; + + /** + The constructor counterpart of PredicatedInCaDispatcher. + PredList must be a typelist of PredicatedCtorForwarder (or + interface-compatible) types. The ReturnType part of the + typelist must be the base type the constructors in the list + can return (they must all share a common base). Clients must + not pass the ContextT parameter - it is required internally + for handling the end-of-typelist case. + + This template instantiates TypeName, so + if that template is to be specialized by client code, it should + be specialized before this template used. + */ + template + struct PredicatedCtorDispatcher + { + /** + Force the ContextT into a native handle type. + */ + typedef typename TypeInfo::NativeHandle ReturnType; + /** + For each PredicatedCtorForwarder (P) in PredList, if P()(argv) + returns true then P::Call(argv) is returned, else the next + predicate in the list is tried. + + If no predicates match then a JS-side exception will be triggered. + */ + static ReturnType Call( v8::Arguments const & argv ) + { + typedef typename PredList::Head Head; + typedef typename tmp::IfElse< tmp::SameType::Value, + Argv_False, + Head>::Type Ftor; + typedef typename PredList::Tail Tail; + return ( Ftor()( argv ) ) + ? Detail::CtorFwdDispatch::Call( argv ) + : PredicatedCtorDispatcher::Call(argv); + } + }; + + //! End-of-list specialization. + template + struct PredicatedCtorDispatcher< tmp::NilType, ContextT > : Signature< ContextT * () > + { + typedef typename TypeInfo::NativeHandle ReturnType; + /** + Triggers a native exception explaining (in English text) that no + overloads could be matched to the given arguments. It's kinda + cryptic, but we can't be more specific at this level of + the API. + */ + static ReturnType Call( v8::Arguments const & argv ) + { + StringBuffer os; + os << "No predicates in the " + << TypeName::Value + << " ctor argument dispatcher matched the given " + << "arguments (arg count="< // arg! Requires C++0x! +#include +#include // hope the client's platform is recent! +#include +#include +#include +#include +#include +#include +#include + +#if !defined(CVV8_CONFIG_HAS_LONG_LONG) +/* long long in C++ requires C++0x or compiler extensions. */ +# define CVV8_CONFIG_HAS_LONG_LONG 0 +#endif + +#include "signature_core.hpp" /* only needed for the Signature used by the generated code. */ +#include "tmp.hpp" + +namespace cvv8 { + + + /** + A convenience base type for TypeInfo specializations. + */ + template + struct TypeInfoBase + { + /** + The unqualified type T. In some special cases, Type _may_ + differ from T. + */ + typedef T Type; + /** + The "handle" type used to pass around native objects + between the JS and Native worlds. + + In _theory_ we can also use shared/smart pointers with + this typedef, but that requires custom handling in other + template code (mainly because we cannot store a + full-fledged shared pointer object directly inside a JS + object). + */ + typedef NHT NativeHandle; + + // MAYBE to do: add a function to get a pointer to the object, e.g. + // for dereferencing smart pointers. So far it's not been necessary. + // static NativeHandle Pointer( NativeHandle x ) { return x; } + }; + + /** + This may optionally be specialized for client-defined types + to define the type name used by some error reporting + code. + + The default implementation is usable but not all that useful. + */ + template + struct TypeName + { + /** Specializations must have a non-NULL value, and any number + of specializations may legally have the same value. + */ + static char const * Value; + }; +#if 0 + /** + This default implementation is unfortunate, but quite a bit + of error-reporting code uses this, with the assumption that + if it was worth binding to JS then it's worth having a + useful type name in error strings. + + FIXME: remove the default specialization if we can, as it will + cause us problems with some planned/potential uses which cross + DLL boundaries (there may be multiple definitions with different + addresses). + */ + template + char const * TypeName::Value = "T"; +#endif + + /** @def CVV8_TypeName_DECL + + A convenience macro for declaring a TypeName specialization. X must + be a type name with extra wrapping parenthesis, e.g.: + + @code + CVV8_TypeName_DECL((MyType)); + @endcode + + They are required so that we can also support template types with commas + in the names, e.g. (std::map). + + It must be called from inside the cvv8 namespace. + */ +#define CVV8_TypeName_DECL(X) template <> struct TypeName< cvv8::sl::At<0,CVV8_TYPELIST(X) >::Type > \ + { const static char * Value; } + + /** @def CVV8_TypeName_IMPL + + The counterpart of CVV8_TypeName_DECL, this must be called from the + cvv8 namespace. The X argument is as documented for CVV8_TypeName_DECL + and the NAME argument must be a C string. + + Example: + + @code + CVV8_TypeName_IMPL((MyType),"MyType"); + @endcode + */ +#define CVV8_TypeName_IMPL(X,NAME) char const * TypeName< cvv8::sl::At<0,CVV8_TYPELIST(X) >::Type >::Value = NAME + /** @def CVV8_TypeName_IMPL2 + + Almost identical to CVV8_TypeName_IMPL(), but can be used without + having first explicitly specializing TypeName. + */ +#define CVV8_TypeName_IMPL2(X,NAME) template <> CVV8_TypeName_IMPL(X,NAME) + + +#if 1 + template + struct TypeName : TypeName {}; + template + struct TypeName : TypeName {}; + template + struct TypeName : TypeName {}; +#endif + + /** + Describes basic type information regarding a type, for purposes + of static typing during JS-to/from-Native conversions. + + The default instantiation is suitable for most + cases. Specializations may be required in certain JS/Native + binding cases. + */ + template + struct TypeInfo : TypeInfoBase + { + }; + + template + struct TypeInfo : TypeInfo {}; + + template + struct TypeInfo : TypeInfo {}; + + template + struct TypeInfo : TypeInfo {}; + + template + struct TypeInfo : TypeInfo {}; + + template + struct TypeInfo : TypeInfo {}; + +#if 1 // this will only theoretically do what i want. Never actually tried to use a non-pointer NativeHandle type... + template + struct TypeInfo< v8::Handle > + { + typedef v8::Handle Type; + typedef v8::Handle NativeHandle; + }; +#endif + + /** + Base instantiation for T-to-v8::Handle conversion functor. + Must be specialized or it will not compile. + */ + template + struct NativeToJS + { + /** + Must be specialized. The argument type may be pointer-qualified. + Implementations for non-pod types are encouraged to have two + overloads, one taking (NT const &) and one taking (NT const *), + as this gives the underlying CastToJS() calls more leeway. + **/ + template + v8::Handle operator()( X const & ) const; + private: + typedef tmp::Assertion NativeToJSMustBeSpecialized; + }; + + /** + Specialization to treat (NT*) as (NT). + + NativeToJS must have an operator() taking + (NT const *). + */ + template + struct NativeToJS : NativeToJS +#if 1 + {}; +#else + { + v8::Handle operator()( NT const * v ) const + { + typedef NativeToJS Proxy; + if( v ) return Proxy()(v); + else return v8::Null() + ; + } + }; +#endif + /** + Specialization to treat (NT const *) as (NT). + */ + template + struct NativeToJS : NativeToJS {}; + // { + // typedef typename TypeInfo::Type const * ArgType; + // v8::Handle operator()( ArgType n ) const + // { + // typedef NativeToJS Proxy; + // return Proxy()( n ); + // } + // }; + + /** + Specialization to treat (NT const &) as (NT). + */ + template + struct NativeToJS : NativeToJS {}; + template + struct NativeToJS : NativeToJS {}; + +#if 0 + /** + Specialization to treat (NT &) as (NT). + */ + template + struct NativeToJS : NativeToJS {}; +#else + /** + A specialization to convert from (T&) to JS. + + Be very careful with this, and make sure that + NativeToJS has its own specialization, + as this implementation uses that one as its + basis. + */ + template + struct NativeToJS + { + typedef typename TypeInfo::Type & ArgType; + v8::Handle operator()( ArgType n ) const + { + typedef NativeToJS< typename TypeInfo::NativeHandle > Cast; + return Cast()( &n ); + } + }; +#endif + +#if 0 + template <> + struct NativeToJS + { + /** + Returns v8::Undefined(). + */ + template + v8::Handle operator()(Ignored const &) const + { + return ::v8::Undefined(); + } + }; +#endif + +#if !defined(DOXYGEN) + namespace Detail { + /** + Base implementation for "small" integer conversions (<=32 + bits). + */ + template + struct NativeToJS_int_small + { + v8::Handle operator()( IntegerT v ) const + { + return v8::Integer::New( static_cast(v) ); + } + }; + /** + Base implementation for "small" unsigned integer conversions + (<=32 bits). + */ + template + struct NativeToJS_uint_small + { + v8::Handle operator()( IntegerT v ) const + { + return v8::Integer::NewFromUnsigned( static_cast(v) ); + } + }; + } +#endif // if !defined(DOXYGEN) + + template <> + struct NativeToJS : Detail::NativeToJS_int_small {}; + + template <> + struct NativeToJS : Detail::NativeToJS_uint_small {}; + + template <> + struct NativeToJS : Detail::NativeToJS_int_small {}; + + template <> + struct NativeToJS : Detail::NativeToJS_uint_small {}; + +#if !defined(DOXYGEN) + namespace Detail { + /** + Base implementation for "big" numeric conversions (>32 bits). + */ + template + struct NativeToJS_int_big + { + /** Returns v as a double value. */ + v8::Handle operator()( IntegerT v ) const + { + return v8::Number::New( static_cast(v) ); + } + }; + } +#endif // if !defined(DOXYGEN) + + template <> + struct NativeToJS : Detail::NativeToJS_int_big {}; + + template <> + struct NativeToJS : Detail::NativeToJS_int_big {}; + + template <> + struct NativeToJS + { + v8::Handle operator()( double v ) const + { + return v8::Number::New( v ); + } + }; + + template <> + struct NativeToJS + { + v8::Handle operator()( bool v ) const + { + return v8::Boolean::New( v ); + } + }; + + template + struct NativeToJS< ::v8::Handle > + { + typedef ::v8::Handle handle_type; + v8::Handle operator()( handle_type const & li ) const + { + return li; + } + }; + + template + struct NativeToJS< ::v8::Local > + { + typedef ::v8::Local handle_type; + v8::Handle operator()( handle_type const & li ) const + { + return li; + } + }; + + template + struct NativeToJS< ::v8::Persistent > + { + typedef ::v8::Persistent handle_type; + v8::Handle operator()( handle_type const & li ) const + { + return li; + } + }; + + template <> + struct NativeToJS< ::v8::InvocationCallback > + { + v8::Handle operator()( ::v8::InvocationCallback const f ) const + { + return ::v8::FunctionTemplate::New(f)->GetFunction(); + } + }; + + + template <> + struct NativeToJS + { + v8::Handle operator()( std::string const & v ) const + { + /** This use of v.data() instead of v.c_str() is highly arguable. */ + char const * const cstr = v.data(); + return cstr ? v8::String::New( cstr, static_cast( v.size() ) ) : v8::String::New("",0); + } + }; + + template <> + struct NativeToJS + { + v8::Handle operator()( char const * v ) const + { + if( ! v ) return v8::Null(); + else return v8::String::New( v ); + } + }; + + /** + "Casts" v to a JS value using NativeToJS. + */ + template + inline v8::Handle CastToJS( T const & v ) + { + typedef NativeToJS F; + return F()( v ); + } + + /** + Overload to avoid ambiguity in certain calls. + */ + static inline v8::Handle CastToJS( char const * v ) + { + typedef NativeToJS F; + return F()( v ); + } + + /** + Overload to avoid mis-selection of templates. + */ + static inline v8::Handle CastToJS( v8::InvocationCallback v ) + { + typedef NativeToJS F; + return F()( v ); + } + + /** + Overload to avoid ambiguity in certain calls. + */ + static inline v8::Handle CastToJS( char * v ) + { + typedef NativeToJS F; + return F()( v ); + } + + /** Convenience instance of NativeToJS. */ + static const NativeToJS Int16ToJS = NativeToJS(); + /** Convenience instance of NativeToJS. */ + static const NativeToJS UInt16ToJS = NativeToJS(); + /** Convenience instance of NativeToJS. */ + static const NativeToJS Int32ToJS = NativeToJS(); + /** Convenience instance of NativeToJS. */ + static const NativeToJS UInt32ToJS = NativeToJS(); + /** Convenience instance of NativeToJS. */ + static const NativeToJS Int64ToJS = NativeToJS(); + /** Convenience instance of NativeToJS. */ + static const NativeToJS UInt64ToJS = NativeToJS(); + /** Convenience instance of NativeToJS. */ + static const NativeToJS DoubleToJS = NativeToJS(); + /** Convenience instance of NativeToJS. */ + static const NativeToJS BoolToJS = NativeToJS(); + /** Convenience instance of NativeToJS. */ + static const NativeToJS StdStringToJS = NativeToJS(); + + /** + Converts a native std::exception to a JS exception and throws + that exception via v8::ThrowException(). + */ + template <> + struct NativeToJS + { + /** Returns v8::Exception::Error(ex.what()). + + ACHTUNG: on 20110717 this function was changed to NOT trigger a + JS exception. Prior versions triggered a JS exception, but that + was done due to a misunderstanding on my part (i didn't know v8 + provided a way to create Error objects without throwing). This + change is semantically incompatible with older code which uses + this conversion. + + OLD way of doing it (don't do this!): + + @code + catch( std::exception const & ex ) { return CastToJS(ex); } + @endcode + + The equivalent is now: + + @code + catch( std::exception const & ex ) { return Toss(CastToJS(ex)); } + @endcode + */ + v8::Handle operator()( std::exception const & ex ) const + { + char const * msg = ex.what(); + return v8::Exception::Error(v8::String::New( msg ? msg : "unspecified std::exception" )); + /** ^^^ String::New() internally calls strlen(), which hates it when string==0. */ + } + }; + template <> + struct NativeToJS : NativeToJS {}; + template <> + struct NativeToJS : NativeToJS {}; + template <> + struct NativeToJS : NativeToJS {}; + + + /** + Base interface for converting from native objects to JS + objects. There is no default implementation, and it must be + specialized to be useful. + + When creating custom implementations, remember that in + practice, all custom client-bound types are passed around + internally by non-const pointer. This is in contrast to + conversions of POD- and POD-like types (numbers and strings), + which are passed around by value. + + It is theoretically possible to use smart pointers (with value + semantics) via this API, but it is untested. + */ + template + struct JSToNative + { + typedef typename TypeInfo::NativeHandle ResultType; + //! Must be specialized to be useful. + ResultType operator()( v8::Handle const & h ) const; + }; + + /** Specialization to treat (JST*) as JST. */ + template + struct JSToNative : JSToNative {}; + + /** Specialization to treat (JST*) as JST. */ + template + struct JSToNative : JSToNative {}; + + /** Specialization to treat (JST const *) as (JST *). */ + template + struct JSToNative : JSToNative {}; + + /** + A specialization to convert from JS to (T&). + */ + template + struct JSToNative + { + /** + Uses JSTNative() to try to convert a JS object to a + pointer, and then dereferences that pointer to form + (T&). Beware, however, that this operation throws a native + exeception (deriving from std::exception) if it fails, + because the only other other option is has is to + dereference null and crash your app. + */ + typedef typename TypeInfo::Type & ResultType; + ResultType operator()( v8::Handle const & h ) const + { + typedef JSToNative Cast; + typedef typename Cast::ResultType NH; + NH n = Cast()( h ); + if( ! n ) + { + throw std::runtime_error("JSToNative could not get native pointer. Throwing to avoid dereferencing null!"); + } + else return *n; + } + }; + + /** Specialization to treat (JST const &) as (JST). */ + template + struct JSToNative + { + typedef typename TypeInfo::Type const & ResultType; + ResultType operator()( v8::Handle const & h ) const + { + typedef JSToNative Cast; + typedef typename Cast::ResultType NH; +#if 0 + NH n = Cast()( h ); + if( ! n ) + { + throw std::runtime_error("JSToNative could not get native pointer. Throwing to avoid dereferencing null!"); + } + else return *n; +#else + return Cast()(h); +#endif + } + }; + + + + /** Specialization which passes on v8 Handles as-is. */ + template + struct JSToNative > + { + typedef v8::Handle ResultType; + ResultType operator()( v8::Handle const & h ) const + { + return h; + } + }; + template + struct JSToNative const &> : JSToNative< v8::Handle > {}; + template + struct JSToNative &> : JSToNative< v8::Handle > {}; + + /** Specialization which passes on v8 local Handles as-is. */ + template + struct JSToNative > + { + typedef v8::Local ResultType; + ResultType operator()( v8::Local const & h ) const + { + return h; + } + }; + template + struct JSToNative const &> : JSToNative< v8::Local > {}; + template + struct JSToNative &> : JSToNative< v8::Local > {}; + +#if !defined(DOXYGEN) + namespace Detail + { + template + struct JSToNative_V8Type + { + /** + If h is not empty and is of the correct type + then its converted handle is returned, else + an empty handle is returned. + */ + typedef v8::Handle ResultType; + ResultType operator()( v8::Handle const & h ) const + { + return (h.IsEmpty() || !((*h)->*IsA)()/*man, what a construct!*/) + ? v8::Handle() + : v8::Handle(V8Type::Cast(*h)); + } + }; + } +#endif + template <> + struct JSToNative > : Detail::JSToNative_V8Type< v8::Object, &v8::Value::IsObject> + {}; + template <> + struct JSToNative< v8::Handle &> : JSToNative< v8::Handle > {}; + template <> + struct JSToNative< v8::Handle const &> : JSToNative< v8::Handle > {}; + + + template <> + struct JSToNative > : Detail::JSToNative_V8Type< v8::Array, &v8::Value::IsArray> + {}; + template <> + struct JSToNative< v8::Handle &> : JSToNative< v8::Handle > {}; + template <> + struct JSToNative< v8::Handle const &> : JSToNative< v8::Handle > {}; + + template <> + struct JSToNative > : Detail::JSToNative_V8Type< v8::Function, &v8::Value::IsFunction> + {}; + template <> + struct JSToNative< v8::Handle &> : JSToNative< v8::Handle > {}; + template <> + struct JSToNative< v8::Handle const &> : JSToNative< v8::Handle > {}; + + /** + An X-to-void specialization which we cannot use in the generic + case due to the syntactic limitations of void. + */ + template <> + struct JSToNative + { + typedef void ResultType; + ResultType operator()( ... ) const + { + return; + } + }; + + /** + A very arguable specialization which tries to convert a JS + value to native (void*) via v8::External. + */ + template <> + struct JSToNative + { + typedef void * ResultType; + /** + If h is-a External then this return its value, else it + return 0. + + We could arguably check if it is an object and has + internal fields, and return the first one, but i think + that would be going too far considering how arguably the + v8-to-(void *) conversion is in the first place. + */ + ResultType operator()( v8::Handle const & h ) const + { + if( h.IsEmpty() || ! h->IsExternal() ) return 0; + return v8::External::Cast(*h)->Value(); + } + }; + /** + A very arguable specialization which tries to convert a JS + value to native (void*) via v8::External. + */ + template <> + struct JSToNative + { + typedef void const * ResultType; + /** + If h is-a External then this return its value, else it + return 0. + + We could arguably check if it is an object and has + internal fields, and return the first one, but i think + that would be going to far considering how arguably the + v8-to-(void *) conversion is in the first place. + */ + ResultType operator()( v8::Handle const & h ) const + { + if( h.IsEmpty() || ! h->IsExternal() ) return 0; + return v8::External::Cast(*h)->Value(); + } + }; + + /** + A concrete JSToNative implementation intended to be used as the + base class for JSToNative implementations where T is "bound + to JS" in JS objects, and those JS objects meet the following + requirements: + + - They have exactly InternalFieldCount internal fields. + + - They have a C/C++-native object of type (T*) (or convertible + to type (T*)) stored as a v8::External value in the JS-object + internal field number InternalFieldIndex. + + Note that the InternalFieldCount check is only a quick + sanity-checking mechanism, and is by far not foolproof because + the majority of JS-bound native types only use 1 internal + field. + + It is illegal for InternalFieldCount to be equal to or smaller + than InternalFieldIndex, or for either value to be + negative. Violating these invariants results in a compile-time + assertion. + + If an object to convert matches the field specification but + is not a T (or publically derived from T) then results are + undefined (this could lead to a crash at runtime). + + There are cases where very-misbehaving JS code can force this + particular conversion algorithm to mis-cast the native. While + they have never been seen "in the wild", they can + theoretically happen. If that bothers you, and you want to be + able to sleep soundly at night, use + JSToNative_ObjectWithInternalFieldsTypeSafe instead of this + class. + + @see JSToNative_ObjectWithInternalFieldsTypeSafe + + */ + template + struct JSToNative_ObjectWithInternalFields + { + private: + typedef char AssertIndexRanges + [tmp::Assertion< + (InternalFieldIndex>=0) + && (InternalFieldCount>0) + && (InternalFieldIndex < InternalFieldCount) + >::Value + ? 1 : -1]; + public: + typedef typename TypeInfo::NativeHandle ResultType; + /** + If h is-a Object and it meets the requirements described + in this class' documentation, then this function returns + the result of static_cast(void*), using the (void*) + extracted from the Object. If the requirements are not met + then NULL is returned. + + See the class docs for more details on the requirements + of the passed-in handle. + + If SearchPrototypeChain is true and this object does not + contain a native then the prototype chain is searched. + This is generally only required when bound types are + subclassed. + */ + ResultType operator()( v8::Handle const & h ) const + { + if( h.IsEmpty() || ! h->IsObject() ) return NULL; + else + { + void * ext = NULL; + v8::Handle proto(h); + while( !ext && !proto.IsEmpty() && proto->IsObject() ) + { + v8::Local const & obj( v8::Object::Cast( *proto ) ); + ext = (obj->InternalFieldCount() != InternalFieldCount) + ? NULL + : obj->GetPointerFromInternalField( InternalFieldIndex ); + if( ! ext ) + { + if( !SearchPrototypeChain ) break; + else proto = obj->GetPrototype(); + } + } + return ext ? static_cast(ext) : NULL; + } + } + }; + + /** + A concrete JSToNative implementation (to be used as a base class) + which does a type-safe conversion from JS to (T*). + + T is the bound native type. A pointer of this type is expected + in the object-internal field specified by ObjectFieldIndex. + + Each value to be converted is checked for an internal field + (of type v8::External) at the index specified by + TypeIdFieldIndex. If (and only if) that field contains a + v8::External which holds the value TypeID is the conversion + considered legal. If they match but the native value stored + in field ObjectFieldIndex is NOT-a-T then results are + undefined. Note that the TypeID value is compared by pointer + address, not by its byte contents (which may legally be + NULL). + + If SearchPrototypeChain is true and the passed-in object + contains no native T then the prototype chain is checked + recursively. This is normally only necessary if the native + type is allowed to be subclasses from JS code (at which point + the JS 'this' is not the same exact object as the one + holding the native 'this' pointer, and we need to search the + prototype chain). + + For this all to work: the class-binding mechanism being used + by the client must store the TypeID value in all new + JS-created instances of T by calling SetInternalField( + TypeIdFieldIndex, theTypeID ) and store the native object + pointer in the field internal field ObjectFieldIndex. And + then they should do: + + @code + // in the cvv8 namespace: + template <> + struct JSToNative : + JSToNative_ObjectWithInternalFieldsTypeSafe + {}; + @endcode + + At which point CastFromJS() will take advantage of this + type check. + + + The real docs end here. What follows is pseudorandom blather... + + Theoretically (i haven't tried this but i know how the + underlying code works), it is possible for script code to + create a condition which will lead to an invalid cast if the + check performed by this class (or something equivalent) is + _not_ performed: + + @code + var x = new Native1(); + var y = new Native2(); + // assume y.someFunc and x.otherFunc are both bound to native functions + y.someFunc = x.otherFunc; + y.someFunc( ... ); // here is where it will likely end badly + @endcode + + When y.someFunc() is called, JS will look for a 'this' object of + type Native1, not Native2, because the type information related to + the conversion is "stored" in the callback function itself, not in + the native object. (This is a side-effect of us using templates to + create InvocationCallback implementations.) It will not find a + Native1, but it might (depending on how both classes are bound to + JS) find a Native2 pointer and _think_ it is a Native1. And by + "think it is" i mean "it will try to cast it to," but the cast is + illegal in that case. In any case it would be bad news. + + The check performed by this class can catch that condition + (and similar ones) and fail gracefully (i.e. returning a + NULL instead of performing an illegal cast). + */ + template + struct JSToNative_ObjectWithInternalFieldsTypeSafe + { + private: + typedef char AssertIndexRanges + [(InternalFieldCount>=2) + && (TypeIdFieldIndex != ObjectFieldIndex) + && (TypeIdFieldIndex >= 0) + && (TypeIdFieldIndex < InternalFieldCount) + && (ObjectFieldIndex >= 0) + && (ObjectFieldIndex < InternalFieldCount) + ? 1 : -1]; + public: + typedef typename TypeInfo::NativeHandle ResultType; + /** + If h is-a Object and it meets the requirements described + in this class' documentation, then this function returns + the result of static_cast(void*), using the (void*) + extracted from the Object. If the requirements are not met + then NULL is returned. + + See the class docs for more details on the requirements + of the passed-in handle. + + If SearchPrototypeChain is true and the object does not + contain a native then the prototype chain is searched + recursively. This is generally only required when bound + types are subclassed from JS code. + */ + ResultType operator()( v8::Handle const & h ) const + { + if( h.IsEmpty() || ! h->IsObject() ) return NULL; + else + { + void const * tid = NULL; + void * ext = NULL; + v8::Handle proto(h); + while( !ext && !proto.IsEmpty() && proto->IsObject() ) + { + v8::Local const & obj( v8::Object::Cast( *proto ) ); + tid = (obj->InternalFieldCount() != InternalFieldCount) + ? NULL + : obj->GetPointerFromInternalField( TypeIdFieldIndex ); + ext = (tid == TypeID) + ? obj->GetPointerFromInternalField( ObjectFieldIndex ) + : NULL; + if( ! ext ) + { + if( ! SearchPrototypeChain ) break; + else proto = obj->GetPrototype(); + } + } + return ext ? static_cast(ext) : NULL; + } + } + }; + + /** Specialization to convert JS values to int16_t. */ + template <> + struct JSToNative + { + typedef int16_t ResultType; + ResultType operator()( v8::Handle const & h ) const + { + return h->IsNumber() + ? static_cast(h->Int32Value()) + : 0; + } + }; + + /** Specialization to convert JS values to uint16_t. */ + template <> + struct JSToNative + { + typedef uint16_t ResultType; + ResultType operator()( v8::Handle const & h ) const + { + return h->IsNumber() + ? static_cast(h->Int32Value()) + : 0; + } + }; + + /** Specialization to convert JS values to int32_t. */ + template <> + struct JSToNative + { + typedef int32_t ResultType; + ResultType operator()( v8::Handle const & h ) const + { + return h->IsNumber() + ? h->Int32Value() + : 0; + } + }; + + /** Specialization to convert JS values to uint32_t. */ + template <> + struct JSToNative + { + typedef uint32_t ResultType; + ResultType operator()( v8::Handle const & h ) const + { + return h->IsNumber() + ? static_cast(h->Uint32Value()) + : 0; + } + }; + + + /** Specialization to convert JS values to int64_t. */ + template <> + struct JSToNative + { + typedef int64_t ResultType; + ResultType operator()( v8::Handle const & h ) const + { + return h->IsNumber() + ? static_cast(h->IntegerValue()) + : 0; + } + }; + + /** Specialization to convert JS values to uint64_t. */ + template <> + struct JSToNative + { + typedef uint64_t ResultType; + ResultType operator()( v8::Handle const & h ) const + { + return h->IsNumber() + ? static_cast(h->IntegerValue()) + : 0; + } + }; + + /** Specialization to convert JS values to double. */ + template <> + struct JSToNative + { + typedef double ResultType; + ResultType operator()( v8::Handle const & h ) const + { + return h->IsNumber() + ? h->NumberValue() + : 0; + } + }; + + /** Specialization to convert JS values to bool. */ + template <> + struct JSToNative + { + typedef bool ResultType; + ResultType operator()( v8::Handle const & h ) const + { + return h->BooleanValue(); + } + }; + + /** Specialization to convert JS values to std::string. */ + template <> + struct JSToNative + { + typedef std::string ResultType; + ResultType operator()( v8::Handle const & h ) const + { + static const std::string emptyString; + v8::String::Utf8Value const utf8String( h ); + const char* s = *utf8String; + return s + ? std::string(s, utf8String.length()) + : emptyString; + } + }; + + /** + Specialization necessary to avoid incorrect default behaviour + for this special case. + + Reminder to self: we'll need a specialization like this any + time we want to use a type which is returned by VALUE from + JSToNative() and might be passed as a const reference as a + function argument type. The vast majority of bound native + types are bound internally as pointers (and don't need a + specialization like this one), whereas the std::string + conversion uses value semantics to simplify usage. + */ + template <> + struct JSToNative : public JSToNative {}; + +#if 0 // leave this unused code here for the sake of the next guy who tries to re-add it + /** + Nonono! This will Cause Grief when used together with CastFromJS() + because the returned pointer's lifetime cannot be guaranteed. + See ArgCaster for more details on the problem. + */ + template <> + struct JSToNative + { + public: + typedef char const * ResultType; + ResultType operator()( v8::Handle const & h ); + }; +#else +#if 0 // it turns out no current (20110627) code uses this. +// We might want to leave it in b/c that will cause compile errors +// in some use cases rather than link errors ("undefined ref..."). + /** Not great, but a happy medium. */ + template <> + struct JSToNative : JSToNative {}; +#endif +#endif + + namespace Detail + { + /** A kludge placeholder type for a ulong-is-not-uint64 + condition on some platforms. + + T is ignored, but is required to avoid class-redefinition + errors for the templates using this class. + */ + template + struct UselessConversionType + { + }; + } + + /** + This specialization is a kludge/workaround for use in cases + where (unsigned long int) is: + + 1) The same type as the platform's pointer type. + 2) Somehow NOT the same as one of the standard uintNN_t types. + 3) Used in CastToJS() or CastFromJS() calls. + + If ulong and uint64 are the same type then this specialization + is a no-op (it generates a converter for a type which will + never be converted), otherwords it performs a numeric conversion. + */ + template <> + struct NativeToJS< tmp::IfElse< tmp::SameType::Value, + Detail::UselessConversionType, + unsigned long >::Type > + : Detail::NativeToJS_int_big + { + }; + + /** + This is a kludge/workaround for use in cases where (unsigned + long int) is: + + 1) The same type as the platform's pointer type. + 2) Somehow NOT the same as one of the standard uintNN_t types. + 3) Used in CastToJS() or CastFromJS() calls. + + If ulong and uint64 are the same type then this specialization + is a no-op (it generates a converter for a type which will + never be converted), otherwords it performs a numeric + conversion. + */ + template <> + struct JSToNative< tmp::IfElse< + tmp::SameType::Value, + Detail::UselessConversionType, + unsigned long >::Type > + : JSToNative + { + }; + + /** + See the equivalent NativeToJS kludge for unsigned long. + */ + template <> + struct NativeToJS< tmp::IfElse< tmp::SameType::Value, + Detail::UselessConversionType, + long >::Type > + : Detail::NativeToJS_int_big + { + }; + + /** + See the equivalent JSToNative kludge for unsigned long. + */ + template <> + struct JSToNative< tmp::IfElse< + tmp::SameType::Value, + Detail::UselessConversionType, + long >::Type > : JSToNative + { + }; + +#if CVV8_CONFIG_HAS_LONG_LONG + /** + See the equivalent JSToNative kludge for unsigned long. + + Added 20100606 to please the sqlite3 plugin, where sqlite3_int64 + collides with (long long) on some platforms and causes an invalid + conversion compile-time error. + */ + template <> + struct JSToNative< tmp::IfElse< + tmp::SameType::Value, + Detail::UselessConversionType, + long long int >::Type > : JSToNative + { + }; + /** + See the equivalent JSToNative kludge for unsigned long. + + Added 20101126 to please the sqlite3 plugin, where + sqlite3_int64 collides with (long long) on some platforms and + causes a link-time error. + */ + template <> + struct NativeToJS< tmp::IfElse< tmp::SameType::Value, + Detail::UselessConversionType, + long long int >::Type > + : Detail::NativeToJS_int_big + { + }; +#endif + + + /** + Converts h to an object of type NT, using JSToNative to do + the conversion. + */ + template + typename JSToNative::ResultType CastFromJS( v8::Handle const & h ) + { + typedef JSToNative F; + return F()( h ); + } + + /** Convenience instance of JSToNative. */ + static const JSToNative JSToInt16 = JSToNative(); + /** Convenience instance of JSToNative. */ + static const JSToNative JSToUInt16 = JSToNative(); + /** Convenience instance of JSToNative. */ + static const JSToNative JSToInt32 = JSToNative(); + /** Convenience instance of JSToNative. */ + static const JSToNative JSToUInt32 = JSToNative(); + /** Convenience instance of JSToNative. */ + static const JSToNative JSToInt64 = JSToNative(); + /** Convenience instance of JSToNative. */ + static const JSToNative JSToUInt64 = JSToNative(); + /** Convenience instance of JSToNative. */ + static const JSToNative JSToDouble = JSToNative(); + /** Convenience instance of JSToNative. */ + static const JSToNative JSToBool = JSToNative(); + /** Convenience instance of JSToNative. */ + static const JSToNative JSToStdString = JSToNative(); + + /** + A utility to add properties to a JS v8::Object or v8::ObjectTemplate. + ObjectType must be either v8::Object or v8::ObjectTemplate. It + _might_ work in limited context with v8::Array, but that is untested. + ObjectType is intended to be v8::Object or v8::ObjectTemplate, + but Object subclasses, e.g. v8::Array and v8::Function, "should" work + as well. + + It is intended to be used like this: + + \code + v8::Handle obj = ...; + ObjectPropSetter set(obj); + set("propOne", CastToJS(32) ) + ("propTwo", ... ) + (32, ... ) + ("func1", anInvocationCallback ) + ; + \endcode + */ + template ::Value, + v8::Handle, + v8::Handle + >::Type + > + class ObjectPropSetter + { + private: + v8::Handle const target; + public: + /** + Initializes this object to use the given array + as its append target. Results are undefined if + target is not a valid Object. + */ + explicit ObjectPropSetter( v8::Handle< ObjectType > const & obj ) :target(obj) + {} + ~ObjectPropSetter(){} + + + /** + Adds an arbtirary property to the target object. + */ + inline ObjectPropSetter & Set( KeyType const & key, v8::Handle const & v ) + { + this->target->Set(key->ToString(), CastToJS(v)); + return *this; + } + /** + Adds an arbtirary property to the target object. + */ + inline ObjectPropSetter & Set( char const * key, v8::Handle const & v ) + { + this->target->Set( v8::String::New(key), CastToJS(v)); + return *this; + } + + /** + Adds an arbitrary property to the target object using + CastToJS(v). + */ + template + inline ObjectPropSetter & operator()( KeyType const & key, T const & v ) + { + this->target->Set(key, CastToJS(v)); + return *this; + } + + /** + Adds a numeric property to the target object. + */ + template + inline ObjectPropSetter & operator()( int32_t ndx, T const & v ) + { + return this->Set( v8::Integer::New(ndx), CastToJS(v) ); + } + + /** + Adds a string-keyed property to the target object. + Note that if key is NULL, the v8::String constructor + will crash your app. (Good luck with that!) + */ + template + inline ObjectPropSetter & operator()( char const * key, T const & v ) + { + return this->Set( v8::String::New(key), CastToJS(v) ); + } + + + /** + Adds the given function as a member of the target object. + */ + inline ObjectPropSetter & operator()( char const * name, v8::InvocationCallback pf ) + { + return this->Set( name, v8::FunctionTemplate::New(pf)->GetFunction() ); + } + + /** + Returns this object's JS object. + */ + v8::Handle< v8::Object > Object() const + { + return this->target; + } + }; + + /** + NativeToJS classes which act on list types compatible with the + STL can subclass this to get an implementation. + */ + template + struct NativeToJS_list + { + v8::Handle operator()( ListT const & li ) const + { + typedef typename ListT::const_iterator IT; + IT it = li.begin(); + const size_t sz = li.size(); +#if 1 + v8::Handle rv( v8::Array::New( static_cast(sz) ) ); + for( int i = 0; li.end() != it; ++it, ++i ) + { + rv->Set( v8::Integer::New(i), CastToJS( *it ) ); + } + return rv; +#else + ObjectPropSetter app(Array::New( static_cast(sz) )); + for( int32_t i = 0; li.end() != it; ++it, ++i ) + { + app( i, CastToJS( *it ) ); + } + return app.Object(); +#endif + } + }; + + /** Partial specialization for std::list<>. */ + template + struct NativeToJS< std::list > : NativeToJS_list< std::list > {}; + /** Partial specialization for std::vector<>. */ + template + struct NativeToJS< std::vector > : NativeToJS_list< std::vector > {}; + + /** + NativeToJS classes which act on map types compatible with the + STL can subclass this to get an implementation. + + Both the key and mapped types of the given Map Type must be + converitible to v8 types using CastToJS(). + */ + template + struct NativeToJS_map + { + v8::Handle operator()( MapT const & li ) const + { + typedef typename MapT::const_iterator IT; + IT it( li.begin() ); + v8::Handle rv( v8::Object::New() ); + for( int i = 0; li.end() != it; ++it, ++i ) + { + rv->Set( CastToJS( (*it).first ), CastToJS( (*it).second ) ); + } + return rv; + } + }; + + /** Partial specialization for std::map<>. */ + template + struct NativeToJS< std::map > : NativeToJS_map< std::map > {}; + + /** + A base class for JSToNative + specializations. ListT must be compatible with std::list and + std::vector, namely: + + - Must support push_back( ListT::value_type ). + + - Must define value_type typedef or the second template + argument must be specified for this template. + + It is technically legal for ValueType to differ from + ListT::value_type if + ListT::push_back(JSToNative::ResultType) is + legal. e.g. if ListT is std::vector and we want to + truncate the values we could use, e.g. int32_t as the + ValueType. + */ + template + struct JSToNative_list + { + typedef ListT ResultType; + /** + Converts jv to a ListT object. + + If jv->IsArray() then the returned object is populated from + jv, otherwise the returned object is empty. Since it is + legal for an array to be empty, it is not generically + possible to know if this routine got an empty Array object + or a non-Array object. + */ + ResultType operator()( v8::Handle jv ) const + { + //typedef typename ListT::value_type VALT; + typedef ValueType VALT; + ListT li; + if( jv.IsEmpty() || ! jv->IsArray() ) return li; + v8::Handle ar( v8::Array::Cast(*jv) ); + uint32_t ndx = 0; + for( ; ar->Has(ndx); ++ndx ) + { + li.push_back( CastFromJS( ar->Get(v8::Integer::New(ndx)) ) ); + } + return li; + } + }; + + /** Partial specialization for std::list<>. */ + template + struct JSToNative< std::list > : JSToNative_list< std::list > {}; + + /** Partial specialization for std::vector<>. */ + template + struct JSToNative< std::vector > : JSToNative_list< std::vector > {}; + +#if 0 // untested code + /** + UNTESTED! + + Intended as a base class for JSToNative specializations + which proxy a std::map-like map. + */ + template + struct JSToNative_map + { + typedef MapT ResultType; + /** + Converts jv to a MapT object. + + If jv->IsObject() then the returned object is populated from + jv, otherwise the returned object is empty. Since it is + legal for an object to be empty, it is not generically + possible to know if this routine got an empty Object + or a non-Object handle. + */ + ResultType operator()( v8::Handle jv ) const + { + typedef ValueType VALT; + MapT map; + if( jv.IsEmpty() || ! jv->IsObject() ) return map; + Local obj( Object::Cast(*jv) ); + Local ar( obj->GetPropertyNames() ); + uint32_t ndx = 0; + for( ; ar->Has(ndx); ++ndx ) + { + Local const & k = ar->Get(Integer::New(ndx)); + if( ! obj->HasRealNamedProperty(k) ) continue; + map[CastFromJS(k)] = CastFromJS(obj->Get(k)); + } + return map; + } + }; +#endif + /** + A utility class for building up message strings, most notably + exception messages, using a mixture of native and JS message + data. + + It is used like a std::ostream: + + @code + StringBuffer msg; + msg << "Could not set property " + << "'" << propName + <<"' on object " << myJSObject << '!'; + return v8::ThrowException(msg.toError()); + // or: + return Toss(msg); + @endcode + */ + class StringBuffer + { + private: + std::ostringstream os; + public: + /** + Initializes the message stream. + */ + StringBuffer() : os() + { + } + StringBuffer(StringBuffer const & other) : os(other.os.str()) + { + } + StringBuffer & operator=(StringBuffer const & other) + { + this->os.str(other.os.str()); + return *this; + } + + /** + Empties out the message buffer. This invalidates any value + returned from previous calls to the (char const *) + operator. + */ + inline void Clear() + { + this->os.str(""); + } + + /** + Returns a copy of the current message content. + */ + inline std::string Content() const + { + return this->os.str(); + } + + /** + Converts the message state to a JS string. + */ + inline operator v8::Handle() const + { + return CastToJS( this->os.str() ); + } + + /** + Converts the message state to a v8::String (for use + with v8::Exception::Error() and friends). + */ + inline operator v8::Handle() const + { + std::string const & str(this->os.str()); + char const * cstr = str.c_str(); + return v8::String::New( cstr ? cstr : "", cstr ? str.size() : 0 ); + } + + /** + Appends to the message using CastFromJS(t) + */ + template + inline StringBuffer & operator<<( v8::Handle const & t ) + { + this->os << CastFromJS( t ); + return *this; + } + /** + Appends to the message using CastFromJS(t) + + Reminder to self: if this function is changed to take + a const reference instead of a copy, we get overload + ambiguity errors in some contexts. See: + + http://code.google.com/p/v8-juice/issues/detail?id=19 + + (And thanks to Feng Fillano for reporting and localizing + the problem.) + */ + template + inline StringBuffer & operator<<( v8::Local const t ) + { + this->os << CastFromJS( t ); + return *this; + } + + /** + Appends t to the message via std::ostream<<. + */ + template + inline StringBuffer & operator<<( T const t) + { + this->os << t; + return *this; + } + + /** + Returns this buffer's value wrapped in + a JS Error object. + */ + v8::Local toError() const + { + return v8::Exception::Error(*this); + } + }; + + /** Outputs sb.Content() to os and returns os. */ + inline std::ostream & operator<<( std::ostream & os, StringBuffer const & sb ) + { + return os << sb.Content(); + } + + + /** + Requi + "Lexically casts" msg to a string and throws a new JS-side + Error. ValT may be any type which can be sent to StringBuffer's + ostream operator. + + The return value is the result of calling + v8::ThrowException() (Undefined except in the face of a + serious internal error like OOM, i'm told by the v8 devs). + */ + template + inline v8::Handle Toss( ValT const & msg ) + { + return v8::ThrowException((StringBuffer() << msg).toError()); + } + + /** + Overload to avoid an ambiguity (and it's more efficient than + the default impl). + */ + inline v8::Handle Toss( char const * msg ) + { + return v8::ThrowException(v8::Exception::Error(v8::String::New( msg ? msg : "Unspecified error."))); + } + + /** + Eqivalent to v8::ThrowException(err). Note that if err is not an + Error object, the JS side will not get an Error object. e.g. if err + is-a String then the JS side will see the error as a string. + + The reason this does not convert err to an Error is because the v8 + API provides no way for us to know if err is already an Error object. + This function is primarily intended to be passed the results of + CastToJS(std::exception), which generates Error objects. + */ + inline v8::Handle Toss( v8::Handle const & err ) + { + return v8::ThrowException(err); + } + + /** + Efficiency overload. + */ + inline v8::Handle Toss( StringBuffer const & msg ) + { + return v8::ThrowException(msg.toError()); + } + /** + Like Toss(Handle), but converts err to a string and creates an + Error object, which is then thrown. + */ + inline v8::Handle TossAsError( v8::Handle const & err ) + { + return Toss(v8::Exception::Error(err->ToString())); + } + + /** + ArgCaster is a thin wrapper around CastFromJS(), and primarily + exists to give us a way to convert JS values to (char const *) + for purposes of passing them to native functions. The main + difference between this type and JSToNative is that this + interface explicitly allows for the conversion to be stored by + an instance of this type. That allows us to get more lifetime + out of converted values in certain cases (namely (char const*)). + + The default implementation is suitable for all cases which + JSToNative supports, but specializations can handle some of + the corner cases which JSToNative cannot (e.g. (char const *)). + + Added 20091121. + */ + template + struct ArgCaster + { + typedef typename JSToNative::ResultType ResultType; + /** + Default impl simply returns CastFromJS(v). + Specializations are allowed to store the result of the + conversion, as long as they release it when the destruct. + See ArgCaster for an example of that. + */ + inline ResultType ToNative( v8::Handle const & v ) const + { + return CastFromJS( v ); + } + /** + To eventually be used for some internal optimizations. + */ + enum { HasConstOp = 1 }; + }; + /** + Specialization for (char const *). The value returned from + ToNative() is guaranteed to be valid as long as the ArgCaster + object is alive or until ToNative() is called again (which will + almost certainly change the pointer). Holding a pointer to the + ToNative() return value after the ArgCaster is destroyed will + lead to undefined behaviour. Likewise, fetching a pointer, then + calling ToNative() a second time, will invalidate the first + pointer. + + BEWARE OF THESE LIMITATIONS: + + 1) This will only work properly for nul-terminated strings, + and not binary data! + + 2) Do not use this to pass (char const *) as a function + parameter if that function will hold a copy of the pointer + after it returns (as opposed to copying/consuming the + pointed-to-data before it returns) OR if it returns the + pointer passed to it. Returning is a specific corner-case + of "holding a copy" for which we cannot guaranty the lifetime + at the function-binding level. + + 3) Do not use the same ArgCaster object to convert multiple + arguments, as each call to ToNative() will invalidate the + pointer returned by previous calls. + + 4) The to-string conversion uses whatever encoding + JSToNative uses. + + Violating any of those leads to undefined behaviour, and + very possibly memory corruption for cases 2 or 3. + */ + template <> + struct ArgCaster + { + private: + /** + Reminder to self: we cannot use v8::String::Utf8Value + here because at the point the bindings call ToNative(), + v8 might have been unlocked, at which point dereferencing + the Utf8Value becomes illegal. + */ + std::string val; + typedef char Type; + public: + typedef Type const * ResultType; + /** + Returns the toString() value of v unless: + + - v.IsEmpty() + - v->IsNull() + - v->IsUndefined() + + In which cases it returns 0. + + The returned value is valid until: + + - ToNative() is called again. + - This object is destructed. + */ + ResultType ToNative( v8::Handle const & v ) + { + typedef JSToNative C; + if( v.IsEmpty() || v->IsNull() || v->IsUndefined() ) + { + return 0; + } + this->val = C()( v ); + return this->val.c_str(); + } + /** + To eventually be used for some internal optimizations. + */ + enum { HasConstOp = 0 }; + }; + +#if !defined(DOXYGEN) + namespace Detail { + /** + Default (unimplemented) CtorForwarderProxy impl. A helper + for the CtorForwarder class. All specializations except + the 0-arity one are generated from script code. + */ + template >::Value > + struct CtorForwarderProxy + { + typedef typename Signature::ReturnType ReturnType; + static ReturnType Call( v8::Arguments const & ); + }; + + //! Specialization for 0-arity ctors. + template + struct CtorForwarderProxy + { + typedef typename Signature::ReturnType ReturnType; + static ReturnType Call( v8::Arguments const & ) + { + typedef typename TypeInfo::Type RType; + return new RType; + } + }; + //! Specialization for ctors taking (v8::Arguments const &). + template + struct CtorForwarderProxy + { + typedef typename Signature::ReturnType ReturnType; + static ReturnType Call( v8::Arguments const & argv ) + { + typedef typename TypeInfo::Type T; + return new T(argv); + } + }; + + } +#endif + /** + A utility type to help forward v8::Arguments to native + constructors. This type is intended to assist in the creation + of ctor functions for JS-bound C++ classes. + + Requirements: + + - Sig is "almost" a function-signature-style type, but + because ctors don't have a return value in the conventional + sense, we have to use a tiny workaround: Sig should be passed + in like this from client code: + + @code + typedef CtorForwarder CF; + @endcode + + - (new T(...)) must be legal, taking a number of + arguments equal to Sig's Arity. + + - All arguments to the native ctor must be convertible + using CastFromJS(). + + Example: + + @code + typedef CtorForwarder CF0; + typedef CtorForwarder CF1; + typedef CtorForwarder CF2; + typedef CtorForwarder CFAny; + @endcode + + @see CtorArityDispatcher + */ + template + struct CtorForwarder : Signature + { + typedef Signature STL; + //typedef typename tmp::AddPointer::Type ReturnType; + typedef typename STL::ReturnType ReturnType; + /** + If (argv.Length()>=Arity) or Arity is less than 0, + then the constructor is called with Arity arguments + (if it >=0) or with 1 v8::Arguments parameter (for Arity<0). + + Returns the result of (new Type(...)), transfering ownership + to the caller. + + May propagate native exceptions. + */ + static ReturnType Call( v8::Arguments const & argv ) + { + enum { Arity = sl::Arity< STL >::Value }; + typedef Detail::CtorForwarderProxy Proxy; + return Proxy::Call( argv ); + } + }; + +#if !defined(DOXYGEN) + namespace Detail + { + + /** + Internal dispatch routine. CTOR _must_ be a CtorForwarder implementation + (or interface-compatible). + */ + template + struct CtorFwdDispatch + { + typedef typename TypeInfo::NativeHandle ReturnType; + static ReturnType Call( v8::Arguments const & argv ) + { + return CTOR::Call( argv ); + } + }; + /** + Internal dispatch end-of-list routine. + */ + template + struct CtorFwdDispatch + { + typedef typename TypeInfo::NativeHandle ReturnType; + static ReturnType Call( v8::Arguments const & ) + { + return 0; + } + }; + /** + Internal type to dispatch a v8::Arguments list to one of + several a bound native constructors, depending on on the + argument count. + + List MUST be a Signature< ... > containing ONLY + CtorFowarder types (or compatible). + */ + template + struct CtorFwdDispatchList + { + typedef typename TypeInfo::NativeHandle ReturnType; + /** + Tries to dispatch Arguments to one of the constructors + in the List type, based on the argument count. + */ + static ReturnType Call( v8::Arguments const & argv ) + { + typedef typename List::Head CTOR; + typedef typename List::Tail Tail; + enum { Arity = (0==sl::Index::Value) + ? -1 : sl::Length::Value + }; + return ( (Arity < 0) || (Arity == argv.Length()) ) + ? CtorFwdDispatch< T, CTOR >::Call(argv ) + : CtorFwdDispatchList::Call(argv); + } + }; + /** + End-of-list specialization. + */ + template + struct CtorFwdDispatchList + { + typedef typename TypeInfo::NativeHandle ReturnType; + /** Writes an error message to errmsg and returns 0. */ + static ReturnType Call( v8::Arguments const & argv ) + { + StringBuffer msg; + msg << "No native constructor was defined for "<, + CtorForwarder, + CtorForwarder, + CtorForwarder + )> Ctors; + @endcode + + All entries in the typelist must be interface-compatible with + CtorForwarder. No two entries should have the same number + of arguments with one exception: an InvocationCallback-like + function taking (v8::Arguments const &) can be used as a + catch-all for any number of arguments. If used, it must be + the LAST entry because it will always match any argument + count (and will therefore trump any which (would) come after + it. + + The ctors are dispatched based solely on the argument count, + not their types. The first one with a matching arity + is called. + + IN THEORY (untested), the factories passed in the list may + legally return a type publically derived from + CtorList::ReturnType. + */ + template + struct CtorArityDispatcher + { + typedef typename CtorList::ReturnType RT; + typedef typename TypeInfo::NativeHandle NativeHandle; + static NativeHandle Call( v8::Arguments const & argv ) + { + typedef typename tmp::PlainType::Type Type; + typedef Detail::CtorFwdDispatchList Proxy; + return Proxy::Call( argv ); + } + }; + +} // namespaces + + +#endif /* CODE_GOOGLE_COM_P_V8_CONVERT_CORE_HPP_INCLUDED */ diff --git a/vendor/libv8-convert/cvv8/detail/doxygen_hack.hpp b/vendor/libv8-convert/cvv8/detail/doxygen_hack.hpp new file mode 100644 index 000000000..85778705d --- /dev/null +++ b/vendor/libv8-convert/cvv8/detail/doxygen_hack.hpp @@ -0,0 +1,28 @@ +/** @file doxygen_hack.hpp + + doxygen REFUSES to document class templates i forward-decl, even when + adding "@class" to the docs. Being the doc-pedant that i am, i felt + compelled to work around that. With gcc we can add an empty body to + those classes but MSVC doesn't like it. So we leave it out unless + doxygen is building, and then doxygen needs to be configured with: + + - ENABLE_PREPROCESSING = YES + - EXPAND_AS_DEFINED = DOXYGEN_FWD_DECL_KLUDGE + + and possibly: + + - MACRO_EXPANSION = YES + + and/or: + + - EXPAND_ONLY_PREDEF = YES +*/ +#if !defined(DOXYGEN) +# if !defined DOXYGEN_FWD_DECL_KLUDGE +# define DOXYGEN_FWD_DECL_KLUDGE +# endif +#else +# if !defined DOXYGEN_FWD_DECL_KLUDGE +# define DOXYGEN_FWD_DECL_KLUDGE {} +# endif +#endif diff --git a/vendor/libv8-convert/cvv8/detail/invocable_core.hpp b/vendor/libv8-convert/cvv8/detail/invocable_core.hpp new file mode 100644 index 000000000..a47b3dcb8 --- /dev/null +++ b/vendor/libv8-convert/cvv8/detail/invocable_core.hpp @@ -0,0 +1,2202 @@ +#if !defined(CODE_GOOGLE_COM_V8_CONVERT_INVOCABLE_V8_HPP_INCLUDED) +#define CODE_GOOGLE_COM_V8_CONVERT_INVOCABLE_V8_HPP_INCLUDED 1 + +/** @file invocable_core.hpp + +This file houses the core-most "invocation-related" parts of the +v8-convert API. These types and functions are for converting +free and member functions to v8::InvocationCallback functions +so that they can be tied to JS objects. It relies on the +CastToJS() and CastFromJS() functions to do non-function type +conversion. + +*/ + +#include "convert_core.hpp" +#include "signature_core.hpp" + +namespace cvv8 { + +/** + A concept class, primarily for documentation and tag-type purposes. +*/ +struct InCa +{ + /** + Matches the v8::InvocationCallback interface. All function bindings + created by this framework use Call() as their class-level + InvocationCallback interface. Some bindings provide additional + overloads as well. + */ + static v8::Handle Call( v8::Arguments const & ); +}; + +/** + A tag type for use with FunctionTo and MethodTo. +*/ +struct InCaVoid : InCa {}; + + +/** + Partial specialization for v8::InvocationCallback-like functions + (differing only in their return type) with an Arity value of -1. +*/ +template +struct FunctionSignature< RV (v8::Arguments const &) > : Signature +{ + typedef RV (*FunctionType)(v8::Arguments const &); +}; + +/** + Partial specialization for v8::InvocationCallback-like non-const + member functions (differing only in their return type) with an + Arity value of -1. +*/ +template +struct MethodSignature< T, RV (v8::Arguments const &) > : Signature< RV (v8::Arguments const &) > +{ + typedef T Type; + typedef RV (T::*FunctionType)(v8::Arguments const &); +}; + +/** + Partial specialization for v8::InvocationCallback-like const member + functions (differing only in their return type) with an Arity value + of -1. +*/ +template +struct ConstMethodSignature< T, RV (v8::Arguments const &) > : Signature< RV (v8::Arguments const &) > +{ + typedef T Type; + typedef RV (T::*FunctionType)(v8::Arguments const &) const; +}; + +/** + Full specialization for InvocationCallback and + InvocationCallback-like functions (differing only by their return + type), which uses an Arity value of -1. +*/ +template +struct FunctionPtr + : FunctionSignature +{ + public: + typedef FunctionSignature SignatureType; + typedef typename SignatureType::ReturnType ReturnType; + typedef typename SignatureType::FunctionType FunctionType; + static FunctionType GetFunction() + { + return FuncPtr; + } +}; + +/** + Full specialization for InvocationCallback and + InvocationCallback-like functions (differing only by their return + type), which uses an Arity value of -1. +*/ +template +struct MethodPtr + : MethodSignature +{ + typedef MethodSignature SignatureType; + typedef typename SignatureType::ReturnType ReturnType; + typedef typename SignatureType::FunctionType FunctionType; + static FunctionType GetFunction() + { + return FuncPtr; + } +}; + +/** + Full specialization for InvocationCallback and + InvocationCallback-like functions (differing only by their return + type), which uses an Arity value of -1. +*/ +template +struct ConstMethodPtr + : ConstMethodSignature +{ + typedef ConstMethodSignature SignatureType; + typedef typename SignatureType::ReturnType ReturnType; + typedef typename SignatureType::FunctionType FunctionType; + static FunctionType GetFunction() + { + return FuncPtr; + } +}; + +#if !defined(DOXYGEN) +namespace Detail { + /** + A sentry class which instantiates a v8::Unlocker + if the boolean value is true or is a no-op if it is false. + */ + template struct V8Unlocker {}; + + /** + Equivalent to v8::Unlocker. + */ + template <> + struct V8Unlocker : v8::Unlocker + { + }; + + +} +#endif + +/** + A metatemplate which we can use to determine if a given type + is "safe" to use in conjunction with v8::Unlock. + + We optimistically assume that most types are safe and + add specializations for types we know are not safe, e.g. + v8::Handle and v8::Arguments. + + Specializations of this type basically make up a collective + "blacklist" of types which we know are not legal to use unless + v8 is locked by our current thread. As new problematic types are + discovered, they can be added to the blacklist by introducing a + specialization of this class. +*/ +template +struct IsUnlockable : tmp::BoolVal {}; +template +struct IsUnlockable : IsUnlockable {}; +template +struct IsUnlockable : IsUnlockable {}; +template +struct IsUnlockable : IsUnlockable {}; +template +struct IsUnlockable : IsUnlockable {}; + +/** + Explicit instantiation to make damned sure that nobody + re-sets this one. We rely on these semantics for + handling FunctionSignature like Const/MethodSignature + in some cases. +*/ +template <> +struct IsUnlockable : tmp::BoolVal {}; + +/* + Todo?: find a mechanism to cause certain highly illegal types to + always trigger an assertion... We could probably do it by + declaring but not definiting JSToNative/NativeToJS + specialializations. +*/ +template <> +struct IsUnlockable : tmp::BoolVal {}; + +template <> +struct IsUnlockable : tmp::BoolVal {}; + +template +struct IsUnlockable< v8::Handle > : tmp::BoolVal {}; + +template +struct IsUnlockable< v8::Persistent > : tmp::BoolVal {}; + +template +struct IsUnlockable< v8::Local > : tmp::BoolVal {}; + +template <> +struct IsUnlockable : tmp::BoolVal {}; + +/** + Given a tmp::TypeList-compatible type list, this metafunction's + Value member evalues to true if IsUnlockable::Value is + true for all types in TList, else Value evaluates to false. + As a special case, an empty list evaluates to true because in this + API an empty list will refer to a function taking no arguments. +*/ +template +struct TypeListIsUnlockable : tmp::BoolVal< + IsUnlockable::Value && TypeListIsUnlockable::Value + > +{ +}; + +//! End-of-typelist specialization. +template <> +struct TypeListIsUnlockable< tmp::NilType > : tmp::BoolVal +{}; +/** + Given a Signature, this metafunction's Value member + evaluates to true if: + + - IsUnlockable::Value is true and... + + - IsUnlockable::Value is true (only relavent + for Const/MethodSignature, not FunctionSignature) and... + + - TypeListIsUnlockable< SigTList >::Value is true. + + If the value is true, the function signature has passed the most + basic check for whether or not it is legal to use v8::Unlocker + to unlock v8 before calling a function with this signature. Note + that this is a best guess, but this code cannot know + app-specific conditions which might make this guess invalid. + e.g. if a bound function itself uses v8 and does not explicitly + acquire a lock then the results are undefined (and will very + possibly trigger an assertion in v8, killing the app). Such + things can and do happen. If you're lucky, you're building + against a debug version of libv8 and its assertion text will + point you directly to the JS code which caused the assertion, + then you can disable unlocking support for that binding. + + If you want to disable unlocking for all bound members of a given + class, create an IsUnlockable specialization whos Value + member evaluates to false. Then no functions/methods using that + class will cause this metafunction to evaluate to true. + + Note that FunctionToInCa, Const/MethodToInCa, etc., are all + Signature subclasses, and can be used directly with + this template. + + Example: + + @code + // This one can be unlocked: + typedef FunctionSignature< int (int) > F1; + // SignatureIsUnlockable::Value == true + + // This one cannot because it contains a v8 type in the arguments: + typedef FunctionSignature< int (v8::Handle) > F2; + // SignatureIsUnlockable::Value == false + @endcode + + For Const/MethodToInCa types, this check will also fail if + IsUnlockable< SigTList::Context >::Value is false. +*/ +template +struct SignatureIsUnlockable : tmp::BoolVal< + IsUnlockable::Value && + IsUnlockable::Value && + IsUnlockable::Value && + SignatureIsUnlockable::Value + > {}; +//! End-of-list specialization. +template <> +struct SignatureIsUnlockable : tmp::BoolVal {}; + +/** + Internal exception type to allow us to differentiate + "no native 'this' pointer found" errors from all other + exceptions. It is thrown by the CallNative() functions + of various JS-to-Native function forwarders. +*/ +struct MissingThisException +{ +protected: + StringBuffer msg; + template + void init() + { + this->msg << "CastFromJS<"<< TypeName::Value + << ">() returned NULL. Throwing to avoid " + << "dereferencing a NULL pointer!"; + } + MissingThisException() {} +public: + /** + Returns the exception message text, which does not change + after construction. + */ + StringBuffer const & Buffer() const { return msg; } +}; + + +/** + This special-case convenience form of Toss() triggers a JS-side + exception containing an English-language message explaining that + CastFromJS() failed, i.e. the native 'this' pointer for a bound + native T object could not be found. It uses TypeName::Value as the + class' name. + + This is primarily intended for use in two cases: + + - Internally in the cvv8 binding mechanisms. + + - In client code when binding non-member functions as JS-side methods of + native objects. + + Returns the result of v8::ThrowException(...). + + Example: + + @code + v8::Handle my_bound_func( v8::Arguments const & argv ) { + T * self = CastFromJS( argv.This() ); + if( ! self ) { + return TossMissingThis(); + } + ... + } + @endcode + + BUG: TypeName::Value is NOT used here because... If we instantiate + TypeName<> from here then we require a value for TypeName<>::Value or we + break FunctorTo and friends (because TypeName'ing functors isn't always + possible). The problem with that is that i want to use TypeName::Value's + address as a type key and that can't work cross-DLL on Windows (and + possibly other platforms) if we have a default value for TypeName::Value. + i hope to eventually find a solution which is both cross-platform and + allows us to invoke TypeName::Value from here. +*/ +template +v8::Handle TossMissingThis() +{ + return Toss(StringBuffer()<<"CastFromJS<" +#if 0 + <::Value +#else + <<'T' +#endif + <<">() returned NULL! Cannot find 'this' pointer!"); +} + +#if !defined(DOXYGEN) +namespace Detail { +/** Temporary internal macro. Undef'd at the end of this file. */ +#define HANDLE_PROPAGATE_EXCEPTION catch( MissingThisException const & ){ return TossMissingThis(); } \ + catch(...){ throw; } (void)0/* (void)0 is a hack to help emacs' indentation out!*/ + + /** + A MissingThisException type holding generic + message text which references TypeName::Value + as being the problematic class. + */ + template + struct MissingThisExceptionT : MissingThisException + { + MissingThisExceptionT() + { + this->init(); + } + }; + +/** + Temporary internal macro to trigger a static assertion if unlocking + support is requested but cannot be implemented for the given + wrapper due to constraints on our use of v8 when it is unlocked. + + This differs from ASSERT_UNLOCK_SANITY_CHECK in that this is intended + for use with functions which we _know_ (while coding, as opposed to + finding out at compile time) are not legally unlockable. +*/ +#define ASSERT_UNLOCKV8_IS_FALSE typedef char ThisSpecializationCannotUseV8Unlocker[!UnlockV8 ? 1 : -1] +/** + Temporary internal macro to trigger a static assertion if: + UnlockV8 is true and SignatureIsUnlockable::Value is false. + This is to prohibit that someone accidentally enables locking + when using a function type which we know (based on its + signature's types) cannot obey the (un)locking rules. +*/ +#define ASSERT_UNLOCK_SANITY_CHECK typedef char AssertCanEnableUnlock[ \ + !UnlockV8 ? 1 : (SignatureIsUnlockable< SignatureType >::Value ? 1 : -1) \ + ] + + template >::Value > + struct FunctionForwarder DOXYGEN_FWD_DECL_KLUDGE; + + template + struct FunctionForwarder + : FunctionSignature + { + public: + typedef FunctionSignature SignatureType; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + return (RV) func(argv); + } + + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + return CastToJS( CallNative( func, argv ) ); + } + + ASSERT_UNLOCKV8_IS_FALSE; + typedef char AssertArity[ sl::Arity::Value == -1 ? 1 : -1]; + }; + + //! Reminder to self: we really do need this specialization for some cases. + template + struct FunctionForwarder + : FunctionForwarder + {}; + + template + struct FunctionForwarder<0,Sig, UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef typename SignatureType::ReturnType ReturnType; + typedef typename SignatureType::FunctionType FunctionType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & ) + { + V8Unlocker const & unlocker = ( V8Unlocker() ); + return func(); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + return CastToJS( CallNative( func, argv ) ); + } + ASSERT_UNLOCK_SANITY_CHECK; + typedef char AssertArity[ sl::Arity::Value == 0 ? 1 : -1]; + }; + + template >::Value> + struct FunctionForwarderVoid DOXYGEN_FWD_DECL_KLUDGE; + + template + struct FunctionForwarderVoid<0,Sig, UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef typename SignatureType::ReturnType ReturnType; + typedef Sig FunctionType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & ) + { + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)func() + /* the explicit cast there is a workaround for the RV==void + case. It is a no-op for other cases, since the return value + is already RV. Some compilers (MSVC) don't allow an explicit + return of a void expression without the cast. + */; + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + CallNative( func, argv ); + return v8::Undefined(); + } + ASSERT_UNLOCK_SANITY_CHECK; + typedef char AssertArity[ sl::Arity::Value == 0 ? 1 : -1]; + }; + + template + struct FunctionForwarderVoid + : FunctionSignature + { + public: + typedef FunctionSignature SignatureType; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)func(argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + CallNative( func, argv ); + return v8::Undefined(); + } + ASSERT_UNLOCKV8_IS_FALSE; + typedef char AssertArity[ sl::Arity::Value == -1 ? 1 : -1]; + }; + + /** + Internal impl for cvv8::ConstMethodForwarder. + */ + template >::Value + > + struct MethodForwarder DOXYGEN_FWD_DECL_KLUDGE; + + + template + struct MethodForwarder : MethodSignature + { + public: + typedef MethodSignature SignatureType; + typedef typename SignatureType::ReturnType ReturnType; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename TypeInfo::Type Type; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (self.*func)(); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + return CastToJS( CallNative( self, func, argv ) ); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + return CastToJS( CallNative( func, argv ) ); + } + HANDLE_PROPAGATE_EXCEPTION; + } + + ASSERT_UNLOCK_SANITY_CHECK; + }; + + template + struct MethodForwarder + : MethodSignature + { + public: + typedef MethodSignature SignatureType; + typedef char AssertArity[ sl::Arity::Value == -1 ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + return (self.*func)(argv); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + return CastToJS( CallNative( self, func, argv ) ); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + return CastToJS( CallNative(func, argv) ); + } + HANDLE_PROPAGATE_EXCEPTION; + } + ASSERT_UNLOCKV8_IS_FALSE; + }; + + template + struct MethodForwarder : + MethodForwarder + {}; + + template >::Value + > + struct MethodForwarderVoid DOXYGEN_FWD_DECL_KLUDGE; + + template + struct MethodForwarderVoid + : MethodSignature + { + public: + typedef MethodSignature SignatureType; + typedef typename SignatureType::FunctionType FunctionType; + typedef T Type; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( Type & self, FunctionType func, v8::Arguments const & ) + { + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)(); + } + static v8::Handle Call( Type & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct MethodForwarderVoid + : MethodSignature + { + public: + typedef MethodSignature SignatureType; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename TypeInfo::Type Type; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( Type & self, FunctionType func, v8::Arguments const & argv ) + { + return (ReturnType)(self.*func)(argv); + } + static v8::Handle Call( Type & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + ASSERT_UNLOCKV8_IS_FALSE; + }; + + template + struct MethodForwarderVoid + : MethodForwarderVoid + {}; + + /** + Internal impl for cvv8::ConstMethodForwarder. + */ + template >::Value + > + struct ConstMethodForwarder DOXYGEN_FWD_DECL_KLUDGE; + + template + struct ConstMethodForwarder : ConstMethodSignature + { + public: + typedef ConstMethodSignature SignatureType; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & ) + { + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (self.*func)(); + } + + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + return CastToJS( CallNative( self, func, argv ) ); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + return CastToJS( CallNative(func, argv) ); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct ConstMethodForwarder + : ConstMethodSignature + { + public: + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ sl::Arity::Value == -1 ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + return (ReturnType)(self.*func)(argv); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + return CastToJS( CallNative( self, func, argv ) ); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + return CastToJS( CallNative(func, argv) ); + } + HANDLE_PROPAGATE_EXCEPTION; + } + ASSERT_UNLOCKV8_IS_FALSE; + }; + + template + struct ConstMethodForwarder + : ConstMethodForwarder + {}; + + template >::Value + > + struct ConstMethodForwarderVoid DOXYGEN_FWD_DECL_KLUDGE; + + template + struct ConstMethodForwarderVoid : ConstMethodSignature + { + public: + typedef ConstMethodSignature SignatureType; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + typedef typename TypeInfo::Type Type; + static ReturnType CallNative( Type const & self, FunctionType func, v8::Arguments const & ) + { + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)(); + } + + static v8::Handle Call( Type const & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + ASSERT_UNLOCK_SANITY_CHECK; + }; + + template + struct ConstMethodForwarderVoid + : ConstMethodSignature + { + public: + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ sl::Arity::Value == -1 ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + typedef typename TypeInfo::Type Type; + static ReturnType CallNative( Type const & self, FunctionType func, v8::Arguments const & argv ) + { + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)(); + } + static v8::Handle Call( Type const & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + return CastToJS( CallNative( func, argv ) ); + } + HANDLE_PROPAGATE_EXCEPTION; + } + ASSERT_UNLOCKV8_IS_FALSE; + }; + + template + struct ConstMethodForwarderVoid + : ConstMethodForwarderVoid + {}; + +} +#endif // DOXYGEN + +/** + A helper type for passing v8::Arguments lists to native non-member + functions. + + Sig must be a function-signature-like argument. e.g. , + and the members of this class expect functions matching that signature. + + If UnlockV8 is true then v8::Unlocker will be used to unlock v8 + for the duration of the call to Func(). HOWEVER... (the rest of + these docs are about the caveats)... + + A UnlockV8 value of SignatureIsUnlockable::Value uses a + reasonably sound heuristic but it cannot predict certain + app-dependent conditions which render its guess semantically + invalid. See SignatureIsUnlockable for more information. + + It is illegal for UnlockV8 to be true if ANY of the following + applies: + + - The callback itself will "use" v8 but does not explicitly use + v8::Locker. If it uses v8::Locker then it may safely enable + unlocking support. We cannot determine via templates whether + or not a function "uses" v8 except by guessing based on the + return and arguments types. + + - Any of the return or argument types for the function are v8 + types, e.g. v8::Handle or v8::Arguments. + SignatureIsUnlockable::Value will evaluate to false + if any of the "known bad" types is contained in the function's + signature. If this function is given a true value but + SignatureIsUnlockable::Value is false then + a compile-time assertion will be triggered. + + - Certain callback signatures cannot have unlocking support + enabled because if we unlock then we cannot legally access the data + we need to convert. These will cause a compile-time assertion + if UnlockV8 is true. All such bits are incidentally covered by + SignatureIsUnlockable's check, so this assertion can + only happen if the client explicitly sets UnlockV8 to true for + those few cases. + + - There might be other, as yet unknown/undocumented, corner cases + where unlocking v8 is semantically illegal at this level of the + API. + + Violating any of these leads to undefined behaviour. The library + tries to fail at compile time for invalid combinations when it + can, but (as described aboved) it can be fooled into thinking that + unlocking is safe. + + Reminder to self: we can implement this completely via inheritance of + the internal Proxy type, but i REALLY want the API docs out here at this + level instead of in the Detail namespace (which i filter out of doxygen + for the most part). +*/ +template >::Value +> +struct FunctionForwarder +{ +private: + typedef typename tmp::IfElse< tmp::SameType::ReturnType>::Value, + Detail::FunctionForwarderVoid< sl::Arity< Signature >::Value, Sig, UnlockV8 >, + Detail::FunctionForwarder< sl::Arity< Signature >::Value, Sig, UnlockV8 > + >::Type + Proxy; +public: + typedef typename Proxy::SignatureType SignatureType; + typedef typename Proxy::ReturnType ReturnType; + typedef typename Proxy::FunctionType FunctionType; + /** + Passes the given arguments to func(), converting them to the appropriate + types. If argv.Length() is less than sl::Arity< SignatureType >::Value then + a JS exception is thrown, with one exception: if the function has "-1 arity" + (i.e. it is InvocationCallback-like) then argv is passed on to it regardless + of the value of argv.Length(). + + The native return value of the call is returned to the caller. + */ + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + return Proxy::CallNative( func, argv ); + } + /** + Equivalent to CastToJS( CallNative(func,argv) ) unless ReturnType + is void, in which case CastToJS() is not invoked and v8::Undefined() + will be returned. + */ + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + return Proxy::Call( func, argv ); + } +}; + +/** + CallForwarder basically does the opposite of FunctionForwarder: it + converts native arguments to JS and calls a JS function. + + The default implementation is useless - it must be specialized + for each arity. +*/ +template +struct CallForwarder +{ + /** + Implementations must be templates taking Arity arguments in addition + to the first two. All argument types must legal for use with + CastToJS(). + + If either self or func.IsEmpty() then a JS exception must be thrown, + else implementations must return func->Call(self, N, ARGS), where + ARGS is an array of v8::Handle and N is the number of + items in that array (and, not coincidentally, is the same value as + Arity). The ARGS array must be populated by calling CastToJS(ARG_N) + for each argument, where ARG_N is the Nth argument. + */ + static v8::Handle Call( v8::Handle const & self, + v8::Handle const & func, + ... ); + /** + Convenience form of Call() which must be equivalent to + Call(func,func,...). + */ + static v8::Handle Call( v8::Handle const & func, ... ); +}; + +//! Specialization for 0-arity calls. +template <> +struct CallForwarder<0> +{ + static v8::Handle Call( v8::Handle const & self, + v8::Handle const & func ) + { + return (self.IsEmpty() || func.IsEmpty()) + ? Toss("Illegal argument: empty v8::Handle<>.") + : func->Call(self, 0, NULL); + } + static v8::Handle Call( v8::Handle const & func ) + { + return Call( func, func ); + } +}; + + +#if !defined(DOXYGEN) +namespace Detail { + + /** + Base internal implementation of cvv8::FunctionToInCa. + */ + template ::FunctionType Func, + bool UnlockV8 = SignatureIsUnlockable< FunctionSignature >::Value > + struct FunctionToInCa : FunctionPtr, InCa + { + + typedef FunctionSignature SignatureType; + typedef FunctionForwarder< sl::Arity::Value, Sig, UnlockV8 > Proxy; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( v8::Arguments const & argv ) + { + return (ReturnType)Proxy::CallNative( Func, argv ); + /** + The (ReturnType) cast is effectively a no-op for all types + except void, where it is used to get around a limitation in + some compilers which does not allow us to explicitly return + foo() when foo() returns void. + */ + } + static v8::Handle Call( v8::Arguments const & argv ) + { + return Proxy::Call( Func, argv ); + } + ASSERT_UNLOCK_SANITY_CHECK; + }; + + /** Almost identical to FunctionToInCa, but expressly does not + instantiate NativeToJS< Signature::ReturnType >, meaning + that: + + a) it can proxy functions which have non-convertible return types. + + b) JS always gets the 'undefined' JS value as the return value. + */ + template ::FunctionType Func, + bool UnlockV8 = SignatureIsUnlockable< FunctionSignature >::Value > + struct FunctionToInCaVoid : FunctionPtr, InCa + { + typedef FunctionSignature SignatureType; + typedef FunctionForwarderVoid< sl::Arity::Value, Sig, UnlockV8 > Proxy; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( v8::Arguments const & argv ) + { + return (ReturnType)Proxy::CallNative( Func, argv ); + } + static v8::Handle Call( v8::Arguments const & argv ) + { + return Proxy::Call( Func, argv ); + } + ASSERT_UNLOCK_SANITY_CHECK; + }; + + /** Method equivalent to FunctionToInCa. */ + template ::FunctionType Func, + bool UnlockV8 = SignatureIsUnlockable< MethodSignature >::Value + > + struct MethodToInCa : MethodPtr, InCa + { + typedef MethodPtr SignatureType; + enum { Arity = sl::Arity::Value }; + typedef MethodForwarder< T, Arity, Sig, UnlockV8 > Proxy; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, v8::Arguments const & argv ) + { + return Proxy::CallNative( self, Func, argv ); + } + static ReturnType CallNative( v8::Arguments const & argv ) + { + return Proxy::Call( Func, argv ); + } + static v8::Handle Call( v8::Arguments const & argv ) + { + return Proxy::Call( Func, argv ); + } + static v8::Handle Call( T & self, v8::Arguments const & argv ) + { + return Proxy::Call( self, Func, argv ); + } + ASSERT_UNLOCK_SANITY_CHECK; + }; + + /** Method equivalent to FunctionToInCaVoid. */ + template ::FunctionType Func, + bool UnlockV8 = SignatureIsUnlockable< MethodSignature >::Value + > + struct MethodToInCaVoid : MethodPtr, InCa + { + typedef MethodPtr SignatureType; + enum { Arity = sl::Arity::Value }; + typedef MethodForwarderVoid< T, Arity, Sig, UnlockV8 > Proxy; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, v8::Arguments const & argv ) + { + return Proxy::CallNative( self, Func, argv ); + } + static ReturnType CallNative( v8::Arguments const & argv ) + { + return Proxy::Call( Func, argv ); + } + static v8::Handle Call( v8::Arguments const & argv ) + { + return Proxy::Call( Func, argv ); + } + static v8::Handle Call( T & self, v8::Arguments const & argv ) + { + return Proxy::Call( self, Func, argv ); + } + ASSERT_UNLOCK_SANITY_CHECK; + }; + + /** Const method equivalent to MethodToInCa. */ + template ::FunctionType Func, + bool UnlockV8 = SignatureIsUnlockable< ConstMethodSignature >::Value + > + struct ConstMethodToInCa : ConstMethodPtr, InCa + { + typedef ConstMethodPtr SignatureType; + typedef ConstMethodForwarder< T, sl::Arity::Value, Sig, UnlockV8 > Proxy; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, v8::Arguments const & argv ) + { + return Proxy::CallNative( self, Func, argv ); + } + static ReturnType CallNative( v8::Arguments const & argv ) + { + return Proxy::Call( Func, argv ); + } + static v8::Handle Call( v8::Arguments const & argv ) + { + return Proxy::Call( Func, argv ); + } + static v8::Handle Call( T const & self, v8::Arguments const & argv ) + { + return Proxy::Call( self, Func, argv ); + } + }; + + template ::FunctionType Func, + bool UnlockV8 = SignatureIsUnlockable< ConstMethodSignature >::Value + > + struct ConstMethodToInCaVoid : ConstMethodPtr, InCa + { + typedef ConstMethodPtr SignatureType; + typedef ConstMethodForwarderVoid< T, sl::Arity::Value, Sig, UnlockV8 > Proxy; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, v8::Arguments const & argv ) + { + return Proxy::CallNative( self, Func, argv ); + } + static ReturnType CallNative( v8::Arguments const & argv ) + { + return Proxy::Call( Func, argv ); + } + static v8::Handle Call( v8::Arguments const & argv ) + { + return Proxy::Call( Func, argv ); + } + static v8::Handle Call( T const & self, v8::Arguments const & argv ) + { + return Proxy::Call( self, Func, argv ); + } + ASSERT_UNLOCK_SANITY_CHECK; + }; + +} // Detail namespace +#endif // DOXYGEN +#undef ASSERT_UNLOCK_SANITY_CHECK +#undef ASSERT_UNLOCKV8_IS_FALSE + + +/** + A template for converting free (non-member) function pointers + to v8::InvocationCallback. + + Sig must be a function signature. Func must be a pointer to a function + with that signature. + + If UnlockV8 is true then v8::Unlocker will be used to unlock v8 + for the duration of the call to Func(). HOWEVER... see + FunctionForwarder for the details/caveats regarding that + parameter. + + Example: + + @code + v8::InvocationCallback cb = + FunctionToInCa< int (int), ::putchar>::Call; + @endcode +*/ +template ::FunctionType Func, + bool UnlockV8 = SignatureIsUnlockable< Signature >::Value + > +struct FunctionToInCa + : tmp::IfElse< tmp::SameType::ReturnType>::Value, + Detail::FunctionToInCaVoid< Sig, Func, UnlockV8>, + Detail::FunctionToInCa< Sig, Func, UnlockV8> + >::Type +{}; + +/** + A variant of FunctionToInCa with the property of NOT invoking the + conversion of the function's return type from native to JS form. i.e. it + does not cause NativeToJS< Signature::ReturnType > to be + instantiated. This is useful when such a conversion is not legal because + CastToJS() won't work on it or, more generally, when you want the JS + interface to always get the undefined return value. + + Call() always returns v8::Undefined(). CallNative(), however, + returns the real return type specified by Sig (which may be void). + + Example: + + @code + v8::InvocationCallback cb = + FunctionToInCaVoid< int (int), ::putchar>::Call; + @endcode +*/ +template ::FunctionType Func, + bool UnlockV8 = SignatureIsUnlockable< Signature >::Value + > +struct FunctionToInCaVoid : Detail::FunctionToInCaVoid< Sig, Func, UnlockV8> +{}; + + +/** + A template for converting non-const member function pointers to + v8::InvocationCallback. If T is const qualified then this works + as for ConstMethodToInCaVoid. + + To convert JS objects to native 'this' pointers this API uses + CastFromJS(arguments.This()), where arguments is the + v8::Arguments instance passed to the generated InvocationCallback + implementation. If that conversion fails then the generated + functions will throw a JS-side exception when called. + + T must be some client-specified type which is presumably bound (or + at least bindable) to JS-side Objects. Sig must be a member + function signature for T. Func must be a pointer to a function with + that signature. + + See FunctionForwarder for details about the UnlockV8 parameter. + + Example: + + @code + v8::InvocationCallback cb = + MethodToInCa::Call; + // For const methods: + cb = MethodToInCa::Call; + @endcode +*/ +template ::FunctionType Func, + bool UnlockV8 = SignatureIsUnlockable< MethodSignature >::Value + > +struct MethodToInCa + : tmp::IfElse< tmp::SameType::ReturnType>::Value, + Detail::MethodToInCaVoid, + Detail::MethodToInCa + >::Type +{ +}; + +/** + See FunctionToInCaVoid - this is identical exception that it + works on member functions of T. If T is const qualified + then this works as for ConstMethodToInCaVoid. + + Example: + + @code + v8::InvocationCallback cb = + MethodToInCaVoid< T, int (int), &T::myFunc>::Call; + @endcode + +*/ +template ::FunctionType Func, + bool UnlockV8 = SignatureIsUnlockable< MethodSignature >::Value + > +struct MethodToInCaVoid + : Detail::MethodToInCaVoid +{ +}; + +#if !defined(DOXYGEN) +namespace Detail { + template + struct FunctorToInCaSelector : ConstMethodForwarder >::Value, Sig, UnlockV8> + { + }; + template + struct FunctorToInCaSelector : ConstMethodForwarderVoid >::Value, Sig, UnlockV8> + {}; +} +#endif + +/** + This class converts a functor to an InvocationCallback. Ftor must + be a functor type. Sig must be a signature unambiguously matching + a Ftor::operator() implementation and Ftor::operator() must be + const. UnlockV8 is as described for FunctionToInCa. +*/ +template >::Value + > +struct FunctorToInCa : InCa +{ + inline static v8::Handle Call( v8::Arguments const & argv ) + { + typedef Detail::FunctorToInCaSelector< + typename Signature::ReturnType, Ftor, Sig, UnlockV8 + > Proxy; + return Proxy::Call( Ftor(), &Ftor::operator(), argv ); + } +}; + +/** + The functor equivalent of FunctionToInCaVoid. See FunctorToInCa for + the requirements of the Ftor and Sig types. +*/ +template >::Value + > +struct FunctorToInCaVoid : InCa +{ + inline static v8::Handle Call( v8::Arguments const & argv ) + { + typedef Detail::FunctorToInCaSelector< + void, Ftor, Sig, UnlockV8 + > Proxy; + return Proxy::Call( Ftor(), &Ftor::operator(), argv ); + } +}; + +/** + Functionally identical to MethodToInCa, but for const member functions. + + See FunctionForwarder for details about the UnlockV8 parameter. + + Note that the Sig signature must be suffixed with a const qualifier! + + Example: + + @code + v8::InvocationCallback cb = + ConstMethodToInCa< T, int (int), &T::myFunc>::Call; + @endcode + +*/ +template ::FunctionType Func, + bool UnlockV8 = SignatureIsUnlockable< ConstMethodSignature >::Value + > +struct ConstMethodToInCa +#if 0 // not working due to an ambiguous Sig vs Sig. Kinda weird, since MethodToInCa works. + : MethodToInCa {}; +#else + : tmp::IfElse< tmp::SameType::ReturnType>::Value, + Detail::ConstMethodToInCaVoid, + Detail::ConstMethodToInCa + >::Type +{}; +#endif +/** + See FunctionToInCaVoid - this is identical exception that it + works on const member functions of T. + + Note that the Sig signature must be suffixed with a const qualifier! + + Example: + + @code + v8::InvocationCallback cb = + ConstMethodToInCaVoid< T, int (int), &T::myFunc>::Call; + @endcode + +*/ +template ::FunctionType Func, + bool UnlockV8 = SignatureIsUnlockable< ConstMethodSignature >::Value + > +struct ConstMethodToInCaVoid : Detail::ConstMethodToInCaVoid +{}; + +/** + Identicial to FunctionForwarder, but works on non-const + member methods of type T. + + Sig must be a function-signature-like argument. e.g. , and the members of this class expect T member + functions matching that signature. +*/ +template >::Value> +struct MethodForwarder +{ +private: + typedef typename + tmp::IfElse< tmp::SameType::ReturnType>::Value, + Detail::MethodForwarderVoid< T, sl::Arity< Signature >::Value, Sig, UnlockV8 >, + Detail::MethodForwarder< T, sl::Arity< Signature >::Value, Sig, UnlockV8 > + >::Type + Proxy; +public: + typedef typename Proxy::SignatureType SignatureType; + typedef typename Proxy::FunctionType FunctionType; + typedef typename Proxy::ReturnType ReturnType; + /** + Passes the given arguments to (self.*func)(), converting them + to the appropriate types. If argv.Length() is less than + sl::Arity::Value then a JS exception is + thrown, with one exception: if the function has "-1 arity" + (i.e. it is InvocationCallback-like) then argv is passed on + to it regardless of the value of argv.Length(). + */ + inline static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + return Proxy::Call( self, func, argv ); + } + + /** + Like the 3-arg overload, but tries to extract the (T*) object using + CastFromJS(argv.This()). + */ + inline static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + return Proxy::Call( func, argv ); + } +}; + + +/** + Identical to MethodForwarder, but works on const member methods. +*/ +template >::Value + > +struct ConstMethodForwarder +#if 1 //?msvc Seems to work. +: MethodForwarder {}; +#else +{ +private: + typedef typename + tmp::IfElse< tmp::SameType::ReturnType>::Value, + Detail::ConstMethodForwarderVoid< T, sl::Arity< Signature >::Value, Sig, UnlockV8 >, + Detail::ConstMethodForwarder< T, sl::Arity< Signature >::Value, Sig, UnlockV8 > + >::Type + Proxy; +public: + typedef typename Proxy::SignatureType SignatureType; + typedef typename Proxy::FunctionType FunctionType; + + /** + Passes the given arguments to (self.*func)(), converting them + to the appropriate types. If argv.Length() is less than + sl::Arity< Signature >::Value then a JS exception is thrown, with one + exception: if the function has "-1 arity" (i.e. it is + InvocationCallback-like) then argv is passed on to it + regardless of the value of argv.Length(). + */ + inline static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + return Proxy::Call( self, func, argv ); + } + + /** + Like the 3-arg overload, but tries to extract the (T const *) + object using CastFromJS(argv.This()). + */ + inline static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + return Proxy::Call( func, argv ); + } +}; +#endif + +/** + Tries to forward the given arguments to the given native + function. Will fail if argv.Lengt() is not at least + sl::Arity>::Value, throwing a JS exception in that + case _unless_ the function is InvocationCallback-like, in which + case argv is passed directly to it regardless of the value of + argv.Length(). +*/ +template +inline typename FunctionSignature::ReturnType +forwardFunction( Sig func, v8::Arguments const & argv ) +{ + typedef FunctionSignature MSIG; + typedef typename MSIG::ReturnType RV; + enum { Arity = sl::Arity< Signature >::Value }; + typedef typename + tmp::IfElse< tmp::SameType::Value, + Detail::FunctionForwarderVoid< Arity, Sig >, + Detail::FunctionForwarder< Arity, Sig > + >::Type Proxy; + return (RV)Proxy::CallNative( func, argv ); +} + +/** + Works like forwardFunction(), but forwards to the + given non-const member function and treats the given object + as the 'this' pointer. +*/ +template +inline typename MethodSignature::ReturnType +forwardMethod( T & self, + Sig func, + /* if i do: typename MethodSignature::FunctionType + then this template is never selected. */ + v8::Arguments const & argv ) +{ + typedef MethodSignature MSIG; + typedef typename MSIG::ReturnType RV; + enum { Arity = sl::Arity< MSIG >::Value }; + typedef typename + tmp::IfElse< tmp::SameType::Value, + Detail::MethodForwarderVoid< T, Arity, Sig >, + Detail::MethodForwarder< T, Arity, Sig > + >::Type Proxy; + return (RV)Proxy::CallNative( self, func, argv ); +} + +/** + Like the 3-arg forwardMethod() overload, but + extracts the native T 'this' object from argv.This(). + + Note that this function requires that the caller specify + the T template parameter - it cannot deduce it. +*/ +template +inline typename MethodSignature::ReturnType +forwardMethod(Sig func, v8::Arguments const & argv ) +{ + typedef MethodSignature MSIG; + typedef typename MSIG::ReturnType RV; + enum { Arity = sl::Arity< MSIG >::Value }; + typedef typename + tmp::IfElse< tmp::SameType::Value, + Detail::MethodForwarderVoid< T, Arity, Sig >, + Detail::MethodForwarder< T, Arity, Sig > + >::Type Proxy; + return (RV)Proxy::CallNative( func, argv ); +} + + +/** + Works like forwardMethod(), but forwards to the given const member + function and treats the given object as the 'this' pointer. + +*/ +template +inline typename ConstMethodSignature::ReturnType +forwardConstMethod( T const & self, + //typename ConstMethodSignature::FunctionType func, + Sig func, + v8::Arguments const & argv ) +{ + typedef ConstMethodSignature MSIG; + typedef typename MSIG::ReturnType RV; + enum { Arity = sl::Arity< MSIG >::Value }; + typedef typename + tmp::IfElse< tmp::SameType::Value, + Detail::ConstMethodForwarderVoid< T, Arity, Sig >, + Detail::ConstMethodForwarder< T, Arity, Sig > + >::Type Proxy; + return (RV)Proxy::CallNative( self, func, argv ); +} + +/** + Like the 3-arg forwardConstMethod() overload, but + extracts the native T 'this' object from argv.This(). + + Note that this function requires that the caller specify + the T template parameter - it cannot deduce it. +*/ +template +inline typename ConstMethodSignature::ReturnType +forwardConstMethod(Sig func, v8::Arguments const & argv ) +{ + typedef ConstMethodSignature MSIG; + typedef typename MSIG::ReturnType RV; + enum { Arity = sl::Arity< MSIG >::Value }; + typedef typename + tmp::IfElse< tmp::SameType::Value, + Detail::ConstMethodForwarderVoid< T, Arity, Sig >, + Detail::ConstMethodForwarder< T, Arity, Sig > + >::Type Proxy; + return (RV)Proxy::CallNative( func, argv ); +} + +/** + A structified/functorified form of v8::InvocationCallback. It is + sometimes convenient to be able to use a typedef to create an alias + for a given InvocationCallback. Since we cannot typedef function + templates this way, this class can fill that gap. +*/ +template +struct InCaToInCa : FunctionToInCa< v8::Handle (v8::Arguments const &), ICB> +{ +}; + + +#if 0 // YAGNI +/** + "Converts" an InCaToInCa instance to JS by treating it as an + InvocationCallback function. This is primarily useful in + conjunction with ClassCreator::Set() to add function bindings. +*/ +template +struct NativeToJS< InCaToInCa > +{ + /** + Returns a JS handle to InCaToInCa::Call(). + */ + v8::Handle operator()( InCaToInCa const & ) + { + return v8::FunctionTemplate::New(InCaToInCa::Call)->GetFunction(); + } +}; +#endif + +#if !defined(DOXYGEN) +namespace Detail { + /** Internal code duplication reducer. */ + template + v8::Handle TossArgCountError( v8::Arguments const & args ) + { + return Toss((StringBuffer() + <<"Incorrect argument count ("< > +> +struct ArityDispatch : InCa +{ + /** + When called, if (Artity==-1) or if (Arity==args.Length()) then + InCaT::Call(args) is returned, else Fallback::Call(args) is returned. + + Implements the InvocationCallback interface. + */ + inline static v8::Handle Call( v8::Arguments const & args ) + { + return ( (-1==Arity) || (Arity == args.Length()) ) + ? InCaT::Call(args) + : Fallback::Call(args); + } +}; + + +/** + InvocationCallback wrapper which calls another InvocationCallback + and translates any native ExceptionT exceptions thrown by that + function into JS exceptions. + + ExceptionT must be an exception type which is thrown by const + reference (e.g. STL-style) as opposed to by pointer (MFC-style). + + SigGetMsg must be a function-signature-style argument describing + a method within ExceptionT which can be used to fetch the message + reported by the exception. It must meet these requirements: + + a) Be const + b) Take no arguments + c) Return a type convertible to JS via CastToJS() + + Getter must be a pointer to a function matching that signature. + + InCaT must be a InCa type. When Call() is called by v8, it will pass + on the call to InCaT::Call() and catch exceptions as described below. + + Exceptions of type (ExceptionT const &) and (ExceptionT const *) which + are thrown by ICB get translated into a JS exception with an error + message fetched using ExceptionT::Getter(). + + If PropagateOtherExceptions is true then exception of types other + than ExceptionT are re-thrown (which can be fatal to v8, so be + careful). If it is false then they are not propagated but the error + message in the generated JS exception is unspecified (because we + have no generic way to get such a message). If a client needs to + catch multiple exception types, enable propagation and chain the + callbacks together. In such a case, the outer-most (last) callback + in the chain should not propagate unknown exceptions (to avoid + killing v8). + + This type can be used to implement "chaining" of exception + catching, such that we can use the InCaCatcher + to catch various distinct exception types in the context + of one v8::InvocationCallback call. + + Example: + + @code + // Here we want to catch MyExceptionType, std::runtime_error, and + // std::exception (the base class of std::runtime_error, by the + // way) separately: + + // When catching within an exception hierarchy, start with the most + // specific (most-derived) exceptions. + + // Client-specified exception type: + typedef InCaCatcher< + MyExceptionType, + std::string (), + &MyExceptionType::getMessage, + InCaToInCa, // the "real" InvocationCallback + true // make sure propagation is turned on so chaining can work! + > Catch_MyEx; + + // std::runtime_error: + typedef InCaCatcher_std< Catch_MyEx, std::runtime_error > Catch_RTE; + + // std::exception: + typedef InCaCatcher_std< Catch_RTE > MyCatcher; + + // Now MyCatcher::Call is-a InvocationCallback which will handle + // MyExceptionType, std::runtime_error, and std::exception via + // different catch blocks. Note, however, that the visible + // behaviour for runtime_error and std::exception (its base class) + // will be identical here, though they actually have different + // code. + @endcode +*/ +template < typename ExceptionT, + typename SigGetMsg, + typename ConstMethodSignature::FunctionType Getter, + typename InCaT, + bool PropagateOtherExceptions = false + > +struct InCaCatcher : InCa +{ + /** + Returns ICB(args), converting any exceptions of type (ExceptionT + const &) or (ExceptionT const *) to JS exceptions. Other exception + types are handled as described in the class-level documentation. + + See the class-level docs for full details. + */ + static v8::Handle Call( v8::Arguments const & args ) + { + try + { + return InCaT::Call( args ); + } + catch( ExceptionT const & e2 ) + { + /* reminder to self: we now have the unusual corner case that + if Getter() returns a v8::Handle it will be thrown + as-is instead of wrapped in an Error object. See the Toss() docs + for why that is so. We could use tmp::SameType to alternately + call TossAsError(), but i'm too tired and i honestly don't ever + expect any exception type to return v8 handles. + */ + return Toss((e2.*Getter)()); + } + catch( ExceptionT const * e2 ) + { + return Toss((e2->*Getter)()); + } + catch(...) + { + if( PropagateOtherExceptions ) throw; + else return Toss("Unknown native exception thrown!"); + } + } +}; + +/** + Convenience form of InCaCatcher which catches std::exception objects and + uses their what() method to fetch the error message. + + The ConcreteException parameter may be std::exception (the default) or + any publically derived subclass of std::exception. When using a + non-default value, one can chain exception catchers to catch most-derived + types first. + + PropagateOtherExceptions determines whether _other_ exception types are + propagated or not. It defaults to false if ConcreteException is + std::exception (exactly, not a subtype), else it defaults to true. The + reasoning is: when chaining these handlers we need to catch the + most-derived first. Those handlers need to propagate other exceptions so + that we can catch the lesser-derived ones (or those from completely + different hierarchies) in subsequent catchers. The final catcher "should" + (arguably) swallow unknown exceptions, converting them to JS exceptions + with an unspecified message string (propagating them is technically legal + but will most likely crash v8). + + Here is an example of chaining: + + @code + typedef InCaCatcher_std< InCaToInCa, std::logic_error > LECatch; + typedef InCaCatcher_std< LECatch, std::runtime_error > RECatch; + typedef InCaCatcher_std< RECatch, std::bad_cast > BCCatch; + typedef InCaCatcher_std< BCCatch > BaseCatch; + v8::InvocationCallback cb = BaseCatch::Call; + @endcode + + In the above example any exceptions would be processed in the order: + logic_error, runtime_error, bad_cast, std::exception, anything else. Notice + that we took advantage of the PropagateOtherExceptions default value for all + cases to get the propagation behaviour we want. +*/ +template < + typename InCaT, + typename ConcreteException = std::exception, + bool PropagateOtherExceptions = !tmp::SameType< std::exception, ConcreteException >::Value +> +struct InCaCatcher_std : + InCaCatcher +{}; + +namespace Detail { + /** + An internal level of indirection for overloading-related + dispatchers. + */ + template + struct OverloadCallHelper : InCa + { + inline static v8::Handle Call( v8::Arguments const & argv ) + { + return InCaT::Call(argv); + } + }; + //! End-of-list specialization. + template <> + struct OverloadCallHelper : InCa + { + inline static v8::Handle Call( v8::Arguments const & argv ) + { + return Toss( StringBuffer() + << "End of typelist reached. Argument count=" + < Call( v8::Arguments const & argv ); + + And a static const integer (or enum) value called Arity, + which must specify the expected number of arguments, or be + negative specify that the function accepts any number of + arguments. + + In other words, all entries in FwdList must implement the + interface used by most of the InCa-related API. + + Example: + + @code + // Overload 3 variants of a member function: + typedef CVV8_TYPELIST(( + MethodToInCa, + MethodToInCa, + MethodToInCa + // Note that "N-arity" callbacks MUST come last in the list + // because they will always match any arity count and therefore + // trump any overloads which follow them. + )) OverloadList; + typedef ArityDispatchList< OverloadList > MyOverloads; + v8::InvocationCallback cb = MyOverloads::Call; + @endcode + + Note that only one line of that code is evaluated at runtime - the rest + is all done at compile-time. +*/ +template +struct ArityDispatchList : InCa +{ + /** + Tries to dispatch argv to one of the bound functions defined + in FwdList, based on the number of arguments in argv and + the Arity + + Implements the v8::InvocationCallback interface. + */ + inline static v8::Handle Call( v8::Arguments const & argv ) + { + typedef typename FwdList::Head FWD; + typedef typename FwdList::Tail Tail; + enum { Arity = sl::Arity< FWD >::Value }; + return ( (-1 == Arity) || (Arity == argv.Length()) ) + ? Detail::OverloadCallHelper::Call(argv) + : ArityDispatchList::Call(argv); + } +}; + +/** + End-of-list specialization. +*/ +template <> +struct ArityDispatchList : Detail::OverloadCallHelper +{ +}; + +#if !defined(DOXYGEN) +namespace Detail { + //! Internal helper for ToInCa impl. + template + struct ToInCaSigSelector : MethodSignature + { + template < typename MethodSignature::FunctionType Func, bool UnlockV8 > + struct Base : cvv8::MethodToInCa + { + }; + }; + + //! Internal helper for ToInCa impl. + template + struct ToInCaSigSelector : FunctionSignature + { + template < typename FunctionSignature::FunctionType Func, bool UnlockV8 > + struct Base : cvv8::FunctionToInCa + { + }; + }; + + //! Internal helper for ToInCaVoid impl. + template + struct ToInCaSigSelectorVoid : MethodSignature + { + template < typename MethodSignature::FunctionType Func, bool UnlockV8 > + struct Base : cvv8::MethodToInCaVoid + { + }; + }; + + //! Internal helper for ToInCaVoid impl. + template + struct ToInCaSigSelectorVoid : FunctionSignature + { + template < typename FunctionSignature::FunctionType Func, bool UnlockV8 > + struct Base : cvv8::FunctionToInCaVoid + { + }; + }; + +} +#endif // DOXYGEN + +/** + A wrapper for MethodToInCa, ConstMethodToInCa, and + FunctionToInCa, which determines which one of those to use based + on the type of T and its constness. + + For non-member functions, T must be void. For non-const member + functions T must be non-cvp-qualified T. For const member functions + T must be const-qualified. + + See FunctionForwarder for the meaning of the UnlockV8 parameter. + + Examples: + + @code + typedef ToInCa NonConstMethod; + typedef ToInCa ConstMethod; + typedef ToInCa Func; + + v8::InvocationCallback cb; + cb = NonConstMethod::Call; + cb = ConstMethod::Call; + cb = Func::Call; + @endcode + + Note the extra 'const' qualification for const method. This is + neccessary to be able to portably distinguish the constness + (some compilers allow us to add the const as part of the + function signature). Also note that the 'void' 1st parameter for + non-member functions is a bit of a hack. +*/ +template ::FunctionType Func, + bool UnlockV8 = SignatureIsUnlockable< Detail::ToInCaSigSelector >::Value + > +struct ToInCa : Detail::ToInCaSigSelector::template Base +{ +}; + +/** + This works just like ToInCa but instead of behaving like + FunctionToInCa or Const/MethoToInCa it behaves like + FunctionToInCaVoid or Const/MethoToInCaVoid. +*/ +template ::FunctionType Func, + bool UnlockV8 = SignatureIsUnlockable< Detail::ToInCaSigSelector >::Value + > +struct ToInCaVoid : Detail::ToInCaSigSelectorVoid::template Base +{ +}; + + +/** + A slightly simplified form of FunctionToInCa which is only + useful for "InvocationCallback-like" functions and requires + only two arguments: + + @code + // int my_func( v8::Arguments const & ); + typedef InCaLikeFunction< int, my_func > F; + @endcode +*/ +template +struct InCaLikeFunction : FunctionToInCa< RV (v8::Arguments const &), Func> +{ +}; + +/** + A slightly simplified form of MethodToInCa which is only + useful for non-const "InvocationCallback-like" methods: + + @code + // Method: int MyType::func( v8::Arguments const & ) + typedef InCaLikeMethod F; + @endcode +*/ +template +struct InCaLikeMethod : MethodToInCa< T, RV (v8::Arguments const &), Func> +{}; + +/** + A slightly simplified form of ConstMethodToInCa which is only + useful for const "InvocationCallback-like" methods: + + @code + // Method: int MyType::func( v8::Arguments const & ) const + typedef InCaLikeConstMethod F; + @endcode +*/ +template +struct InCaLikeConstMethod : ConstMethodToInCa< T, RV (v8::Arguments const &), Func> +{}; + + +#if 0 +//! Don't use. Doesn't yet compile. Trying to consolidate Const/MethodXyz +template ::FunctionType Func> +struct SigToInCa : + tmp::IfElse< + sl::IsFunction< Signature >::Value, + FunctionToInCa< ASig, Func >, + typename tmp::IfElse< + sl::IsConstMethod< Signature >::Value, + ConstMethodToInCa< typename tmp::PlainType::Context>::Type, ASig, Func >, + MethodToInCa< typename Signature::Context, ASig, Func > + >::Type + >::Type +{}; +#endif + +/** + This class acts as a proxy for another InCa-compatible class, + running client-defined intialization code the _first_ time + its callback is called from JS. This could be used to run + library-dependent intialization routines such as lt_dlinit(). + + InCaT must conform to the InCa interface (i.e., have a static Call() + function which implements the v8::InvocationCallback interface). + + InitFunctor must be default-constructable and have an operator() + (preferably const) taking no args and returning any type which can be + ignored (i.e. not dynamically-allocated resources). +*/ +template +struct OneTimeInitInCa : InCa +{ + /** + The first time this function is called it runs + InitFunctor()() to execute any client-dependent setup. If + that throws a native exception it is propagated back to the + caller and initialization is considered NOT to have + occurred, meaning the next call to this function will also + run InitFunctor()(). + + If initialization does not throw, InCaT::Call(argv) is + called and its value is returned. Once initialization + succeeds, it is _not_ triggered on subsequent calls to this + function. + + Pedantic note: if this class is used in code which is linked + in from multiple DLLs, the init routine might be called + more than once, depending on the platform. + */ + static v8::Handle Call( v8::Arguments const & argv ) + { + static bool bob = false; + if( ! bob ) + { + InitFunctor()(); + /* Reminder: if it throws we do not set bob=true. + This is part of the interface, not an accident. + */ + bob = true; + } + return InCaT::Call( argv ); + } +}; + + +#if 0// i'm not yet decided on these bits... +struct NativeToJS_InCa_Base +{ + typedef v8::InvocationCallback ArgType; + template + inline v8::Handle operator()( SigT const & ) const + { + return v8::FunctionTemplate::New(SigT::Call)->GetFunction(); + } +}; + +template ::FunctionType Func> +struct NativeToJS< FunctionToInCa > : NativeToJS_InCa_Base {}; +template ::FunctionType Func> +struct NativeToJS< FunctionToInCaVoid > : NativeToJS_InCa_Base {}; + +template ::FunctionType Func> +struct NativeToJS< MethodToInCa > : NativeToJS_InCa_Base {}; +template ::FunctionType Func> +struct NativeToJS< MethodToInCaVoid > : NativeToJS_InCa_Base {}; + +template ::FunctionType Func> +struct NativeToJS< ConstMethodToInCa > : NativeToJS_InCa_Base {}; +template ::FunctionType Func> +struct NativeToJS< ConstMethodToInCaVoid > : NativeToJS_InCa_Base {}; + +template ::FunctionType Func> +struct NativeToJS< ToInCa > : NativeToJS_InCa_Base {}; +template ::FunctionType Func> +struct NativeToJS< ToInCaVoid > : NativeToJS_InCa_Base {}; +#endif + +#include "invocable_generated.hpp" +} // namespace + +#undef HANDLE_PROPAGATE_EXCEPTION +#undef ENABLE_TOINCA + +#endif /* CODE_GOOGLE_COM_V8_CONVERT_INVOCABLE_V8_HPP_INCLUDED */ diff --git a/vendor/libv8-convert/cvv8/detail/invocable_generated.hpp b/vendor/libv8-convert/cvv8/detail/invocable_generated.hpp new file mode 100644 index 000000000..6c7227f5f --- /dev/null +++ b/vendor/libv8-convert/cvv8/detail/invocable_generated.hpp @@ -0,0 +1,3588 @@ +/* AUTO-GENERATED CODE! EDIT AT YOUR OWN RISK! */ +#if !defined(DOXYGEN) +namespace Detail { + template + struct FunctionForwarder<1,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (1 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + + typedef ArgCaster AC0; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + return CastToJS( CallNative( func, argv ) ); + } + }; + + template + struct FunctionForwarderVoid<1,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (1 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + + typedef ArgCaster AC0; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + CallNative( func, argv ); + return v8::Undefined(); + } + }; +} +namespace Detail { + template + struct MethodForwarder : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (1 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + + typedef ArgCaster AC0; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct MethodForwarderVoid : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (1 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + + typedef ArgCaster AC0; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +namespace Detail { + template + struct ConstMethodForwarder : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (1 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + + typedef ArgCaster AC0; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct ConstMethodForwarderVoid : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (1 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + + typedef ArgCaster AC0; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +//! Specialization for 1-arity calls. +template <> +struct CallForwarder<1> +{ + template < typename A0> + static v8::Handle Call( v8::Handle const & self, + v8::Handle const & func, + A0 a0 + ) + { + v8::Handle args[] = { + CastToJS(a0) + }; + return (self.IsEmpty() || func.IsEmpty()) + ? Toss("Illegal argument: empty v8::Handle<>.") + : func->Call(self, sizeof(args)/sizeof(args[0]), args); + } + template < typename A0> + static v8::Handle Call( v8::Handle const & func, + A0 a0 + ) + { + return Call( func, func, a0 ); + } + +}; +namespace Detail { +template +struct CtorForwarderProxy +{ + enum { Arity = 1 }; + typedef typename Signature::ReturnType ReturnType; + static ReturnType Call( v8::Arguments const & argv ) + { + if( argv.Length() < Arity ) + { + throw std::range_error("CtorForwarder::Ctor() expects at least 1 JS arguments!"); + } + else + { + typedef typename sl::At< 0, Signature >::Type A0; + + typedef ArgCaster AC0; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + + typedef typename TypeInfo::Type Type; + return new Type( arg0 ); + } + } +}; +} +namespace Detail { + template + struct FunctionForwarder<2,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (2 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0, arg1 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + return CastToJS( CallNative( func, argv ) ); + } + }; + + template + struct FunctionForwarderVoid<2,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (2 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0, arg1 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + CallNative( func, argv ); + return v8::Undefined(); + } + }; +} +namespace Detail { + template + struct MethodForwarder : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (2 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct MethodForwarderVoid : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (2 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +namespace Detail { + template + struct ConstMethodForwarder : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (2 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct ConstMethodForwarderVoid : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (2 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +//! Specialization for 2-arity calls. +template <> +struct CallForwarder<2> +{ + template < typename A0, typename A1> + static v8::Handle Call( v8::Handle const & self, + v8::Handle const & func, + A0 a0, A1 a1 + ) + { + v8::Handle args[] = { + CastToJS(a0), CastToJS(a1) + }; + return (self.IsEmpty() || func.IsEmpty()) + ? Toss("Illegal argument: empty v8::Handle<>.") + : func->Call(self, sizeof(args)/sizeof(args[0]), args); + } + template < typename A0, typename A1> + static v8::Handle Call( v8::Handle const & func, + A0 a0, A1 a1 + ) + { + return Call( func, func, a0,a1 ); + } + +}; +namespace Detail { +template +struct CtorForwarderProxy +{ + enum { Arity = 2 }; + typedef typename Signature::ReturnType ReturnType; + static ReturnType Call( v8::Arguments const & argv ) + { + if( argv.Length() < Arity ) + { + throw std::range_error("CtorForwarder::Ctor() expects at least 2 JS arguments!"); + } + else + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + + typedef typename TypeInfo::Type Type; + return new Type( arg0, arg1 ); + } + } +}; +} +namespace Detail { + template + struct FunctionForwarder<3,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (3 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0, arg1, arg2 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + return CastToJS( CallNative( func, argv ) ); + } + }; + + template + struct FunctionForwarderVoid<3,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (3 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0, arg1, arg2 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + CallNative( func, argv ); + return v8::Undefined(); + } + }; +} +namespace Detail { + template + struct MethodForwarder : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (3 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct MethodForwarderVoid : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (3 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +namespace Detail { + template + struct ConstMethodForwarder : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (3 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct ConstMethodForwarderVoid : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (3 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +//! Specialization for 3-arity calls. +template <> +struct CallForwarder<3> +{ + template < typename A0, typename A1, typename A2> + static v8::Handle Call( v8::Handle const & self, + v8::Handle const & func, + A0 a0, A1 a1, A2 a2 + ) + { + v8::Handle args[] = { + CastToJS(a0), CastToJS(a1), CastToJS(a2) + }; + return (self.IsEmpty() || func.IsEmpty()) + ? Toss("Illegal argument: empty v8::Handle<>.") + : func->Call(self, sizeof(args)/sizeof(args[0]), args); + } + template < typename A0, typename A1, typename A2> + static v8::Handle Call( v8::Handle const & func, + A0 a0, A1 a1, A2 a2 + ) + { + return Call( func, func, a0,a1,a2 ); + } + +}; +namespace Detail { +template +struct CtorForwarderProxy +{ + enum { Arity = 3 }; + typedef typename Signature::ReturnType ReturnType; + static ReturnType Call( v8::Arguments const & argv ) + { + if( argv.Length() < Arity ) + { + throw std::range_error("CtorForwarder::Ctor() expects at least 3 JS arguments!"); + } + else + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + + typedef typename TypeInfo::Type Type; + return new Type( arg0, arg1, arg2 ); + } + } +}; +} +namespace Detail { + template + struct FunctionForwarder<4,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (4 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0, arg1, arg2, arg3 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + return CastToJS( CallNative( func, argv ) ); + } + }; + + template + struct FunctionForwarderVoid<4,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (4 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0, arg1, arg2, arg3 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + CallNative( func, argv ); + return v8::Undefined(); + } + }; +} +namespace Detail { + template + struct MethodForwarder : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (4 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct MethodForwarderVoid : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (4 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +namespace Detail { + template + struct ConstMethodForwarder : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (4 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct ConstMethodForwarderVoid : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (4 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +//! Specialization for 4-arity calls. +template <> +struct CallForwarder<4> +{ + template < typename A0, typename A1, typename A2, typename A3> + static v8::Handle Call( v8::Handle const & self, + v8::Handle const & func, + A0 a0, A1 a1, A2 a2, A3 a3 + ) + { + v8::Handle args[] = { + CastToJS(a0), CastToJS(a1), CastToJS(a2), CastToJS(a3) + }; + return (self.IsEmpty() || func.IsEmpty()) + ? Toss("Illegal argument: empty v8::Handle<>.") + : func->Call(self, sizeof(args)/sizeof(args[0]), args); + } + template < typename A0, typename A1, typename A2, typename A3> + static v8::Handle Call( v8::Handle const & func, + A0 a0, A1 a1, A2 a2, A3 a3 + ) + { + return Call( func, func, a0,a1,a2,a3 ); + } + +}; +namespace Detail { +template +struct CtorForwarderProxy +{ + enum { Arity = 4 }; + typedef typename Signature::ReturnType ReturnType; + static ReturnType Call( v8::Arguments const & argv ) + { + if( argv.Length() < Arity ) + { + throw std::range_error("CtorForwarder::Ctor() expects at least 4 JS arguments!"); + } + else + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + + typedef typename TypeInfo::Type Type; + return new Type( arg0, arg1, arg2, arg3 ); + } + } +}; +} +namespace Detail { + template + struct FunctionForwarder<5,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (5 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0, arg1, arg2, arg3, arg4 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + return CastToJS( CallNative( func, argv ) ); + } + }; + + template + struct FunctionForwarderVoid<5,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (5 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0, arg1, arg2, arg3, arg4 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + CallNative( func, argv ); + return v8::Undefined(); + } + }; +} +namespace Detail { + template + struct MethodForwarder : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (5 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct MethodForwarderVoid : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (5 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +namespace Detail { + template + struct ConstMethodForwarder : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (5 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct ConstMethodForwarderVoid : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (5 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +//! Specialization for 5-arity calls. +template <> +struct CallForwarder<5> +{ + template < typename A0, typename A1, typename A2, typename A3, typename A4> + static v8::Handle Call( v8::Handle const & self, + v8::Handle const & func, + A0 a0, A1 a1, A2 a2, A3 a3, A4 a4 + ) + { + v8::Handle args[] = { + CastToJS(a0), CastToJS(a1), CastToJS(a2), CastToJS(a3), CastToJS(a4) + }; + return (self.IsEmpty() || func.IsEmpty()) + ? Toss("Illegal argument: empty v8::Handle<>.") + : func->Call(self, sizeof(args)/sizeof(args[0]), args); + } + template < typename A0, typename A1, typename A2, typename A3, typename A4> + static v8::Handle Call( v8::Handle const & func, + A0 a0, A1 a1, A2 a2, A3 a3, A4 a4 + ) + { + return Call( func, func, a0,a1,a2,a3,a4 ); + } + +}; +namespace Detail { +template +struct CtorForwarderProxy +{ + enum { Arity = 5 }; + typedef typename Signature::ReturnType ReturnType; + static ReturnType Call( v8::Arguments const & argv ) + { + if( argv.Length() < Arity ) + { + throw std::range_error("CtorForwarder::Ctor() expects at least 5 JS arguments!"); + } + else + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + + typedef typename TypeInfo::Type Type; + return new Type( arg0, arg1, arg2, arg3, arg4 ); + } + } +}; +} +namespace Detail { + template + struct FunctionForwarder<6,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (6 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0, arg1, arg2, arg3, arg4, arg5 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + return CastToJS( CallNative( func, argv ) ); + } + }; + + template + struct FunctionForwarderVoid<6,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (6 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0, arg1, arg2, arg3, arg4, arg5 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + CallNative( func, argv ); + return v8::Undefined(); + } + }; +} +namespace Detail { + template + struct MethodForwarder : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (6 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct MethodForwarderVoid : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (6 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +namespace Detail { + template + struct ConstMethodForwarder : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (6 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct ConstMethodForwarderVoid : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (6 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +//! Specialization for 6-arity calls. +template <> +struct CallForwarder<6> +{ + template < typename A0, typename A1, typename A2, typename A3, typename A4, typename A5> + static v8::Handle Call( v8::Handle const & self, + v8::Handle const & func, + A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5 + ) + { + v8::Handle args[] = { + CastToJS(a0), CastToJS(a1), CastToJS(a2), CastToJS(a3), CastToJS(a4), CastToJS(a5) + }; + return (self.IsEmpty() || func.IsEmpty()) + ? Toss("Illegal argument: empty v8::Handle<>.") + : func->Call(self, sizeof(args)/sizeof(args[0]), args); + } + template < typename A0, typename A1, typename A2, typename A3, typename A4, typename A5> + static v8::Handle Call( v8::Handle const & func, + A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5 + ) + { + return Call( func, func, a0,a1,a2,a3,a4,a5 ); + } + +}; +namespace Detail { +template +struct CtorForwarderProxy +{ + enum { Arity = 6 }; + typedef typename Signature::ReturnType ReturnType; + static ReturnType Call( v8::Arguments const & argv ) + { + if( argv.Length() < Arity ) + { + throw std::range_error("CtorForwarder::Ctor() expects at least 6 JS arguments!"); + } + else + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + + typedef typename TypeInfo::Type Type; + return new Type( arg0, arg1, arg2, arg3, arg4, arg5 ); + } + } +}; +} +namespace Detail { + template + struct FunctionForwarder<7,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (7 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + return CastToJS( CallNative( func, argv ) ); + } + }; + + template + struct FunctionForwarderVoid<7,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (7 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + CallNative( func, argv ); + return v8::Undefined(); + } + }; +} +namespace Detail { + template + struct MethodForwarder : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (7 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct MethodForwarderVoid : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (7 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +namespace Detail { + template + struct ConstMethodForwarder : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (7 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct ConstMethodForwarderVoid : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (7 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +//! Specialization for 7-arity calls. +template <> +struct CallForwarder<7> +{ + template < typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> + static v8::Handle Call( v8::Handle const & self, + v8::Handle const & func, + A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6 + ) + { + v8::Handle args[] = { + CastToJS(a0), CastToJS(a1), CastToJS(a2), CastToJS(a3), CastToJS(a4), CastToJS(a5), CastToJS(a6) + }; + return (self.IsEmpty() || func.IsEmpty()) + ? Toss("Illegal argument: empty v8::Handle<>.") + : func->Call(self, sizeof(args)/sizeof(args[0]), args); + } + template < typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6> + static v8::Handle Call( v8::Handle const & func, + A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6 + ) + { + return Call( func, func, a0,a1,a2,a3,a4,a5,a6 ); + } + +}; +namespace Detail { +template +struct CtorForwarderProxy +{ + enum { Arity = 7 }; + typedef typename Signature::ReturnType ReturnType; + static ReturnType Call( v8::Arguments const & argv ) + { + if( argv.Length() < Arity ) + { + throw std::range_error("CtorForwarder::Ctor() expects at least 7 JS arguments!"); + } + else + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + + typedef typename TypeInfo::Type Type; + return new Type( arg0, arg1, arg2, arg3, arg4, arg5, arg6 ); + } + } +}; +} +namespace Detail { + template + struct FunctionForwarder<8,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (8 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + return CastToJS( CallNative( func, argv ) ); + } + }; + + template + struct FunctionForwarderVoid<8,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (8 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + CallNative( func, argv ); + return v8::Undefined(); + } + }; +} +namespace Detail { + template + struct MethodForwarder : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (8 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct MethodForwarderVoid : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (8 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +namespace Detail { + template + struct ConstMethodForwarder : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (8 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct ConstMethodForwarderVoid : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (8 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +//! Specialization for 8-arity calls. +template <> +struct CallForwarder<8> +{ + template < typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7> + static v8::Handle Call( v8::Handle const & self, + v8::Handle const & func, + A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7 + ) + { + v8::Handle args[] = { + CastToJS(a0), CastToJS(a1), CastToJS(a2), CastToJS(a3), CastToJS(a4), CastToJS(a5), CastToJS(a6), CastToJS(a7) + }; + return (self.IsEmpty() || func.IsEmpty()) + ? Toss("Illegal argument: empty v8::Handle<>.") + : func->Call(self, sizeof(args)/sizeof(args[0]), args); + } + template < typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7> + static v8::Handle Call( v8::Handle const & func, + A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7 + ) + { + return Call( func, func, a0,a1,a2,a3,a4,a5,a6,a7 ); + } + +}; +namespace Detail { +template +struct CtorForwarderProxy +{ + enum { Arity = 8 }; + typedef typename Signature::ReturnType ReturnType; + static ReturnType Call( v8::Arguments const & argv ) + { + if( argv.Length() < Arity ) + { + throw std::range_error("CtorForwarder::Ctor() expects at least 8 JS arguments!"); + } + else + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + + typedef typename TypeInfo::Type Type; + return new Type( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7 ); + } + } +}; +} +namespace Detail { + template + struct FunctionForwarder<9,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (9 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + typedef typename sl::At< 8, Signature >::Type A8; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + typedef ArgCaster AC8; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + AC8 ac8; A8 arg8(ac8.ToNative(argv[8])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + return CastToJS( CallNative( func, argv ) ); + } + }; + + template + struct FunctionForwarderVoid<9,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (9 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + typedef typename sl::At< 8, Signature >::Type A8; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + typedef ArgCaster AC8; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + AC8 ac8; A8 arg8(ac8.ToNative(argv[8])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + CallNative( func, argv ); + return v8::Undefined(); + } + }; +} +namespace Detail { + template + struct MethodForwarder : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (9 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + typedef typename sl::At< 8, Signature >::Type A8; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + typedef ArgCaster AC8; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + AC8 ac8; A8 arg8(ac8.ToNative(argv[8])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct MethodForwarderVoid : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (9 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + typedef typename sl::At< 8, Signature >::Type A8; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + typedef ArgCaster AC8; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + AC8 ac8; A8 arg8(ac8.ToNative(argv[8])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +namespace Detail { + template + struct ConstMethodForwarder : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (9 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + typedef typename sl::At< 8, Signature >::Type A8; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + typedef ArgCaster AC8; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + AC8 ac8; A8 arg8(ac8.ToNative(argv[8])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct ConstMethodForwarderVoid : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (9 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + typedef typename sl::At< 8, Signature >::Type A8; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + typedef ArgCaster AC8; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + AC8 ac8; A8 arg8(ac8.ToNative(argv[8])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +//! Specialization for 9-arity calls. +template <> +struct CallForwarder<9> +{ + template < typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8> + static v8::Handle Call( v8::Handle const & self, + v8::Handle const & func, + A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8 + ) + { + v8::Handle args[] = { + CastToJS(a0), CastToJS(a1), CastToJS(a2), CastToJS(a3), CastToJS(a4), CastToJS(a5), CastToJS(a6), CastToJS(a7), CastToJS(a8) + }; + return (self.IsEmpty() || func.IsEmpty()) + ? Toss("Illegal argument: empty v8::Handle<>.") + : func->Call(self, sizeof(args)/sizeof(args[0]), args); + } + template < typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8> + static v8::Handle Call( v8::Handle const & func, + A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8 + ) + { + return Call( func, func, a0,a1,a2,a3,a4,a5,a6,a7,a8 ); + } + +}; +namespace Detail { +template +struct CtorForwarderProxy +{ + enum { Arity = 9 }; + typedef typename Signature::ReturnType ReturnType; + static ReturnType Call( v8::Arguments const & argv ) + { + if( argv.Length() < Arity ) + { + throw std::range_error("CtorForwarder::Ctor() expects at least 9 JS arguments!"); + } + else + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + typedef typename sl::At< 8, Signature >::Type A8; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + typedef ArgCaster AC8; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + AC8 ac8; A8 arg8(ac8.ToNative(argv[8])); + + typedef typename TypeInfo::Type Type; + return new Type( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8 ); + } + } +}; +} +namespace Detail { + template + struct FunctionForwarder<10,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (10 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + typedef typename sl::At< 8, Signature >::Type A8; + typedef typename sl::At< 9, Signature >::Type A9; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + typedef ArgCaster AC8; + typedef ArgCaster AC9; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + AC8 ac8; A8 arg8(ac8.ToNative(argv[8])); + AC9 ac9; A9 arg9(ac9.ToNative(argv[9])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + return CastToJS( CallNative( func, argv ) ); + } + }; + + template + struct FunctionForwarderVoid<10,Sig,UnlockV8> : FunctionSignature + { + typedef FunctionSignature SignatureType; + typedef char AssertArity[ (10 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + typedef typename sl::At< 8, Signature >::Type A8; + typedef typename sl::At< 9, Signature >::Type A9; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + typedef ArgCaster AC8; + typedef ArgCaster AC9; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + AC8 ac8; A8 arg8(ac8.ToNative(argv[8])); + AC9 ac9; A9 arg9(ac9.ToNative(argv[9])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + CallNative( func, argv ); + return v8::Undefined(); + } + }; +} +namespace Detail { + template + struct MethodForwarder : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (10 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + typedef typename sl::At< 8, Signature >::Type A8; + typedef typename sl::At< 9, Signature >::Type A9; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + typedef ArgCaster AC8; + typedef ArgCaster AC9; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + AC8 ac8; A8 arg8(ac8.ToNative(argv[8])); + AC9 ac9; A9 arg9(ac9.ToNative(argv[9])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct MethodForwarderVoid : MethodSignature + { + typedef MethodSignature SignatureType; + typedef char AssertArity[ (10 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + typedef typename sl::At< 8, Signature >::Type A8; + typedef typename sl::At< 9, Signature >::Type A9; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + typedef ArgCaster AC8; + typedef ArgCaster AC9; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + AC8 ac8; A8 arg8(ac8.ToNative(argv[8])); + AC9 ac9; A9 arg9(ac9.ToNative(argv[9])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ); + } + static v8::Handle Call( T & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +namespace Detail { + template + struct ConstMethodForwarder : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (10 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + typedef typename sl::At< 8, Signature >::Type A8; + typedef typename sl::At< 9, Signature >::Type A9; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + typedef ArgCaster AC8; + typedef ArgCaster AC9; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + AC8 ac8; A8 arg8(ac8.ToNative(argv[8])); + AC9 ac9; A9 arg9(ac9.ToNative(argv[9])); + + V8Unlocker const & unlocker = ( V8Unlocker() ); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative( self, func, argv ) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try { return CastToJS( CallNative(func, argv) ); } + HANDLE_PROPAGATE_EXCEPTION; + } + }; + + template + struct ConstMethodForwarderVoid : ConstMethodSignature + { + typedef ConstMethodSignature SignatureType; + typedef char AssertArity[ (10 == sl::Arity::Value) ? 1 : -1]; + typedef typename SignatureType::FunctionType FunctionType; + typedef typename SignatureType::ReturnType ReturnType; + static ReturnType CallNative( T const & self, FunctionType func, v8::Arguments const & argv ) + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + typedef typename sl::At< 8, Signature >::Type A8; + typedef typename sl::At< 9, Signature >::Type A9; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + typedef ArgCaster AC8; + typedef ArgCaster AC9; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + AC8 ac8; A8 arg8(ac8.ToNative(argv[8])); + AC9 ac9; A9 arg9(ac9.ToNative(argv[9])); + + V8Unlocker const & unlocker = V8Unlocker(); + return (ReturnType)(self.*func)( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ); + } + static v8::Handle Call( T const & self, FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative( self, func, argv ); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + static ReturnType CallNative( FunctionType func, v8::Arguments const & argv ) + { + T const * self = CastFromJS(argv.This()); + if( ! self ) throw MissingThisExceptionT(); + return (ReturnType)CallNative(*self, func, argv); + } + static v8::Handle Call( FunctionType func, v8::Arguments const & argv ) + { + try + { + CallNative(func, argv); + return v8::Undefined(); + } + HANDLE_PROPAGATE_EXCEPTION; + } + }; +} +//! Specialization for 10-arity calls. +template <> +struct CallForwarder<10> +{ + template < typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9> + static v8::Handle Call( v8::Handle const & self, + v8::Handle const & func, + A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9 + ) + { + v8::Handle args[] = { + CastToJS(a0), CastToJS(a1), CastToJS(a2), CastToJS(a3), CastToJS(a4), CastToJS(a5), CastToJS(a6), CastToJS(a7), CastToJS(a8), CastToJS(a9) + }; + return (self.IsEmpty() || func.IsEmpty()) + ? Toss("Illegal argument: empty v8::Handle<>.") + : func->Call(self, sizeof(args)/sizeof(args[0]), args); + } + template < typename A0, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9> + static v8::Handle Call( v8::Handle const & func, + A0 a0, A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9 + ) + { + return Call( func, func, a0,a1,a2,a3,a4,a5,a6,a7,a8,a9 ); + } + +}; +namespace Detail { +template +struct CtorForwarderProxy +{ + enum { Arity = 10 }; + typedef typename Signature::ReturnType ReturnType; + static ReturnType Call( v8::Arguments const & argv ) + { + if( argv.Length() < Arity ) + { + throw std::range_error("CtorForwarder::Ctor() expects at least 10 JS arguments!"); + } + else + { + typedef typename sl::At< 0, Signature >::Type A0; + typedef typename sl::At< 1, Signature >::Type A1; + typedef typename sl::At< 2, Signature >::Type A2; + typedef typename sl::At< 3, Signature >::Type A3; + typedef typename sl::At< 4, Signature >::Type A4; + typedef typename sl::At< 5, Signature >::Type A5; + typedef typename sl::At< 6, Signature >::Type A6; + typedef typename sl::At< 7, Signature >::Type A7; + typedef typename sl::At< 8, Signature >::Type A8; + typedef typename sl::At< 9, Signature >::Type A9; + + typedef ArgCaster AC0; + typedef ArgCaster AC1; + typedef ArgCaster AC2; + typedef ArgCaster AC3; + typedef ArgCaster AC4; + typedef ArgCaster AC5; + typedef ArgCaster AC6; + typedef ArgCaster AC7; + typedef ArgCaster AC8; + typedef ArgCaster AC9; + + AC0 ac0; A0 arg0(ac0.ToNative(argv[0])); + AC1 ac1; A1 arg1(ac1.ToNative(argv[1])); + AC2 ac2; A2 arg2(ac2.ToNative(argv[2])); + AC3 ac3; A3 arg3(ac3.ToNative(argv[3])); + AC4 ac4; A4 arg4(ac4.ToNative(argv[4])); + AC5 ac5; A5 arg5(ac5.ToNative(argv[5])); + AC6 ac6; A6 arg6(ac6.ToNative(argv[6])); + AC7 ac7; A7 arg7(ac7.ToNative(argv[7])); + AC8 ac8; A8 arg8(ac8.ToNative(argv[8])); + AC9 ac9; A9 arg9(ac9.ToNative(argv[9])); + + typedef typename TypeInfo::Type Type; + return new Type( arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9 ); + } + } +}; +} +#endif // if !defined(DOXYGEN) diff --git a/vendor/libv8-convert/cvv8/detail/signature_core.hpp b/vendor/libv8-convert/cvv8/detail/signature_core.hpp new file mode 100644 index 000000000..b4ff3fe6d --- /dev/null +++ b/vendor/libv8-convert/cvv8/detail/signature_core.hpp @@ -0,0 +1,498 @@ +#if !defined(CODE_GOOGLE_COM_V8_CONVERT_SIGNATURE_CORE_HPP_INCLUDED) +#define CODE_GOOGLE_COM_V8_CONVERT_SIGNATURE_CORE_HPP_INCLUDED 1 +#include "tmp.hpp" +#include "doxygen_hack.hpp" + +namespace cvv8 { +/** @file signature_core.hpp + +This file houses the core-most templates related to handling +function/method signatures as full-fleged types. +*/ + + + +/** @class Signature + + Base (unimplemented) template for holding function-signature-style + argument lists in a type-rich manner. Most implementations are + script-generated and accept up to some library-build-time-defined number + of types in their argument list (the interface guarantees at least 10 + unless the client builds a custom copy with a smaller limit). + + All specializations implement a "type list" interface. The sl namespace + contains several different compile-time algorithms (sometimes called + template metafunctions) for querying the arity and types in a signature. + + Sig must be a function-signature-style parameter list, e.g.: + + @code + Signature< void (int, double) > + Signature< void (MyType::*)( int double ) > + Signature< void (MyType::*)( char const * ) const > + @endcode + + This interface treates the "function parameter part" of its arguments as + a "type list", and several algorithms in the sl namespace are available + for fetching type information from a Signature type. This is an + "extended" typelist, however, because it also remembers the return type + and optionally the class containing a member function described by the + signature (neither of those are counted as part of the list, but are + accessible separately). + + Required interface for specializations: + + @code + typedef functionSignature FunctionType; // e.g. void () or void (T::*)() const. + typedef functionReturnType ReturnType; + typedef T Context; // void for non-member functions, non-vp-qualified T + // for all T members. const-qualified T for const members. + typedef firstArgType Head; // head type of type-list. + typedef Signature< RV (...)> Tail; // tail of type-list. (...)==arg types 2..N. + // When Arity==0, Head and Tail must both be tmp::NilType. For Arity==1 + // Tail is Signature but one could argue that it should be tmp::NilType. + + @endcode + + It is intended to be used like this: + + @code + typedef Signature< int (char const *, double) > Sig; + assert( 2 == sl::Arity::Value ); + assert( 2 == sl::Length::Value ) + assert( (tmp::SameType< char const *, sl::At<0,Sig>::Type >::Value) ); + assert( (tmp::SameType< double, sl::At<1,Sig>::Type >::Value) ); + assert( 1 == sl::Index< double, Sig >::Value) ); + assert( !sl::Contains< int, Sig >::Value) ); // Sig::ReturnType doesn't count here! + assert( sl::IsConstMethod< Signature< void (MyType::*)() const > >::Value ); + assert( sl::IsMethod< Signature< void (MyType::*)() const > >::Value ); + assert( !sl::IsConstMethod< Signature< void (MyType::*)() > >::Value ); + // Those can all be made into static assertions, by the way. + @endcode + + Note that the length of the typelist does not include the return value + type nor (for member methods) the containing class (the Context typedef). + + Functions taking one (v8::Arguments const &) argument and + returning any type are considered to be + "InvocationCallback-like" and are treated specially. They have + an Arity value of -1, which is used as a hint by binding code + that the function can accept any number of arguments when called + from JS code (there is no way to create Arguments objects + directly from C++, only indirectly via Call()ing or Apply()ing a + v8::Function). +*/ +template struct Signature DOXYGEN_FWD_DECL_KLUDGE; + +/** @def CVV8_TYPELIST + + CVV8_TYPELIST is a (slightly) convenience form of + Signature for creating typelists where we do not care about the + "return type" or "context" parts of the list. + + It is used like this: + + @code + typedef CVV8_TYPELIST(( int, double, char )) MyList; + @endcode + + NOTE the doubled parenthesis! + + Many members of the API which take a type-list require a + Signature-compatible typelist because they need the ReturnValue and/or + Context parts. CVV8_TYPELIST is intended for cases where niether the + ReturnValue nor Context are evaluated (both are void for CVV8_TYPELIST). + + The maximum number of types the typelist can hold is limited + to some build-time configuration option. +*/ +#define CVV8_TYPELIST(X) ::cvv8::Signature< void (*)X > + +/** \namespace cvv8::sl + + The sl namespace exclusively holds template metafunctions for working + with Signature-style typelists. +*/ +namespace sl { + + /** + Metafunction whose Value member evaluates to the length of the + given Signature. + */ + template < typename ListT > + struct Length : tmp::IntVal< + tmp::IsNil::Value ? 0 : (1 + Length::Value) + > {}; + + //! End-of-list specialization. + template <> + struct Length : tmp::IntVal<0> {}; + /** + Metafunction whose Type member evaluates to the type of the + I'th argument type in the given Signature. Fails to compile + if I is out of range. + */ + template < unsigned short I, typename ListT > + struct At : At + { + typedef char AssertIndex[ (I >= Length::Value) ? -1 : 1 ]; + }; + + //! Beginning-of-list specialization. + template < typename ListT > + struct At<0, ListT> + { + typedef typename ListT::Head Type; + }; + /** + End-of-list specialization. i don't think we need this, actually. + */ + template + struct At : tmp::Identity + {}; + + /** + Metafunction whose Type Value member evaluates to the 0-based + index of the first occurrance of the the type T in the + given Signature's argument list. Evaluates to -1 if T is not + contained in the argument list. Signature::ReturnType and + Signature::Context are not evaluated. + + Clients _must not_ pass a value for the 3rd template parameter. + */ + template < typename T, typename ListT, unsigned short Internal = 0 > + struct Index : tmp::IntVal< tmp::SameType::Value + ? Internal + : Index::Value> + { + }; + + //! End-of-list specialization. + template < typename T, unsigned short Internal > + struct Index : tmp::IntVal<-1> {}; + + /** + Convenience form of Index which evaluates to true + if Index returns a non-negative value, else it evaluates + to false. + */ + template < typename T, typename ListT> + struct Contains : tmp::BoolVal< Index::Value >= 0 > {}; + + + /** + A metatype which calculates the number of arguments in the given + typelist, but evaluates to -1 if SigT's only argument is + (v8::Arguments const &), as such function signatures are considered + to be n-arity. + */ + template + struct Arity + { + enum { + Value = ((1==Length::Value) + && (0==Index::Value)) + ? -1 + : Length::Value + }; + }; + + /** + This metafunction evaluates to true if SigT appears to be + "InvocationCallback-like" (returns any type and takes one + (v8::Arguments const &) parameter). + + We could implement this a number of different ways. The + current impl simply checks if the arity is -1. + */ + template + struct IsInCaLike : tmp::BoolVal< -1 == Arity::Value > {}; + + /** + A metafunction which has a true Value if the Signature type SigT + represents a non-member function. + */ + template + struct IsFunction : tmp::BoolVal< tmp::SameType::Value > {}; + + /** + A metafunction which has a true Value if the Signature type SigT + represents a member function (const or not). + */ + template + struct IsMethod : tmp::BoolVal< !tmp::SameType::Value > {}; + + /** + A metafunction which has a true Value if the Signature type SigT + represents a non-const member function. + */ + template + struct IsNonConstMethod : tmp::BoolVal< !tmp::IsConst< typename SigT::Context >::Value && IsMethod::Value > {}; + + /** + A metafunction which has a true Value if the Signature type SigT + represents a const member function. + */ + template + struct IsConstMethod : + tmp::BoolVal< tmp::IsConst< typename SigT::Context >::Value && IsMethod::Value > {}; + //tmp::BoolVal< SigT::IsConst && IsMethod::Value > {}; + +} + +namespace tmp { + /** + A metatemplate who's Type member resolves to IF if Cond is + true, or ELSE if Cond is false. Its Value member evaluates + to 1 or 0, accordingly. + */ + template + struct IfElse : sl::At< Cond ? 0 : 1, Signature > + { + }; +} + +#if 0 +//! Highly arguably specialization. +template struct Signature< Signature > : Signature {}; +#endif + +/** + Specialization to give "InvacationCallback-like" functions + an Arity value of -1. + + Reminder: we can get rid of this if we factory out the Arity definition + and use sl::Arity instead. +*/ +template +struct Signature +{ + typedef RV ReturnType; + typedef RV (*FunctionType)(v8::Arguments const &); + typedef void Context; + typedef v8::Arguments const & Head; + typedef Signature Tail; +}; + +template +struct Signature : Signature +{}; + +template +struct Signature : Signature +{ + typedef T Context; + typedef RV (Context::*FunctionType)(v8::Arguments const &); +}; + + +template +struct Signature : Signature +{ + typedef T const Context; + typedef RV (Context::*FunctionType)(v8::Arguments const &) const; +}; + + + +/** @class FunctionSignature + Base (unimplemented) signature for FunctionSignature + specializations. The type passed to it must be a function + signature. + + All implementations must define the interface described for + Signature and its Context typedef must be void for this type. + + Examples: + + @code + // void func_foo(): + typedef FunctionSignature< void () > NoArgsReturnsVoid; + + // int func_foo(double): + typedef FunctionSignature< int (double) > OneArgReturnsInt; + + // double func_foo(int,int): + typedef FunctionSignature< double (int,int) > TwoArgsReturnsDouble; + @endcode + +*/ +template +struct FunctionSignature : Signature< FunctionSig > {}; + +/** @class MethodSignature + Base (unimplemented) signature for MethodSignature + specializations. The Sig type passed to it must match a member method + signature of a function from the class T. + e.g. (void (T::*)(int)) or its equivalent (void (int)). + + All implementations must have the interface called for by Signature + and the Context typedef must be non-cvp-qualified T. + + Examples: + + @code + // void MyType::func(): + typedef MethodSignature< MyType, void () > NoArgsReturnsVoid; + + // int MyType::func(double): + typedef MethodSignature< MyType, int (double) > OneArgReturnsInt; + + // double MyType::func(int,int): + typedef MethodSignature< MyType, double (int,int) > TwoArgsReturnsDouble; + @endcode + + As of r2019 (20110723), MethodSignature and + ConstMethodSignature are equivalent. + + Reminders to self: + + i would really like this class to simply subclass Signature and we + would add in a couple typedefs we need. This would cut the specializations + we generate. However, i don't know how to make this work. The problems + include: + + - i can't "refactor" Signature::FunctionType to the proper type + at this level. +*/ +template +struct MethodSignature DOXYGEN_FWD_DECL_KLUDGE; + +/** @class ConstMethodSignature + Base (unimplemented) signature for ConstMethodSignature + specializations. The Sig type passed to it must be a member + method signature of a const function from the class T. + e.g. (void (T::*)(int) const) + + All implementations must have the interface called for by Signature + and the Context typedef must be non-cvp-qualified T. The IsConst + member (enum or static/const boolean) must be a true value. + + Examples: + + @code + // void MyType::func() const: + typedef ConstMethodSignature< MyType, void () > NoArgsReturnsVoid; + + // int MyType::func(double) const: + typedef ConstMethodSignature< MyType, int (double) > OneArgReturnsInt; + + // double MyType::func(int,int) const: + typedef ConstMethodSignature< MyType, double (int,int) > TwoArgsReturnsDouble; + @endcode + + As of r2019 (20110723), MethodSignature and + ConstMethodSignature are equivalent. +*/ +template +struct ConstMethodSignature DOXYGEN_FWD_DECL_KLUDGE; +//template +//struct ConstMethodSignature : ConstMethodSignature {}; + +template +struct MethodSignature< T, RV () > : Signature< RV () > +{ + typedef T Context; + typedef RV (Context::*FunctionType)(); +}; + + +template +struct MethodSignature< T, RV (T::*)() > : MethodSignature +{ +}; + +template +struct MethodSignature< T const, RV () > : ConstMethodSignature< T, RV () > +{}; + +template +struct MethodSignature< T const, RV (T::*)() > : MethodSignature +{ +}; +#if 1 //msvc? +template +struct MethodSignature< T const, RV (T::*)() const > : MethodSignature +{ +}; +#endif + +template +struct ConstMethodSignature< T, RV () > : Signature< RV (T::*)() const > +{ + typedef T const Context; + typedef RV (Context::*FunctionType)() const; +}; +template +struct ConstMethodSignature< T, RV (T::*)() const > : ConstMethodSignature +{ +}; + + +/** + A "type-rich" function pointer. + + Sig must be a function signature type usable in the construct + FunctionSignature. FuncPtr must be a function of that type. +*/ +template ::FunctionType FuncPtr> +struct FunctionPtr : FunctionSignature +{ + /** + This type's full "signature" type. + */ + typedef FunctionSignature SignatureType; + /** + The data type of FuncPtr. + */ + typedef typename SignatureType::FunctionType FunctionType; + + /** The function specifies in the template arguments. */ + static const FunctionType Function; +}; +template ::FunctionType FuncPtr> +typename FunctionPtr::FunctionType const FunctionPtr::Function = FuncPtr; + +/** + Used like FunctionPtr, but in conjunction with non-const + member functions ("methods") of the T class. See FunctionPtr + for the requirements of the Sig type. +*/ +template ::FunctionType FuncPtr> +struct MethodPtr : MethodSignature +{ + typedef MethodSignature SignatureType; + typedef typename SignatureType::FunctionType FunctionType; + static const FunctionType Function; +}; +template ::FunctionType FuncPtr> +typename MethodPtr::FunctionType const MethodPtr::Function = FuncPtr; +/** + Used like MethodPtr, but in conjunction with const methods of the T + class. +*/ +template ::FunctionType FuncPtr> +struct ConstMethodPtr : ConstMethodSignature +{ + typedef ConstMethodSignature SignatureType; + typedef typename SignatureType::FunctionType FunctionType; + static const FunctionType Function; +}; +template ::FunctionType FuncPtr> +typename ConstMethodPtr::FunctionType const ConstMethodPtr::Function = FuncPtr; + +#if 0 //!msvc +//! Specialization to treat (const T) as ConstMethodPtr. +template ::FunctionType FuncPtr> +struct MethodPtr : ConstMethodPtr +{ + typedef MethodSignature SignatureType; + typedef typename SignatureType::FunctionType FunctionType; + static const FunctionType Function; +}; +#endif + +#include "signature_generated.hpp" +} // namespaces + +#endif /* CODE_GOOGLE_COM_V8_CONVERT_SIGNATURE_CORE_HPP_INCLUDED */ diff --git a/vendor/libv8-convert/cvv8/detail/signature_generated.hpp b/vendor/libv8-convert/cvv8/detail/signature_generated.hpp new file mode 100644 index 000000000..30102c1f2 --- /dev/null +++ b/vendor/libv8-convert/cvv8/detail/signature_generated.hpp @@ -0,0 +1,911 @@ +/* AUTO-GENERATED CODE! EDIT AT YOUR OWN RISK! */ +#if !defined(DOXYGEN) + +template +struct Signature< RV () > +{ + typedef RV ReturnType; + enum { IsConst = 0 }; + typedef void Context; + typedef RV (*FunctionType)(); + typedef tmp::NilType Head; + typedef Head Tail; +}; +template +struct Signature< RV (*)() > : Signature +{}; + +template +struct Signature< RV (T::*)() > : Signature +{ + typedef T Context; + typedef RV (T::*FunctionType)(); +}; +template +struct Signature< RV (T::*)() const > : Signature +{ + typedef T const Context; + typedef RV (T::*FunctionType)() const; + enum { IsConst = 1 }; +}; +//! Specialization for 1 arg(s). +template +struct Signature< RV (A1) > +{ + typedef RV ReturnType; + typedef void Context; + typedef RV (*FunctionType)(A1); + typedef A1 Head; + typedef Signature< RV () > Tail; +}; + +//! Specialization for 1 arg(s). +template +struct Signature< RV (*)(A1) > : Signature +{}; + +//! Specialization for T non-const methods taking 1 arg(s). +template +struct Signature< RV (T::*)(A1) > : Signature +{ + typedef T Context; + typedef RV (T::*FunctionType)(A1); +}; + +//! Specialization for T const methods taking 1 arg(s). +template +struct Signature< RV (T::*)(A1) const > : Signature +{ + typedef T const Context; + typedef RV (T::*FunctionType)(A1) const; +}; + +//! Specialization for 2 arg(s). +template +struct Signature< RV (A1, A2) > +{ + typedef RV ReturnType; + typedef void Context; + typedef RV (*FunctionType)(A1, A2); + typedef A1 Head; + typedef Signature Tail; +}; + +//! Specialization for 2 arg(s). +template +struct Signature< RV (*)(A1, A2) > : Signature +{}; + +//! Specialization for T non-const methods taking 2 arg(s). +template +struct Signature< RV (T::*)(A1, A2) > : Signature +{ + typedef T Context; + typedef RV (T::*FunctionType)(A1, A2); +}; + +//! Specialization for T const methods taking 2 arg(s). +template +struct Signature< RV (T::*)(A1, A2) const > : Signature +{ + typedef T const Context; + typedef RV (T::*FunctionType)(A1, A2) const; +}; + +//! Specialization for 3 arg(s). +template +struct Signature< RV (A1, A2, A3) > +{ + typedef RV ReturnType; + typedef void Context; + typedef RV (*FunctionType)(A1, A2, A3); + typedef A1 Head; + typedef Signature Tail; +}; + +//! Specialization for 3 arg(s). +template +struct Signature< RV (*)(A1, A2, A3) > : Signature +{}; + +//! Specialization for T non-const methods taking 3 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3) > : Signature +{ + typedef T Context; + typedef RV (T::*FunctionType)(A1, A2, A3); +}; + +//! Specialization for T const methods taking 3 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3) const > : Signature +{ + typedef T const Context; + typedef RV (T::*FunctionType)(A1, A2, A3) const; +}; + +//! Specialization for 4 arg(s). +template +struct Signature< RV (A1, A2, A3, A4) > +{ + typedef RV ReturnType; + typedef void Context; + typedef RV (*FunctionType)(A1, A2, A3, A4); + typedef A1 Head; + typedef Signature Tail; +}; + +//! Specialization for 4 arg(s). +template +struct Signature< RV (*)(A1, A2, A3, A4) > : Signature +{}; + +//! Specialization for T non-const methods taking 4 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4) > : Signature +{ + typedef T Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4); +}; + +//! Specialization for T const methods taking 4 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4) const > : Signature +{ + typedef T const Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4) const; +}; + +//! Specialization for 5 arg(s). +template +struct Signature< RV (A1, A2, A3, A4, A5) > +{ + typedef RV ReturnType; + typedef void Context; + typedef RV (*FunctionType)(A1, A2, A3, A4, A5); + typedef A1 Head; + typedef Signature Tail; +}; + +//! Specialization for 5 arg(s). +template +struct Signature< RV (*)(A1, A2, A3, A4, A5) > : Signature +{}; + +//! Specialization for T non-const methods taking 5 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5) > : Signature +{ + typedef T Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5); +}; + +//! Specialization for T const methods taking 5 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5) const > : Signature +{ + typedef T const Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5) const; +}; + +//! Specialization for 6 arg(s). +template +struct Signature< RV (A1, A2, A3, A4, A5, A6) > +{ + typedef RV ReturnType; + typedef void Context; + typedef RV (*FunctionType)(A1, A2, A3, A4, A5, A6); + typedef A1 Head; + typedef Signature Tail; +}; + +//! Specialization for 6 arg(s). +template +struct Signature< RV (*)(A1, A2, A3, A4, A5, A6) > : Signature +{}; + +//! Specialization for T non-const methods taking 6 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6) > : Signature +{ + typedef T Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6); +}; + +//! Specialization for T const methods taking 6 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6) const > : Signature +{ + typedef T const Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6) const; +}; + +//! Specialization for 7 arg(s). +template +struct Signature< RV (A1, A2, A3, A4, A5, A6, A7) > +{ + typedef RV ReturnType; + typedef void Context; + typedef RV (*FunctionType)(A1, A2, A3, A4, A5, A6, A7); + typedef A1 Head; + typedef Signature Tail; +}; + +//! Specialization for 7 arg(s). +template +struct Signature< RV (*)(A1, A2, A3, A4, A5, A6, A7) > : Signature +{}; + +//! Specialization for T non-const methods taking 7 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6, A7) > : Signature +{ + typedef T Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6, A7); +}; + +//! Specialization for T const methods taking 7 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6, A7) const > : Signature +{ + typedef T const Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6, A7) const; +}; + +//! Specialization for 8 arg(s). +template +struct Signature< RV (A1, A2, A3, A4, A5, A6, A7, A8) > +{ + typedef RV ReturnType; + typedef void Context; + typedef RV (*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8); + typedef A1 Head; + typedef Signature Tail; +}; + +//! Specialization for 8 arg(s). +template +struct Signature< RV (*)(A1, A2, A3, A4, A5, A6, A7, A8) > : Signature +{}; + +//! Specialization for T non-const methods taking 8 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6, A7, A8) > : Signature +{ + typedef T Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8); +}; + +//! Specialization for T const methods taking 8 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6, A7, A8) const > : Signature +{ + typedef T const Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8) const; +}; + +//! Specialization for 9 arg(s). +template +struct Signature< RV (A1, A2, A3, A4, A5, A6, A7, A8, A9) > +{ + typedef RV ReturnType; + typedef void Context; + typedef RV (*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9); + typedef A1 Head; + typedef Signature Tail; +}; + +//! Specialization for 9 arg(s). +template +struct Signature< RV (*)(A1, A2, A3, A4, A5, A6, A7, A8, A9) > : Signature +{}; + +//! Specialization for T non-const methods taking 9 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9) > : Signature +{ + typedef T Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9); +}; + +//! Specialization for T const methods taking 9 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9) const > : Signature +{ + typedef T const Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9) const; +}; + +//! Specialization for 10 arg(s). +template +struct Signature< RV (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) > +{ + typedef RV ReturnType; + typedef void Context; + typedef RV (*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); + typedef A1 Head; + typedef Signature Tail; +}; + +//! Specialization for 10 arg(s). +template +struct Signature< RV (*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) > : Signature +{}; + +//! Specialization for T non-const methods taking 10 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) > : Signature +{ + typedef T Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10); +}; + +//! Specialization for T const methods taking 10 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) const > : Signature +{ + typedef T const Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10) const; +}; + +//! Specialization for 11 arg(s). +template +struct Signature< RV (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11) > +{ + typedef RV ReturnType; + typedef void Context; + typedef RV (*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11); + typedef A1 Head; + typedef Signature Tail; +}; + +//! Specialization for 11 arg(s). +template +struct Signature< RV (*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11) > : Signature +{}; + +//! Specialization for T non-const methods taking 11 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11) > : Signature +{ + typedef T Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11); +}; + +//! Specialization for T const methods taking 11 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11) const > : Signature +{ + typedef T const Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11) const; +}; + +//! Specialization for 12 arg(s). +template +struct Signature< RV (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12) > +{ + typedef RV ReturnType; + typedef void Context; + typedef RV (*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12); + typedef A1 Head; + typedef Signature Tail; +}; + +//! Specialization for 12 arg(s). +template +struct Signature< RV (*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12) > : Signature +{}; + +//! Specialization for T non-const methods taking 12 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12) > : Signature +{ + typedef T Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12); +}; + +//! Specialization for T const methods taking 12 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12) const > : Signature +{ + typedef T const Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12) const; +}; + +//! Specialization for 13 arg(s). +template +struct Signature< RV (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13) > +{ + typedef RV ReturnType; + typedef void Context; + typedef RV (*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13); + typedef A1 Head; + typedef Signature Tail; +}; + +//! Specialization for 13 arg(s). +template +struct Signature< RV (*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13) > : Signature +{}; + +//! Specialization for T non-const methods taking 13 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13) > : Signature +{ + typedef T Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13); +}; + +//! Specialization for T const methods taking 13 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13) const > : Signature +{ + typedef T const Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13) const; +}; + +//! Specialization for 14 arg(s). +template +struct Signature< RV (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14) > +{ + typedef RV ReturnType; + typedef void Context; + typedef RV (*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14); + typedef A1 Head; + typedef Signature Tail; +}; + +//! Specialization for 14 arg(s). +template +struct Signature< RV (*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14) > : Signature +{}; + +//! Specialization for T non-const methods taking 14 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14) > : Signature +{ + typedef T Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14); +}; + +//! Specialization for T const methods taking 14 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14) const > : Signature +{ + typedef T const Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14) const; +}; + +//! Specialization for 15 arg(s). +template +struct Signature< RV (A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15) > +{ + typedef RV ReturnType; + typedef void Context; + typedef RV (*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15); + typedef A1 Head; + typedef Signature Tail; +}; + +//! Specialization for 15 arg(s). +template +struct Signature< RV (*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15) > : Signature +{}; + +//! Specialization for T non-const methods taking 15 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15) > : Signature +{ + typedef T Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15); +}; + +//! Specialization for T const methods taking 15 arg(s). +template +struct Signature< RV (T::*)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15) const > : Signature +{ + typedef T const Context; + typedef RV (T::*FunctionType)(A1, A2, A3, A4, A5, A6, A7, A8, A9, A10, A11, A12, A13, A14, A15) const; +}; + +template +struct MethodSignature< T, RV ( A0) > : Signature< RV (T::*)( A0) > +{ +}; +template +struct MethodSignature< T, RV (*)( A0) > : MethodSignature< T, RV ( A0) > +{ +}; + +template +struct MethodSignature< T, RV (T::*)( A0) > : + MethodSignature< T, RV ( A0) > +{}; + +template +struct MethodSignature< T const, RV ( A0) > : + ConstMethodSignature< T, RV ( A0) > +{}; + +template +struct MethodSignature< T const, RV (T::*)( A0) > : + MethodSignature< T const, RV ( A0) > +{}; + +#if 1 // msvc? Apparently this works. +template +struct MethodSignature< T const, RV (T::*)( A0) const > : + MethodSignature< T const, RV ( A0) > +{}; +#endif + + +template +struct ConstMethodSignature< T, RV ( A0) > : Signature< RV (T::*)( A0) const > +{ +}; +template +struct ConstMethodSignature< T, RV (T::*)( A0) const > : + ConstMethodSignature< T, RV ( A0) > +{}; +template +struct MethodSignature< T, RV ( A0, A1) > : Signature< RV (T::*)( A0, A1) > +{ +}; +template +struct MethodSignature< T, RV (*)( A0, A1) > : MethodSignature< T, RV ( A0, A1) > +{ +}; + +template +struct MethodSignature< T, RV (T::*)( A0, A1) > : + MethodSignature< T, RV ( A0, A1) > +{}; + +template +struct MethodSignature< T const, RV ( A0, A1) > : + ConstMethodSignature< T, RV ( A0, A1) > +{}; + +template +struct MethodSignature< T const, RV (T::*)( A0, A1) > : + MethodSignature< T const, RV ( A0, A1) > +{}; + +#if 1 // msvc? Apparently this works. +template +struct MethodSignature< T const, RV (T::*)( A0, A1) const > : + MethodSignature< T const, RV ( A0, A1) > +{}; +#endif + + +template +struct ConstMethodSignature< T, RV ( A0, A1) > : Signature< RV (T::*)( A0, A1) const > +{ +}; +template +struct ConstMethodSignature< T, RV (T::*)( A0, A1) const > : + ConstMethodSignature< T, RV ( A0, A1) > +{}; +template +struct MethodSignature< T, RV ( A0, A1, A2) > : Signature< RV (T::*)( A0, A1, A2) > +{ +}; +template +struct MethodSignature< T, RV (*)( A0, A1, A2) > : MethodSignature< T, RV ( A0, A1, A2) > +{ +}; + +template +struct MethodSignature< T, RV (T::*)( A0, A1, A2) > : + MethodSignature< T, RV ( A0, A1, A2) > +{}; + +template +struct MethodSignature< T const, RV ( A0, A1, A2) > : + ConstMethodSignature< T, RV ( A0, A1, A2) > +{}; + +template +struct MethodSignature< T const, RV (T::*)( A0, A1, A2) > : + MethodSignature< T const, RV ( A0, A1, A2) > +{}; + +#if 1 // msvc? Apparently this works. +template +struct MethodSignature< T const, RV (T::*)( A0, A1, A2) const > : + MethodSignature< T const, RV ( A0, A1, A2) > +{}; +#endif + + +template +struct ConstMethodSignature< T, RV ( A0, A1, A2) > : Signature< RV (T::*)( A0, A1, A2) const > +{ +}; +template +struct ConstMethodSignature< T, RV (T::*)( A0, A1, A2) const > : + ConstMethodSignature< T, RV ( A0, A1, A2) > +{}; +template +struct MethodSignature< T, RV ( A0, A1, A2, A3) > : Signature< RV (T::*)( A0, A1, A2, A3) > +{ +}; +template +struct MethodSignature< T, RV (*)( A0, A1, A2, A3) > : MethodSignature< T, RV ( A0, A1, A2, A3) > +{ +}; + +template +struct MethodSignature< T, RV (T::*)( A0, A1, A2, A3) > : + MethodSignature< T, RV ( A0, A1, A2, A3) > +{}; + +template +struct MethodSignature< T const, RV ( A0, A1, A2, A3) > : + ConstMethodSignature< T, RV ( A0, A1, A2, A3) > +{}; + +template +struct MethodSignature< T const, RV (T::*)( A0, A1, A2, A3) > : + MethodSignature< T const, RV ( A0, A1, A2, A3) > +{}; + +#if 1 // msvc? Apparently this works. +template +struct MethodSignature< T const, RV (T::*)( A0, A1, A2, A3) const > : + MethodSignature< T const, RV ( A0, A1, A2, A3) > +{}; +#endif + + +template +struct ConstMethodSignature< T, RV ( A0, A1, A2, A3) > : Signature< RV (T::*)( A0, A1, A2, A3) const > +{ +}; +template +struct ConstMethodSignature< T, RV (T::*)( A0, A1, A2, A3) const > : + ConstMethodSignature< T, RV ( A0, A1, A2, A3) > +{}; +template +struct MethodSignature< T, RV ( A0, A1, A2, A3, A4) > : Signature< RV (T::*)( A0, A1, A2, A3, A4) > +{ +}; +template +struct MethodSignature< T, RV (*)( A0, A1, A2, A3, A4) > : MethodSignature< T, RV ( A0, A1, A2, A3, A4) > +{ +}; + +template +struct MethodSignature< T, RV (T::*)( A0, A1, A2, A3, A4) > : + MethodSignature< T, RV ( A0, A1, A2, A3, A4) > +{}; + +template +struct MethodSignature< T const, RV ( A0, A1, A2, A3, A4) > : + ConstMethodSignature< T, RV ( A0, A1, A2, A3, A4) > +{}; + +template +struct MethodSignature< T const, RV (T::*)( A0, A1, A2, A3, A4) > : + MethodSignature< T const, RV ( A0, A1, A2, A3, A4) > +{}; + +#if 1 // msvc? Apparently this works. +template +struct MethodSignature< T const, RV (T::*)( A0, A1, A2, A3, A4) const > : + MethodSignature< T const, RV ( A0, A1, A2, A3, A4) > +{}; +#endif + + +template +struct ConstMethodSignature< T, RV ( A0, A1, A2, A3, A4) > : Signature< RV (T::*)( A0, A1, A2, A3, A4) const > +{ +}; +template +struct ConstMethodSignature< T, RV (T::*)( A0, A1, A2, A3, A4) const > : + ConstMethodSignature< T, RV ( A0, A1, A2, A3, A4) > +{}; +template +struct MethodSignature< T, RV ( A0, A1, A2, A3, A4, A5) > : Signature< RV (T::*)( A0, A1, A2, A3, A4, A5) > +{ +}; +template +struct MethodSignature< T, RV (*)( A0, A1, A2, A3, A4, A5) > : MethodSignature< T, RV ( A0, A1, A2, A3, A4, A5) > +{ +}; + +template +struct MethodSignature< T, RV (T::*)( A0, A1, A2, A3, A4, A5) > : + MethodSignature< T, RV ( A0, A1, A2, A3, A4, A5) > +{}; + +template +struct MethodSignature< T const, RV ( A0, A1, A2, A3, A4, A5) > : + ConstMethodSignature< T, RV ( A0, A1, A2, A3, A4, A5) > +{}; + +template +struct MethodSignature< T const, RV (T::*)( A0, A1, A2, A3, A4, A5) > : + MethodSignature< T const, RV ( A0, A1, A2, A3, A4, A5) > +{}; + +#if 1 // msvc? Apparently this works. +template +struct MethodSignature< T const, RV (T::*)( A0, A1, A2, A3, A4, A5) const > : + MethodSignature< T const, RV ( A0, A1, A2, A3, A4, A5) > +{}; +#endif + + +template +struct ConstMethodSignature< T, RV ( A0, A1, A2, A3, A4, A5) > : Signature< RV (T::*)( A0, A1, A2, A3, A4, A5) const > +{ +}; +template +struct ConstMethodSignature< T, RV (T::*)( A0, A1, A2, A3, A4, A5) const > : + ConstMethodSignature< T, RV ( A0, A1, A2, A3, A4, A5) > +{}; +template +struct MethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6) > : Signature< RV (T::*)( A0, A1, A2, A3, A4, A5, A6) > +{ +}; +template +struct MethodSignature< T, RV (*)( A0, A1, A2, A3, A4, A5, A6) > : MethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6) > +{ +}; + +template +struct MethodSignature< T, RV (T::*)( A0, A1, A2, A3, A4, A5, A6) > : + MethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6) > +{}; + +template +struct MethodSignature< T const, RV ( A0, A1, A2, A3, A4, A5, A6) > : + ConstMethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6) > +{}; + +template +struct MethodSignature< T const, RV (T::*)( A0, A1, A2, A3, A4, A5, A6) > : + MethodSignature< T const, RV ( A0, A1, A2, A3, A4, A5, A6) > +{}; + +#if 1 // msvc? Apparently this works. +template +struct MethodSignature< T const, RV (T::*)( A0, A1, A2, A3, A4, A5, A6) const > : + MethodSignature< T const, RV ( A0, A1, A2, A3, A4, A5, A6) > +{}; +#endif + + +template +struct ConstMethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6) > : Signature< RV (T::*)( A0, A1, A2, A3, A4, A5, A6) const > +{ +}; +template +struct ConstMethodSignature< T, RV (T::*)( A0, A1, A2, A3, A4, A5, A6) const > : + ConstMethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6) > +{}; +template +struct MethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6, A7) > : Signature< RV (T::*)( A0, A1, A2, A3, A4, A5, A6, A7) > +{ +}; +template +struct MethodSignature< T, RV (*)( A0, A1, A2, A3, A4, A5, A6, A7) > : MethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6, A7) > +{ +}; + +template +struct MethodSignature< T, RV (T::*)( A0, A1, A2, A3, A4, A5, A6, A7) > : + MethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6, A7) > +{}; + +template +struct MethodSignature< T const, RV ( A0, A1, A2, A3, A4, A5, A6, A7) > : + ConstMethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6, A7) > +{}; + +template +struct MethodSignature< T const, RV (T::*)( A0, A1, A2, A3, A4, A5, A6, A7) > : + MethodSignature< T const, RV ( A0, A1, A2, A3, A4, A5, A6, A7) > +{}; + +#if 1 // msvc? Apparently this works. +template +struct MethodSignature< T const, RV (T::*)( A0, A1, A2, A3, A4, A5, A6, A7) const > : + MethodSignature< T const, RV ( A0, A1, A2, A3, A4, A5, A6, A7) > +{}; +#endif + + +template +struct ConstMethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6, A7) > : Signature< RV (T::*)( A0, A1, A2, A3, A4, A5, A6, A7) const > +{ +}; +template +struct ConstMethodSignature< T, RV (T::*)( A0, A1, A2, A3, A4, A5, A6, A7) const > : + ConstMethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6, A7) > +{}; +template +struct MethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6, A7, A8) > : Signature< RV (T::*)( A0, A1, A2, A3, A4, A5, A6, A7, A8) > +{ +}; +template +struct MethodSignature< T, RV (*)( A0, A1, A2, A3, A4, A5, A6, A7, A8) > : MethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6, A7, A8) > +{ +}; + +template +struct MethodSignature< T, RV (T::*)( A0, A1, A2, A3, A4, A5, A6, A7, A8) > : + MethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6, A7, A8) > +{}; + +template +struct MethodSignature< T const, RV ( A0, A1, A2, A3, A4, A5, A6, A7, A8) > : + ConstMethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6, A7, A8) > +{}; + +template +struct MethodSignature< T const, RV (T::*)( A0, A1, A2, A3, A4, A5, A6, A7, A8) > : + MethodSignature< T const, RV ( A0, A1, A2, A3, A4, A5, A6, A7, A8) > +{}; + +#if 1 // msvc? Apparently this works. +template +struct MethodSignature< T const, RV (T::*)( A0, A1, A2, A3, A4, A5, A6, A7, A8) const > : + MethodSignature< T const, RV ( A0, A1, A2, A3, A4, A5, A6, A7, A8) > +{}; +#endif + + +template +struct ConstMethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6, A7, A8) > : Signature< RV (T::*)( A0, A1, A2, A3, A4, A5, A6, A7, A8) const > +{ +}; +template +struct ConstMethodSignature< T, RV (T::*)( A0, A1, A2, A3, A4, A5, A6, A7, A8) const > : + ConstMethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6, A7, A8) > +{}; +template +struct MethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) > : Signature< RV (T::*)( A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) > +{ +}; +template +struct MethodSignature< T, RV (*)( A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) > : MethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) > +{ +}; + +template +struct MethodSignature< T, RV (T::*)( A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) > : + MethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) > +{}; + +template +struct MethodSignature< T const, RV ( A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) > : + ConstMethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) > +{}; + +template +struct MethodSignature< T const, RV (T::*)( A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) > : + MethodSignature< T const, RV ( A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) > +{}; + +#if 1 // msvc? Apparently this works. +template +struct MethodSignature< T const, RV (T::*)( A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) const > : + MethodSignature< T const, RV ( A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) > +{}; +#endif + + +template +struct ConstMethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) > : Signature< RV (T::*)( A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) const > +{ +}; +template +struct ConstMethodSignature< T, RV (T::*)( A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) const > : + ConstMethodSignature< T, RV ( A0, A1, A2, A3, A4, A5, A6, A7, A8, A9) > +{}; +#endif // if !defined(DOXYGEN) diff --git a/vendor/libv8-convert/cvv8/detail/tmp.hpp b/vendor/libv8-convert/cvv8/detail/tmp.hpp new file mode 100644 index 000000000..aff069f6c --- /dev/null +++ b/vendor/libv8-convert/cvv8/detail/tmp.hpp @@ -0,0 +1,120 @@ +#ifndef CODE_GOOGLE_COM_P_V8_CONVERT_TMP_HPP_INCLUDED +#define CODE_GOOGLE_COM_P_V8_CONVERT_TMP_HPP_INCLUDED + +namespace cvv8 { +/** + The tmp namespace contains code related to template + metaprogramming, a-la Alexandrescu's Loki library or Boost MPL. + + All of it is independent of the core library. + + This is not a complete/full-featured TMP library - it only + contains the functions needed by our library-level code. +*/ +namespace tmp { + + struct NilType {}; + typedef NilType nil; + + + /** + An utmost most-basic compile-time assertion template. + If Condition is false, an incomplete specialization of + this type is invoked, causing a compile-time error. + */ + template + struct Assertion + { + enum { Value = 1 }; + }; + /** Unimplemented - causes a compile-time error if used. */ + template <> + struct Assertion; + + + /** A convenience base type for metafunctions holding a constant value. */ + template + struct ConstVal + { + static const ValType Value = Val; + }; + /** A metafunction holding an integer constant. */ + template + struct IntVal : ConstVal {}; + /** A metafunction holding an unsigned short constant. */ + template + struct UShortVal : ConstVal {}; + /** A metafunction holding a bool constant. */ + template + struct BoolVal : ConstVal {}; + + /** A metatype whos Value member is true if X and Y are the same type. */ + template + struct SameType : BoolVal {}; + /** Specialization for X==Y. */ + template + struct SameType : BoolVal {}; + + template + struct Identity + { + typedef T Type; + }; + + template + struct PlainType + { + typedef T Type; + }; + template + struct PlainType : PlainType {}; + template + struct PlainType : PlainType {}; + template + struct PlainType : PlainType {}; + +#if 0 + /** Metatemplate whose Type evaluates to (T*). */ + template + struct AddPointer + { + typedef T * Type; + }; + /** Specialization whose Type evaluates to (T *). */ + template + struct AddPointer + { + typedef T * Type; + }; + /** Specialization whose Type evaluates to (T const *). */ + template + struct AddPointer + { + typedef T const * Type; + }; + + //! Unimplemented. How to handle this? + template + struct AddPointer; + //! Unimplemented. How to handle this? + template + struct AddPointer; +#endif + + template + struct IsConst : BoolVal {}; + template + struct IsConst : BoolVal {}; + template + struct IsConst : IsConst {}; + template + struct IsConst : IsConst {}; + + + template + struct IsNil : SameType {}; + + + +}} // namespaces +#endif // CODE_GOOGLE_COM_P_V8_CONVERT_TMP_HPP_INCLUDED diff --git a/vendor/libv8-convert/cvv8/generator/Signature.hpp b/vendor/libv8-convert/cvv8/generator/Signature.hpp new file mode 100644 index 000000000..969a5e54b --- /dev/null +++ b/vendor/libv8-convert/cvv8/generator/Signature.hpp @@ -0,0 +1,72 @@ +#if !defined(BOOST_PP_IS_ITERATING) +# include +# include +# include +# include +# include +# if !defined(CVV8_PP_ITER_MAX) +# error "Define CVV8_PP_ITER_MAX before including this file." +# endif +# if !defined(CVV8_SIGNATURE_GENERATED_HPP_INCLUDED) +# define BOOST_PP_ITERATION_LIMITS (0, CVV8_PP_ITER_MAX) +# define BOOST_PP_FILENAME_1 "Signature.hpp" +# include BOOST_PP_ITERATE() +# endif /* include guard */ +#else +#define n BOOST_PP_ITERATION() + +template +struct Signature< RV (BOOST_PP_ENUM_PARAMS(n, A)) > +{ + typedef RV ReturnType; + static const bool IsConst = false; + typedef void Context; + typedef RV (*FunctionType)(BOOST_PP_ENUM_PARAMS(n, A)); +#if n > 0 + typedef A0 Head; + typedef Signature< RV (BOOST_PP_ENUM_SHIFTED_PARAMS(n, A)) > Tail; +#else + typedef tmp::NilType Head; + typedef Head Tail; +#endif +}; + +template +struct Signature< RV (*)(BOOST_PP_ENUM_PARAMS(n, A)) > + : Signature< RV (BOOST_PP_ENUM_PARAMS(n, A)) > +{}; + +//! Non-const method. +template +struct Signature< RV (T::*)(BOOST_PP_ENUM_PARAMS(n, A)) > + : Signature< RV (BOOST_PP_ENUM_PARAMS(n, A))> +{ + typedef T Context; + typedef RV (Context::*FunctionType)(BOOST_PP_ENUM_PARAMS(n, A)); +#if n > 0 + typedef A0 Head; + typedef Signature< RV (T::*)(BOOST_PP_ENUM_SHIFTED_PARAMS(n, A)) > Tail; +#else + typedef tmp::NilType Head; + typedef Head Tail; +#endif +}; + +//! Const method. +template +struct Signature< RV (T::*)(BOOST_PP_ENUM_PARAMS(n, A)) const > + : Signature< RV (BOOST_PP_ENUM_PARAMS(n, A))> +{ + typedef T const Context; + typedef RV (Context::*FunctionType)(BOOST_PP_ENUM_PARAMS(n, A)) const; + static const bool IsConst = true; +#if n > 0 + typedef A0 Head; + typedef Signature< RV (T::*)(BOOST_PP_ENUM_SHIFTED_PARAMS(n, A)) const > Tail; +#else + typedef tmp::NilType Head; + typedef Head Tail; +#endif +}; + +#endif /* BOOST_PP_IS_ITERATING */ diff --git a/vendor/libv8-convert/cvv8/invocable.hpp b/vendor/libv8-convert/cvv8/invocable.hpp new file mode 100644 index 000000000..dac513380 --- /dev/null +++ b/vendor/libv8-convert/cvv8/invocable.hpp @@ -0,0 +1,67 @@ +#if !defined(CODE_GOOGLE_COM_P_V8_CONVERT_INVOKE_HPP_INCLUDED) +#define CODE_GOOGLE_COM_P_V8_CONVERT_INVOKE_HPP_INCLUDED 1 + +#include "convert.hpp" +#include "detail/invocable_core.hpp" +/** LICENSE + + This software's source code, including accompanying documentation and + demonstration applications, are licensed under the following + conditions... + + The author (Stephan G. Beal [http://wanderinghorse.net/home/stephan/]) + explicitly disclaims copyright in all jurisdictions which recognize + such a disclaimer. In such jurisdictions, this software is released + into the Public Domain. + + In jurisdictions which do not recognize Public Domain property + (e.g. Germany as of 2011), this software is Copyright (c) 2011 + by Stephan G. Beal, and is released under the terms of the MIT License + (see below). + + In jurisdictions which recognize Public Domain property, the user of + this software may choose to accept it either as 1) Public Domain, 2) + under the conditions of the MIT License (see below), or 3) under the + terms of dual Public Domain/MIT License conditions described here, as + they choose. + + The MIT License is about as close to Public Domain as a license can + get, and is described in clear, concise terms at: + + http://en.wikipedia.org/wiki/MIT_License + + The full text of the MIT License follows: + + -- + Copyright (c) 2011 Stephan G. Beal (http://wanderinghorse.net/home/stephan/) + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following + conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. + + --END OF MIT LICENSE-- + + For purposes of the above license, the term "Software" includes + documentation and demonstration source code which accompanies + this software. ("Accompanies" = is contained in the Software's + primary public source code repository.) + +*/ +#endif /* CODE_GOOGLE_COM_P_V8_CONVERT_INVOKE_HPP_INCLUDED */ diff --git a/vendor/libv8-convert/cvv8/properties.hpp b/vendor/libv8-convert/cvv8/properties.hpp new file mode 100644 index 000000000..1b4b936ad --- /dev/null +++ b/vendor/libv8-convert/cvv8/properties.hpp @@ -0,0 +1,730 @@ +#if !defined(CODE_GOOGLE_COM_P_V8_CONVERT_PROPERTIES_HPP_INCLUDED) +#define CODE_GOOGLE_COM_P_V8_CONVERT_PROPERTIES_HPP_INCLUDED 1 + +#include "invocable.hpp" + +namespace cvv8 { + + /** + Marker class, primarily for documentation purposes. + + This class models the v8::AccessorGetter interface, and + XyzToGetter classes inherit this type as a sign that they + implement this interface. + + This class has no implemention - it only exists for + documentation purposes. + */ + struct AccessorGetterType + { + /** + The v8::AccessorGetter() interface. + */ + static v8::Handle Get(v8::Local property, const v8::AccessorInfo &info); + //{ return Toss(StringBuffer()<<"Property '"< property, v8::Local value, const v8::AccessorInfo& info); + }; + + /** @typedef AccessorGetterType Getter + + Convenience typedef, primarily to simplify usage of + FunctionTo and friends. + */ + typedef AccessorGetterType Getter; + + /** @typedef AccessorSetterType Setter + + Convenience typedef, primarily to simplify usage of + FunctionTo and friends. + */ + typedef AccessorSetterType Setter; + + /** + A tag type for use with VarTo, MemberTo, MethodTo, and FunctionTo. + */ + struct Accessors : AccessorGetterType, AccessorSetterType {}; + + /** + This template create an v8::AccessorGetter from a static/shared + variable. + + SharedVar must be pointer to a static variable and must not + be NULL. + + CastToJS(*SharedVar) must be legal. + */ + template + struct VarToGetter : AccessorGetterType + { + /** Implements the v8::AccessorGetter() interface. */ + inline static v8::Handle Get(v8::Local property, const v8::AccessorInfo &info) + { + return CastToJS( *SharedVar ); + } + }; + + /** + The setter counterpart of StaticVarToGetter(). + + SharedVar must be pointer to a static variable and must not + be NULL. + + (*SharedVar = CastFromJS()) must be legal. + + Reminder: this is not included in the StaticVarToGetter + template so that we can avoid either the Get or Set + conversion for cases where it is not legal (or not desired). + If they were both in one class, both Get and Set would _have_ + to be legal. + */ + template + struct VarToSetter : AccessorSetterType + { + /** Implements the v8::AccessorSetter() interface. */ + inline static void Set(v8::Local property, v8::Local value, const v8::AccessorInfo& info) + { + *SharedVar = CastFromJS( value ); + } + }; + + /** + A proxy for both VarToGetter and VarToSetter, providing both + Get() and Set() functions. + */ + template + struct VarToAccessors : VarToGetter, + VarToSetter + {}; + + /** + This template creates a v8::AcessorGetter which binds directly to + a non-const native class member variable. + + Requirements: + + - T must be convertible to (T*) via CastFromJS(). + - MemVar must be an accessible member of T. + - PropertyType must be convertible via CastToJS(). + + If the underlying native 'this' object cannot be found (that + is, if CastFromJS() fails) then this routine will + trigger a JS exception. + */ + template + struct MemberToGetter : AccessorGetterType + { + /** Implements the v8::AccessorGetter() interface. */ + inline static v8::Handle Get(v8::Local property, const v8::AccessorInfo &info) + { + typedef typename TypeInfo::Type Type; + typedef typename JSToNative::ResultType NativeHandle; + NativeHandle self = CastFromJS( info.This() ); + return ( ! self ) + ? Toss( StringBuffer() << "Native member property getter '" + << property << "' could not access native 'this' object!" ) + : CastToJS( (self->*MemVar) ); + } + }; + + /** + This is the Setter counterpart of MemberToGetter. + + Requirements: + + - T must be convertible to (T*) via CastFromJS(). + - PropertyType must be convertible via CastToJS(). + - MemVar must be an accessible member of T. + + If the underlying native This object cannot be found then this + routine will trigger a JS exception. + */ + template + struct MemberToSetter : AccessorSetterType + { + /** Implements the v8::AccessorSetter() interface. */ + inline static void Set(v8::Local property, v8::Local value, const v8::AccessorInfo& info) + { + typedef typename TypeInfo::Type Type; + typedef typename JSToNative::ResultType NativeHandle; + NativeHandle self = CastFromJS( info.This() ); + if( self ) self->*MemVar = CastFromJS( value ); + else Toss( StringBuffer() << "Native member property setter '" + << property << "' could not access native 'this'his object!" ); + } + }; + + /** + A proxy for both MemberToGetter and MemberToSetter, providing both + Get() and Set() functions. + + This should be called MembersToAccessors (plural Members). + */ + template + struct MemberToAccessors : MemberToGetter, + MemberToSetter + {}; + + /** + An AccessorSetter() implementation which always triggers a JS exception. + Can be used to enforce "pedantically read-only" variables. Note that + JS does not allow us to assign an AccessorSetter _without_ assigning + an AccessorGetter. Also note that there is no AccessorGetterThrow, + because a write-only var doesn't make all that much sense (use + methods for those use cases). + */ + struct ThrowingSetter : AccessorSetterType + { + inline static void Set(v8::Local property, v8::Local, const v8::AccessorInfo &) + { + Toss(StringBuffer() << + "Native member property setter '" + << property + << "' is configured to throw an exception when modifying " + << "this read-only member!"); + } + }; + + /** + Implements the v8::AccessorGetter interface to bind a JS + member property to a native getter function. This function + can be used as the getter parameter to + v8::ObjectTemplate::SetAccessor(). + + Sig must be a function-signature-style type and Getter must + capable of being called with no arguments and returning a + value which can be CastToJS() to a JS value. + + If Getter() throws a native exception it is converted to a JS + exception. + */ + template ::FunctionType Getter> + struct FunctionToGetter : AccessorGetterType + { + inline static v8::Handle Get( v8::Local< v8::String > property, const v8::AccessorInfo & info ) + { + return CastToJS( (*Getter)() ); + } + }; + + /** + Implements the v8::AccessorSetter interface to bind a JS + member property to a native getter function. This function + can be used as the getter parameter to + v8::ObjectTemplate::SetAccessor(). + + SigSet must be function-signature-style pattern + for the setter function. The native + function must follow conventional mutator signature: + + ReturnType ( PropertyType ) + + PropertyType may differ from the return type. PropertyType + may not be void but the ReturnType may be. Any return value + from the setter is ignored by the JS engine. + + Note that the v8 API appears to not allow us to just set + a setter, but not a getter. We have to set a getter without + a setter, a getter with a setter, or neither. At least that's + been my experience. + + If Setter() throws a native exception it is converted to a JS + exception. + */ + template ::FunctionType Func> + struct FunctionToSetter : AccessorSetterType + { + inline static void Set( v8::Local< v8::String > property, v8::Local< v8::Value > value, const v8::AccessorInfo &info) + { + typedef FunctionSignature FT; + (*Func)( CastFromJS::Type>( value ) ); + } + }; + + + /** + Implements the v8::AccessorGetter interface to bind a JS + member property to a native getter function. This function + can be used as the getter parameter to + v8::ObjectTemplate::SetAccessor(). + + Sig must be a function-pointer-style argument with a + non-void return type convertible to v8 via CastToJS(), and + Getter must be function capable of being called with 0 + arguments (either because it has none or they have + defaults). + */ + template ::FunctionType Getter> + struct MethodToGetter : AccessorGetterType + { + inline static v8::Handle Get( v8::Local< v8::String > property, const v8::AccessorInfo & info ) + { + typedef typename TypeInfo::Type Type; + typedef typename JSToNative::ResultType NativeHandle; + NativeHandle self = CastFromJS( info.This() ); + return self + ? CastToJS( (self->*Getter)() ) + : Toss( StringBuffer() << "Native member property getter '" + << property << "' could not access native This object!" ); + } + }; + + /** + Overload for const native getter functions. + */ + template ::FunctionType Getter> + struct ConstMethodToGetter : AccessorGetterType + { + inline static v8::Handle Get( v8::Local< v8::String > property, const v8::AccessorInfo & info ) + { + typedef typename TypeInfo::Type Type; + typedef typename JSToNative::ResultType NativeHandle; + NativeHandle const self = CastFromJS( info.This() ); + return self + ? CastToJS( (self->*Getter)() ) + : Toss( (StringBuffer() << "Native member property getter '" + << property << "' could not access native This object!").toError() ) + ; + } + }; + + /** + Implements v8::AccessorSetter interface to proxy a JS + member property through a native member setter function. + + This function can be used as the setter parameter to + v8::ObjectTemplate::SetAccessor(). + + Sig must be a function-pointer-style type and Getter must + be a T member function of that type. The function must be + capable of being called with only 1 argument (either + because it only accepts 1 or has defaults for the others), + and its return value is discarded (not converted to v8) + because that's how v8's native setters work. + + Exceptions thrown by the underlying function are + translated to JS exceptions. + + FIXME: code is 100% identical to ConstMethodToSetter except + for FunctionType typedef. Consolidate them in a base class. + */ + template ::FunctionType Setter> + struct MethodToSetter : AccessorSetterType + { + static void Set(v8::Local< v8::String > property, v8::Local< v8::Value > value, const v8::AccessorInfo &info) + { + typedef typename TypeInfo::Type Type; + typedef typename JSToNative::ResultType NativeHandle; + NativeHandle self = CastFromJS( info.This() ); + if( ! self ) + { + Toss( StringBuffer() << "Native member property setter '" + << property << "' could not access native This object!" ); + } + else + { + + typedef typename sl::At< 0, Signature >::Type ArgT; + (self->*Setter)( CastFromJS( value ) ); + } + return; + } + }; + + /** + Const-method equivalent of MethodToSetter. + + FIXME: code is 100% identical to ConstMethodToSetter except + for FunctionType typedef. Consolidate them in a base class. + */ + template ::FunctionType Setter> + struct ConstMethodToSetter : AccessorSetterType + { + static void Set(v8::Local< v8::String > property, v8::Local< v8::Value > value, const v8::AccessorInfo &info) + { + typedef typename TypeInfo::Type Type; + typedef typename JSToNative::ResultType NativeHandle; + NativeHandle self = CastFromJS( info.This() ); + if( ! self ) + { + Toss( StringBuffer() << "Native member property setter '" + << property << "' could not access native This object!" ); + } + else + { + typedef typename sl::At< 0, Signature >::Type ArgT; + (self->*Setter)( CastFromJS( value ) ); + } + } + }; + + + /** + Similar to FunctionToGetter but uses a functor as a getter. + This is rarely useful, since the functor has no direct access + to any application state (unless that is static/shared within + the Ftor class). + + Ftor must be a functor. Sig must be a signature matching a const + Ftor::operator() implementation. CastToJS(Signature::ReturnType) + must be legal. + + The signature's return type may not be void (this is a getter, + and getters don't return void). + */ + template + struct FunctorToGetter + { + inline static v8::Handle Get( v8::Local< v8::String > property, const v8::AccessorInfo & info ) + { + //const static Ftor f(); + return CastToJS(Ftor()()); + } + }; + + /** + The setter counterpart of FunctorToGetter. + + Ftor must be a functor which accepts 1 arguments. + Sig must be a signature matching a Ftor::operator() + implementation. + + The return value of Ftor::operator() is not evaluated, so it may be + void or any non-convertible type. It is semantically illegal to bind + a setter which return resources allocated by the setter, if those + resources are passed to the caller. In such a case, each access + _will_ leak memory. But nobody returns allocated memory from a + setter, right? + + CastFromJS() must be legal, where ArgType1 + is sl::At<0, Signature >::Type. + */ + template + struct FunctorToSetter + { + inline static void Set(v8::Local< v8::String > property, v8::Local< v8::Value > value, const v8::AccessorInfo &info) + { + typedef typename sl::At< 0, Signature >::Type ArgT; + Ftor()( CastFromJS( value ) ); + } + }; + + /** + SetterCatcher is the AccessorSetter equivalent of InCaCatcher, and + is functionality identical except that its 4th template parameter + must be-a AccessorSetterType instead of an InCa type. + */ + template < typename ExceptionT, + typename SigGetMsg, + typename ConstMethodSignature::FunctionType Getter, + typename SetterT, + bool PropagateOtherExceptions = false + > + struct SetterCatcher : AccessorSetterType + { + static void Set(v8::Local< v8::String > property, v8::Local< v8::Value > value, const v8::AccessorInfo &info) + { + try + { + SetterT::Set( property, value, info ); + } + catch( ExceptionT const & e2 ) + { + Toss((e2.*Getter)()); + } + catch( ExceptionT const * e2 ) + { + Toss((e2->*Getter)()); + } + catch(...) + { + if( PropagateOtherExceptions ) throw; + else Toss("Unknown native exception thrown!"); + } + } + }; + + /** + A convenience form of SetterCatcher which catches std::exception + and subtyes. See InCaCatcher_std for full details - this type is + identical except that its first template parameter must be-a + AccessorSetterType instead of InCa type. + */ + template < + typename SetterT, + typename ConcreteException = std::exception, + bool PropagateOtherExceptions = !tmp::SameType< std::exception, ConcreteException >::Value + > + struct SetterCatcher_std : + SetterCatcher + {}; + + /** + GetterCatcher is the AccessorSetter equivalent of InCaCatcher, and + is functionality identical except that its 4th template parameter + must be-a AccessorGetterType instead of an InCa type. + */ + template < typename ExceptionT, + typename SigGetMsg, + typename ConstMethodSignature::FunctionType Getter, + typename GetterT, + bool PropagateOtherExceptions = false + > + struct GetterCatcher : AccessorGetterType + { + static v8::Handle Get( v8::Local< v8::String > property, const v8::AccessorInfo & info ) + { + try + { + return GetterT::Get( property, info ); + } + catch( ExceptionT const & e2 ) + { + return Toss(CastToJS((e2.*Getter)())); + } + catch( ExceptionT const * e2 ) + { + return Toss(CastToJS((e2->*Getter)())); + } + catch(...) + { + if( PropagateOtherExceptions ) throw; + else return Toss("Unknown native exception thrown!"); + } + } + }; + + /** + A convenience form of GetterCatcher which catches std::exception + and subtyes. See InCaCatcher_std for full details - this type is + identical except that its first template parameter must be-a + AccessorGetterType instead of InCa type. + */ + template < + typename GetterT, + typename ConcreteException = std::exception, + bool PropagateOtherExceptions = !tmp::SameType< std::exception, ConcreteException >::Value + > + struct GetterCatcher_std : + GetterCatcher + {}; + + + /** + AccessAdder is a convenience class for use when applying several + (or more) accessor bindings to a prototype object. + + Example: + + @code + AccessorAdder acc(myPrototype); + acc("foo", MemberToGetter(), + MemberToSetter()) + ("bar", ConstMethodToGetter(), + MethodToSetter()) + ... + ; + @endcode + */ + class AccessorAdder + { + private: + v8::Handle const & proto; + + /** A "null" setter which does nothing. Used only as default + argument to operator(). Its Set() is not actually used + but this type is used as a placeholder for a NULL + v8::AccessorSetter. + */ + struct NullSetter + { + /** The v8::AccessorSetter() interface. */ + static void Set(v8::Local< v8::String > property, v8::Local< v8::Value > value, const v8::AccessorInfo &info) + { + } + }; + public: + /** + Initializes this object so that calls to operator() will + apply to p. p must out-live this object. More specifically, + operator() must not be called after p has been destroyed. + */ + explicit AccessorAdder( v8::Handle const & p ) + : proto(p) + {} + AccessorAdder const & operator()( char const * name, + v8::AccessorGetter g, + v8::AccessorSetter s = NULL, + v8::Handle< v8::Value > data=v8::Handle< v8::Value >(), + v8::AccessControl settings=v8::DEFAULT, + v8::PropertyAttribute attribute=v8::None) const + { + proto->SetAccessor(v8::String::New(name), g, s, data, settings, attribute); + return *this; + } + /** + Adds GetterT::Get and SetterT::Set as accessors for the + given property in the prototype object. + + GetterT must be-a AccessorGetterType. SetterT must be-a + AccessorSetterType. Note that their values are not used, + but GetterT::Get and SetterT::Set are used + directly. The objects are only passed in to keep the + client from having to specify them as template + parameters (which is clumsy for operator()), as their + types can be deduced. + + The 3rd and higher arguments are as documented (or not!) + for v8::ObjectTemplate::SetAccessor(). + + Returns this object, for chaining calls. + */ + template + AccessorAdder const & operator()( char const * name, + GetterT const &, + SetterT const & = NullSetter(), + v8::Handle< v8::Value > data=v8::Handle< v8::Value >(), + v8::AccessControl settings=v8::DEFAULT, + v8::PropertyAttribute attribute=v8::None) const + { + // jump through a small hoop to ensure identical semantics vis-a-vis + // the other overload. + return this->operator()( name, GetterT::Get, + tmp::SameType::Value ? NULL : SetterT::Set, + data, settings, attribute); + } + }; + +#if 0 /* i'm still undecided on the in-class naming conventions here... */ + /** + ClassAccessor provides a slight simplification for cases + where several different members/methods of a given bound + class (T) need to be bound to v8. It wraps the following + classes so that clients can use them one fewer template + parameters: + + MemberToGetter, MemberToSetter, MethodToGetter, MethodToSetter, + ConstMethodToGetter, ConstMethodToSetter + + Example: + + @code + typedef ClassAccessor CA; + v8::AccessorGetter get; + + get = MemberToGetter::Get + // is equivalent to: + get = CA::MemGet::Set + @endcode + + Its only real benefit is saving a bit of typing when several T + member/method bindings are made and T's real type name is longer + than 'T'. e.g. it gets tedious to repeatedly type + MyExceedinglyLongClassName in method/member-binding templates. + (Function-local typedefs help.) + */ + template + struct ClassAccessor + { + template + struct MemGet : MemberToGetter {}; + template + struct MemSet : MemberToSetter {}; + template ::FunctionType Getter> + struct MethGet : MethodToGetter {}; + template ::FunctionType Getter> + struct CMethGet : ConstMethodToGetter {}; + template ::FunctionType Setter> + struct MethSet : MethodToSetter {}; + template ::FunctionType Setter> + struct CMethSet : ConstMethodToSetter {}; + }; +#endif /* ClassAccessor */ + +} // namespaces +/** LICENSE + + This software's source code, including accompanying documentation and + demonstration applications, are licensed under the following + conditions... + + The author (Stephan G. Beal [http://wanderinghorse.net/home/stephan/]) + explicitly disclaims copyright in all jurisdictions which recognize + such a disclaimer. In such jurisdictions, this software is released + into the Public Domain. + + In jurisdictions which do not recognize Public Domain property + (e.g. Germany as of 2011), this software is Copyright (c) 2011 + by Stephan G. Beal, and is released under the terms of the MIT License + (see below). + + In jurisdictions which recognize Public Domain property, the user of + this software may choose to accept it either as 1) Public Domain, 2) + under the conditions of the MIT License (see below), or 3) under the + terms of dual Public Domain/MIT License conditions described here, as + they choose. + + The MIT License is about as close to Public Domain as a license can + get, and is described in clear, concise terms at: + + http://en.wikipedia.org/wiki/MIT_License + + The full text of the MIT License follows: + + -- + Copyright (c) 2011 Stephan G. Beal (http://wanderinghorse.net/home/stephan/) + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following + conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. + + --END OF MIT LICENSE-- + + For purposes of the above license, the term "Software" includes + documentation and demonstration source code which accompanies + this software. ("Accompanies" = is contained in the Software's + primary public source code repository.) + +*/ +#endif /* CODE_GOOGLE_COM_P_V8_CONVERT_PROPERTIES_HPP_INCLUDED */ diff --git a/vendor/libv8-convert/cvv8/signature.hpp b/vendor/libv8-convert/cvv8/signature.hpp new file mode 100644 index 000000000..4961d7039 --- /dev/null +++ b/vendor/libv8-convert/cvv8/signature.hpp @@ -0,0 +1,70 @@ +#if !defined(WANDERINGHORSE_NET_SIGNATURE_HPP_INCLUDED) +#define WANDERINGHORSE_NET_SIGNATURE_HPP_INCLUDED 1 + + +namespace cvv8 { +#include "detail/signature_core.hpp" +#include "detail/signature_generated.hpp" +} +/** LICENSE + + This software's source code, including accompanying documentation and + demonstration applications, are licensed under the following + conditions... + + The author (Stephan G. Beal [http://wanderinghorse.net/home/stephan/]) + explicitly disclaims copyright in all jurisdictions which recognize + such a disclaimer. In such jurisdictions, this software is released + into the Public Domain. + + In jurisdictions which do not recognize Public Domain property + (e.g. Germany as of 2011), this software is Copyright (c) 2011 + by Stephan G. Beal, and is released under the terms of the MIT License + (see below). + + In jurisdictions which recognize Public Domain property, the user of + this software may choose to accept it either as 1) Public Domain, 2) + under the conditions of the MIT License (see below), or 3) under the + terms of dual Public Domain/MIT License conditions described here, as + they choose. + + The MIT License is about as close to Public Domain as a license can + get, and is described in clear, concise terms at: + + http://en.wikipedia.org/wiki/MIT_License + + The full text of the MIT License follows: + + -- + Copyright (c) 2011 Stephan G. Beal (http://wanderinghorse.net/home/stephan/) + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following + conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. + + --END OF MIT LICENSE-- + + For purposes of the above license, the term "Software" includes + documentation and demonstration source code which accompanies + this software. ("Accompanies" = is contained in the Software's + primary public source code repository.) + +*/ +#endif /* WANDERINGHORSE_NET_SIGNATURE_HPP_INCLUDED */ diff --git a/vendor/libv8-convert/cvv8/v8-convert.hpp b/vendor/libv8-convert/cvv8/v8-convert.hpp new file mode 100644 index 000000000..1ee91d73e --- /dev/null +++ b/vendor/libv8-convert/cvv8/v8-convert.hpp @@ -0,0 +1,169 @@ +#if !defined(CODE_GOOGLE_COM_P_V8_CONVERT_V8_CONVERT_HPP_INCLUDED) +#define CODE_GOOGLE_COM_P_V8_CONVERT_V8_CONVERT_HPP_INCLUDED 1 + +// Doxygen REFUSES to use this block as namespace docs: @namespace cvv8 +/** @mainpage libv8-convert (cvv8) + +The cvv8 namespace (formerly v8::convert) houses APIs for handling the +following: + +- Converting between v8 Value handles and "native types" using generic +interface. This allows us to write generic algorithms which convert +between JS/C++ without having to know the exact types we're dealing +with. The basic POD types and some STL types are supported out of the +box and plugging in one's own types is normally quite simple. + +- Converting free- and member functions into v8::InvocationCallback +functions. These generated functions convert the JavaScript-originated +function arguments into native counterparts, forward the data to the +original native function, and convert the return values back to +something JS can use. + +Those two core features give us all we need in order to be able to +bind near-arbitrary C/C++ functions with JavaScript (where calling +conventions and type conversions allow us to do so). For cases where +the "automatic" function-to-InvocationCallback conversions are not +suitable, the type-conversion API can simplify the implementation of +custom v8::InvocationCallback functions. + +All of the conversions are compile-time typesafe where possible and +fail gracefully when such a determination can only be made at runtime. + +This code originated as the core-most component of the v8-juice +library (http://code.google.com/p/v8-juice). After a couple years +i felt compelled to refactor it into a toolkit usable by arbitrary +v8-using clients, doing a bit of cleanup along the way. The eventuall +intention is that this code will replace the v8::juice::convert +code. + +Author: Stephan Beal (http://wanderinghorse.net/home/stephan/) + +License: Dual MIT/Public Domain + +Project home page: http://code.google.com/p/v8-juice/wiki/V8Convert + +The most important functions and types, from a user's perspective, +include: + +Converting types: + +- cvv8::CastToJS() +- cvv8::CastFromJS() + +Implementing custom conversions: + +- cvv8::NativeToJS +- cvv8::JSToNative + +Converting functions to v8::InvocationCallback: + +- cvv8::FunctionToInCa +- cvv8::MethodToInCa +- cvv8::ConstMethodToInCa +- cvv8::ToInCa +- cvv8::FunctorToInCa +- cvv8::PredicatedInCa and cvv8::PredicatedInCaDispatcher + +Binding JS properties to native properties, functions, methods, or +functors: + +- cvv8::FunctionToGetter, cvv8::FunctionToSetter +- cvv8::MethodToGetter, cvv8::MethodToSetter +- cvv8::ConstMethodToGetter, cvv8::ConstMethodToSetter +- cvv8::FunctorToGetter, cvv8::FunctorToSetter + +Other utilities: + +- cvv8::CtorForwarder and cvv8::CtorArityDispatcher +- cvv8::ClassCreator simplifies binding of C++ classes with v8. +- cvv8::FunctionTo converts functions to ... +- cvv8::MethodTo converts methods to ... +- cvv8::FunctorTo converts functors to ... +- cvv8::VarTo converts variables to ... +- cvv8::CallForwarder forwards native arguments to JS functions. +- The tmp and sl namespaces hold various template metaprogramming bits. +- ... there's more ... + +Most of the code in this library are internal template specializations +which take care of the dirty work. Typical clients won't typically need +more than what's listed above. + +A core rule of this library is "if it ain't documented, don't use +it." All public API members which are intended for client-side use +are documented. Some one-line proxies whose purpose is either very +obvious, exist only for template type resolution reasons, or +are strictly internal are not necessarily documented. + +*/ +namespace cvv8 { +} + +#include "convert.hpp" +#include "invocable.hpp" +#include "arguments.hpp" +#include "ClassCreator.hpp" +#include "properties.hpp" +#include "XTo.hpp" +/** LICENSE + + This software's source code, including accompanying documentation and + demonstration applications, are licensed under the following + conditions... + + The author (Stephan G. Beal [http://wanderinghorse.net/home/stephan/]) + explicitly disclaims copyright in all jurisdictions which recognize + such a disclaimer. In such jurisdictions, this software is released + into the Public Domain. + + In jurisdictions which do not recognize Public Domain property + (e.g. Germany as of 2011), this software is Copyright (c) 2011 + by Stephan G. Beal, and is released under the terms of the MIT License + (see below). + + In jurisdictions which recognize Public Domain property, the user of + this software may choose to accept it either as 1) Public Domain, 2) + under the conditions of the MIT License (see below), or 3) under the + terms of dual Public Domain/MIT License conditions described here, as + they choose. + + The MIT License is about as close to Public Domain as a license can + get, and is described in clear, concise terms at: + + http://en.wikipedia.org/wiki/MIT_License + + The full text of the MIT License follows: + + -- + Copyright (c) 2011 Stephan G. Beal (http://wanderinghorse.net/home/stephan/) + + Permission is hereby granted, free of charge, to any person + obtaining a copy of this software and associated documentation + files (the "Software"), to deal in the Software without + restriction, including without limitation the rights to use, + copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following + conditions: + + The above copyright notice and this permission notice shall be + included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. + + --END OF MIT LICENSE-- + + For purposes of the above license, the term "Software" includes + documentation and demonstration source code which accompanies + this software. ("Accompanies" = is contained in the Software's + primary public source code repository.) + +*/ + +#endif /* CODE_GOOGLE_COM_P_V8_CONVERT_V8_CONVERT_HPP_INCLUDED */ diff --git a/vendor/nodeunit b/vendor/nodeunit deleted file mode 160000 index 1f2038189..000000000 --- a/vendor/nodeunit +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 1f203818990be48e327c95f067301a6b713eb812 diff --git a/vendor/rimraf b/vendor/rimraf deleted file mode 160000 index 7e9818fcc..000000000 --- a/vendor/rimraf +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7e9818fcc9eb7a967731d8e84b062375c5221621 diff --git a/wscript b/wscript deleted file mode 100755 index 04fc90b85..000000000 --- a/wscript +++ /dev/null @@ -1,62 +0,0 @@ -import Options, Utils -import os, shutil, platform -from os.path import exists, abspath -from subprocess import Popen - -# Ensure version is updated with each new release. -VERSION = '0.0.6' -# These constants shouldn't change, probably. -APPNAME = 'nodegit' -srcdir = '.' -blddir = 'build' - -def set_options(opt): - opt.tool_options('gcc') - opt.tool_options('compiler_cxx') - -def configure(conf): - import preproc - preproc.go_absolute = True - - conf.check_tool('gcc') - conf.check_tool('compiler_cxx') - conf.check_tool('node_addon') - - # Build libgit2, create necessary folders - os.mkdir('vendor/libgit2/build') - os.chdir('vendor/libgit2/build') - - Popen('cmake -DBUILD_TESTS=OFF -DTHREADSAFE=ON .. ', shell=True).wait() - - conf.env.append_value('LIBPATH_GIT2', abspath('.')) - conf.env.append_value('LIB_GIT2', 'git2') - -def build(bld): - try: os.chdir('vendor/libgit2/build') - except: pass - - Popen('cmake --build .', shell=True).wait() - - os.chdir('../../') - - main = bld.new_task_gen('cxx', 'shlib', 'node_addon') - main.target = 'nodegit' - main.source = ''' - src/base.cc - src/sig.cc - src/blob.cc - src/error.cc - src/object.cc - src/reference.cc - src/repo.cc - src/commit.cc - src/oid.cc - src/revwalk.cc - src/tree.cc - src/tree_entry.cc - ''' - - main.includes = './vendor/libgit2/include' - main.rpath = '$ORIGIN/../../vendor/libgit2/build' - main.uselib = 'GIT2' -