gash 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/CHANGELOG +2 -0
  2. data/Rakefile +1 -0
  3. data/gash.gemspec +16 -3
  4. data/lib/gash.rb +47 -41
  5. metadata +15 -2
data/CHANGELOG CHANGED
@@ -1,3 +1,5 @@
1
+ v0.1.3. Removed nasty eval. Switching to open4.
2
+
1
3
  v0.1.2. Working correctly on empty branches.
2
4
 
3
5
  v0.1.1. Tree got more Hash-methods. Better documentation.
data/Rakefile CHANGED
@@ -7,6 +7,7 @@ Echoe.new('gash') do |p|
7
7
  p.email = "judofyr@gmail.com"
8
8
  p.summary = "Git + Hash"
9
9
  p.url = "http://dojo.rubyforge.org/gash/"
10
+ p.runtime_dependencies = ["open4 >= 0.9.6"]
10
11
  p.rdoc_options += ["--main", "Gash", "--title", "Gash"]
11
12
  end
12
13
 
@@ -1,20 +1,33 @@
1
1
 
2
- # Gem::Specification for Gash-0.1.2
2
+ # Gem::Specification for Gash-0.1.3
3
3
  # Originally generated by Echoe
4
4
 
5
5
  --- !ruby/object:Gem::Specification
6
6
  name: gash
7
7
  version: !ruby/object:Gem::Version
8
- version: 0.1.2
8
+ version: 0.1.3
9
9
  platform: ruby
10
10
  authors:
11
11
  - Magnus Holm
12
12
  autorequire:
13
13
  bindir: bin
14
14
 
15
- date: 2008-09-28 00:00:00 +02:00
15
+ date: 2008-10-02 00:00:00 +02:00
16
16
  default_executable:
17
17
  dependencies:
18
+ - !ruby/object:Gem::Dependency
19
+ name: open4
20
+ type: :runtime
21
+ version_requirement:
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: "0"
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.6
30
+ version:
18
31
  - !ruby/object:Gem::Dependency
19
32
  name: echoe
20
33
  type: :development
@@ -1,4 +1,5 @@
1
1
  require 'delegate'
2
+ require 'open4'
2
3
 
3
4
  # == What is Gash?
4
5
  #
@@ -7,7 +8,7 @@ require 'delegate'
7
8
  # * Gash only cares about the data, not the commits.
8
9
  # * Gash only cares about the _latest_ data.
9
10
  # * Gash can commit.
10
- # * Gash will automatically create branches if they don't exists.
11
+ # * Gash will automatically create branches if they don't exist.
11
12
  # * Gash only loads what it needs, so it handles large repos well.
12
13
  # * Gash got {pretty good documentation}[http://dojo.rubyforge.org/gash].
13
14
  # * Gash got {a bug tracker}[http://dojo.lighthouseapp.com/projects/17529-gash].
@@ -327,12 +328,10 @@ class Gash < SimpleDelegator
327
328
  attr_accessor :branch, :repository
328
329
 
329
330
  # Opens the +repo+ with the specified +branch+.
330
- #
331
- # <b>Please note:</b> The +repo+ must link to the actual repo,
332
- # not the working directory!
333
- def initialize(repo = ".git", branch = "master")
331
+ def initialize(repo = ".", branch = "master")
334
332
  @branch = branch
335
- @repository = File.expand_path(repo)
333
+ @repository = repo
334
+ @repository = find_repo(repo)
336
335
  __setobj__(Tree.new(:parent => self))
337
336
  update!
338
337
  end
@@ -355,9 +354,6 @@ class Gash < SimpleDelegator
355
354
  type = line[7]
356
355
  sha1 = line[12, 40]
357
356
  name = line[53..-1]
358
- if name[0] == ?" && name[-1] == ?"
359
- name = eval(name)
360
- end
361
357
  name = name[/[^\/]+$/]
