Class: Hglib::Repo::Id
- Inherits:
-
Object
- Object
- Hglib::Repo::Id
- Extended by:
- MethodUtilities
- Defined in:
- lib/hglib/repo/id.rb
Overview
The identification of a particular revision of a repository.
Constant Summary collapse
- DEFAULT_ID =
The SHA of the zeroth node
'0000000000000000000000000000000000000000'
- DEFAULT_BRANCH =
The default branch name to use
'default'
- DEFAULT_NODE =
The SHA of the node when the repo is at tip
'ffffffffffffffffffffffffffffffffffffffff'
Instance Attribute Summary collapse
-
#bookmarks ⇒ Object
readonly
The bookmarks set on the revision of the repo.
-
#branch ⇒ Object
readonly
The name of the current branch.
-
#id ⇒ Object
(also: #global)
readonly
The long-form revision ID.
-
#node ⇒ Object
readonly
The ID of the current changeset node.
-
#parents ⇒ Object
readonly
The current IDs of the current revision’s parent(s).
-
#tags ⇒ Object
readonly
The tags belonging to the revision of the repo.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Comparison operator – returns
true
if theother
object is another Hglib::Repo::Id with the same values, or a String containing the #global revision identifier. -
#default? ⇒ Boolean
Returns
true
if the Id’s revision ID is the DEFAULT_ID. -
#dirty ⇒ Object
Does the repo have uncommitted changes?.
-
#initialize(id:, branch: DEFAULT_BRANCH, node: DEFAULT_NODE, dirty: false, parents: [], tags: [], bookmarks: []) ⇒ Id
constructor
Create a new repository ID with the given
global
revision identifier, one or moretags
, and other options. -
#short_id ⇒ Object
Return the short form of the global ID.
-
#to_s ⇒ Object
Return the ID as a String in the form used by the command line.
Methods included from MethodUtilities
attr_predicate, attr_predicate_accessor, singleton_attr_accessor, singleton_attr_reader, singleton_attr_writer, singleton_method_alias
Constructor Details
#initialize(id:, branch: DEFAULT_BRANCH, node: DEFAULT_NODE, dirty: false, parents: [], tags: [], bookmarks: []) ⇒ Id
Create a new repository ID with the given global
revision identifier, one or more tags
, and other options.
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/hglib/repo/id.rb', line 25 def initialize( id:, branch: DEFAULT_BRANCH, node: DEFAULT_NODE, dirty: false, parents: [], tags: [], bookmarks: [] ) @id = id[ /\p{XDigit}{40}/ ] @branch = branch @node = node @dirty = dirty == '+' @tags = Array( ) @parents = Array( parents ) @bookmarks = Array( bookmarks ) end |
Instance Attribute Details
#bookmarks ⇒ Object (readonly)
The bookmarks set on the revision of the repo.
71 72 73 |
# File 'lib/hglib/repo/id.rb', line 71 def bookmarks @bookmarks end |
#branch ⇒ Object (readonly)
The name of the current branch
49 50 51 |
# File 'lib/hglib/repo/id.rb', line 49 def branch @branch end |
#id ⇒ Object (readonly) Also known as: global
The long-form revision ID
44 45 46 |
# File 'lib/hglib/repo/id.rb', line 44 def id @id end |
#node ⇒ Object (readonly)
The ID of the current changeset node
53 54 55 |
# File 'lib/hglib/repo/id.rb', line 53 def node @node end |
#parents ⇒ Object (readonly)
The current IDs of the current revision’s parent(s).
57 58 59 |
# File 'lib/hglib/repo/id.rb', line 57 def parents @parents end |
#tags ⇒ Object (readonly)
The tags belonging to the revision of the repo.
67 68 69 |
# File 'lib/hglib/repo/id.rb', line 67 def @tags end |
Instance Method Details
#==(other) ⇒ Object
Comparison operator – returns true
if the other
object is another Hglib::Repo::Id with the same values, or a String containing the #global revision identifier.
95 96 97 98 |
# File 'lib/hglib/repo/id.rb', line 95 def ==( other ) return (other.is_a?( self.class ) && self.to_s == other.to_s) || self.global == other end |
#default? ⇒ Boolean
Returns true
if the Id’s revision ID is the DEFAULT_ID
102 103 104 |
# File 'lib/hglib/repo/id.rb', line 102 def default? return self.id == DEFAULT_ID end |
#dirty ⇒ Object
Does the repo have uncommitted changes?
61 |
# File 'lib/hglib/repo/id.rb', line 61 attr_predicate :dirty |
#short_id ⇒ Object
Return the short form of the global ID.
75 76 77 |
# File 'lib/hglib/repo/id.rb', line 75 def short_id return self.id[ 0, 12 ] end |
#to_s ⇒ Object
Return the ID as a String in the form used by the command line.
81 82 83 84 85 86 87 88 89 |
# File 'lib/hglib/repo/id.rb', line 81 def to_s str = self.global.dup str << '+' if self.uncommitted_changes? str << ' ' << self..join( '/' ) unless self..empty? str << ' ' << self.bookmarks.join( '/' ) unless self.bookmarks.empty? return str end |