WorkSpace.py revision 0df7087fda4bb16f7e1cf07d1b90fcf070c19484
1N/A# This program is free software; you can redistribute it and/or modify 1N/A# it under the terms of the GNU General Public License version 2 1N/A# as published by the Free Software Foundation. 1N/A# This program is distributed in the hope that it will be useful, 1N/A# but WITHOUT ANY WARRANTY; without even the implied warranty of 1N/A# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1N/A# GNU General Public License for more details. 1N/A# You should have received a copy of the GNU General Public License 1N/A# along with this program; if not, write to the Free Software 1N/A# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 1N/A# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 1N/A# Use is subject to license terms. 1N/A# All important operations apply to the changes between the two. 1N/A# However, for the sake of remote operation, the 'parent' of a 1N/A# workspace is not seen as a literal entity, instead the figurative 1N/A# parent contains the last changeset common to both parent and child, 1N/A# as such the 'parent tip' is actually nothing of the sort, but instead a 1N/A# convenient imitation. 1N/A# Any change made to a workspace is a change to a file therein, such 1N/A# changes can be represented briefly as whether the file was 1N/A# the file has a different name in the parent and if so, whether it 1N/A# was renamed or merely copied. Each changed file has an 1N/A# associated ActiveEntry. 1N/A# The ActiveList being a list ActiveEntrys can thus present the entire 1N/A# change in workspace state between a parent and its child, and is the 1N/A# important bit here (in that if it is incorrect, everything else will 1N/A# be as incorrect, or more) 1N/A '''Representation of the changes made to a single file. 1N/A MODIFIED - Contents changed, but no other changes were made 1N/A ADDED - File is newly created 1N/A REMOVED - File is being removed 1N/A Copies are represented by an Entry whose .parentname is non-nil 1N/A Truly copied files have non-nil .parentname and .renamed = False 1N/A Renames have non-nil .parentname and .renamed = True 1N/A Do not access any of this information directly, do so via the 1N/A .is_<change>() methods.''' 1N/A # As opposed to copied (or neither) 1N/A # ActiveEntrys sort by the name of the file they represent. '''Complete representation of workspace change. In practice, a container for ActiveEntrys, and methods to build them, update them, and deal with them en masse.''' # If we couldn't find a parenttip, the two repositories must # be unrelated (Hg catches most of this, but this case is valid for it # When a file is renamed, two operations actually occur. # A file copy from source to dest and a removal of source. # These are represented as two distinct entries in the # changectx and status (one on the dest file for the # copy, one on the source file for the remove). # Since these are unconnected in both the context and # status we can only make the association by explicitly # We deal with this thusly: # We maintain a dict dest -> source of all copies # (updating dest as appropriate, but leaving source alone). # After all other processing, we mark as renamed any pair # where source is on the removed list. # Walk revs looking for renames and adding files that # are in both change context and status to the active # We store comments per-entry as well, for the sake of # webrev and similar. We store twice to avoid the problems # of uniquifying comments for the general list (and possibly # destroying multi-line entities in the process). # NB: .renamed() is a misnomer, this actually checks # If the source file is a known copy we know its # ancestry leads us to the parent. # Otherwise make sure the source file is known to # be in the parent, we need not care otherwise. # We detect cycles at a later point. There is no # reason to continuously handle them. # Walk the copy list marking as copied any non-cyclic pair # where the destination file is still present in the local # tip (to avoid ephemeral changes) # Where source is removed, mark as renamed, and remove the # AL entry for the source file # Walk the active list setting the change type for each active # In the case of modified files that are not renames or # copies, we do a content comparison, and drop entries that # are not actually modified. # We walk a copy of the AL such that we can drop entries # There are cases during a merge where a file will be in # the status return as modified, but in reality be an # addition (ie, not in the parenttip). # We need to check whether the file is actually present # in the parenttip, and set it as an add, if not. # Return list of files represented in this AL, # including the parent file of a rename # It's not uncommon for a child workspace to itself contain the # merge of several other children, with initial branch points in # the parent (possibly from the cset a project gate was created # Immediately after recommit, this leaves us looking like this: # * <- recommitted changeset (real tip) # [left-most is parent, next is child, right two being # branches in child, intermediate merges parent->child # Obviously stripping base (the first child-specific delta on the # main child workspace line) doesn't remove the vestigial branches # from other workspaces (or in-workspace branches, or whatever) # In reality, what we need to strip in a recommit is any # child-specific branch descended from the parent (rather than # another part of the child). Note that this by its very nature # includes the branch representing the 'main' child workspace. # We calculate these by walking from base (which is guaranteed to # be the oldest child-local cset) to localtip searching for # changesets with only one parent cset, and where that cset is not # part of the active list (and is therefore outgoing). '''Find the bases that in combination define the "old" side of a recommitted set of changes, based on AL''' # We don't rebuild the AL So the AL local tip is the old tip '''Find tags that refer to a changeset in the ActiveList, returning a list of 3-tuples (tag, node, is_local) for each. We return all instances of a tag that refer to such a node, not just that which takes precedence.''' # We want to use the tags file from the localtip '''Compare two revisions of two files Return True if file changed, False otherwise. The fast path compares file metadata, slow path is a real comparison of file content.''' # NB: Keep these ordered such as to make every attempt # to short-circuit the more time consuming checks. '''Return the canonical workspace parent, either SPEC (which will be expanded) if provided or the default parent '''Return the most representative changeset to act as the If the working directory is modified (has file changes, is a merge, or has switched branches), this will be a workingctx. If the working directory is unmodified, this will be the most recent (highest revision number) local (outgoing) head on the current branch, if no heads are determined to be outgoing, it will be the most recent head on the current branch. # A modified working copy is seen as a proto-branch, and thus # our only option as the local tip. self.
ui.
warn(
'The current branch has more than one head, ' '''Return the highest-numbered, non-outgoing changeset that is an ancestor of a changeset in heads. This is intended to find the most recent changeset on a given branch that is shared between a parent and child workspace, such that it can act as a stand-in for the parent workspace. '''Return the tipmost node on the same branch as head that is not We walk from head to the bottom of the workspace (revision 0) collecting nodes not in outnodes during the add phase and return the first node we see in the iter phase that was previously collected. If no node is found (all revisions >= 0 are outgoing), the only possible parenttip is the null node (node.nullid) which is returned explicitly. See the docstring of mercurial.cmdutil.walkchangerevs() for the phased approach to the iterator returned. The important part to note is that the 'add' phase gathers nodes, which the 'iter' phase then iterates through.''' '''Translate from the hg 6-tuple status format to a hash keyed states = [
'modified',
'added',
'removed',
'deleted',
'unknown',
# Cache findoutgoing results "Warning: Parent workspace %s is not accessible\n" %
parent)
self.
ui.
warn(
"active list will be incomplete\n\n")
'''Return a list of files modified in the workspace''' '''Return boolean indicating whether the workspace has an uncommitted '''Return boolean indicating whether the workspace has an uncommitted named branch''' '''Return an ActiveList describing changes between workspace and parent workspace (including uncommitted changes). If workspace has no parent ActiveList will still describe any outgoing = []
# No parent, no outgoing nodes 'Return diffs relative to PARENT, as best as we can make out' # act.localtip maybe nil, in the case of uncommitted local # We wish to go from a single series of consecutive changesets # (possibly including merges with the parent) to a single # changeset faithfully representing contents and copy history. # We achieve this in a somewhat confusing fashion. # - Sanity check the workspace # - Update the workspace to tip # - Enter into the dirstate the sum total of file contents in the # to-be-squished changesets # - Commit this in-progress change (which has no changes at all, # in reality) On top of the effective parent tip. # - Strip the child-local branch(es) (see ActiveList.bases()) '''Create a single conglomerate changeset, with log message MESSAGE containing the changes from ACTIVE. USER, if set, is used The old changes are removed.''' '''Remove any tags referring to the specified nodes.''' # The files involved need to be present in the workspace and # not otherwise molested, rather than the workspace not being # modified we also need to prevent files being deleted (but # The easiest way to achieve this is to update the working raise util.
Abort(
'Could not recommit tags: %s\n' % e)
# For copied files, we need to enter the copy into the # dirstate before we force the commit such that the # file logs of both branches (old and new) contain # representation of the copy. (
"parentname '%s' (of '%s') not in parent" %
# If the source file exists, and used to be versioned # this will cause this to become a true copy # (re-introducing the source file) # We bandaid this, by removing the source file in this # case. If we're here, the user has already agreed to this # If all we're doing is stripping the old nodes, we want to # update the working copy such that we're not at a revision # that's about to go away. # Silence all the strip and update fun # We must strip away the old representation of the child # branch(es). This may involve stripping a theoretically # large number of branches in certain cases # If this fails, it may leave us in a surprising place in # We want to warn the user that something went wrong, # and what will happen next, re-raise the exception, and # bring the working copy back into a consistent state # (which the finally block will do) self.
ui.
warn(
"stripping failed, your workspace will have " "your workspace has been updated to the " raise # Re-raise the exception # We need to remove Hg's undo information (used for rollback), # since it refers to data that will probably not exist after raise util.
Abort(
'failed to remove undo data: %s\n' % e)
'Return the full path to a workspace file.' '''Bring workspace up to REV (or tip) forcefully (discarding in '''True if the workspace has Mq patches applied'''