mercurial-ruby 0.6.1 → 0.7.0

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.
data/README.rdoc CHANGED
@@ -16,7 +16,7 @@ Github doesn't support some YARd-specific syntax so this README can look broken.
16
16
 
17
17
  == Compatibility
18
18
 
19
- Tested with Mercurial 1.9 and 1.9.1 and Ruby 1.8.7.
19
+ Tested with Mercurial versions 1.9, 1.9.1 and 2.1; Ruby version 1.8.7.
20
20
 
21
21
  == Configuration
22
22
 
@@ -89,6 +89,6 @@ Cache expires automatically when repository's mtime changes, and it's your job t
89
89
 
90
90
  == Copyright
91
91
 
92
- Copyright (c) 2011 Ilya Sabanin. See LICENSE.txt for
92
+ Copyright (c) 2012 Ilya Sabanin. See LICENSE.txt for
93
93
  further details.
94
94
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.1
1
+ 0.7.0
@@ -22,14 +22,18 @@ module Mercurial
22
22
  # State of the branch: closed or active.
23
23
  attr_reader :status
24
24
 
25
- # Mercurial changeset ID of the latest commit in the branch. 40-chars long SHA1 hash.
26
- attr_reader :latest_commit
25
+ # ID of a commit associated with the branch. 40-chars long SHA1 hash.
26
+ attr_reader :hash_id
27
27
 
28
28
  def initialize(repository, name, options={})
29
29
  @repository = repository
30
30
  @name = name
31
31
  @status = options[:status] == 'closed' ? 'closed' : 'active'
32
- @latest_commit = options[:commit]
32
+ @hash_id = options[:commit]
33
+ end
34
+
35
+ def commit
36
+ repository.commits.by_hash_id(hash_id)
33
37
  end
34
38
 
35
39
  def active?
@@ -36,8 +36,8 @@ module Mercurial
36
36
  # Array of {Mercurial::ChangedFile ChangedFile} objects.
37
37
  attr_reader :changed_files
38
38
 
39
- # Array of commit's branches.
40
- attr_reader :branches_names
39
+ # Name of a branch associated with the commit.
40
+ attr_reader :branch_name
41
41
 
42
42
  # Array of commit's tags.
43
43
  attr_reader :tags_names
@@ -55,8 +55,8 @@ module Mercurial
55
55
  @date = Time.iso8601(opts[:date])
56
56
  @message = opts[:message]
57
57
  @changed_files = files_to_array(opts[:changed_files])
58
- @branches_names = branches_or_tags_to_array(opts[:branches_names])
59
- @tags_names = branches_or_tags_to_array(opts[:tags_names])
58
+ @branch_name = opts[:branch_name]
59
+ @tags_names = tags_to_array(opts[:tags_names])
60
60
  @parents_ids = parents_to_array(opts[:parents])
61
61
  end
62
62
 
@@ -75,6 +75,10 @@ module Mercurial
75
75
  def parents
76
76
  repository.commits.by_hash_ids(parents_ids)
77
77
  end
78
+
79
+ def ancestors
80
+ repository.commits.ancestors_of(hash_id)
81
+ end
78
82
 
79
83
  def parent_id
80
84
  parents_ids.first
@@ -92,7 +96,7 @@ module Mercurial
92
96
  {
93
97
  'id' => hash_id,
94
98
  'parents' => parents_ids.map { |p| { 'id' => p.id } },
95
- 'branches' => branches_names,
99
+ 'branch' => branch_name,
96
100
  'tags' => tags_names,
97
101
  'message' => message,
98
102
  'date' => date,
@@ -123,9 +127,9 @@ module Mercurial
123
127
  Mercurial::ChangedFileFactory.delete_hg_artefacts(files)
124
128
  end
125
129
 
126
- def branches_or_tags_to_array(branches_str)
127
- string_to_array(branches_str) do |returning|
128
- returning << branches_str
130
+ def tags_to_array(tags_str)
131
+ string_to_array(tags_str) do |returning|
132
+ returning << tags_str
129
133
  end
130
134
  end
131
135
 
@@ -23,6 +23,17 @@ module Mercurial
23
23
  build(line)
24
24
  end
25
25
  end
26
+
27
+ # Run a block for every {Mercurial::Branch Branch} instance of all branches in the repository.
28
+ #
29
+ # == Example:
30
+ # repository.branches.each {|commit| ... }
31
+ #
32
+ def each(&block)
33
+ all.each do |branch|
34
+ block.call(branch)
35
+ end
36
+ end
26
37
 
27
38
  # Return an array of {Mercurial::Branch Branch} instances for all active branches in the repository.
28
39
  #
@@ -156,6 +156,18 @@ module Mercurial
156
156
  end
157
157
  end
158
158
  alias :latest :tip
159
+
160
+ # Return an array of {Mercurial::Commit Commit} instances that appear in hg log as ancestors of the specified commit ID.
161
+ #
162
+ # == Example:
163
+ # repository.commits.ancestors_of('bf6386c0a0cc')
164
+ #
165
+ def ancestors_of(hash_id, options={}, cmd_options={})
166
+ cmd = command_with_limit(["log -r \"ancestors(?)\" --style ?", hash_id, style], options[:limit])
167
+ hg_to_array(cmd, {:separator => changeset_separator}, cmd_options) do |line|
168
+ build(line)
169
+ end
170
+ end
159
171
 
160
172
  protected
161
173
 
@@ -190,7 +202,7 @@ module Mercurial
190
202
  :date => data[3],
191
203
  :message => data[4],
192
204
  :changed_files => [data[5], data[6], data[7], data[8]],
193
- :branches_names => data[9],
205
+ :branch_name => data[9],
194
206
  :tags_names => data[10],
195
207
  :parents => data[11]
196
208
  )
