Class: Hglib::Repo::Id

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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( tags )
	@parents = Array( parents )
	@bookmarks = Array( bookmarks )
end

Instance Attribute Details

#bookmarksObject (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

#branchObject (readonly)

The name of the current branch



49
50
51
# File 'lib/hglib/repo/id.rb', line 49

def branch
  @branch
end

#idObject (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

#nodeObject (readonly)

The ID of the current changeset node



53
54
55
# File 'lib/hglib/repo/id.rb', line 53

def node
  @node
end

#parentsObject (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

#tagsObject (readonly)

The tags belonging to the revision of the repo.



67
68
69
# File 'lib/hglib/repo/id.rb', line 67

def tags
  @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

Returns:

  • (Boolean)


102
103
104
# File 'lib/hglib/repo/id.rb', line 102

def default?
	return self.id == DEFAULT_ID
end

#dirtyObject

Does the repo have uncommitted changes?



61
# File 'lib/hglib/repo/id.rb', line 61

attr_predicate :dirty

#short_idObject

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_sObject

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.tags.join( '/' ) unless self.tags.empty?
	str << ' ' << self.bookmarks.join( '/' ) unless self.bookmarks.empty?

	return str
end