#
# 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 2008, 2010 Richard Lowe
#
'''OpenSolaris extensions to Mercurial
This extension contains a number of commands to help you work with
the OpenSolaris consolidations. It provides commands to check your
changes against the various style rules used for OpenSolaris, to
backup and restore your changes, to generate code reviews, and to
prepare your changes for integration.
The Parent
To provide a uniform notion of parent workspace regardless of
filesystem-based access, Cadmium uses the highest numbered changeset
on the current branch that is also in the parent workspace to
represent the parent workspace.
The Active List
Many Cadmium commands operate on the active list, the set of
files ('active files') you have changed in this workspace in relation
to its parent workspace, and the metadata (commentary, primarily)
associated with those changes.
NOT Files
Many of Cadmium's commands to check that your work obeys the
various stylistic rules of the OpenSolaris consolidations (such as
those run by 'hg nits') allow files to be excluded from this checking
repository for one-time exceptions, and in the exception_lists
directory at the repository root for permanent exceptions. (For ON,
these would mean one in $CODEMGR_WS and one in
$CODEMGR_WS/usr/closed).
These files are in the same format as the Mercurial hgignore
file, a description of which is available in the hgignore(5) manual
page.
Common Tasks
- Show diffs relative to parent workspace - pdiffs
- Check source style rules - nits
- Run pre-integration checks - pbchk
- Collapse all your changes into a single changeset - recommit
'''
#
# Adjust the load path based on the location of cdm.py and the version
# of python into which it is being loaded. This assumes the normal
# onbld directory structure, where cdm.py is in
# this.
#
# This and the case below are not equivalent. In this case we may be
# python2.Y in sys.path.
#
#
# such that a cdm.py loaded from the source tree uses the modules also
# within the source tree.
#
try:
import ConfigParser
if default:
prompt = ' [Y/n]:'
defanswer = 'y'
else:
prompt = ' [y/N]:'
defanswer = 'n'
else:
'''Build a list of files in which we're interested.
If no files are specified take files from the active list relative
to 'parent'.
Return a list of 2-tuples the first element being a path relative
to the current directory and the second an entry from the active
list, or None if an explicit file list was given.'''
if files:
else:
'''return a function which returns boolean indicating whether a file
should be skipped for CMD.'''
#
# The ignore routines need a canonical path to the file (relative to the
# repo root), whereas the check commands get paths relative to the cwd.
#
# Wrap our argument such that the path is canonified before it is checked.
#
def f(path):
else:
return f
ignorefiles = []
if ignorefiles:
return canonified_check(ign)
else:
'''Abort if the workspace has uncommitted changes, merges,
branches, or has Mq patches applied'''
if ws.mq_applied():
#
# Adding a reference to WorkSpace from a repo causes a circular reference
# repo <-> WorkSpace.
#
# This prevents repo, WorkSpace and members thereof from being garbage
# collected. Since transactions are aborted when the transaction object
# is collected, and localrepo holds a reference to the most recently created
# transaction, this prevents transactions from cleanly aborting.
#
# Instead, we hold the repo->WorkSpace association in a dictionary, breaking
# that dependence.
#
wslist = {}
else:
'python:hgext_cdm.pbconfirm')
if source == 'push':
return 1
else:
'''diff workspace against its parent
Show differences between this workspace and its parent workspace
in the same manner as 'hg diff'.
For a description of the changeset used to represent the parent
workspace, see The Parent in the extension documentation ('hg help
cdm').
'''
if diffs:
else:
'''list active files (those changed in this workspace)
Display a list of files changed in this workspace as compared to
its parent workspace.
File names are displayed one-per line, grouped by manner in which
they changed (added, modified, removed). Information about
renames or copies is output in parentheses following the file
name.
For a description of the changeset used to represent the parent
workspace, see The Parent in the extension documentation ('hg help
cdm').
Output can be filtered by change type with --added, --modified,
and --removed. By default, all files are shown.
'''
wanted = []
if opts['added']:
if opts['modified']:
if opts['removed']:
lst = {}
continue
if elt.is_renamed():
else:
'''show all ARC cases referenced in changeset comments'''
# We take a set of the appropriate comments to eliminate duplicates.
'''show all bug IDs referenced in changeset comments'''
'''show changeset commentary for all active changesets'''
'''show renamed active files
Renamed files are shown in the format::
new-name old-name
One pair per-line.
'''
'''check active changeset comment formatting
Check that active changeset comments conform to O/N rules.
Each comment line must contain either one bug or ARC case ID
followed by its synopsis, or credit an external contributor.
'''
'''check for a valid CDDL header comment in all active files.
Check active files for a valid Common Development and Distribution
License (CDDL) block comment.
Newly added files are checked for a copy of the CDDL header
comment. Modified files are only checked if they contain what
appears to be an existing CDDL header comment.
Files can be excluded from this check using the cddlchk.NOT file.
See NOT Files in the extension documentation ('hg help cdm').
'''
ret = 0
for f, e in filelist:
if e and e.is_removed():
continue
continue
elif e and e.is_added():
else:
return ret
'''check for a valid mapfile header block in active files
Check that all link-editor mapfiles contain the standard mapfile
header comment directing the reader to the document containing
Solaris object versioning rules (README.mapfile).
Files can be excluded from this check using the mapfilechk.NOT
file. See NOT Files in the extension documentation ('hg help
cdm').
'''
ret = 0
# We are interested in examining any file that has the following
# in its final path segment:
# - Contains the word 'mapfile'
# - Begins with 'map.'
# - Ends with '.map'
# We don't want to match unless these things occur in final path segment
# because directory names with these strings don't indicate a mapfile.
# We also ignore files with suffixes that tell us that the files
# are not mapfiles.
for f, e in filelist:
if e and e.is_removed():
continue
continue
continue
return ret
'''check each active file for a current and correct copyright notice
Check that all active files have a correctly formed copyright
notice containing the current year.
See the Non-Formatting Considerations section of the OpenSolaris
Developer's Reference for more info on the correct form of
copyright notice.
(http://hub.opensolaris.org/bin/view/Community+Group+on/devref_7#H723NonFormattingConsiderations)
Files can be excluded from this check using the copyright.NOT file.
See NOT Files in the extension documentation ('hg help cdm').
'''
ret = 0
for f, e in filelist:
if e and e.is_removed():
continue
continue
return ret
'''check active C header files conform to the O/N header rules
Check that any added or modified C header files conform to the O/N
header rules.
See the section 'HEADER STANDARDS' in the hdrchk(1) manual page
for more information on the rules for O/N header file formatting.
Files can be excluded from this check using the hdrchk.NOT file.
See NOT Files in the extension documentation ('hg help cdm').
'''
ret = 0
for f, e in filelist:
if e and e.is_removed():
continue
elif not f.endswith('.h'):
continue
continue
return ret
'''check active C source files conform to the C Style Guide
Check that any added or modified C source file conform to the C
Style Guide.
See the C Style Guide for more information about correct C source
formatting.
Files can be excluded from this check using the cstyle.NOT file.
See NOT Files in the extension documentation ('hg help cdm').
'''
ret = 0
for f, e in filelist:
if e and e.is_removed():
continue
continue
continue
return ret
'''check active Java source files for common stylistic errors
Files can be excluded from this check using the jstyle.NOT file.
See NOT Files in the extension documentation ('hg help cdm').
'''
ret = 0
for f, e in filelist:
if e and e.is_removed():
continue
elif not f.endswith('.java'):
continue
continue
return ret
'''check the permissions of each active file
Check that the file permissions of each added or modified file do not
contain the executable bit.
Files can be excluded from this check using the permchk.NOT file.
See NOT Files in the extension documentation ('hg help cdm').
'''
exeFiles = []
for f, e in filelist:
if e and e.is_removed():
continue
continue
'(+x) permission set,\nremove unless intentional:\n')
'''check modification of workspace tags
Check for any modification of the repository's .hgtags file.
With the exception of the gatekeepers, nobody should introduce or
modify a repository's tags.
'''
if ".hgtags" in active:
'Only gatekeepers should add or modify such tags.\n'
'Use the following commands to revert these changes:\n'
' hg revert -r%d %s\n'
' hg commit %s\n'
'You should also recommit before integration\n' %
return 1
return 0
'''check for changes in number or name of branches
Check that the workspace contains only a single head, that it is
on the branch 'default', and that no new branches have been
introduced.
'''
#
# We care if there's more than one head, and those heads aren't
# identical to the dirstate parents (if they are identical, it's
# an uncommitted merge which mergechk will catch, no need to
# complain twice).
#
return 1
"Only gatekeepers should push new branches.\n"
"Use the following commands to restore the branch name:\n"
" hg branch [-f] default\n"
" hg commit\n"
"You should also recommit before integration\n" %
return 1
for t in branches:
if t == 'default':
continue
"Use the following commands to remove extraneous branches.\n"
" hg branch [-f] default\n"
" hg commit"
"You should also recommit before integration\n")
return 1
return 0
Check that any CR IDs mentioned in active changeset comments have
an associated, approved Request to Integrate (RTI).
This check only works on systems with access to webrti.us.oracle.com.
This check maybe disabled by creating an empty file rtichk.NOT.
See NOT Files in the extension documentation ('hg help cdm').
'''
return 0
if not onSWAN():
return 0
bugs = []
# RTI normalizes the gate path for us
'''check active files for SCCS keywords
Check that any added or modified files do not contain SCCS keywords
(#ident lines, etc.).
Files can be excluded from this check using the keywords.NOT file.
See NOT Files in the extension documentation ('hg help cdm').
'''
ret = 0
for f, e in filelist:
if e and e.is_removed():
continue
continue
return ret
#
# NB:
# There's no reason to hook this up as an invokable command, since
# we have 'hg status', but it must accept the same arguments.
#
'''Warn the user if they have uncommitted changes'''
if st:
return 1
return 0
'''Warn the user if their workspace contains merges'''
if merges:
return 1
return 0
'''Run CMDS (with OPTS) over active files in WS'''
ret = 0
else:
return ret
'''check for stylistic nits in active files
Check each active file for basic stylistic errors.
The following checks are run over each active file (see 'hg help
<check>' for more information about each):
- cddlchk (CDDL block comments)
- copyright (copyright statements)
- cstyle (C source style)
- hdrchk (C header style)
- jstyle (java source style)
- mapfilechk (link-editor mapfiles)
- permchk (file permissions)
- keywords (SCCS keywords)
With the global -q/--quiet option, only provide output for those
checks which fail.
'''
cmds = [cdm_cddlchk,
'''run pre-integration checks on this workspace
Check this workspace for common errors prior to integration.
The following checks are run over the active list (see 'hg help
<check>' for more information about each):
- branchchk (addition/modification of branches)
- cddlchk (CDDL block comments)
- comchk (changeset descriptions)
- copyright (copyright statements)
- cstyle (C source style)
- hdrchk (C header style)
- jstyle (java source style)
- keywords (SCCS keywords)
- mapfilechk (link-editor mapfiles)
- permchk (file permissions)
- rtichk (requests to integrate)
- tagchk (addition/modification of tags)
Additionally, the workspace is checked for outgoing merges (which
should be removed with 'hg recommit'), and uncommitted changes.
With the global -q/--quiet option, only provide output for those
checks which fail.
'''
#
# The current ordering of these is that the commands from cdm_nits
# run first in the same order as they would in cdm_nits, then the
# pbchk specifics are run.
#
cmds = [cdm_cddlchk,
'''replace outgoing changesets with a single equivalent changeset
Replace all outgoing changesets with a single changeset containing
equivalent changes. This removes uninteresting changesets created
during development that would only serve as noise in the gate.
Any changed file that is now identical in content to that in the
parent workspace (whether identical in history or otherwise) will
not be included in the new changeset. Any merges information will
also be removed.
If no files are changed in comparison to the parent workspace, the
outgoing changesets will be removed, but no new changeset created.
recommit will refuse to run if the workspace contains more than
one outgoing head, even if those heads are on the same branch. To
recommit with only one branch containing outgoing changesets, your
workspace must be on that branch and at that branch head.
recommit will prompt you to take a backup if your workspace has
been changed since the last backup was taken. In almost all
cases, you should allow it to take one (the default).
recommit cannot be run if the workspace contains any uncommitted
changes, applied Mq patches, or has multiple outgoing heads (or
branches).
'''
try:
'changesets')
#
# During the course of a recommit, any file bearing a name
# matching the source name of any renamed file will be
# clobbered by the operation.
#
# As such, we ask the user before proceeding.
#
if bogosity:
"rename and also present\n"
"in the working directory:\n")
" Continue?",
False):
else:
if not message:
if bk.need_backup():
finally:
if clearedtags:
if not changedir:
if changedir:
'''run specified command for each active file
Run the command specified on the command line for each active
file, with the following variables present in the environment:
:$file: - active file basename.
:$dir: - active file dirname.
:$filepath: - path from workspace root to active file.
:$workspace: - full path to workspace root.
For example:
hg eval 'echo $dir; hg log -l3 $file'
will show the last the 3 log entries for each active file,
preceded by its directory.
'''
'''apply specified command to all active files
Run the command specified on the command line over each active
file.
For example 'hg apply "wc -l"' will output a count of the lines in
each active file.
'''
if opts['remain']:
appnd = ' $filepath'
else:
appnd = ' $file'
try:
try:
except IOError, e:
# In 1.9 (changeset d764463b433e in the mercurial repo), atomictempfile()
# stopped delegating all undefined methods to file() using __getattr__(), so
# use of "closed" and "tell" now raise an exception. Then in 2.0 (changeset
# 774da7121fc9), rename() got renamed to close() and close() got renamed to
# discard(). Hence the ugliness.
fp = None
try:
'default = %s\n\n' % parent)
finally:
'default = %s\n\n' % parent)
else:
fp = None
try:
finally:
#
# line will be the last line of any continued block, go back
# to the first removing the continuation as we go.
#
line -= 1
else:
else:
try:
finally:
else:
return
if not source:
return
else:
"default path is from: %s" % source)
else:
Update the 'default' path alias that is used as the default source
for 'hg pull' and the default destination for 'hg push' (unless
there is a 'default-push' alias). This is also the path all
Cadmium commands treat as your parent workspace.
'''
'''Create a backup directory name based on the specified path.
In most cases this is the basename of the path specified, but
certain cases are handled specially to create meaningful names'''
#
# If a path is 'special', we append the basename of the path to
# the path element preceding the constant, special, part.
#
# Such that for instance:
# /foo/bar/onnv-fixes/usr/closed
# has a backup name of:
# onnv-fixes-closed
#
else:
return fullpath[-1]
'''backup workspace changes and metadata
Create a backup copy of changes made in this workspace as compared
to its parent workspace, as well as important metadata of this
workspace.
NOTE: Only changes as compared to the parent workspace are backed
up. If you lose this workspace and its parent, you will not be
able to restore a backup into a clone of the grandparent
workspace.
By default, backups are stored in the cdm.backup/ directory in
your home directory. This is configurable using the cdm.backupdir
configuration variable, for example:
or place the following in an appropriate hgrc file::
[cdm]
Backups have the same name as the workspace in which they were
'''
try:
else:
finally:
'''restore workspace from backup
Restore this workspace from a backup (taken by 'hg backup').
If the specified backup directory does not exist, it is assumed to
be relative to the cadmium backup directory (~/cdm.backup/ by
default).
For example::
% hg restore on-rfe - Restore the latest backup of ~/cdm.backup/on-rfe
% hg restore -g3 on-rfe - Restore the 3rd backup of ~/cdm.backup/on-rfe
'''
if opts['generation']:
else:
gen = None
try:
finally:
'''generate web-based code review and optionally upload it
Generate a web-based code review using webrev(1) and optionally
upload it. All known arguments are passed through to webrev(1).
'''
webrev_args = ""
else:
if retval != 0:
return retval - 255
return 0
cmdtable = {
('r', 'remain', None, 'do not change directory')],
'hg apply [-p PARENT] [-r] command...'),
'hg arcs [-p PARENT]'),
'only backup if workspace files are newer')],
'hg backup [-t]'),
'hg branchchk [-p PARENT]'),
'hg bugs [-p PARENT]'),
'hg cddlchk [-p PARENT]'),
('N', 'nocheck', None,
'do not compare comments with databases')],
'hg comchk [-p PARENT]'),
'hg comments [-p PARENT]'),
'hg copyright [-p PARENT]'),
'hg cstyle [-p PARENT]'),
('r', 'remain', None, 'do not change directory')],
'hg eval [-p PARENT] [-r] command...'),
'hg hdrchk [-p PARENT]'),
'hg jstyle [-p PARENT]'),
'hg keywords [-p PARENT]'),
('a', 'added', None, 'show added files'),
('m', 'modified', None, 'show modified files'),
('r', 'removed', None, 'show removed files')],
'hg list [-amrRu] [-p PARENT]'),
'hg mapfilechk [-p PARENT]'),
'hg nits [-p PARENT]'),
('N', 'nocheck', None,
'hg pbchk [-N] [-p PARENT]'),
'hg permchk [-p PARENT]'),
('a', 'text', None, 'treat all files as text'),
('g', 'git', None, 'use extended git diff format'),
('w', 'ignore-all-space', None,
'ignore white space when comparing lines'),
('b', 'ignore-space-change', None,
'ignore changes in the amount of white space'),
('B', 'ignore-blank-lines', None,
'ignore changes whose lines are all blank'),
('U', 'unified', 3,
'number of lines of context to show'),
('I', 'include', [],
'include names matching the given patterns'),
('X', 'exclude', [],
'exclude names matching the given patterns')],
'hg pdiffs [OPTION...] [-p PARENT] [FILE...]'),
('m', 'message', '',
'use <text> as commit message'),
('l', 'logfile', '',
'read commit message from file'),
('u', 'user', '',
'record user as committer')],
'hg recommit [-m TEXT] [-l FILE] [-u USER] [-p PARENT]'),
'hg renamed [-p PARENT]'),
'hg restore [-g GENERATION] BACKUP'),
('N', 'nocheck', None, 'skip RTI check')],
'hg rtichk [-N] [-p PARENT]'),
'hg tagchk [-p PARENT]'),
('D', 'D', None, 'delete remote webrev'),
('I', 'I', '', 'ITS configuration file'),
('i', 'i', '', 'include file'),
('N', 'N', None, 'suppress comments'),
('n', 'n', None, 'do not generate webrev'),
('O', 'O', None, 'OpenSolaris mode'),
('o', 'o', '', 'output directory'),
('p', 'p', '', 'use specified parent'),
('t', 't', '', 'upload target'),
('U', 'U', None, 'upload the webrev'),
('w', 'w', '', 'use wx active file'),
('z', 'z', None, 'compress the webrev in ZIP format')],
'hg webrev [WEBREV_OPTIONS]'),
}