# HG changeset patch # User Matt Mackall # Date 2008-08-10 23:38:43 # Node ID 077f1e637cd829ae3dfa10431d3e5d78e7567bd4 # Parent 0d714a48ab53eb5352374ebadaf2e5a70eb75ff6 # Parent c7cc40fd74f6cf713441ff4fc39aba0f59200e00 Merge with stable Simplify the copy search algorithm diff --git a/.hgignore b/.hgignore --- a/.hgignore +++ b/.hgignore @@ -7,6 +7,7 @@ syntax: glob *.mergebackup *.o *.so +*.pyd *.pyc *.swp *.prof diff --git a/contrib/dumprevlog b/contrib/dumprevlog new file mode 100644 --- /dev/null +++ b/contrib/dumprevlog @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# Dump revlogs as raw data stream +# $ find .hg/store/ -name "*.i" | xargs dumprevlog > repo.dump + +import sys +from mercurial import revlog, node, util + +for fp in (sys.stdin, sys.stdout, sys.stderr): + util.set_binary(fp) + +for f in sys.argv[1:]: + binopen = lambda fn: open(fn, 'rb') + r = revlog.revlog(binopen, f) + print "file:", f + for i in r: + n = r.node(i) + p = r.parents(n) + d = r.revision(n) + print "node:", node.hex(n) + print "linkrev:", r.linkrev(n) + print "parents:", node.hex(p[0]), node.hex(p[1]) + print "length:", len(d) + print "-start-" + print d + print "-end-" diff --git a/contrib/mercurial.el b/contrib/mercurial.el --- a/contrib/mercurial.el +++ b/contrib/mercurial.el @@ -35,8 +35,10 @@ ;; This code has been developed under XEmacs 21.5, and may not work as ;; well under GNU Emacs (albeit tested under 21.4). Patches to ;; enhance the portability of this code, fix bugs, and add features -;; are most welcome. You can clone a Mercurial repository for this -;; package from http://www.serpentine.com/hg/hg-emacs +;; are most welcome. + +;; As of version 22.3, GNU Emacs's VC mode has direct support for +;; Mercurial, so this package may not prove as useful there. ;; Please send problem reports and suggestions to bos@serpentine.com. diff --git a/contrib/undumprevlog b/contrib/undumprevlog new file mode 100644 --- /dev/null +++ b/contrib/undumprevlog @@ -0,0 +1,37 @@ +#!/usr/bin/env python +# Undump a dump from dumprevlog +# $ hg init +# $ undumprevlog < repo.dump + +import sys +from mercurial import revlog, node, util, transaction + +for fp in (sys.stdin, sys.stdout, sys.stderr): + util.set_binary(fp) + +opener = util.opener('.', False) +tr = transaction.transaction(sys.stderr.write, opener, "undump.journal") +while 1: + l = sys.stdin.readline() + if not l: + break + if l.startswith("file:"): + f = l[6:-1] + r = revlog.revlog(opener, f) + print f + elif l.startswith("node:"): + n = node.bin(l[6:-1]) + elif l.startswith("linkrev:"): + lr = int(l[9:-1]) + elif l.startswith("parents:"): + p = l[9:-1].split() + p1 = node.bin(p[0]) + p2 = node.bin(p[1]) + elif l.startswith("length:"): + length = int(l[8:-1]) + sys.stdin.readline() # start marker + d = sys.stdin.read(length) + sys.stdin.readline() # end marker + r.addrevision(d, tr, lr, p1, p2) + +tr.close() diff --git a/contrib/win32/hg.bat b/contrib/win32/hg.bat new file mode 100644 --- /dev/null +++ b/contrib/win32/hg.bat @@ -0,0 +1,12 @@ +@echo off +rem Windows Driver script for Mercurial + +setlocal +set HG=%~f0 + +rem Use a full path to Python (relative to this script) as the standard Python +rem install does not put python.exe on the PATH... +rem %~dp0 is the directory of this script + +%~dp0..\python "%~dp0hg" %* +endlocal diff --git a/contrib/zsh_completion b/contrib/zsh_completion --- a/contrib/zsh_completion +++ b/contrib/zsh_completion @@ -205,8 +205,7 @@ typeset -A _hg_cmd_globals _hg_config() { typeset -a items - local line - items=(${${(%f)"$(_hg_cmd showconfig)"}%%\=*}) + items=(${${(%f)"$(_call_program hg hg showconfig)"}%%\=*}) (( $#items )) && _describe -t config 'config item' items } @@ -291,10 +290,14 @@ typeset -A _hg_cmd_globals '--cwd[change working directory]:new working directory:_files -/' '(--noninteractive -y)'{-y,--noninteractive}'[do not prompt, assume yes for any required answers]' '(--verbose -v)'{-v,--verbose}'[enable additional output]' + '*--config[set/override config option]:defined config items:_hg_config' '(--quiet -q)'{-q,--quiet}'[suppress output]' '(--help -h)'{-h,--help}'[display help and exit]' '--debug[debug mode]' '--debugger[start debugger]' + '--encoding[set the charset encoding (default: UTF8)]' + '--encodingmode[set the charset encoding mode (default: strict)]' + '--lsprof[print improved command execution profile]' '--traceback[print traceback on exception]' '--time[time how long the command takes]' '--profile[profile]' diff --git a/doc/gendoc.py b/doc/gendoc.py --- a/doc/gendoc.py +++ b/doc/gendoc.py @@ -69,6 +69,7 @@ def show_doc(ui): if f.startswith("debug"): continue d = get_cmd(h[f]) # synopsis + ui.write("[[%s]]\n" % d['cmd']) ui.write("%s::\n" % d['synopsis'].replace("hg ","", 1)) # description ui.write("%s\n\n" % d['desc'][1]) @@ -91,11 +92,10 @@ def show_doc(ui): ui.write(_(" aliases: %s\n\n") % " ".join(d['aliases'])) # print topics - for t in helptable: + for t, doc in helptable: l = t.split("|") section = l[-1] underlined(_(section).upper()) - doc = helptable[t] if callable(doc): doc = doc() ui.write(_(doc)) diff --git a/doc/hg.1.txt b/doc/hg.1.txt --- a/doc/hg.1.txt +++ b/doc/hg.1.txt @@ -30,65 +30,13 @@ revision:: repository path:: either the pathname of a local repository or the URI of a remote - repository. There are two available URI protocols, http:// which is + repository. There are two available URI protocols, http:// which is fast and the static-http:// protocol which is much slower but does not require a special server on the web host. include::hg.1.gendoc.txt[] -SPECIFYING SINGLE REVISIONS ---------------------------- - - Mercurial accepts several notations for identifying individual - revisions. - - A plain integer is treated as a revision number. Negative - integers are treated as offsets from the tip, with -1 denoting the - tip. - - A 40-digit hexadecimal string is treated as a unique revision - identifier. - - A hexadecimal string less than 40 characters long is treated as a - unique revision identifier, and referred to as a short-form - identifier. A short-form identifier is only valid if it is the - prefix of one full-length identifier. - - Any other string is treated as a tag name, which is a symbolic - name associated with a revision identifier. Tag names may not - contain the ":" character. - - The reserved name "tip" is a special tag that always identifies - the most recent revision. - - The reserved name "null" indicates the null revision. This is the - revision of an empty repository, and the parent of revision 0. - - The reserved name "." indicates the working directory parent. If - no working directory is checked out, it is equivalent to null. - If an uncommitted merge is in progress, "." is the revision of - the first parent. - -SPECIFYING MULTIPLE REVISIONS ------------------------------ - - When Mercurial accepts more than one revision, they may be - specified individually, or provided as a continuous range, - separated by the ":" character. - - The syntax of range notation is [BEGIN]:[END], where BEGIN and END - are revision identifiers. Both BEGIN and END are optional. If - BEGIN is not specified, it defaults to revision number 0. If END - is not specified, it defaults to the tip. The range ":" thus - means "all revisions". - - If BEGIN is greater than END, revisions are treated in reverse - order. - - A range acts as a closed interval. This means that a range of 3:5 - gives 3, 4 and 5. Similarly, a range of 4:2 gives 4, 3, and 2. - FILES ----- .hgignore:: @@ -103,7 +51,7 @@ FILES /etc/mercurial/hgrc, $HOME/.hgrc, .hg/hgrc:: This file contains defaults and configuration. Values in .hg/hgrc override those in $HOME/.hgrc, and these override settings made in the - global /etc/mercurial/hgrc configuration. See hgrc(5) for details of + global /etc/mercurial/hgrc configuration. See hgrc(5) for details of the contents and format of these files. Some commands (e.g. revert) produce backup files ending in .orig, if diff --git a/doc/hgignore.5.txt b/doc/hgignore.5.txt --- a/doc/hgignore.5.txt +++ b/doc/hgignore.5.txt @@ -17,25 +17,25 @@ DESCRIPTION ----------- Mercurial ignores every unmanaged file that matches any pattern in an -ignore file. The patterns in an ignore file do not apply to files -managed by Mercurial. To control Mercurial's handling of files that -it manages, see the hg(1) man page. Look for the "-I" and "-X" +ignore file. The patterns in an ignore file do not apply to files +managed by Mercurial. To control Mercurial's handling of files that +it manages, see the hg(1) man page. Look for the "-I" and "-X" options. In addition, a Mercurial configuration file can point to a set of -per-user or global ignore files. See the hgrc(5) man page for details -of how to configure these files. Look for the "ignore" entry in the +per-user or global ignore files. See the hgrc(5) man page for details +of how to configure these files. Look for the "ignore" entry in the "ui" section. SYNTAX ------ An ignore file is a plain text file consisting of a list of patterns, -with one pattern per line. Empty lines are skipped. The "#" +with one pattern per line. Empty lines are skipped. The "#" character is treated as a comment character, and the "\" character is treated as an escape character. -Mercurial supports several pattern syntaxes. The default syntax used +Mercurial supports several pattern syntaxes. The default syntax used is Python/Perl-style regular expressions. To change the syntax used, use a line of the following form: @@ -52,9 +52,9 @@ glob:: The chosen syntax stays in effect when parsing all patterns that follow, until another syntax is selected. -Neither glob nor regexp patterns are rooted. A glob-syntax pattern of +Neither glob nor regexp patterns are rooted. A glob-syntax pattern of the form "*.c" will match a file ending in ".c" in any directory, and -a regexp pattern of the form "\.c$" will do the same. To root a +a regexp pattern of the form "\.c$" will do the same. To root a regexp pattern, start it with "^". EXAMPLE diff --git a/doc/hgrc.5.txt b/doc/hgrc.5.txt --- a/doc/hgrc.5.txt +++ b/doc/hgrc.5.txt @@ -17,26 +17,26 @@ FILES Mercurial reads configuration data from several files, if they exist. The names of these files depend on the system on which Mercurial is -installed. *.rc files from a single directory are read in -alphabetical order, later ones overriding earlier ones. Where +installed. *.rc files from a single directory are read in +alphabetical order, later ones overriding earlier ones. Where multiple paths are given below, settings from later paths override earlier ones. (Unix) /etc/mercurial/hgrc.d/*.rc:: (Unix) /etc/mercurial/hgrc:: Per-installation configuration files, searched for in the - directory where Mercurial is installed. is the + directory where Mercurial is installed. is the parent directory of the hg executable (or symlink) being run. For example, if installed in /shared/tools/bin/hg, Mercurial will - look in /shared/tools/etc/mercurial/hgrc. Options in these files + look in /shared/tools/etc/mercurial/hgrc. Options in these files apply to all Mercurial commands executed by any user in any directory. (Unix) /etc/mercurial/hgrc.d/*.rc:: (Unix) /etc/mercurial/hgrc:: Per-system configuration files, for the system on which Mercurial - is running. Options in these files apply to all Mercurial - commands executed by any user in any directory. Options in these + is running. Options in these files apply to all Mercurial + commands executed by any user in any directory. Options in these files override per-installation options. (Windows) \Mercurial.ini:: @@ -45,7 +45,7 @@ earlier ones. or else:: (Windows) C:\Mercurial\Mercurial.ini:: Per-installation/system configuration files, for the system on - which Mercurial is running. Options in these files apply to all + which Mercurial is running. Options in these files apply to all Mercurial commands executed by any user in any directory. Registry keys contain PATH-like strings, every part of which must reference a Mercurial.ini file or be a directory where *.rc files @@ -59,16 +59,16 @@ earlier ones. Per-user configuration file(s), for the user running Mercurial. On Windows 9x, %HOME% is replaced by %APPDATA%. Options in these files apply to all Mercurial commands executed - by this user in any directory. Options in thes files override + by this user in any directory. Options in thes files override per-installation and per-system options. (Unix, Windows) /.hg/hgrc:: Per-repository configuration options that only apply in a - particular repository. This file is not version-controlled, and - will not get transferred during a "clone" operation. Options in + particular repository. This file is not version-controlled, and + will not get transferred during a "clone" operation. Options in this file override options in all other configuration files. On Unix, most of this file will be ignored if it doesn't belong - to a trusted user or to a trusted group. See the documentation + to a trusted user or to a trusted group. See the documentation for the trusted section below for more details. SYNTAX @@ -82,10 +82,10 @@ and followed by "name: value" entries; " green= eggs -Each line contains one entry. If the lines that follow are indented, +Each line contains one entry. If the lines that follow are indented, they are treated as continuations of that entry. -Leading whitespace is removed from values. Empty lines are skipped. +Leading whitespace is removed from values. Empty lines are skipped. The optional values can contain format strings which refer to other values in the same section, or values in a special DEFAULT section. @@ -100,6 +100,7 @@ This section describes the different sec Mercurial "hgrc" file, the purpose of each section, its possible keys, and their possible values. +[[decode]] decode/encode:: Filters for transforming files on checkout/checkin. This would typically be used for newline processing or other @@ -107,12 +108,12 @@ decode/encode:: Filters consist of a filter pattern followed by a filter command. Filter patterns are globs by default, rooted at the repository - root. For example, to match any file ending in ".txt" in the root - directory only, use the pattern "*.txt". To match any file ending + root. For example, to match any file ending in ".txt" in the root + directory only, use the pattern "*.txt". To match any file ending in ".c" anywhere in the repository, use the pattern "**.c". The filter command can start with a specifier, either "pipe:" or - "tempfile:". If no specifier is given, "pipe:" is used by default. + "tempfile:". If no specifier is given, "pipe:" is used by default. A "pipe:" command must accept data on stdin and return the transformed data on stdout. @@ -129,9 +130,9 @@ decode/encode:: # can safely omit "pipe:", because it's the default) *.gz = gzip - A "tempfile:" command is a template. The string INFILE is replaced + A "tempfile:" command is a template. The string INFILE is replaced with the name of a temporary file that contains the data to be - filtered by the command. The string OUTFILE is replaced with the + filtered by the command. The string OUTFILE is replaced with the name of an empty temporary file, where the filtered data must be written by the command. @@ -158,6 +159,7 @@ decode/encode:: [decode] **.txt = dumbdecode: +[[defaults]] defaults:: Use the [defaults] section to define command defaults, i.e. the default options/arguments to pass to the specified commands. @@ -173,6 +175,7 @@ defaults:: defining command defaults. The command defaults will also be applied to the aliases of the commands defined. +[[diff]] diff:: Settings used when displaying diffs. They are all boolean and defaults to False. @@ -189,25 +192,26 @@ diff:: ignoreblanklines;; Ignore changes whose lines are all blank. +[[email]] email:: Settings for extensions that send email messages. from;; - Optional. Email address to use in "From" header and SMTP envelope + Optional. Email address to use in "From" header and SMTP envelope of outgoing messages. to;; - Optional. Comma-separated list of recipients' email addresses. + Optional. Comma-separated list of recipients' email addresses. cc;; - Optional. Comma-separated list of carbon copy recipients' + Optional. Comma-separated list of carbon copy recipients' email addresses. bcc;; - Optional. Comma-separated list of blind carbon copy - recipients' email addresses. Cannot be set interactively. + Optional. Comma-separated list of blind carbon copy + recipients' email addresses. Cannot be set interactively. method;; - Optional. Method to use to send email messages. If value is + Optional. Method to use to send email messages. If value is "smtp" (default), use SMTP (see section "[smtp]" for - configuration). Otherwise, use as name of program to run that + configuration). Otherwise, use as name of program to run that acts like sendmail (takes "-f" option for sender, list of - recipients on command line, message on stdin). Normally, setting + recipients on command line, message on stdin). Normally, setting this to "sendmail" or "/usr/sbin/sendmail" is enough to use sendmail to send messages. @@ -217,6 +221,7 @@ email:: from = Joseph User method = /usr/sbin/sendmail +[[extensions]] extensions:: Mercurial has an extension mechanism for adding new features. To enable an extension, create an entry for it in this section. @@ -241,6 +246,7 @@ extensions:: # (this extension will get loaded from the file specified) myfeature = ~/.hgext/myfeature.py +[[format]] format:: usestore;; @@ -250,6 +256,7 @@ format:: you to store longer filenames in some situations at the expense of compatibility. +[[merge-patterns]] merge-patterns:: This section specifies merge tools to associate with particular file patterns. Tools matched here will take precedence over the default @@ -261,6 +268,7 @@ merge-patterns:: **.c = kdiff3 **.jpg = myimgmerge +[[merge-tools]] merge-tools:: This section configures external merge tools to use for file-level merges. @@ -281,6 +289,7 @@ merge-tools:: myHtmlTool.priority = 1 Supported arguments: + priority;; The priority in which to evaluate this tool. Default: 0. @@ -297,10 +306,10 @@ merge-tools:: launching external tool. Default: True binary;; - This tool can merge binary files. Defaults to False, unless tool + This tool can merge binary files. Defaults to False, unless tool was selected by file pattern match. symlink;; - This tool can merge symlinks. Defaults to False, even if tool was + This tool can merge symlinks. Defaults to False, even if tool was selected by file pattern match. checkconflicts;; Check whether there are conflicts even though the tool reported @@ -313,19 +322,20 @@ merge-tools:: fixeol;; Attempt to fix up EOL changes caused by the merge tool. Default: False - gui:; + gui;; This tool requires a graphical interface to run. Default: False regkey;; Windows registry key which describes install location of this tool. Mercurial will search for this key first under HKEY_CURRENT_USER and - then under HKEY_LOCAL_MACHINE. Default: None + then under HKEY_LOCAL_MACHINE. Default: None regname;; - Name of value to read from specified registry key. Defaults to the + Name of value to read from specified registry key. Defaults to the unnamed (default) value. regappend;; String to append to the value read from the registry, typically the - executable name of the tool. Default: None + executable name of the tool. Default: None +[[hooks]] hooks:: Commands or Python functions that get automatically executed by various actions such as starting or finishing a commit. Multiple @@ -342,24 +352,24 @@ hooks:: incoming.autobuild = /my/build/hook Most hooks are run with environment variables set that give added - useful information. For each hook below, the environment variables + useful information. For each hook below, the environment variables it is passed are listed with names of the form "$HG_foo". changegroup;; Run after a changegroup has been added via push, pull or - unbundle. ID of the first new changeset is in $HG_NODE. URL from + unbundle. ID of the first new changeset is in $HG_NODE. URL from which changes came is in $HG_URL. commit;; Run after a changeset has been created in the local repository. - ID of the newly created changeset is in $HG_NODE. Parent + ID of the newly created changeset is in $HG_NODE. Parent changeset IDs are in $HG_PARENT1 and $HG_PARENT2. incoming;; Run after a changeset has been pulled, pushed, or unbundled into - the local repository. The ID of the newly arrived changeset is in - $HG_NODE. URL that was source of changes came is in $HG_URL. + the local repository. The ID of the newly arrived changeset is in + $HG_NODE. URL that was source of changes came is in $HG_URL. outgoing;; - Run after sending changes from local repository to another. ID of - first changeset sent is in $HG_NODE. Source of operation is in + Run after sending changes from local repository to another. ID of + first changeset sent is in $HG_NODE. Source of operation is in $HG_SOURCE; see "preoutgoing" hook for description. post-;; Run after successful invocations of the associated command. The @@ -371,56 +381,56 @@ hooks:: the command doesn't execute and Mercurial returns the failure code. prechangegroup;; Run before a changegroup is added via push, pull or unbundle. - Exit status 0 allows the changegroup to proceed. Non-zero status - will cause the push, pull or unbundle to fail. URL from which + Exit status 0 allows the changegroup to proceed. Non-zero status + will cause the push, pull or unbundle to fail. URL from which changes will come is in $HG_URL. precommit;; - Run before starting a local commit. Exit status 0 allows the - commit to proceed. Non-zero status will cause the commit to fail. + Run before starting a local commit. Exit status 0 allows the + commit to proceed. Non-zero status will cause the commit to fail. Parent changeset IDs are in $HG_PARENT1 and $HG_PARENT2. preoutgoing;; Run before collecting changes to send from the local repository to - another. Non-zero status will cause failure. This lets you - prevent pull over http or ssh. Also prevents against local pull, + another. Non-zero status will cause failure. This lets you + prevent pull over http or ssh. Also prevents against local pull, push (outbound) or bundle commands, but not effective, since you - can just copy files instead then. Source of operation is in - $HG_SOURCE. If "serve", operation is happening on behalf of - remote ssh or http repository. If "push", "pull" or "bundle", + can just copy files instead then. Source of operation is in + $HG_SOURCE. If "serve", operation is happening on behalf of + remote ssh or http repository. If "push", "pull" or "bundle", operation is happening on behalf of repository on same system. pretag;; - Run before creating a tag. Exit status 0 allows the tag to be - created. Non-zero status will cause the tag to fail. ID of - changeset to tag is in $HG_NODE. Name of tag is in $HG_TAG. Tag + Run before creating a tag. Exit status 0 allows the tag to be + created. Non-zero status will cause the tag to fail. ID of + changeset to tag is in $HG_NODE. Name of tag is in $HG_TAG. Tag is local if $HG_LOCAL=1, in repo if $HG_LOCAL=0. pretxnchangegroup;; Run after a changegroup has been added via push, pull or unbundle, - but before the transaction has been committed. Changegroup is - visible to hook program. This lets you validate incoming changes - before accepting them. Passed the ID of the first new changeset - in $HG_NODE. Exit status 0 allows the transaction to commit. + but before the transaction has been committed. Changegroup is + visible to hook program. This lets you validate incoming changes + before accepting them. Passed the ID of the first new changeset + in $HG_NODE. Exit status 0 allows the transaction to commit. Non-zero status will cause the transaction to be rolled back and - the push, pull or unbundle will fail. URL that was source of + the push, pull or unbundle will fail. URL that was source of changes is in $HG_URL. pretxncommit;; Run after a changeset has been created but the transaction not yet - committed. Changeset is visible to hook program. This lets you - validate commit message and changes. Exit status 0 allows the - commit to proceed. Non-zero status will cause the transaction to - be rolled back. ID of changeset is in $HG_NODE. Parent changeset + committed. Changeset is visible to hook program. This lets you + validate commit message and changes. Exit status 0 allows the + commit to proceed. Non-zero status will cause the transaction to + be rolled back. ID of changeset is in $HG_NODE. Parent changeset IDs are in $HG_PARENT1 and $HG_PARENT2. preupdate;; - Run before updating the working directory. Exit status 0 allows - the update to proceed. Non-zero status will prevent the update. - Changeset ID of first new parent is in $HG_PARENT1. If merge, ID + Run before updating the working directory. Exit status 0 allows + the update to proceed. Non-zero status will prevent the update. + Changeset ID of first new parent is in $HG_PARENT1. If merge, ID of second new parent is in $HG_PARENT2. tag;; - Run after a tag is created. ID of tagged changeset is in - $HG_NODE. Name of tag is in $HG_TAG. Tag is local if + Run after a tag is created. ID of tagged changeset is in + $HG_NODE. Name of tag is in $HG_TAG. Tag is local if $HG_LOCAL=1, in repo if $HG_LOCAL=0. update;; - Run after updating the working directory. Changeset ID of first - new parent is in $HG_PARENT1. If merge, ID of second new parent - is in $HG_PARENT2. If update succeeded, $HG_ERROR=0. If update + Run after updating the working directory. Changeset ID of first + new parent is in $HG_PARENT1. If merge, ID of second new parent + is in $HG_PARENT2. If update succeeded, $HG_ERROR=0. If update failed (e.g. because conflicts not resolved), $HG_ERROR=1. Note: it is generally better to use standard hooks rather than the @@ -438,16 +448,17 @@ hooks:: hookname = python:modulename.submodule.callable - Python hooks are run within the Mercurial process. Each hook is + Python hooks are run within the Mercurial process. Each hook is called with at least three keyword arguments: a ui object (keyword "ui"), a repository object (keyword "repo"), and a "hooktype" - keyword that tells what kind of hook is used. Arguments listed as + keyword that tells what kind of hook is used. Arguments listed as environment variables above are passed as keyword arguments, with no "HG_" prefix, and names in lower case. If a Python hook returns a "true" value or raises an exception, this is treated as failure of the hook. +[[http_proxy]] http_proxy:: Used to access web-based Mercurial repositories through a HTTP proxy. @@ -455,68 +466,72 @@ http_proxy:: Host name and (optional) port of the proxy server, for example "myproxy:8000". no;; - Optional. Comma-separated list of host names that should bypass + Optional. Comma-separated list of host names that should bypass the proxy. passwd;; - Optional. Password to authenticate with at the proxy server. + Optional. Password to authenticate with at the proxy server. user;; - Optional. User name to authenticate with at the proxy server. + Optional. User name to authenticate with at the proxy server. +[[smtp]] smtp:: Configuration for extensions that need to send email messages. host;; Host name of mail server, e.g. "mail.example.com". port;; - Optional. Port to connect to on mail server. Default: 25. + Optional. Port to connect to on mail server. Default: 25. tls;; - Optional. Whether to connect to mail server using TLS. True or - False. Default: False. + Optional. Whether to connect to mail server using TLS. True or + False. Default: False. username;; - Optional. User name to authenticate to SMTP server with. + Optional. User name to authenticate to SMTP server with. If username is specified, password must also be specified. Default: none. password;; - Optional. Password to authenticate to SMTP server with. + Optional. Password to authenticate to SMTP server with. If username is specified, password must also be specified. Default: none. local_hostname;; - Optional. It's the hostname that the sender can use to identify itself + Optional. It's the hostname that the sender can use to identify itself to the MTA. +[[paths]] paths:: - Assigns symbolic names to repositories. The left side is the + Assigns symbolic names to repositories. The left side is the symbolic name, and the right gives the directory or URL that is the - location of the repository. Default paths can be declared by + location of the repository. Default paths can be declared by setting the following entries. default;; Directory or URL to use when pulling if no source is specified. Default is set to repository from which the current repository was cloned. default-push;; - Optional. Directory or URL to use when pushing if no destination + Optional. Directory or URL to use when pushing if no destination is specified. +[[server]] server:: Controls generic server settings. uncompressed;; Whether to allow clients to clone a repo using the uncompressed - streaming protocol. This transfers about 40% more data than a + streaming protocol. This transfers about 40% more data than a regular clone, but uses less memory and CPU on both server and - client. Over a LAN (100Mbps or better) or a very fast WAN, an + client. Over a LAN (100Mbps or better) or a very fast WAN, an uncompressed streaming clone is a lot faster (~10x) than a regular - clone. Over most WAN connections (anything slower than about + clone. Over most WAN connections (anything slower than about 6Mbps), uncompressed streaming is slower, because of the extra - data transfer overhead. Default is False. + data transfer overhead. Default is False. +[[trusted]] trusted:: For security reasons, Mercurial will not use the settings in the .hg/hgrc file from a repository if it doesn't belong to a - trusted user or to a trusted group. The main exception is the + trusted user or to a trusted group. The main exception is the web interface, which automatically uses some safe settings, since it's common to serve repositories from different users. - This section specifies what users and groups are trusted. The - current user is always trusted. To trust everybody, list a user + This section specifies what users and groups are trusted. The + current user is always trusted. To trust everybody, list a user or a group with name "*". users;; @@ -524,6 +539,7 @@ trusted:: groups;; Comma-separated list of trusted groups. +[[ui]] ui:: User interface controls. archivemeta;; @@ -531,13 +547,19 @@ ui:: (hashes for the repository base and for tip) in archives created by the hg archive command or downloaded via hgweb. Default is true. + askusername;; + Whether to prompt for a username when committing. If True, and + neither $HGUSER nor $EMAIL has been specified, then the user will + be prompted to enter a username. If no username is entered, the + default USER@HOST is used instead. + Default is False. debug;; - Print debugging information. True or False. Default is False. + Print debugging information. True or False. Default is False. editor;; - The editor to use during a commit. Default is $EDITOR or "vi". + The editor to use during a commit. Default is $EDITOR or "vi". fallbackencoding;; Encoding to try if it's not possible to decode the changelog using - UTF-8. Default is ISO-8859-1. + UTF-8. Default is ISO-8859-1. ignore;; A file to read per-user ignore patterns from. This file should be in the same format as a repository-wide .hgignore file. This option @@ -546,7 +568,7 @@ ui:: "ignore.other = ~/.hgignore2". For details of the ignore file format, see the hgignore(5) man page. interactive;; - Allow to prompt the user. True or False. Default is True. + Allow to prompt the user. True or False. Default is True. logtemplate;; Template string for commands that print changesets. merge;; @@ -563,18 +585,19 @@ ui:: fail to merge See the merge-tools section for more information on configuring tools. + patch;; command to use to apply patches. Look for 'gpatch' or 'patch' in PATH if unset. quiet;; - Reduce the amount of output printed. True or False. Default is False. + Reduce the amount of output printed. True or False. Default is False. remotecmd;; remote command to use for clone/push/pull operations. Default is 'hg'. report_untrusted;; Warn if a .hg/hgrc file is ignored due to not being owned by a - trusted user or group. True or False. Default is True. + trusted user or group. True or False. Default is True. slash;; - Display paths using a slash ("/") as the path separator. This only + Display paths using a slash ("/") as the path separator. This only makes a difference on systems where the default path separator is not the slash character (e.g. Windows uses the backslash character ("\")). Default is False. @@ -582,7 +605,7 @@ ui:: command to use for SSH connections. Default is 'ssh'. strict;; Require exact command names, instead of allowing unambiguous - abbreviations. True or False. Default is False. + abbreviations. True or False. Default is False. style;; Name of style to use for command output. timeout;; @@ -591,14 +614,15 @@ ui:: username;; The committer of a changeset created when running "commit". Typically a person's name and email address, e.g. "Fred Widget - ". Default is $EMAIL or username@hostname. + ". Default is $EMAIL or username@hostname. If the username in hgrc is empty, it has to be specified manually or in a different hgrc file (e.g. $HOME/.hgrc, if the admin set "username =" in the system hgrc). verbose;; - Increase the amount of output printed. True or False. Default is False. + Increase the amount of output printed. True or False. Default is False. +[[web]] web:: Web interface configuration. accesslog;; @@ -617,9 +641,9 @@ web:: allowpull;; Whether to allow pulling from the repository. Default is true. allow_push;; - Whether to allow pushing to the repository. If empty or not set, - push is not allowed. If the special value "*", any remote user - can push, including unauthenticated users. Otherwise, the remote + Whether to allow pushing to the repository. If empty or not set, + push is not allowed. If the special value "*", any remote user + can push, including unauthenticated users. Otherwise, the remote user must have been authenticated, and the authenticated user name must be present in this list (separated by whitespace or ","). The contents of the allow_push list are examined after the @@ -635,11 +659,11 @@ web:: Name or email address of the person in charge of the repository. Defaults to ui.username or $EMAIL or "unknown" if unset or empty. deny_push;; - Whether to deny pushing to the repository. If empty or not set, - push is not denied. If the special value "*", all remote users - are denied push. Otherwise, unauthenticated users are all denied, + Whether to deny pushing to the repository. If empty or not set, + push is not denied. If the special value "*", all remote users + are denied push. Otherwise, unauthenticated users are all denied, and any authenticated user name present in this list (separated by - whitespace or ",") is also denied. The contents of the deny_push + whitespace or ",") is also denied. The contents of the deny_push list are examined before the allow_push list. description;; Textual description of the repository's purpose or contents. @@ -666,7 +690,7 @@ web:: Prefix path to serve from. Default is '' (server root). push_ssl;; Whether to require that inbound pushes be transported over SSL to - prevent password sniffing. Default is true. + prevent password sniffing. Default is true. staticurl;; Base URL to use for static files. If unset, static files (e.g. the hgicon.png favicon) will be served by the CGI script itself. diff --git a/hgext/acl.py b/hgext/acl.py --- a/hgext/acl.py +++ b/hgext/acl.py @@ -46,79 +46,45 @@ # ** = user6 from mercurial.i18n import _ -from mercurial.node import bin, short from mercurial import util import getpass -class checker(object): - '''acl checker.''' - - def buildmatch(self, key): - '''return tuple of (match function, list enabled).''' - if not self.ui.has_section(key): - self.ui.debug(_('acl: %s not enabled\n') % key) - return None, False - - thisuser = self.getuser() - pats = [pat for pat, users in self.ui.configitems(key) - if thisuser in users.replace(',', ' ').split()] - self.ui.debug(_('acl: %s enabled, %d entries for user %s\n') % - (key, len(pats), thisuser)) - if pats: - match = util.matcher(self.repo.root, names=pats)[1] - else: - match = util.never - return match, True - - def getuser(self): - '''return name of authenticated user.''' - return self.user +def buildmatch(ui, repo, user, key): + '''return tuple of (match function, list enabled).''' + if not ui.has_section(key): + ui.debug(_('acl: %s not enabled\n') % key) + return None - def __init__(self, ui, repo): - self.ui = ui - self.repo = repo - self.user = getpass.getuser() - cfg = self.ui.config('acl', 'config') - if cfg: - self.ui.readsections(cfg, 'acl.allow', 'acl.deny') - self.allow, self.allowable = self.buildmatch('acl.allow') - self.deny, self.deniable = self.buildmatch('acl.deny') - - def skipsource(self, source): - '''true if incoming changes from this source should be skipped.''' - ok_sources = self.ui.config('acl', 'sources', 'serve').split() - return source not in ok_sources - - def check(self, node): - '''return if access allowed, raise exception if not.''' - files = self.repo.changectx(node).files() - if self.deniable: - for f in files: - if self.deny(f): - self.ui.debug(_('acl: user %s denied on %s\n') % - (self.getuser(), f)) - raise util.Abort(_('acl: access denied for changeset %s') % - short(node)) - if self.allowable: - for f in files: - if not self.allow(f): - self.ui.debug(_('acl: user %s not allowed on %s\n') % - (self.getuser(), f)) - raise util.Abort(_('acl: access denied for changeset %s') % - short(node)) - self.ui.debug(_('acl: allowing changeset %s\n') % short(node)) + pats = [pat for pat, users in ui.configitems(key) + if user in users.replace(',', ' ').split()] + ui.debug(_('acl: %s enabled, %d entries for user %s\n') % + (key, len(pats), user)) + if pats: + return util.matcher(repo.root, names=pats)[1] + return util.never def hook(ui, repo, hooktype, node=None, source=None, **kwargs): if hooktype != 'pretxnchangegroup': raise util.Abort(_('config error - hook type "%s" cannot stop ' 'incoming changesets') % hooktype) - - c = checker(ui, repo) - if c.skipsource(source): + if source not in ui.config('acl', 'sources', 'serve').split(): ui.debug(_('acl: changes have source "%s" - skipping\n') % source) return - start = repo.changelog.rev(bin(node)) - end = repo.changelog.count() - for rev in xrange(start, end): - c.check(repo.changelog.node(rev)) + user = getpass.getuser() + cfg = ui.config('acl', 'config') + if cfg: + ui.readsections(cfg, 'acl.allow', 'acl.deny') + allow = buildmatch(ui, repo, user, 'acl.allow') + deny = buildmatch(ui, repo, user, 'acl.deny') + + for rev in xrange(repo[node], len(repo)): + ctx = repo[rev] + for f in ctx.files(): + if deny and deny(f): + ui.debug(_('acl: user %s denied on %s\n') % (user, f)) + raise util.Abort(_('acl: access denied for changeset %s') % ctx) + if allow and not allow(f): + ui.debug(_('acl: user %s not allowed on %s\n') % (user, f)) + raise util.Abort(_('acl: access denied for changeset %s') % ctx) + ui.debug(_('acl: allowing changeset %s\n') % ctx) diff --git a/hgext/bugzilla.py b/hgext/bugzilla.py --- a/hgext/bugzilla.py +++ b/hgext/bugzilla.py @@ -55,7 +55,7 @@ from mercurial.i18n import _ from mercurial.node import short from mercurial import cmdutil, templater, util -import os, re, time +import re, time MySQLdb = None @@ -99,9 +99,7 @@ class bugzilla_2_16(object): def filter_real_bug_ids(self, ids): '''filter not-existing bug ids from list.''' self.run('select bug_id from bugs where bug_id in %s' % buglist(ids)) - ids = [c[0] for c in self.cursor.fetchall()] - ids.sort() - return ids + return util.sort([c[0] for c in self.cursor.fetchall()]) def filter_unknown_bug_ids(self, node, ids): '''filter bug ids from list that already refer to this changeset.''' @@ -114,9 +112,7 @@ class bugzilla_2_16(object): self.ui.status(_('bug %d already knows about changeset %s\n') % (id, short(node))) unknown.pop(id, None) - ids = unknown.keys() - ids.sort() - return ids + return util.sort(unknown.keys()) def notify(self, ids): '''tell bugzilla to send mail.''' @@ -127,7 +123,7 @@ class bugzilla_2_16(object): cmd = self.ui.config('bugzilla', 'notify', 'cd /var/www/html/bugzilla && ' './processmail %s nobody@nowhere.com') % id - fp = os.popen('(%s) 2>&1' % cmd) + fp = util.popen('(%s) 2>&1' % cmd) out = fp.read() ret = fp.close() if ret: @@ -300,7 +296,7 @@ def hook(ui, repo, hooktype, node=None, hooktype) try: bz = bugzilla(ui, repo) - ctx = repo.changectx(node) + ctx = repo[node] ids = bz.find_bug_ids(ctx) if ids: for id in ids: diff --git a/hgext/children.py b/hgext/children.py --- a/hgext/children.py +++ b/hgext/children.py @@ -25,7 +25,7 @@ def children(ui, repo, file_=None, **opt if file_: ctx = repo.filectx(file_, changeid=rev) else: - ctx = repo.changectx(rev) + ctx = repo[rev] displayer = cmdutil.show_changeset(ui, repo, opts) for node in [cp.node() for cp in ctx.children()]: diff --git a/hgext/churn.py b/hgext/churn.py --- a/hgext/churn.py +++ b/hgext/churn.py @@ -4,15 +4,10 @@ # # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -# -# -# Aliases map file format is simple one alias per line in the following -# format: -# -# +'''allow graphing the number of lines changed per contributor''' from mercurial.i18n import gettext as _ -from mercurial import mdiff, cmdutil, util, node +from mercurial import patch, cmdutil, util, node import os, sys def get_tty_width(): @@ -36,98 +31,41 @@ def get_tty_width(): pass return 80 -def __gather(ui, repo, node1, node2): - def dirtywork(f, mmap1, mmap2): - lines = 0 - - to = mmap1 and repo.file(f).read(mmap1[f]) or None - tn = mmap2 and repo.file(f).read(mmap2[f]) or None - - diff = mdiff.unidiff(to, "", tn, "", f, f).split("\n") - - for line in diff: - if not line: - continue # skip EOF - if line.startswith(" "): - continue # context line - if line.startswith("--- ") or line.startswith("+++ "): - continue # begining of diff - if line.startswith("@@ "): - continue # info line - - # changed lines - lines += 1 - - return lines - - ## - - lines = 0 - - changes = repo.status(node1, node2, None, util.always)[:5] - - modified, added, removed, deleted, unknown = changes - - who = repo.changelog.read(node2)[1] - who = util.email(who) # get the email of the person - - mmap1 = repo.manifest.read(repo.changelog.read(node1)[0]) - mmap2 = repo.manifest.read(repo.changelog.read(node2)[0]) - for f in modified: - lines += dirtywork(f, mmap1, mmap2) - - for f in added: - lines += dirtywork(f, None, mmap2) - - for f in removed: - lines += dirtywork(f, mmap1, None) - - for f in deleted: - lines += dirtywork(f, mmap1, mmap2) - - for f in unknown: - lines += dirtywork(f, mmap1, mmap2) - - return (who, lines) - -def gather_stats(ui, repo, amap, revs=None, progress=False): +def countrevs(ui, repo, amap, revs, progress=False): stats = {} - - cl = repo.changelog - + count = pct = 0 if not revs: - revs = range(0, cl.count()) - - nr_revs = len(revs) - cur_rev = 0 + revs = range(len(repo)) for rev in revs: - cur_rev += 1 # next revision - - node2 = cl.node(rev) - node1 = cl.parents(node2)[0] - - if cl.parents(node2)[1] != node.nullid: + ctx2 = repo[rev] + parents = ctx2.parents() + if len(parents) > 1: ui.note(_('Revision %d is a merge, ignoring...\n') % (rev,)) continue - who, lines = __gather(ui, repo, node1, node2) + ctx1 = parents[0] + lines = 0 + ui.pushbuffer() + patch.diff(repo, ctx1.node(), ctx2.node()) + diff = ui.popbuffer() - # remap the owner if possible - if who in amap: - ui.note("using '%s' alias for '%s'\n" % (amap[who], who)) - who = amap[who] + for l in diff.split('\n'): + if (l.startswith("+") and not l.startswith("+++ ") or + l.startswith("-") and not l.startswith("--- ")): + lines += 1 - if not who in stats: - stats[who] = 0 - stats[who] += lines - - ui.note("rev %d: %d lines by %s\n" % (rev, lines, who)) + user = util.email(ctx2.user()) + user = amap.get(user, user) # remap + stats[user] = stats.get(user, 0) + lines + ui.debug("rev %d: %d lines by %s\n" % (rev, lines, user)) if progress: - nr_revs = max(nr_revs, 1) - if int(100.0*(cur_rev - 1)/nr_revs) < int(100.0*cur_rev/nr_revs): - ui.write("\rGenerating stats: %d%%" % (int(100.0*cur_rev/nr_revs),)) + count += 1 + newpct = int(100.0 * count / max(len(revs), 1)) + if pct < newpct: + pct = newpct + ui.write("\rGenerating stats: %d%%" % pct) sys.stdout.flush() if progress: @@ -137,64 +75,39 @@ def gather_stats(ui, repo, amap, revs=No return stats def churn(ui, repo, **opts): - "Graphs the number of lines changed" + '''graphs the number of lines changed + + The map file format used to specify aliases is fairly simple: + + ''' def pad(s, l): - if len(s) < l: - return s + " " * (l-len(s)) - return s[0:l] - - def graph(n, maximum, width, char): - maximum = max(1, maximum) - n = int(n * width / float(maximum)) - - return char * (n) - - def get_aliases(f): - aliases = {} - - for l in f.readlines(): - l = l.strip() - alias, actual = l.split() - aliases[alias] = actual - - return aliases + return (s + " " * l)[:l] amap = {} aliases = opts.get('aliases') if aliases: - try: - f = open(aliases,"r") - except OSError, e: - print "Error: " + e - return + for l in open(aliases, "r"): + l = l.strip() + alias, actual = l.split() + amap[alias] = actual - amap = get_aliases(f) - f.close() - - revs = [int(r) for r in cmdutil.revrange(repo, opts['rev'])] - revs.sort() - stats = gather_stats(ui, repo, amap, revs, opts.get('progress')) + revs = util.sort([int(r) for r in cmdutil.revrange(repo, opts['rev'])]) + stats = countrevs(ui, repo, amap, revs, opts.get('progress')) + if not stats: + return - # make a list of tuples (name, lines) and sort it in descending order - ordered = stats.items() - if not ordered: - return - ordered.sort(lambda x, y: cmp(y[1], x[1])) - max_churn = ordered[0][1] + stats = util.sort([(-l, u, l) for u,l in stats.items()]) + maxchurn = float(max(1, stats[0][2])) + maxuser = max([len(u) for k, u, l in stats]) - tty_width = get_tty_width() - ui.note(_("assuming %i character terminal\n") % tty_width) - tty_width -= 1 - - max_user_width = max([len(user) for user, churn in ordered]) + ttywidth = get_tty_width() + ui.debug(_("assuming %i character terminal\n") % ttywidth) + width = ttywidth - maxuser - 2 - 6 - 2 - 2 - graph_width = tty_width - max_user_width - 1 - 6 - 2 - 2 - - for user, churn in ordered: - print "%s %6d %s" % (pad(user, max_user_width), - churn, - graph(churn, max_churn, graph_width, '*')) + for k, user, churn in stats: + print "%s %6d %s" % (pad(user, maxuser), churn, + "*" * int(churn * width / maxchurn)) cmdtable = { "churn": diff --git a/hgext/convert/__init__.py b/hgext/convert/__init__.py --- a/hgext/convert/__init__.py +++ b/hgext/convert/__init__.py @@ -4,6 +4,7 @@ # # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. +'''converting foreign VCS repositories to Mercurial''' import convcmd from mercurial import commands @@ -85,6 +86,50 @@ def convert(ui, src, dest=None, revmapfi --config convert.hg.saverev=True (boolean) allow target to preserve source revision ID + CVS Source + ---------- + + CVS source will use a sandbox (i.e. a checked-out copy) from CVS + to indicate the starting point of what will be converted. Direct + access to the repository files is not needed, unless of course + the repository is :local:. The conversion uses the top level + directory in the sandbox to find the CVS repository, and then uses + CVS rlog commands to find files to convert. This means that unless + a filemap is given, all files under the starting directory will be + converted, and that any directory reorganisation in the CVS + sandbox is ignored. + + Because CVS does not have changesets, it is necessary to collect + individual commits to CVS and merge them into changesets. CVS source + can use the external 'cvsps' program (this is a legacy option and may + be removed in future) or use its internal changeset merging code. + External cvsps is default, and options may be passed to it by setting + --config convert.cvsps='cvsps -A -u --cvs-direct -q' + The options shown are the defaults. + + Internal cvsps is selected by setting + --config convert.cvsps=builtin + and has a few more configurable options: + --config convert.cvsps.fuzz=60 (integer) + Specify the maximum time (in seconds) that is allowed between + commits with identical user and log message in a single + changeset. When very large files were checked in as part + of a changeset then the default may not be long enough. + --config convert.cvsps.mergeto='{{mergetobranch ([-\w]+)}}' + Specify a regular expression to which commit log messages are + matched. If a match occurs, then the conversion process will + insert a dummy revision merging the branch on which this log + message occurs to the branch indicated in the regex. + --config convert.cvsps.mergefrom='{{mergefrombranch ([-\w]+)}}' + Specify a regular expression to which commit log messages are + matched. If a match occurs, then the conversion process will + add the most recent revision on the branch indicated in the + regex as the second parent of the changeset. + + The hgext/convert/cvsps wrapper script allows the builtin changeset + merging code to be run without doing a conversion. Its parameters and + output are similar to that of cvsps 2.1. + Subversion Source ----------------- diff --git a/hgext/convert/common.py b/hgext/convert/common.py --- a/hgext/convert/common.py +++ b/hgext/convert/common.py @@ -153,26 +153,18 @@ class converter_sink(object): mapping equivalent authors identifiers for each system.""" return None - def putfile(self, f, e, data): - """Put file for next putcommit(). - f: path to file - e: '', 'x', or 'l' (regular file, executable, or symlink) - data: file contents""" - raise NotImplementedError() - - def delfile(self, f): - """Delete file for next putcommit(). - f: path to file""" - raise NotImplementedError() - - def putcommit(self, files, parents, commit): + def putcommit(self, files, copies, parents, commit, source): """Create a revision with all changed files listed in 'files' and having listed parents. 'commit' is a commit object containing at a minimum the author, date, and message for this changeset. - Called after putfile() and delfile() calls. Note that the sink - repository is not told to update itself to a particular revision - (or even what that revision would be) before it receives the - file data.""" + 'files' is a list of (path, version) tuples, 'copies'is a dictionary + mapping destinations to sources, and 'source' is the source repository. + Only getfile() and getmode() should be called on 'source'. + + Note that the sink repository is not told to update itself to + a particular revision (or even what that revision would be) + before it receives the file data. + """ raise NotImplementedError() def puttags(self, tags): @@ -181,7 +173,7 @@ class converter_sink(object): raise NotImplementedError() def setbranch(self, branch, pbranches): - """Set the current branch name. Called before the first putfile + """Set the current branch name. Called before the first putcommit on the branch. branch: branch name for subsequent commits pbranches: (converted parent revision, parent branch) tuples""" diff --git a/hgext/convert/convcmd.py b/hgext/convert/convcmd.py --- a/hgext/convert/convcmd.py +++ b/hgext/convert/convcmd.py @@ -221,8 +221,6 @@ class converter(object): def copy(self, rev): commit = self.commitcache[rev] - do_copies = hasattr(self.dest, 'copyfile') - filenames = [] changes = self.source.getchanges(rev) if isinstance(changes, basestring): @@ -241,21 +239,6 @@ class converter(object): pbranches.append((self.map[prev], self.commitcache[prev].branch)) self.dest.setbranch(commit.branch, pbranches) - for f, v in files: - filenames.append(f) - try: - data = self.source.getfile(f, v) - except IOError, inst: - self.dest.delfile(f) - else: - e = self.source.getmode(f, v) - self.dest.putfile(f, e, data) - if do_copies: - if f in copies: - copyf = copies[f] - # Merely marks that a copy happened. - self.dest.copyfile(copyf, f) - try: parents = self.splicemap[rev].replace(',', ' ').split() self.ui.status('spliced in %s as parents of %s\n' % @@ -263,7 +246,7 @@ class converter(object): parents = [self.map.get(p, p) for p in parents] except KeyError: parents = [b[0] for b in pbranches] - newnode = self.dest.putcommit(filenames, parents, commit) + newnode = self.dest.putcommit(files, copies, parents, commit, self.source) self.source.converted(rev, newnode) self.map[rev] = newnode diff --git a/hgext/convert/cvs.py b/hgext/convert/cvs.py --- a/hgext/convert/cvs.py +++ b/hgext/convert/cvs.py @@ -3,8 +3,10 @@ import os, locale, re, socket from cStringIO import StringIO from mercurial import util +from mercurial.i18n import _ from common import NoRepo, commit, converter_source, checktool +import cvsps class convert_cvs(converter_source): def __init__(self, ui, path, rev=None): @@ -14,10 +16,13 @@ class convert_cvs(converter_source): if not os.path.exists(cvs): raise NoRepo("%s does not look like a CVS checkout" % path) + checktool('cvs') self.cmd = ui.config('convert', 'cvsps', 'cvsps -A -u --cvs-direct -q') cvspsexe = self.cmd.split(None, 1)[0] - for tool in (cvspsexe, 'cvs'): - checktool(tool) + self.builtin = cvspsexe == 'builtin' + + if not self.builtin: + checktool(cvspsexe) self.changeset = {} self.files = {} @@ -28,10 +33,11 @@ class convert_cvs(converter_source): self.cvsroot = file(os.path.join(cvs, "Root")).read()[:-1] self.cvsrepo = file(os.path.join(cvs, "Repository")).read()[:-1] self.encoding = locale.getpreferredencoding() - self._parse() + + self._parse(ui) self._connect() - def _parse(self): + def _parse(self, ui): if self.changeset: return @@ -56,80 +62,114 @@ class convert_cvs(converter_source): id = None state = 0 filerevids = {} - for l in util.popen(cmd): - if state == 0: # header - if l.startswith("PatchSet"): - id = l[9:-2] - if maxrev and int(id) > maxrev: - # ignore everything - state = 3 - elif l.startswith("Date"): - date = util.parsedate(l[6:-1], ["%Y/%m/%d %H:%M:%S"]) - date = util.datestr(date) - elif l.startswith("Branch"): - branch = l[8:-1] - self.parent[id] = self.lastbranch.get(branch, 'bad') - self.lastbranch[branch] = id - elif l.startswith("Ancestor branch"): - ancestor = l[17:-1] - # figure out the parent later - self.parent[id] = self.lastbranch[ancestor] - elif l.startswith("Author"): - author = self.recode(l[8:-1]) - elif l.startswith("Tag:") or l.startswith("Tags:"): - t = l[l.index(':')+1:] - t = [ut.strip() for ut in t.split(',')] - if (len(t) > 1) or (t[0] and (t[0] != "(none)")): - self.tags.update(dict.fromkeys(t, id)) - elif l.startswith("Log:"): - # switch to gathering log - state = 1 - log = "" - elif state == 1: # log - if l == "Members: \n": - # switch to gathering members - files = {} - oldrevs = [] - log = self.recode(log[:-1]) - state = 2 - else: - # gather log - log += l - elif state == 2: # members - if l == "\n": # start of next entry - state = 0 - p = [self.parent[id]] - if id == "1": - p = [] - if branch == "HEAD": - branch = "" - if branch: - latest = None - # the last changeset that contains a base - # file is our parent - for r in oldrevs: - latest = max(filerevids.get(r, None), latest) - if latest: - p = [latest] + + if self.builtin: + # builtin cvsps code + ui.status(_('using builtin cvsps\n')) + + db = cvsps.createlog(ui, cache='update') + db = cvsps.createchangeset(ui, db, + fuzz=int(ui.config('convert', 'cvsps.fuzz', 60)), + mergeto=ui.config('convert', 'cvsps.mergeto', None), + mergefrom=ui.config('convert', 'cvsps.mergefrom', None)) + + for cs in db: + if maxrev and cs.id>maxrev: + break + id = str(cs.id) + cs.author = self.recode(cs.author) + self.lastbranch[cs.branch] = id + cs.comment = self.recode(cs.comment) + date = util.datestr(cs.date) + self.tags.update(dict.fromkeys(cs.tags, id)) + + files = {} + for f in cs.entries: + files[f.file] = "%s%s" % ('.'.join([str(x) for x in f.revision]), + ['', '(DEAD)'][f.dead]) - # add current commit to set - c = commit(author=author, date=date, parents=p, - desc=log, branch=branch) - self.changeset[id] = c - self.files[id] = files - else: - colon = l.rfind(':') - file = l[1:colon] - rev = l[colon+1:-2] - oldrev, rev = rev.split("->") - files[file] = rev + # add current commit to set + c = commit(author=cs.author, date=date, + parents=[str(p.id) for p in cs.parents], + desc=cs.comment, branch=cs.branch or '') + self.changeset[id] = c + self.files[id] = files + else: + # external cvsps + for l in util.popen(cmd): + if state == 0: # header + if l.startswith("PatchSet"): + id = l[9:-2] + if maxrev and int(id) > maxrev: + # ignore everything + state = 3 + elif l.startswith("Date"): + date = util.parsedate(l[6:-1], ["%Y/%m/%d %H:%M:%S"]) + date = util.datestr(date) + elif l.startswith("Branch"): + branch = l[8:-1] + self.parent[id] = self.lastbranch.get(branch, 'bad') + self.lastbranch[branch] = id + elif l.startswith("Ancestor branch"): + ancestor = l[17:-1] + # figure out the parent later + self.parent[id] = self.lastbranch[ancestor] + elif l.startswith("Author"): + author = self.recode(l[8:-1]) + elif l.startswith("Tag:") or l.startswith("Tags:"): + t = l[l.index(':')+1:] + t = [ut.strip() for ut in t.split(',')] + if (len(t) > 1) or (t[0] and (t[0] != "(none)")): + self.tags.update(dict.fromkeys(t, id)) + elif l.startswith("Log:"): + # switch to gathering log + state = 1 + log = "" + elif state == 1: # log + if l == "Members: \n": + # switch to gathering members + files = {} + oldrevs = [] + log = self.recode(log[:-1]) + state = 2 + else: + # gather log + log += l + elif state == 2: # members + if l == "\n": # start of next entry + state = 0 + p = [self.parent[id]] + if id == "1": + p = [] + if branch == "HEAD": + branch = "" + if branch: + latest = None + # the last changeset that contains a base + # file is our parent + for r in oldrevs: + latest = max(filerevids.get(r, None), latest) + if latest: + p = [latest] - # save some information for identifying branch points - oldrevs.append("%s:%s" % (oldrev, file)) - filerevids["%s:%s" % (rev, file)] = id - elif state == 3: - # swallow all input - continue + # add current commit to set + c = commit(author=author, date=date, parents=p, + desc=log, branch=branch) + self.changeset[id] = c + self.files[id] = files + else: + colon = l.rfind(':') + file = l[1:colon] + rev = l[colon+1:-2] + oldrev, rev = rev.split("->") + files[file] = rev + + # save some information for identifying branch points + oldrevs.append("%s:%s" % (oldrev, file)) + filerevids["%s:%s" % (rev, file)] = id + elif state == 3: + # swallow all input + continue self.heads = self.lastbranch.values() finally: @@ -297,10 +337,7 @@ class convert_cvs(converter_source): def getchanges(self, rev): self.modecache = {} - files = self.files[rev] - cl = files.items() - cl.sort() - return (cl, {}) + return util.sort(self.files[rev].items()), {} def getcommit(self, rev): return self.changeset[rev] @@ -309,7 +346,4 @@ class convert_cvs(converter_source): return self.tags def getchangedfiles(self, rev, i): - files = self.files[rev].keys() - files.sort() - return files - + return util.sort(self.files[rev].keys()) diff --git a/hgext/convert/cvsps b/hgext/convert/cvsps new file mode 100644 --- /dev/null +++ b/hgext/convert/cvsps @@ -0,0 +1,154 @@ +#!/usr/bin/env python +# +# Commandline front-end for cvsps.py +# +# Copyright 2008, Frank Kingswood +# +# This software may be used and distributed according to the terms +# of the GNU General Public License, incorporated herein by reference. + +import sys +from mercurial import util +from mercurial.i18n import _ +from optparse import OptionParser, SUPPRESS_HELP +from hgext.convert.cvsps import createlog, createchangeset, logerror + +def main(): + '''Main program to mimic cvsps.''' + + op = OptionParser(usage='%prog [-bpruvxz] path', + description='Read CVS rlog for current directory or named ' + 'path in repository, and convert the log to changesets ' + 'based on matching commit log entries and dates.') + + # Options that are ignored for compatibility with cvsps-2.1 + op.add_option('-A', dest='Ignore', action='store_true', help=SUPPRESS_HELP) + op.add_option('--cvs-direct', dest='Ignore', action='store_true', help=SUPPRESS_HELP) + op.add_option('-q', dest='Ignore', action='store_true', help=SUPPRESS_HELP) + + # Main options shared with cvsps-2.1 + op.add_option('-b', dest='Branches', action='append', default=[], + help='Only return changes on specified branches') + op.add_option('-p', dest='Prefix', action='store', default='', + help='Prefix to remove from file names') + op.add_option('-r', dest='Revisions', action='append', default=[], + help='Only return changes after or between specified tags') + op.add_option('-u', dest='Cache', action='store_const', const='update', + help="Update cvs log cache") + op.add_option('-v', dest='Verbose', action='count', default=0, + help='Be verbose') + op.add_option('-x', dest='Cache', action='store_const', const='write', + help="Create new cvs log cache") + op.add_option('-z', dest='Fuzz', action='store', type='int', default=60, + help='Set commit time fuzz', metavar='seconds') + op.add_option('--root', dest='Root', action='store', default='', + help='Specify cvsroot', metavar='cvsroot') + + # Options specific to this version + op.add_option('--parents', dest='Parents', action='store_true', + help='Show parent changesets') + op.add_option('--ancestors', dest='Ancestors', action='store_true', + help='Show current changeset in ancestor branches') + + options, args = op.parse_args() + + # Create a ui object for printing progress messages + class UI: + def __init__(self, verbose): + if verbose: + self.status = self.message + if verbose>1: + self.note = self.message + if verbose>2: + self.debug = self.message + def message(self, msg): + sys.stderr.write(msg) + def nomessage(self, msg): + pass + status = nomessage + note = nomessage + debug = nomessage + ui = UI(options.Verbose) + + try: + if args: + log = [] + for d in args: + log += createlog(ui, d, root=options.Root, cache=options.Cache) + else: + log = createlog(ui, root=options.Root, cache=options.Cache) + except logerror, e: + print e + return + + changesets = createchangeset(ui, log, options.Fuzz) + del log + + # Print changesets (optionally filtered) + + off = len(options.Revisions) + branches = {} # latest version number in each branch + ancestors = {} # parent branch + for cs in changesets: + + if options.Ancestors: + if cs.branch not in branches and cs.parents and cs.parents[0].id: + ancestors[cs.branch] = changesets[cs.parents[0].id-1].branch, cs.parents[0].id + branches[cs.branch] = cs.id + + # limit by branches + if options.Branches and (cs.branch or 'HEAD') not in options.Branches: + continue + + if not off: + # Note: trailing spaces on several lines here are needed to have + # bug-for-bug compatibility with cvsps. + print '---------------------' + print 'PatchSet %d ' % cs.id + print 'Date: %s' % util.datestr(cs.date, '%Y/%m/%d %H:%M:%S %1%2') + print 'Author: %s' % cs.author + print 'Branch: %s' % (cs.branch or 'HEAD') + print 'Tag%s: %s ' % (['', 's'][len(cs.tags)>1], + ','.join(cs.tags) or '(none)') + if options.Parents and cs.parents: + if len(cs.parents)>1: + print 'Parents: %s' % (','.join([str(p.id) for p in cs.parents])) + else: + print 'Parent: %d' % cs.parents[0].id + + if options.Ancestors: + b = cs.branch + r = [] + while b: + b, c = ancestors[b] + r.append('%s:%d:%d' % (b or "HEAD", c, branches[b])) + if r: + print 'Ancestors: %s' % (','.join(r)) + + print 'Log:' + print cs.comment + print + print 'Members: ' + for f in cs.entries: + fn = f.file + if fn.startswith(options.Prefix): + fn = fn[len(options.Prefix):] + print '\t%s:%s->%s%s ' % (fn, '.'.join([str(x) for x in f.parent]) or 'INITIAL', + '.'.join([str(x) for x in f.revision]), ['', '(DEAD)'][f.dead]) + print + + # have we seen the start tag? + if options.Revisions and off: + if options.Revisions[0] == str(cs.id) or \ + options.Revisions[0] in cs.tags: + off = False + + # see if we reached the end tag + if len(options.Revisions)>1 and not off: + if options.Revisions[1] == str(cs.id) or \ + options.Revisions[1] in cs.tags: + break + + +if __name__ == '__main__': + main() diff --git a/hgext/convert/cvsps.py b/hgext/convert/cvsps.py new file mode 100644 --- /dev/null +++ b/hgext/convert/cvsps.py @@ -0,0 +1,548 @@ +# +# Mercurial built-in replacement for cvsps. +# +# Copyright 2008, Frank Kingswood +# +# This software may be used and distributed according to the terms +# of the GNU General Public License, incorporated herein by reference. + +import os +import re +import sys +import cPickle as pickle +from mercurial import util +from mercurial.i18n import _ + +def listsort(list, key): + "helper to sort by key in Python 2.3" + try: + list.sort(key=key) + except TypeError: + list.sort(lambda l, r: cmp(key(l), key(r))) + +class logentry(object): + '''Class logentry has the following attributes: + .author - author name as CVS knows it + .branch - name of branch this revision is on + .branches - revision tuple of branches starting at this revision + .comment - commit message + .date - the commit date as a (time, tz) tuple + .dead - true if file revision is dead + .file - Name of file + .lines - a tuple (+lines, -lines) or None + .parent - Previous revision of this entry + .rcs - name of file as returned from CVS + .revision - revision number as tuple + .tags - list of tags on the file + ''' + def __init__(self, **entries): + self.__dict__.update(entries) + +class logerror(Exception): + pass + +def createlog(ui, directory=None, root="", rlog=True, cache=None): + '''Collect the CVS rlog''' + + # Because we store many duplicate commit log messages, reusing strings + # saves a lot of memory and pickle storage space. + _scache = {} + def scache(s): + "return a shared version of a string" + return _scache.setdefault(s, s) + + ui.status(_('collecting CVS rlog\n')) + + log = [] # list of logentry objects containing the CVS state + + # patterns to match in CVS (r)log output, by state of use + re_00 = re.compile('RCS file: (.+)$') + re_01 = re.compile('cvs \\[r?log aborted\\]: (.+)$') + re_02 = re.compile('cvs (r?log|server): (.+)\n$') + re_03 = re.compile("(Cannot access.+CVSROOT)|(can't create temporary directory.+)$") + re_10 = re.compile('Working file: (.+)$') + re_20 = re.compile('symbolic names:') + re_30 = re.compile('\t(.+): ([\\d.]+)$') + re_31 = re.compile('----------------------------$') + re_32 = re.compile('=============================================================================$') + re_50 = re.compile('revision ([\\d.]+)(\s+locked by:\s+.+;)?$') + re_60 = re.compile(r'date:\s+(.+);\s+author:\s+(.+);\s+state:\s+(.+?);(\s+lines:\s+(\+\d+)?\s+(-\d+)?;)?') + re_70 = re.compile('branches: (.+);$') + + prefix = '' # leading path to strip of what we get from CVS + + if directory is None: + # Current working directory + + # Get the real directory in the repository + try: + prefix = file(os.path.join('CVS','Repository')).read().strip() + if prefix == ".": + prefix = "" + directory = prefix + except IOError: + raise logerror('Not a CVS sandbox') + + if prefix and not prefix.endswith('/'): + prefix += '/' + + # Use the Root file in the sandbox, if it exists + try: + root = file(os.path.join('CVS','Root')).read().strip() + except IOError: + pass + + if not root: + root = os.environ.get('CVSROOT', '') + + # read log cache if one exists + oldlog = [] + date = None + + if cache: + cachedir = os.path.expanduser('~/.hg.cvsps') + if not os.path.exists(cachedir): + os.mkdir(cachedir) + + # The cvsps cache pickle needs a uniquified name, based on the + # repository location. The address may have all sort of nasties + # in it, slashes, colons and such. So here we take just the + # alphanumerics, concatenated in a way that does not mix up the + # various components, so that + # :pserver:user@server:/path + # and + # /pserver/user/server/path + # are mapped to different cache file names. + cachefile = root.split(":") + [directory, "cache"] + cachefile = ['-'.join(re.findall(r'\w+', s)) for s in cachefile if s] + cachefile = os.path.join(cachedir, + '.'.join([s for s in cachefile if s])) + + if cache == 'update': + try: + ui.note(_('reading cvs log cache %s\n') % cachefile) + oldlog = pickle.load(file(cachefile)) + ui.note(_('cache has %d log entries\n') % len(oldlog)) + except Exception, e: + ui.note(_('error reading cache: %r\n') % e) + + if oldlog: + date = oldlog[-1].date # last commit date as a (time,tz) tuple + date = util.datestr(date, '%Y/%m/%d %H:%M:%S %1%2') + + # build the CVS commandline + cmd = ['cvs', '-q'] + if root: + cmd.append('-d%s' % root) + p = root.split(':')[-1] + if not p.endswith('/'): + p += '/' + prefix = p + prefix + cmd.append(['log', 'rlog'][rlog]) + if date: + # no space between option and date string + cmd.append('-d>%s' % date) + cmd.append(directory) + + # state machine begins here + tags = {} # dictionary of revisions on current file with their tags + state = 0 + store = False # set when a new record can be appended + + cmd = [util.shellquote(arg) for arg in cmd] + ui.note("running %s\n" % (' '.join(cmd))) + ui.debug("prefix=%r directory=%r root=%r\n" % (prefix, directory, root)) + + for line in util.popen(' '.join(cmd)): + if line.endswith('\n'): + line = line[:-1] + #ui.debug('state=%d line=%r\n' % (state, line)) + + if state == 0: + # initial state, consume input until we see 'RCS file' + match = re_00.match(line) + if match: + rcs = match.group(1) + tags = {} + if rlog: + filename = rcs[:-2] + if filename.startswith(prefix): + filename = filename[len(prefix):] + if filename.startswith('/'): + filename = filename[1:] + if filename.startswith('Attic/'): + filename = filename[6:] + else: + filename = filename.replace('/Attic/', '/') + state = 2 + continue + state = 1 + continue + match = re_01.match(line) + if match: + raise Exception(match.group(1)) + match = re_02.match(line) + if match: + raise Exception(match.group(2)) + if re_03.match(line): + raise Exception(line) + + elif state == 1: + # expect 'Working file' (only when using log instead of rlog) + match = re_10.match(line) + assert match, _('RCS file must be followed by working file') + filename = match.group(1) + state = 2 + + elif state == 2: + # expect 'symbolic names' + if re_20.match(line): + state = 3 + + elif state == 3: + # read the symbolic names and store as tags + match = re_30.match(line) + if match: + rev = [int(x) for x in match.group(2).split('.')] + + # Convert magic branch number to an odd-numbered one + revn = len(rev) + if revn > 3 and (revn % 2) == 0 and rev[-2] == 0: + rev = rev[:-2] + rev[-1:] + rev = tuple(rev) + + if rev not in tags: + tags[rev] = [] + tags[rev].append(match.group(1)) + + elif re_31.match(line): + state = 5 + elif re_32.match(line): + state = 0 + + elif state == 4: + # expecting '------' separator before first revision + if re_31.match(line): + state = 5 + else: + assert not re_32.match(line), _('Must have at least some revisions') + + elif state == 5: + # expecting revision number and possibly (ignored) lock indication + # we create the logentry here from values stored in states 0 to 4, + # as this state is re-entered for subsequent revisions of a file. + match = re_50.match(line) + assert match, _('expected revision number') + e = logentry(rcs=scache(rcs), file=scache(filename), + revision=tuple([int(x) for x in match.group(1).split('.')]), + branches=[], parent=None) + state = 6 + + elif state == 6: + # expecting date, author, state, lines changed + match = re_60.match(line) + assert match, _('revision must be followed by date line') + d = match.group(1) + if d[2] == '/': + # Y2K + d = '19' + d + + if len(d.split()) != 3: + # cvs log dates always in GMT + d = d + ' UTC' + e.date = util.parsedate(d, ['%y/%m/%d %H:%M:%S', '%Y/%m/%d %H:%M:%S', '%Y-%m-%d %H:%M:%S']) + e.author = scache(match.group(2)) + e.dead = match.group(3).lower() == 'dead' + + if match.group(5): + if match.group(6): + e.lines = (int(match.group(5)), int(match.group(6))) + else: + e.lines = (int(match.group(5)), 0) + elif match.group(6): + e.lines = (0, int(match.group(6))) + else: + e.lines = None + e.comment = [] + state = 7 + + elif state == 7: + # read the revision numbers of branches that start at this revision + # or store the commit log message otherwise + m = re_70.match(line) + if m: + e.branches = [tuple([int(y) for y in x.strip().split('.')]) + for x in m.group(1).split(';')] + state = 8 + elif re_31.match(line): + state = 5 + store = True + elif re_32.match(line): + state = 0 + store = True + else: + e.comment.append(line) + + elif state == 8: + # store commit log message + if re_31.match(line): + state = 5 + store = True + elif re_32.match(line): + state = 0 + store = True + else: + e.comment.append(line) + + if store: + # clean up the results and save in the log. + store = False + e.tags = util.sort([scache(x) for x in tags.get(e.revision, [])]) + e.comment = scache('\n'.join(e.comment)) + + revn = len(e.revision) + if revn > 3 and (revn % 2) == 0: + e.branch = tags.get(e.revision[:-1], [None])[0] + else: + e.branch = None + + log.append(e) + + if len(log) % 100 == 0: + ui.status(util.ellipsis('%d %s' % (len(log), e.file), 80)+'\n') + + listsort(log, key=lambda x:(x.rcs, x.revision)) + + # find parent revisions of individual files + versions = {} + for e in log: + branch = e.revision[:-1] + p = versions.get((e.rcs, branch), None) + if p is None: + p = e.revision[:-2] + e.parent = p + versions[(e.rcs, branch)] = e.revision + + # update the log cache + if cache: + if log: + # join up the old and new logs + listsort(log, key=lambda x:x.date) + + if oldlog and oldlog[-1].date >= log[0].date: + raise logerror('Log cache overlaps with new log entries,' + ' re-run without cache.') + + log = oldlog + log + + # write the new cachefile + ui.note(_('writing cvs log cache %s\n') % cachefile) + pickle.dump(log, file(cachefile, 'w')) + else: + log = oldlog + + ui.status(_('%d log entries\n') % len(log)) + + return log + + +class changeset(object): + '''Class changeset has the following attributes: + .author - author name as CVS knows it + .branch - name of branch this changeset is on, or None + .comment - commit message + .date - the commit date as a (time,tz) tuple + .entries - list of logentry objects in this changeset + .parents - list of one or two parent changesets + .tags - list of tags on this changeset + ''' + def __init__(self, **entries): + self.__dict__.update(entries) + +def createchangeset(ui, log, fuzz=60, mergefrom=None, mergeto=None): + '''Convert log into changesets.''' + + ui.status(_('creating changesets\n')) + + # Merge changesets + + listsort(log, key=lambda x:(x.comment, x.author, x.branch, x.date)) + + changesets = [] + files = {} + c = None + for i, e in enumerate(log): + + # Check if log entry belongs to the current changeset or not. + if not (c and + e.comment == c.comment and + e.author == c.author and + e.branch == c.branch and + ((c.date[0] + c.date[1]) <= + (e.date[0] + e.date[1]) <= + (c.date[0] + c.date[1]) + fuzz) and + e.file not in files): + c = changeset(comment=e.comment, author=e.author, + branch=e.branch, date=e.date, entries=[]) + changesets.append(c) + files = {} + if len(changesets) % 100 == 0: + t = '%d %s' % (len(changesets), repr(e.comment)[1:-1]) + ui.status(util.ellipsis(t, 80) + '\n') + + c.entries.append(e) + files[e.file] = True + c.date = e.date # changeset date is date of latest commit in it + + # Sort files in each changeset + + for c in changesets: + def pathcompare(l, r): + 'Mimic cvsps sorting order' + l = l.split('/') + r = r.split('/') + nl = len(l) + nr = len(r) + n = min(nl, nr) + for i in range(n): + if i + 1 == nl and nl < nr: + return -1 + elif i + 1 == nr and nl > nr: + return +1 + elif l[i] < r[i]: + return -1 + elif l[i] > r[i]: + return +1 + return 0 + def entitycompare(l, r): + return pathcompare(l.file, r.file) + + c.entries.sort(entitycompare) + + # Sort changesets by date + + def cscmp(l, r): + d = sum(l.date) - sum(r.date) + if d: + return d + + # detect vendor branches and initial commits on a branch + le = {} + for e in l.entries: + le[e.rcs] = e.revision + re = {} + for e in r.entries: + re[e.rcs] = e.revision + + d = 0 + for e in l.entries: + if re.get(e.rcs, None) == e.parent: + assert not d + d = 1 + break + + for e in r.entries: + if le.get(e.rcs, None) == e.parent: + assert not d + d = -1 + break + + return d + + changesets.sort(cscmp) + + # Collect tags + + globaltags = {} + for c in changesets: + tags = {} + for e in c.entries: + for tag in e.tags: + # remember which is the latest changeset to have this tag + globaltags[tag] = c + + for c in changesets: + tags = {} + for e in c.entries: + for tag in e.tags: + tags[tag] = True + # remember tags only if this is the latest changeset to have it + c.tags = util.sort([tag for tag in tags if globaltags[tag] is c]) + + # Find parent changesets, handle {{mergetobranch BRANCHNAME}} + # by inserting dummy changesets with two parents, and handle + # {{mergefrombranch BRANCHNAME}} by setting two parents. + + if mergeto is None: + mergeto = r'{{mergetobranch ([-\w]+)}}' + if mergeto: + mergeto = re.compile(mergeto) + + if mergefrom is None: + mergefrom = r'{{mergefrombranch ([-\w]+)}}' + if mergefrom: + mergefrom = re.compile(mergefrom) + + versions = {} # changeset index where we saw any particular file version + branches = {} # changeset index where we saw a branch + n = len(changesets) + i = 0 + while i= stop_rev curr_rev = start_rev revs = [] - filerev = repo.file(path).count() - 1 + filerev = len(repo.file(path)) - 1 while filerev >= 0: fctx = repo.filectx(path, fileid=filerev) @@ -104,8 +105,7 @@ def filelog_grapher(repo, path, start_re for parent in parents: if parent not in next_revs: parents_to_add.append(parent) - parents_to_add.sort() - next_revs[rev_index:rev_index + 1] = parents_to_add + next_revs[rev_index:rev_index + 1] = util.sort(parents_to_add) edges = [] for parent in parents: @@ -197,7 +197,7 @@ def get_revs(repo, rev_opt): revs = revrange(repo, rev_opt) return (max(revs), min(revs)) else: - return (repo.changelog.count() - 1, 0) + return (len(repo) - 1, 0) def graphlog(ui, repo, path=None, **opts): """show revision history alongside an ASCII revision graph diff --git a/hgext/hgk.py b/hgext/hgk.py --- a/hgext/hgk.py +++ b/hgext/hgk.py @@ -4,60 +4,58 @@ # # This software may be used and distributed according to the terms # of the GNU General Public License, incorporated herein by reference. -# -# The hgk extension allows browsing the history of a repository in a -# graphical way. It requires Tcl/Tk version 8.4 or later. (Tcl/Tk is -# not distributed with Mercurial.) -# -# hgk consists of two parts: a Tcl script that does the displaying and -# querying of information, and an extension to mercurial named hgk.py, -# which provides hooks for hgk to get information. hgk can be found in -# the contrib directory, and hgk.py can be found in the hgext -# directory. -# -# To load the hgext.py extension, add it to your .hgrc file (you have -# to use your global $HOME/.hgrc file, not one in a repository). You -# can specify an absolute path: -# -# [extensions] -# hgk=/usr/local/lib/hgk.py -# -# Mercurial can also scan the default python library path for a file -# named 'hgk.py' if you set hgk empty: -# -# [extensions] -# hgk= -# -# The hg view command will launch the hgk Tcl script. For this command -# to work, hgk must be in your search path. Alternately, you can -# specify the path to hgk in your .hgrc file: -# -# [hgk] -# path=/location/of/hgk -# -# hgk can make use of the extdiff extension to visualize -# revisions. Assuming you had already configured extdiff vdiff -# command, just add: -# -# [hgk] -# vdiff=vdiff -# -# Revisions context menu will now display additional entries to fire -# vdiff on hovered and selected revisions. +'''browsing the repository in a graphical way + +The hgk extension allows browsing the history of a repository in a +graphical way. It requires Tcl/Tk version 8.4 or later. (Tcl/Tk is +not distributed with Mercurial.) + +hgk consists of two parts: a Tcl script that does the displaying and +querying of information, and an extension to mercurial named hgk.py, +which provides hooks for hgk to get information. hgk can be found in +the contrib directory, and hgk.py can be found in the hgext directory. + +To load the hgext.py extension, add it to your .hgrc file (you have +to use your global $HOME/.hgrc file, not one in a repository). You +can specify an absolute path: + + [extensions] + hgk=/usr/local/lib/hgk.py + +Mercurial can also scan the default python library path for a file +named 'hgk.py' if you set hgk empty: + + [extensions] + hgk= + +The hg view command will launch the hgk Tcl script. For this command +to work, hgk must be in your search path. Alternately, you can +specify the path to hgk in your .hgrc file: + + [hgk] + path=/location/of/hgk + +hgk can make use of the extdiff extension to visualize revisions. +Assuming you had already configured extdiff vdiff command, just add: + + [hgk] + vdiff=vdiff + +Revisions context menu will now display additional entries to fire +vdiff on hovered and selected revisions.''' import os -from mercurial import commands, util, patch, revlog +from mercurial import commands, util, patch, revlog, cmdutil from mercurial.node import nullid, nullrev, short def difftree(ui, repo, node1=None, node2=None, *files, **opts): """diff trees from two commits""" def __difftree(repo, node1, node2, files=[]): assert node2 is not None - mmap = repo.changectx(node1).manifest() - mmap2 = repo.changectx(node2).manifest() - status = repo.status(node1, node2, files=files)[:5] - modified, added, removed, deleted, unknown = status - + mmap = repo[node1].manifest() + mmap2 = repo[node2].manifest() + m = cmdutil.match(repo, files) + modified, added, removed = repo.status(node1, node2, m)[:3] empty = short(nullid) for f in modified: @@ -92,8 +90,8 @@ def difftree(ui, repo, node1=None, node2 if opts['patch']: if opts['pretty']: catcommit(ui, repo, node2, "") - patch.diff(repo, node1, node2, - files=files, + m = cmdutil.match(repo, files) + patch.diff(repo, node1, node2, match=m, opts=patch.diffopts(ui, {'git': True})) else: __difftree(repo, node1, node2, files=files) @@ -103,11 +101,11 @@ def difftree(ui, repo, node1=None, node2 def catcommit(ui, repo, n, prefix, ctx=None): nlprefix = '\n' + prefix; if ctx is None: - ctx = repo.changectx(n) - (p1, p2) = ctx.parents() + ctx = repo[n] ui.write("tree %s\n" % short(ctx.changeset()[0])) # use ctx.node() instead ?? - if p1: ui.write("parent %s\n" % short(p1.node())) - if p2: ui.write("parent %s\n" % short(p2.node())) + for p in ctx.parents(): + ui.write("parent %s\n" % p) + date = ctx.date() description = ctx.description().replace("\0", "") lines = description.splitlines() @@ -175,7 +173,7 @@ def catfile(ui, repo, type=None, r=None, # you can specify a commit to stop at by starting the sha1 with ^ def revtree(ui, args, repo, full="tree", maxnr=0, parents=False): def chlogwalk(): - count = repo.changelog.count() + count = len(repo) i = count l = [0] * 100 chunk = 100 @@ -191,7 +189,7 @@ def revtree(ui, args, repo, full="tree", l[chunk - x:] = [0] * (chunk - x) break if full != None: - l[x] = repo.changectx(i + x) + l[x] = repo[i + x] l[x].changeset() # force reading else: l[x] = 1 diff --git a/hgext/highlight.py b/hgext/highlight.py --- a/hgext/highlight.py +++ b/hgext/highlight.py @@ -1,6 +1,4 @@ -""" -This is Mercurial extension for syntax highlighting in the file -revision view of hgweb. +"""a mercurial extension for syntax highlighting in hgweb It depends on the pygments syntax highlighting library: http://pygments.org/ @@ -15,23 +13,15 @@ There is a single configuration option: [web] pygments_style =