Module: Amp::Repositories::TagManager
- Includes:
- Amp::RevlogSupport::Node
- Included in:
- LocalRepository
- Defined in:
- lib/amp/repository/tag_manager.rb
Overview
TagManager
This module handles all tag-related (but not branch tag) functionality of the repository.
Constant Summary collapse
- TAG_FORBIDDEN_LETTERS =
":\r\n"
Constants included from Amp::RevlogSupport::Node
Amp::RevlogSupport::Node::NULL_ID, Amp::RevlogSupport::Node::NULL_REV
Instance Method Summary collapse
-
#apply_tag(names, node, opts = {}) ⇒ Object
Adds the given tag to a given changeset, and commits to preserve it.
-
#invalidate_tag_cache! ⇒ Object
Invalidates the tag cache.
-
#tag_list ⇒ Hash
Returns a list of all the tags as a hash, mapping each tag to the tip-most changeset it applies to.
-
#tag_type(tag_name) ⇒ String
Returns the tag-type of the given tag.
-
#tags ⇒ Hash
Loads all of the tags from the tag-cache file stored as .hgtags.
-
#tags_for_node(node) ⇒ Array<String>
Returns the tags for a given revision (by ID).
Methods included from Amp::RevlogSupport::Node
Instance Method Details
#apply_tag(names, node, opts = {}) ⇒ Object
Adds the given tag to a given changeset, and commits to preserve it.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/amp/repository/tag_manager.rb', line 132 def apply_tag(names, node, opts={}) use_dirstate = opts[:parent].nil? all_letters = names.kind_of?(Array) ? names.join : names (TAG_FORBIDDEN_LETTERS.size-1).downto 0 do |i| if all_letters.include? TAG_FORBIDDEN_LETTERS[i, 1] raise abort("#{TAG_FORBIDDEN_LETTERS[i,1]} not allowed in a tag name!") end end = "" # If it's a local tag, we just write the file and bounce. mad easy yo. if opts[:local] @hg_opener.open("localtags","r+") do |fp| = fp.read (fp,names, nil, ) end return end # ok, it's a global tag. now we have to handle versioning and shit. if use_dirstate = working_read(".hgtags") rescue "" file = @file_opener.open(".hgtags","a") else = versioned_file(".hgtags", :change_id => parent).data file = @file_opener.open(".hgtags","w") file.write if && .any? end (file, node, names, ) file.close if use_dirstate && dirstate[".hgtags"].status == :untracked self.add([".hgtags"]) end tag_node = commit :files => [".hgtags"], :message => opts[:message], :user => opts[:user], :date => opts[:date], :p1 => opts[:parent], :extra => opts[:extra] tag_node end |
#invalidate_tag_cache! ⇒ Object
Invalidates the tag cache. Removes all ivars relating to tags.
61 62 63 64 65 |
# File 'lib/amp/repository/tag_manager.rb', line 61 def invalidate_tag_cache! @tags_for_node_cache = nil @tags_cache = nil @tags_type_cache = nil end |
#tag_list ⇒ Hash
Returns a list of all the tags as a hash, mapping each tag to the tip-most changeset it applies to.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/amp/repository/tag_manager.rb', line 20 def tag_list list = [] .each do |tag, node| begin r = changelog.revision(node) rescue r = -2 end list << {:revision => r, :tag => tag, :node => node} end list.sort {|i1, i2| i1[:revision] <=> i2[:revision] } end |
#tag_type(tag_name) ⇒ String
Returns the tag-type of the given tag. This could be “local”, which means it is not shared among repositories.
39 40 41 42 |
# File 'lib/amp/repository/tag_manager.rb', line 39 def tag_type(tag_name) #load the tags @tags_type_cache[tag_name] end |
#tags ⇒ Hash
Loads all of the tags from the tag-cache file stored as .hgtags. Returns a hash, mapping tag names to node-IDs.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/amp/repository/tag_manager.rb', line 72 def return @tags_cache if @tags_cache , tag_types = {}, {} file = nil # For each current .hgtags file in our history (including multi-heads), read in # the tags .each do |rev, node, file_node| # get the file f = (f && f.file(file_node)) || self.versioned_file(".hgtags", :file_id => file_node.file_node) # read the tags, as global, because they're versioned. (f.data.split("\n"), f, "global", , tag_types) end # Now do locally stored tags, that aren't committed/versioned begin # get the local file, stored in .hg/ data = @hg_opener.read("localtags") # Read the tags as local, because they are not versioned (data.split_newlines,"local_tags","local",, tag_types) rescue Errno::ENOENT # do nothing. most people don't have this file. end # Save our tags for use later. Use ivars. @tags_cache = {} @tags_type_cache = {} # Go through the global tags to store them in the cache .each do |k, nh| # the node ID is the first part of the stored data n = nh.first # update the cache @tags_cache[k] = n unless n == NULL_ID @tags_type_cache[k] = tag_types[k] end # tip = special tag @tags_cache["tip"] = self.changelog.tip # return our tags @tags_cache end |
#tags_for_node(node) ⇒ Array<String>
Returns the tags for a given revision (by ID).
49 50 51 52 53 54 55 56 57 |
# File 'lib/amp/repository/tag_manager.rb', line 49 def (node) return (@tags_for_node_cache[node] || []) if @tags_for_node_cache @tags_for_node_cache = {} .each do |tag, tag_node| @tags_for_node_cache[tag_node] ||= [] # make sure there's an array @tags_for_node_cache[tag_node] << tag # add the tag to it end @tags_for_node_cache[node] || [] end |