362
358
  parent = if $`.empty?
363
359
  self
@@ -386,18 +382,24 @@ class Gash < SimpleDelegator
386
382
 
387
383
  # Checks if the current branch exists
388
384
  def branch_exists?
389
- git('rev-parse', @branch, '2>&1')
390
- true
391
- rescue Errors::Git
392
- false
385
+ git_status('rev-parse', @branch) == 0
393
386
  end
394
387
 
395
388
  def inspect #:nodoc:
396
389
  __getobj__.inspect
397
390
  end
391
+ undef_method :dup
398
392
 
399
393
  private
400
394
 
395
+ def find_repo(dir)
396
+ Dir.chdir(dir) do
397
+ File.expand_path(git('rev-parse', '--git-dir', :git_dir => false))
398
+ end
399
+ rescue Errno::ENOENT, Gash::Errors::Git
400
+ raise Errors::NoGitRepo.new("No Git repository at: " + @repository)
401
+ end
402
+
401
403
  def cat_file(blob)
402
404
  git('cat-file', 'blob', blob)
403
405
  end
@@ -405,18 +407,17 @@ class Gash < SimpleDelegator
405
407
  def to_tree!(from = self)
406
408
  input = []
407
409
  from.each do |key, value|
408
- key = key.inspect
409
410
  if value.tree?
410
411
  value.sha1 ||= to_tree!(value)
411
412
  value.mode ||= "040000"
412
- input << "#{value.mode} tree #{value.sha1}\t#{key}\n"
413
+ input << "#{value.mode} tree #{value.sha1}\t#{key}\0"
413
414
  else
414
415
  value.sha1 ||= git('hash-object', '-w', '--stdin', :input => value.to_s)
415
416
  value.mode ||= "100644"
416
- input << "#{value.mode} blob #{value.sha1}\t#{key}\n"
417
+ input << "#{value.mode} blob #{value.sha1}\t#{key}\0"
417
418
  end
418
419
  end
419
- git('mktree', :input => input)
420
+ git('mktree', '-z', :input => input)
420
421
  end
421
422
 
422
423
  def update_head(new_head)
@@ -435,13 +436,13 @@ class Gash < SimpleDelegator
435
436
  end
436
437
 
437
438
  def git_tree(&blk)
438
- git('ls-tree', '-r', '-t', @branch, '2>&1').each_line(&blk)
439
+ git('ls-tree', '-r', '-t', '-z', @branch).split("\0").each(&blk)
439
440
  rescue Errors::Git
440
441
  ""
441
442
  end
442
443
 
443
444
  def git_tree_sha1(from = @branch)
444
- git('rev-parse', @branch + '^{tree}', '2>&1')
445
+ git('rev-parse', @branch + '^{tree}')
445
446
  rescue Errors::Git
446
447
  end
447
448
 
@@ -469,14 +470,10 @@ class Gash < SimpleDelegator
469
470
  # ==== Returns
470
471
  # String:: if you didn't supply a block, the things git said on STDOUT, otherwise noting
471
472
  def git(cmd, *rest, &block)
472
- result, status = run_git(cmd, *rest, &block)
473
+ result, reserr, status = run_git(cmd, *rest, &block)
473
474
 
474
475
  if status != 0
475
- if result =~ /Not a git repository/
476
- raise Errors::NoGitRepo.new("No Git repository at: " + @repository)
477
- else
478
- raise Errors::Git.new("Error: #{cmd} returned #{status}. Result: #{result}")
479
- end
476
+ raise Errors::Git.new("Error: #{cmd} returned #{status}. STDERR: #{reserr}")
480
477
  end
481
478
  result
482
479
  end
@@ -492,7 +489,7 @@ class Gash < SimpleDelegator
492
489
  # ==== Returns
493
490
  # Integer:: the return status of git
494
491
  def git_status(cmd, *rest, &block)
495
- run_git(cmd, *rest, &block)[1]
492
+ run_git(cmd, *rest, &block)[2]
496
493
  end
497
494
 
498
495
  # passes the command over to git (you should not call this directly)
@@ -504,44 +501,53 @@ class Gash < SimpleDelegator
504
501
  #
505
502
  # ==== Options
506
503
  # :strip<Boolean>:: true to strip the output String#strip, false not to to it
504
+ # :git_dir<Boolean>:: true to automatically use @repository as git-dir, false to not use anything.
507
505
  #
508
506
  # ==== Raises
509
507
  # Errors::Git:: if git returns non-null, an Exception is raised
510
508
  #
511
509
  # ==== Returns
512
- # Array[String, Integer]:: the first item is the STDOUT of git, the second is the return-status
510
+ # Array[String, String, Integer]:: the first item is the STDOUT of git, the second is the STDERR, the third is the return-status
513
511
  def run_git(cmd, *args, &block)
514
512
  options = if args.last.kind_of?(Hash)
515
513
  args.pop
516
514
  else
517
515
  {}
518
516
  end
519
-
520
517
  options[:strip] = true unless options.key?(:strip)
518
+
519
+ git_cmd = ["git"]
520
+
521
+ unless options[:git_dir] == false
522
+ git_cmd.push("--git-dir", @repository)
523
+ end
521
524
 
522
- ENV["GIT_DIR"] = @repository
523
- cmd = "git #{cmd} #{args.join(' ')}"
524
-
525
+ git_cmd.push(cmd, *args)
526
+
525
527
  result = ""
526
- IO.popen(cmd, "w+") do |f|
528
+ reserr = ""
529
+ status = Open4.popen4(*git_cmd) do |pid, stdin, stdout, stderr|
527
530
  if input = options.delete(:input)
528
- f.write(input)
529
- f.close_write
531
+ stdin.write(input)
530
532
  elsif block_given?
531
- yield f
532
- f.close_write
533
+ yield stdin
533
534
  end
535
+ stdin.close_write
534
536
 
535
537
  result = ""
538
+ reserr = ""
536
539
 
537
- while !f.eof
538
- result << f.read
540
+ while !stdout.eof
541
+ result << stdout.read
542
+ end
543
+
544
+ while !stderr.eof
545
+ reserr << stderr.read
539
546
  end
540
547
  end
541
- status = $?
542
548
 
543
549
  result.strip! if options[:strip] == true
544
-
545
- [result, status]
550
+
551
+ [result, reserr, status]
546
552
  end
547
553
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gash
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Magnus Holm
@@ -9,9 +9,22 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-28 00:00:00 +02:00
12
+ date: 2008-10-02 00:00:00 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: open4
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ - - "="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.6
27
+ version:
15
28
  - !ruby/object:Gem::Dependency
16
29
  name: echoe
17
30
  type: :development