Skip to content

Commit

Permalink
Remove trailing whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximilian Schüßler committed Jun 20, 2014
1 parent 7d300d7 commit e4557ff
Show file tree
Hide file tree
Showing 15 changed files with 173 additions and 173 deletions.
6 changes: 3 additions & 3 deletions src/actor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ module.exports = class Actor
constructor: (@name, @email) ->
if @email
@hash = crypto.createHash("md5").update(@email, "ascii").digest("hex")

# Public: Get a string representation of the Actor.
toString: ->
"#{@name} <#{@email}>"

# Public: Parse an Actor from a "bla <[email protected]>" string.
#
#
# Returns Actor.
@from_string: (str) ->
if /<.+>/.test str
Expand Down
10 changes: 5 additions & 5 deletions src/blob.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ path = require 'path'
module.exports = class Blob
constructor: (@repo, attrs) ->
{@id, @name, @mode} = attrs

# Public: Get the blob contents.
#
#
# callback - Receives `(err, data)`.
#
# Warning, this only returns files less than 200k, the standard buffer size for
#
# Warning, this only returns files less than 200k, the standard buffer size for
# node's exec(). If you need to get bigger files, you should use dataStream() to
# get a stream for the file's data
#
data: (callback) ->
@repo.git "cat-file", {p: true}, @id
, (err, stdout, stderr) ->
return callback err, stdout

# Public: Get the blob contents as a stream
#
# returns - [dataStream, errstream]
Expand Down
52 changes: 26 additions & 26 deletions src/commit.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,42 @@ Tree = require './tree'
module.exports = class Commit
constructor: (@repo, @id, parents, tree, @author, @authored_date, @committer, @committed_date, @gpgsig, @message) ->
# Public: Get the commit's Tree.
#
#
# Returns Tree.
@tree = _.memoize => (new Tree @repo, tree)

# Public: Get the Commit's parent Commits.
#
#
# Returns an Array of Commits.
@parents = _.memoize =>
_.map parents, (parent) =>
new Commit @repo, parent


toJSON: ->
{@id, @author, @authored_date, @committer, @committed_date, @message}


# Public: Find the matching commits.
#
#
# callback - Receives `(err, commits)`
#
#
@find_all: (repo, ref, options, callback) ->
options = _.extend {pretty: "raw"}, options
repo.git "rev-list", options, ref
, (err, stdout, stderr) =>
return callback err if err
return callback null, @parse_commits(repo, stdout)


@find: (repo, id, callback) ->
options = {pretty: "raw", "max-count": 1}
repo.git "rev-list", options, id
, (err, stdout, stderr) =>
return callback err if err
return callback null, @parse_commits(repo, stdout)[0]


@find_commits: (repo, ids, callback) ->
commits = []
next = (i) ->
Expand All @@ -53,10 +53,10 @@ module.exports = class Commit
else
callback null, commits
next 0


# Internal: Parse the commits from `git rev-list`
#
#
# Return Commit[]
@parse_commits: (repo, text) ->
commits = []
Expand All @@ -65,17 +65,17 @@ module.exports = class Commit
id = _.last lines.shift().split(" ")
break if !id
tree = _.last lines.shift().split(" ")

parents = []
while /^parent/.test lines[0]
parents.push _.last lines.shift().split(" ")

author_line = lines.shift()
[author, authored_date] = @actor author_line

committer_line = lines.shift()
[committer, committed_date] = @actor committer_line

gpgsig = []
if /^gpgsig/.test lines[0]
gpgsig.push lines.shift().replace /^gpgsig /, ''
Expand All @@ -86,22 +86,22 @@ module.exports = class Commit
# not doing anything with this yet, but it's sometimes there
if /^encoding/.test lines[0]
encoding = _.last lines.shift().split(" ")

lines.shift()

message_lines = []
while /^ {4}/.test lines[0]
message_lines.push lines.shift()[4..-1]

while lines[0]? && !lines[0].length
lines.shift()

commits.push new Commit(repo, id, parents, tree, author, authored_date, committer, committed_date, gpgsig.join("\n"), message_lines.join("\n"))
return commits


# Internal: Parse the actor.
#
#
# Returns [String name and email, Date]
@actor: (line) ->
[m, actor, epoch] = /^.+? (.*) (\d+) .*$/.exec line
Expand Down
26 changes: 13 additions & 13 deletions src/diff.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,37 @@ module.exports = class Diff
if b_blob isnt null
@b_blob = new Blob @repo, {id: b_blob}
@b_sha = b_blob

toJSON: ->
{@a_path, @b_path, @a_mode, @b_mode, @new_file
, @deleted_file, @diff, @renamed_file, @similarity_index}