@@ -4,7 +4,7 @@
4
4
  #
5
5
  module Mercurial
6
6
 
7
- VERSION = '0.6.1'
7
+ VERSION = '0.7.0'
8
8
 
9
9
  class Error < RuntimeError; end
10
10
 
@@ -1,4 +1,4 @@
1
- changeset = "{node}|><|{author|person}|><|{author|email}|><|{date|rfc3339date}|><|{desc}|><|{file_mods}|><|{file_adds}|><|{file_dels}|><|{file_copies}|><|{branches}|><|{tags}|><|{parents}||$||\n"
1
+ changeset = "{node}|><|{author|person}|><|{author|email}|><|{date|rfc3339date}|><|{desc}|><|{file_mods}|><|{file_adds}|><|{file_dels}|><|{file_copies}|><|{branch}|><|{tags}|><|{parents}||$||\n"
2
2
  file_add = "A {file_add};"
3
3
  file_mod = "M {file_mod};"
4
4
  file_del = "D {file_del};"
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mercurial-ruby}
8
- s.version = "0.6.1"
8
+ s.version = "0.7.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ilya Sabanin"]
12
- s.date = %q{2011-12-08}
12
+ s.date = %q{2012-03-02}
13
13
  s.description = %q{Ruby API for Mercurial DVCS.}
14
14
  s.email = %q{ilya.sabanin@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -12,6 +12,13 @@ describe Mercurial::BranchFactory do
12
12
  branches.map(&:name).sort.must_equal %w(branch-from-remote another-branch new-branch old-branch default).sort
13
13
  branches.map(&:status).sort.must_equal %w(active active closed active active).sort
14
14
  end
15
+
16
+ it "should iterate through branches" do
17
+ names = []
18
+ @repository.branches.each{|b| names << b.name }
19
+ names.size.must_equal 5
20
+ names.must_equal %w(default another-branch branch-from-remote new-branch old-branch)
21
+ end
15
22
 
16
23
  it "should find active branches" do
17
24
  branches = @repository.branches.active
data/test/test_commit.rb CHANGED
@@ -15,13 +15,9 @@ describe Mercurial::Commit do
15
15
  @commit.date.must_be_kind_of Time
16
16
  end
17
17
 
18
- it "should represent branches as Array" do
19
- @commit.branches_names.must_be_kind_of Array
20
- end
21
-
22
- it "branches array should be empty if there are no branches" do
18
+ it "branch name should be 'default' by default" do
23
19
  @commit = @repository.commits.by_hash_id('4474d1ddaf65')
24
- @commit.branches_names.must_equal []
20
+ @commit.branch_name.must_equal 'default'
25
21
  end
26
22
 
27
23
  it "should represent tags as Array" do
@@ -106,6 +106,11 @@ describe Mercurial::CommitFactory do
106
106
  Mercurial::Repository.create('/tmp/new-crazy-repo').commits.latest.must_equal nil
107
107
  end
108
108
 
109
+ it "should return array of commit's ancestors" do
110
+ expected_ancestors = %w(bf6386c0a0ccd1282dbbe51888f52fe82b1806e3 bc729b15e2b556065dd4f32c161f54be5dd92776 63f70b2314ede1e12813cae87f6f303ee8d5c09a 6157254a442343181939c7af1a744cf2a16afcce 25bb5c51fd613b8b58d88ef1caf99da559af51f3 63e18640e83af60196334f16cc31f4f99c419918 34f85a44acf11c3386f771a65445d6c39e5261d6 4474d1ddaf653cb7fbf18bb62ff1e39a4e571969 cd9fa0c59c7f189fa1d70edea564e534ac9478d0 611407bf9b369e061eaf0bee1a261c9e62ad713d d14b0c16b21d9d3e08101ef264959a7d91a8b5db 3e1ea66bdd04dbfb8d91e4f2de3baca218cd4cca)
111
+ @repository.commits.ancestors_of('3e1ea66bdd04').map(&:hash_id).must_equal(expected_ancestors)
112
+ end
113
+
109
114
  private
110
115
 
111
116
  def really_long_commit_message
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mercurial-ruby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 3
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 6
9
- - 1
10
- version: 0.6.1
8
+ - 7
9
+ - 0
10
+ version: 0.7.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ilya Sabanin
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-12-08 00:00:00 -05:00
18
+ date: 2012-03-02 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency