WorkSpace.py revision c7f512e49da83ae2cd3d4b339e1a8366544471e2
#
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
#
# Copyright 2010 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# Theory:
#
# All important operations apply to the changes between the two.
#
# However, for the sake of remote operation, the 'parent' of a
# workspace is not seen as a literal entity, instead the figurative
# parent contains the last changeset common to both parent and child,
# as such the 'parent tip' is actually nothing of the sort, but instead a
# convenient imitation.
#
# Any change made to a workspace is a change to a file therein, such
# changes can be represented briefly as whether the file was
# the file has a different name in the parent and if so, whether it
# was renamed or merely copied. Each changed file has an
# associated ActiveEntry.
#
# The ActiveList being a list ActiveEntrys can thus present the entire
# change in workspace state between a parent and its child, and is the
# important bit here (in that if it is incorrect, everything else will
# be as incorrect, or more)
#
import cStringIO
import os
#
# Mercurial >= 1.2 has its exception types in a mercurial.error
# module, prior versions had them in their associated modules.
#
else:
class ActiveEntry(object):
'''Representation of the changes made to a single file.
MODIFIED - Contents changed, but no other changes were made
ADDED - File is newly created
REMOVED - File is being removed
Copies are represented by an Entry whose .parentname is non-nil
Truly copied files have non-nil .parentname and .renamed = False
Renames have non-nil .parentname and .renamed = True
Do not access any of this information directly, do so via the
.is_<change>() methods.'''
MODIFIED = 1
ADDED = 2
REMOVED = 3
self.parentname = None
# As opposed to copied (or neither)
#
# ActiveEntrys sort by the name of the file they represent.
#
def is_modified(self):
def is_removed(self):
def is_renamed(self):
class ActiveList(object):
'''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
# but invalid for us)
#
if revs:
if not revs:
return
files = []
#
# 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
# looking for it.
#
# 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.
#
copies = {}
#
# Walk revs looking for renames and adding files that
# are in both change context and status to the active
# list.
#
#
# 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).
#
try:
except HgLookupError:
continue
#
# NB: .renamed() is a misnomer, this actually checks
# for copies.
#
if rn:
#
# 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
#
continue
#
# Walk the active list setting the change type for each active
# file.
#
# 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
# within the loop.
#
continue
#
# 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.
#
continue
yield entry
'''Return the list of pathnames of all files touched by this
ActiveList
Where files have been renamed, this will include both their
current name and the name which they had in the parent tip.
'''
return ret
'''Return the list of changesets that are roots of the ActiveList.
This is the set of active changesets where neither parent
changeset is itself active.'''
'''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.'''
tags = []
# We want to use the tags file from the localtip
return tags
'''Return a copy of data, which should correspond to the
contents of a Mercurial tags file, with any tags that refer to
changesets which are components of the ActiveList removed.'''
'''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 True
return True
return True
'''Return a Mercurial context object representing the entire
ActiveList as one change.'''
'''Represent an ActiveList as a Mercurial context object.
Part of the WorkSpace.squishdeltas implementation.'''
'''Build an activectx object.
active - The ActiveList object used as the source for all data.
message - Changeset description
user - Committing user'''
#
# .hgtags is a special case, tags referring to active list
# component changesets should be elided.
#
if fname == '.hgtags':
return ret
self.activecache = {}
'''Return the canonical workspace parent, either SPEC (which
will be expanded) if provided or the default parent
otherwise.'''
if spec:
if p == 'default':
return None
else:
return p
'''Return the most representative changeset to act as the
localtip.
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.
#
return wctx
return ltip
'''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
in outnodes.
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.'''
'follow': True}
seen = []
if st == 'add':
if n not in outnodes:
elif st == 'iter':
if n in seen:
return rev
'''Translate from the hg 6-tuple status format to a hash keyed
on change-type'''
'ignored']
'''Return the base set of outgoing nodes.
A caching wrapper around mercurial.localrepo.findoutgoing().
Complains (to the user), if the parent workspace is
non-existent or inaccessible'''
try:
try:
except HgRepoError:
"accessible\n"
"active list will be incomplete\n\n" % parent)
return []
finally:
'''Return a list of files modified in the workspace'''
'''Return boolean indicating whether the workspace has an uncommitted
merge'''
'''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
uncommitted changes'''
if parent:
else:
outgoing = [] # No parent, no outgoing nodes
outnodes = []
else:
return act
'Return diffs relative to PARENT, as best as we can make out'
#
# act.localtip maybe nil, in the case of uncommitted local
# changes.
#
return
'''Create a single conglomerate changeset based on a given
active list. Removes the original changesets comprising the
given active list, and any tags pointing to them.
Operation:
- Commit an activectx object representing the specified
active list,
- Remove any local tags pointing to changesets in the
specified active list.
- Remove the changesets comprising the specified active
list.
- Remove any metadata that may refer to changesets that were
removed.
Calling code is expected to hold both the working copy lock
and repository lock of the destination workspace
'''
def strip_local_tags(active):
'''Remove any local tags referring to the specified nodes.'''
fh = None
try:
finally:
#
# Work around Mercurial issue #1666, if the source
# file of a rename exists in the working copy
# Mercurial will complain, and remove the file.
#
# We preemptively remove the file to avoid the
# complaint (the user was asked about this in
# cdm_recommit)
#
if entry.is_renamed():
wsstate = "recommitted"
else:
#
# 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.
#
wsstate = "tip"
#
# Tags were elided by the activectx object. Local tags,
# however, must be removed manually.
#
try:
except EnvironmentError, e:
# Silence all the strip and update fun
#
# Remove the active lists component changesets by stripping
# the base of any active branch (of which there may be
# several)
#
try:
try:
#
# Any cached information about the repository is
# likely to be invalid during the strip. The
# caching of branch tags is especially
# problematic.
#
except:
#
# If this fails, it may leave us in a surprising place in
# the history.
#
# 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)
#
"superfluous heads.\n"
"your workspace has been updated to the "
"%s changeset.\n" % wsstate)
raise # Re-raise the exception
finally:
#
# We need to remove Hg's undo information (used for rollback),
# since it refers to data that will probably not exist after
# the strip.
#
try:
except EnvironmentError, e:
'Return the full path to a workspace file.'
'''Bring workspace up to REV (or tip) forcefully (discarding in
progress changes)'''
if rev != None:
else:
def mq_applied(self):
'''True if the workspace has Mq patches applied'''
return q.applied
def workingctx(self):
try:
finally:
# Workaround Hg bug 1651