# Public: Parse the Diffs from the command output.
#
#
# text - String stdout of a `git diff` command.
#
#
# Returns Array of Diff.
@parse: (repo, text) ->
lines = text.split "\n"
diffs = []

while lines.length && lines[0]
# FIXME shift is O(n), so iterating n over O(n) operation might be O(n^2)
[m, a_path, b_path] = ///^diff\s--git\s"?a/(.+?)"?\s"?b/(.+)"?$///.exec lines.shift()

if /^old mode/.test lines[0]
[m, a_mode] = /^old mode (\d+)/.exec lines.shift()
[m, b_mode] = /^new mode (\d+)/.exec lines.shift()

if !lines.length || /^diff --git/.test(lines[0])
diffs.push new Diff(repo, a_path, b_path, null, null, a_mode, b_mode, false, false, null)
continue

sim_index = 0
new_file = false
deleted_file = false
renamed_file = false

if /^new file/.test lines[0]
[m, b_mode] = /^new file mode (.+)$/.exec lines.shift()
a_mode = null
Expand All @@ -56,17 +56,17 @@ module.exports = class Diff
# shift away the 2 `rename from/to ...` lines
lines.shift()
lines.shift()

[m, a_blob, b_blob, b_mode] = ///^index\s([0-9A-Fa-f]+)\.\.([0-9A-Fa-f]+)\s?(.+)?$///.exec lines.shift()
b_mode = b_mode.trim() if b_mode

diff_lines = []
while lines[0] && !/^diff/.test(lines[0])
diff_lines.push lines.shift()
diff = diff_lines.join "\n"

diffs.push new Diff(repo, a_path, b_path, a_blob, b_blob, a_mode, b_mode, new_file, deleted_file, diff, renamed_file, sim_index)

return diffs

# Public: Parse the raw diff format from the command output.
Expand Down
10 changes: 5 additions & 5 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,18 @@
Repo = require './repo'

# Public: Create a Repo from the given path.
#
#
# Returns Repo.
module.exports = Git = (path, bare=false) ->
return new Repo path, bare


# Public: Initialize a git repository.
#
#
# path - The directory to run `git init .` in.
# bare - Create a bare repository when true.
# callback - Receives `(err, repo)`.
#
#
Git.init = (path, bare, callback) ->
[bare, callback] = [callback, bare] if !callback
if bare
Expand All @@ -26,11 +26,11 @@ Git.init = (path, bare, callback) ->
return callback err, (new Repo path, bare)

# Public: Clone a git repository.
#
#
# repository - The repository to clone from.
# path - The directory to clone into.
# callback - Receives `(err, repo)`.
#
#
Git.clone = (repository, path, callback) ->
bash = "git clone #{repository} #{path}"
exec bash, (err, stdout, stderr) ->
Expand Down
12 changes: 6 additions & 6 deletions src/ref.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ Commit = require './commit'
exports.Ref = class Ref
constructor: (@name, @commit) ->
{@repo} = @commit

# Public: Get a String representation of the Ref.
toString: ->
"#<Ref '#{@name}'>"

# Internal: Find all refs.
#
#
# options - (optional).
#
#
# Returns Array of Ref.
@find_all: (repo, type, RefClass, callback) ->
repo.git.refs type, {}, (err, text) ->
Expand All @@ -24,7 +24,7 @@ exports.Ref = class Ref
[name, id] = ref.split(' ')
names.push name
ids.push id

Commit.find_commits repo, ids, (err, commits) ->
return callback err if err
refs = []
Expand All @@ -36,7 +36,7 @@ exports.Ref = class Ref
exports.Head = class Head extends Ref
@find_all: (repo, callback) ->
Ref.find_all repo, "head", Head, callback

@current: (repo, callback) ->
fs.readFile "#{repo.dot_git}/HEAD", (err, data) ->
return callback err if err
Expand Down
8 changes: 4 additions & 4 deletions src/status.coffee
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Public: Create a Status.
#
#
# repo - A Repo.
# callback - Receives `(err, status)`
#
#
module.exports = S = (repo, callback) ->
repo.git "status --porcelain", (err, stdout, stderr) ->
status = new Status repo
Expand All @@ -11,13 +11,13 @@ module.exports = S = (repo, callback) ->

S.Status = class Status
constructor: (@repo) ->

# Internal: Parse the status from stdout of a `git status` command.
parse: (text) ->
@files = {}
@clean = text.length == 0
for line in text.split("\n")
if line.length == 0
if line.length == 0
continue
file = line.substr 3
type = line.substr 0,2
Expand Down
Loading

0 comments on commit e4557ff

Please sign in to comment.