diff --git a/.gitignore b/.gitignore index 8a17e69..2b90e60 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,6 @@ response_body.bin test/fixtures/test-repo1/ test/fixtures/test-repo1-packed .DS_store -demos/serve \ No newline at end of file +demos/serve +build +node_modules diff --git a/Rakefile b/Rakefile index 9958c3e..e57eee7 100644 --- a/Rakefile +++ b/Rakefile @@ -1,6 +1,4 @@ - - namespace :test do desc "Reset the github test repo" task :reset do @@ -17,18 +15,96 @@ end desc "Concatenate the javascript for the client" task :package_client do - load_file = File.read(File.dirname(__FILE__) + "/lib/git-client.js") - paths = load_file.scan(/getScript\("\/([^"]*)"\)/) - js = ["jsGitInNode = false"] - paths.each do |path| - js << File.read(File.dirname(__FILE__) + "/" + path.first) - end + preamble = <<-PREAMBLE + (function(exp) { + exp.Git = {} + exp.Git.modules = {} + var getModule = function(path) { + var module = exp.Git.modules[path] + if(module) + return module + module = { + exports:{}, + path:path, + execute:null, + toString:function() { return ''; } + } + exp.Git.modules[path] = module + return module + } + + var resolve = function(path) { + var bits = path.split('/') + var out = [] + for(var i = 0, len = bits.length; i < len; ++i) { + var cur = bits[i] + if(bits[i] === '.') + continue; + else if(bits[i] === '..') + out.pop() + else + out.push(bits[i]) + } + return out.join('/') + } + + var getRequire = function(module) { + var basename = module.path.split('/').slice(0, -1).join('/'); + return function(path) { + path === 'underscore' && + (path = 'vendor/underscore-min') + + var first = path.slice(0, 2), + fullpath + if(first === './' || first === '..') { + fullpath = resolve(basename+'/'+path) + } else { + fullpath = resolve(path) + } + var mod = exp.Git.modules[fullpath] + mod.execute && mod.execute() + return mod.exports + } + } + + exp.GIT__module__ = getModule + exp.GIT__require__ = getRequire + exp.Git.require = getRequire(getModule('.')) + })(window); + PREAMBLE + + wrap = <<-WRAP + (function() { + var module = GIT__module__('%s') + var require = GIT__require__(module) + module.execute = function() { + (function(module, exports, require) { + %s + })(this, this.exports, require) + module.execute = null; + } + })(); + WRAP + + # TODO: replace this hackiness with something better. + libraries = Dir['lib/*.js'] + Dir['lib/*/*.js'] + Dir['lib/*/*/*.js'] + vendor = Dir['vendor/*.js'] + Dir['vendor/*/*.js'] + + js = [preamble] + (libraries + vendor).each do |path| + js << wrap % [ + path.sub('.js', ''), + File.read(File.dirname(__FILE__) + "/" + path) + ] + end + total_js = js.join("\n\n") - File.open("lib/git.min.js", "w") {|f| f.puts total_js } - puts "packaged lib/git.min.js" + FileUtils.mkdir_p("build") + File.open("build/git.min.js", "w") {|f| f.puts total_js } + puts "packaged build/git.min.js" end desc "Run the demo repo-viewer webapp off a local git http instance" task :demo => :package_client do exec("thin -R demos/config.ru -p 9292 start") -end \ No newline at end of file +end diff --git a/bin/git.js b/bin/git.js index e48bdde..5126de6 100755 --- a/bin/git.js +++ b/bin/git.js @@ -1,10 +1,10 @@ #!/usr/bin/env node -require('../lib/git-server') +var Cli = require('../lib/git/cli') // Get rid of process runner ('node' in most cases) var arg, args = [], argv = process.argv.slice(2); -var cli = new Git.Cli(argv) +var cli = new Cli(argv) cli.run() diff --git a/demos/config.ru b/demos/config.ru index 99605b8..8716c81 100644 --- a/demos/config.ru +++ b/demos/config.ru @@ -16,7 +16,7 @@ class ServeGitJs def call(env) if env["PATH_INFO"] == "/git.min.js" - path = File.expand_path(File.dirname(__FILE__) + "/../lib/git.min.js") + path = File.expand_path(File.dirname(__FILE__) + "/../build/git.min.js") if File.exist?(path) content = File.read(path) status = 200 @@ -51,4 +51,4 @@ puts puts " * visit #{bold}http://localhost:9292/repo-viewer/index.html#{nobold}" puts " * serving git repos from #{bold}#{serve_path}#{nobold}. " puts " * Add more (bare) repos here to view them in repo-viewer. (SMALL repos work best) " -puts \ No newline at end of file +puts diff --git a/demos/repo-viewer/index.html b/demos/repo-viewer/index.html index 26f003f..e2ba1da 100644 --- a/demos/repo-viewer/index.html +++ b/demos/repo-viewer/index.html @@ -7,7 +7,6 @@ - diff --git a/demos/repo-viewer/repo-viewer.js b/demos/repo-viewer/repo-viewer.js index 79f1c72..f5f8169 100644 --- a/demos/repo-viewer/repo-viewer.js +++ b/demos/repo-viewer/repo-viewer.js @@ -1,3 +1,8 @@ +var MemoryRepo = Git.require('lib/git/memory_repo') + , GithubProxyRepo = Git.require('lib/git/github_repo') + , TreeDiff = Git.require('lib/git/tree-diff') + , _ = Git.require('underscore') + , MyMD5 = Git.require('vendor/md5') RepoViewer = { repo: null, @@ -72,7 +77,7 @@ RepoViewer = { displayCommitDiffDiff: function(commit) { RepoViewer.repo.getObject(commit.parents[0], function(err, parent) { var parentTree = parent ? parent.tree : null - var treeDiff = new Git.TreeDiff(RepoViewer.repo, parentTree, commit.tree) + var treeDiff = new TreeDiff(RepoViewer.repo, parentTree, commit.tree) treeDiff.toHtml(function(html) { $("#diff").append(html) }) @@ -212,7 +217,7 @@ RepoViewer = { }, githubDemo: function(username, reponame, password) { - RepoViewer.repo = new Git.GithubProxyRepo(username, reponame, password) + RepoViewer.repo = new GithubProxyRepo(username, reponame, password) var origin = RepoViewer.repo.getRemote("origin") origin.fetchRefs(function() { RepoViewer.displayRefs(RepoViewer.repo.getAllRefs()) @@ -229,7 +234,7 @@ RepoViewer = { RepoViewer.clearRefs() RepoViewer.clearCommits() RepoViewer.clearErrors() - var repo = new Git.MemoryRepo() + var repo = new MemoryRepo() RepoViewer.repo = repo console.log("creating repo with origin: " + uri) // if (uri.indexOf("//github.com")) { @@ -242,4 +247,4 @@ RepoViewer = { }) } -} \ No newline at end of file +} diff --git a/lib/binary_file.js b/lib/binary_file.js index d66dbf9..ad1114a 100644 --- a/lib/binary_file.js +++ b/lib/binary_file.js @@ -1,99 +1,121 @@ +var btoa = this.btoa || require('./btoa'); -BinaryFile = function(strData, iDataOffset, iDataLength) { - var data = strData; - var dataOffset = iDataOffset || 0; - var dataLength = 0; +// these are created (dynamically!) via +// a