Vim Tips Wiki
(→‎Useful commands to "get information": missing section to enable the pager)
(→‎Useful commands to "get information": add -v for "verbose" to help commands)
(16 intermediate revisions by 4 users not shown)
Line 1: Line 1:
  +
{{TipNew
{{TipProposed
 
|id=0
+
|id=1653
|previous=0
+
|previous=1652
|next=0
+
|next=1654
 
|created=May 14, 2010
 
|created=May 14, 2010
 
|complexity=basic
 
|complexity=basic
Line 11: Line 11:
 
|category2=
 
|category2=
 
}}
 
}}
This tip describes how to get the Vim source from the new Mercurial repository. It assumes that you know how to compile Vim once you have the source. Examples are for Linux but it shouldn't be hard to adapt them to whatever OS you're running on (provided of course that there exists a version of Mercurial that runs on your OS). Also, the examples are written for GNU make: in case of doubt, try replacing <tt>make</tt> by <tt>gmake</tt> everywhere.
+
This tip describes how to get the Vim source from the new Mercurial repository. It assumes that you know how to compile Vim once you have the source. Examples are for Linux but it shouldn't be hard to adapt them to whatever OS you're running on (provided of course that there exists a version of Mercurial that runs on your OS). Also, the examples are written for GNU make: in case of doubt, try replacing <code>make</code> by <code>gmake</code> everywhere.
   
 
==First time only: Creating your repository==
 
==First time only: Creating your repository==
 
===Make sure that Mercurial and Python are installed on your system===
 
===Make sure that Mercurial and Python are installed on your system===
e.g. by checking that there is a program named <tt>hg</tt> and another named <tt>python</tt> in your PATH. If you haven't got Mercurial, install it, either (if available) by installing the <tt>Mercurial</tt> package from your distro, or else from [http://mercurial.selenic.com/ the Mercurial site]. As of this writing (15 May 2010) the Python version required by the Mercurial package is python 2.4. ''(I use it with no trouble with python 2.6.2; I got both packages from my openSUSE Linux distro — [[User:Tonymec|Tonymec]] 23:41, May 14, 2010 (UTC).)''
+
For example, check there is a program named <code>hg</code> and another named <code>python</code> in your PATH. If you haven't got Mercurial, install it, either (if available) by installing the <code>Mercurial</code> package from your distro, or else from the [http://mercurial.selenic.com/ Mercurial site]. As of May 2010 the Python version required by the Mercurial package is Python 2.4, but it seems to work fine with later versions like Python 2.6.2.
  +
  +
If you're uncomfortable with a command-line interface (or simply prefer a GUI), there are options available such as [http://tortoisehg.bitbucket.org/ TortoiseHg] to simplify common tasks with an easy-to-use GUI front-end. On Windows, the installer even includes Python and a command-line hg tool, so that you get everything you need in one package.
   
 
===Install a copy of Bram's latest source, runtime and ancillary files===
 
===Install a copy of Bram's latest source, runtime and ancillary files===
Line 28: Line 30:
 
(date && hg clone https://vim.googlecode.com/hg/ vim) 2>&1 |tee hg-vim.log
 
(date && hg clone https://vim.googlecode.com/hg/ vim) 2>&1 |tee hg-vim.log
 
</pre>
 
</pre>
The above is slightly more complicated than absolutely necessary because I recommend to keep a running log. The important part starts with <tt>hg</tt> and ends immediately before the right parenthesis. Similarly for other hg commands below.
+
The above is slightly more complicated than absolutely necessary because it can be useful to keep a running log. The important part starts with <code>hg</code> and ends immediately before the right parenthesis. Similarly for other hg commands below.
   
 
==Simple case: Getting new patches==
 
==Simple case: Getting new patches==
 
This applies if '''all''' of the following are true:
 
This applies if '''all''' of the following are true:
* You have no local changes to the Vim source, ancillary and runtime files ''(including the Makefile: see [[#External links|my Compiling HowTo pages]] for a way to set compilation options with no changes to the Makefile)''
+
*You have no local changes to the Vim source, ancillary and runtime files ''(including the Makefile; you can easily compile a custom Vim with no Makefile changes, as detailed in the [[#External links|compiling "how to" pages]] below)''
* You compile only one Vim and therefore don't use a shadow directory
+
*You compile only one Vim and therefore don't use a shadow directory
* You don't build a cscope database inside the Vim source tree
+
*You don't build a cscope database inside the Vim source tree
 
In this case, all you need to check for (and, if necessary, get) any changes to the Vim source is:
 
In this case, all you need to check for (and, if necessary, get) any changes to the Vim source is:
 
<pre>
 
<pre>
Line 43: Line 45:
 
==Complex case: You have local changes and/or compile several Vim versions==
 
==Complex case: You have local changes and/or compile several Vim versions==
 
===Enable the fetch extension===
 
===Enable the fetch extension===
by adding the following to the .hg/hgrc file in your repository (it was created by the clone process, with Bram's repository as the default remote source):
+
Add the following to the .hg/hgrc file in your repository (it was created by the clone process, with Bram's repository as the default remote source):
 
<pre>
 
<pre>
 
[extensions]
 
[extensions]
hgext.fetch =
+
hgext.fetch =
 
</pre>
 
</pre>
 
No need to add anything after the equal sign, this extension comes packed with Mercurial (but disabled by default)
 
No need to add anything after the equal sign, this extension comes packed with Mercurial (but disabled by default)
   
===Patch your <tt>.hgignore</tt> file===
+
===Patch your <code>.hgignore</code> file===
 
It is found at the top level of your repository. This step is unnecessary if you have '''neither''' additional help files nor additional Vim versions '''and''' you don't add a cscope database inside the Vim source tree.
 
It is found at the top level of your repository. This step is unnecessary if you have '''neither''' additional help files nor additional Vim versions '''and''' you don't add a cscope database inside the Vim source tree.
Copy the following patch and apply it with <tt>patch -p1 < hgignore.diff</tt> from the top directory where the file resides.
+
Copy the following patch and apply it with <code>patch -p1 < hgignore.diff</code> from the top directory where the file resides.
 
<pre>
 
<pre>
 
diff -r 2bd29808d1f6 -r a5e628a08c4e .hgignore
 
diff -r 2bd29808d1f6 -r a5e628a08c4e .hgignore
Line 91: Line 93:
   
 
===Create shadow directories===
 
===Create shadow directories===
If you want to compile more than one version of Vim, create shadow directories to avoid conflicts between them. We create them with names starting with <tt>shadow-</tt> so <tt>.hgignore</tt> (after applying the above patch) will see them. Here is an example:
+
If you want to compile more than one version of Vim, create shadow directories to avoid conflicts between them. We create them with names starting with <code>shadow-</code> so <code>.hgignore</code> (after applying the above patch) will see them. Here is an example:
 
<pre>
 
<pre>
 
cd ~/.build/hg/vim/src
 
cd ~/.build/hg/vim/src
Line 97: Line 99:
 
(date && SHADOWDIR='shadow-tiny' make -e shadow) 2>&1 |tee -a ../../hg-vim.log
 
(date && SHADOWDIR='shadow-tiny' make -e shadow) 2>&1 |tee -a ../../hg-vim.log
 
</pre>
 
</pre>
The -e command-line switch is necessary so that make won't override our <tt>SHADOWDIR</tt> names with the default which is just <tt>shadow</tt>
+
The -e command-line switch is necessary so that make won't override our <code>SHADOWDIR</code> names with the default which is just <code>shadow</code>
   
 
===Apply your local changes and commit them===
 
===Apply your local changes and commit them===
You do this by editing the sources in the src directory. The case where you want to compile different versions of Vim with not only different configuration options but even different changes to the sources is not covered by the present tip, and neither is the case when your changes could conflict with Bram's (the changes I have consist of added sections in out-of-the-way parts of <tt>Makefile</tt> and <tt>feature.h</tt> plus Bill McCarthy's extra float functions).
+
You do this by editing the sources in the src directory. The case where you want to compile different versions of Vim with not only different configuration options but even different changes to the sources is not covered by the present tip, and neither is the case when your changes could conflict with Bram's (the changes I have consist of added sections in out-of-the-way parts of <code>Makefile</code> and <code>feature.h</code> plus Bill McCarthy's extra float functions).
   
Also, check that your "nonstandard" patches are mentioned in <tt>src/version.c</tt> so that they will appear in the <tt>:version</tt> output of your home-compiled Vim: here is the relevant part of mine, normally you would add one line (with a string followed by a comma) per extra patch with a <tt>/**/</tt> comment between each of them:
+
Also, check that your "nonstandard" patches are mentioned in <code>src/version.c</code> so that they will appear in the <code>:version</code> output of your home-compiled Vim: here is the relevant part of mine, normally you would add one line (with a string followed by a comma) per extra patch with a <code>/**/</code> comment between each of them:
 
<pre>
 
<pre>
 
static char *(extra_patches[]) =
 
static char *(extra_patches[]) =
Line 125: Line 127:
 
(date && hg fetch --switch-parent) 2>&1 |tee -a ../hg-vim.log
 
(date && hg fetch --switch-parent) 2>&1 |tee -a ../hg-vim.log
 
</pre>
 
</pre>
The <tt>--switch-parent</tt> switch places the local directory (where changes are few and far between) as the "first" parent of any resulting merge, so that the local changes won't be removed and added back every time: this reduces the number of source files which make will see as "modified".
+
The <code>--switch-parent</code> switch places the local directory (where changes are few and far between) as the "first" parent of any resulting merge, so that the local changes won't be removed and added back every time: this reduces the number of source files which make will see as "modified".
   
Before compiling, you may want to check any files listed as "merged" (possibly with the help of the <tt>hg diff</tt> function) to make sure that the changes are what you would expect.
+
Before compiling, you may want to check any files listed as "merged" (possibly with the help of the <code>hg diff</code> function) to make sure that the changes are what you would expect.
   
 
==See also==
 
==See also==
 
===Manpages===
 
===Manpages===
* <tt>man hg</tt>
+
*<code>man hg</code>
* <tt>man hgrc</tt>
+
*<code>man hgrc</code>
* <tt>man hgignore</tt>
+
*<code>man hgignore</code>
  +
  +
===The Mercurial online help===
  +
In my experience, second only to the Vim help itself. It includes the whole contents of the [[#Manpages|manpages]], and more.
  +
*<code>hg help</code>
  +
*<code>hg help ''subject''</code>
  +
where <code>''subject''</code> is a Mercurial command ''(e.g. <code>pull</code>)'' or other help subject ''(e.g. <code>extensions</code>).''
  +
: '''Note:''' The full text of the help is only obtained with <code>-v</code> or <code>--verbose</code>, or when the <code>[ui]</code> section of your <code>hgrc</code> (or, on Windows, <code>Mercurial.ini</code>) contains the line <code>verbose=1</code>
  +
 
===In this wiki===
 
===In this wiki===
* [[:Category:Building Vim]]
+
*[[:Category:Building Vim]]
   
 
===External links===
 
===External links===
* [http://mercurial.selenic.com/ The Mercurial site]
+
*[http://mercurial.selenic.com/ The Mercurial site]
* [http://mercurial.selenic.com/guide/ The Mercurial Guide]
+
*[http://mercurial.selenic.com/guide/ The Mercurial Guide]
  +
*[http://selenic.com/mailman/listinfo/mercurial The Mercurial mailing list]
* [http://users.skynet.be/antoine.mechelynck/vim/compile.htm Compiling Vim on Windows]
 
* [http://users.skynet.be/antoine.mechelynck/vim/compunix.htm Compiling Vim on Unix/Linux]
+
*[http://users.skynet.be/antoine.mechelynck/vim/compile.htm Compiling Vim on Windows]
 
*[http://users.skynet.be/antoine.mechelynck/vim/compunix.htm Compiling Vim on Unix/Linux]
   
 
==Comments==
 
==Comments==
Please sign your comments with <tt><nowiki>~~~~</nowiki></tt> and separate unrelated topics with <tt><nowiki>----</nowiki></tt> on its own line. — [[User:Tonymec|Tonymec]] 23:41, May 14, 2010 (UTC)
 
----
 
 
===Known bug: Logging and interactive merge===
 
===Known bug: Logging and interactive merge===
 
A problem which I haven't solved about the above method of keeping a running log, is that is doesn't mesh well with Mercurial's "interactive merge tool": if the interactive merge asks a question, you don't see it, and you will have to blind-type a guessed response.
 
A problem which I haven't solved about the above method of keeping a running log, is that is doesn't mesh well with Mercurial's "interactive merge tool": if the interactive merge asks a question, you don't see it, and you will have to blind-type a guessed response.
Line 153: Line 162:
 
If you hit Ctrl-C to break the run, you won't see what Mercurial has output so far: it is not in the log; and your local repository is left in an uncertain state: once I did this, but then "hg status" replied nothing and "hg fetch" gave an error saying local files needed update -C or merge. Finally "hg merge" (with no logging) gave me the c/d question again so I could bring back my local repo to a "sane" state by replying d then manually committing the merge (with a -m message inspired by the "description" on the remote head, as obtained with "hg heads").
 
If you hit Ctrl-C to break the run, you won't see what Mercurial has output so far: it is not in the log; and your local repository is left in an uncertain state: once I did this, but then "hg status" replied nothing and "hg fetch" gave an error saying local files needed update -C or merge. Finally "hg merge" (with no logging) gave me the c/d question again so I could bring back my local repo to a "sane" state by replying d then manually committing the merge (with a -m message inspired by the "description" on the remote head, as obtained with "hg heads").
 
:— [[User:Tonymec|Tonymec]] 04:39, May 18, 2010 (UTC)
 
:— [[User:Tonymec|Tonymec]] 04:39, May 18, 2010 (UTC)
:'''Workaround:''' First, use <tt>hg -v incoming</tt> (see below; <tt>-v</tt> means "verbose"). No need to log this since it makes no change to the repository. If it tells you "No changes found", no need to do anything more at the moment. Otherwise, it will tell you which files will be changed if you pull. Then if <tt>runtime/doc/tags</tt> is included, you know that fetch may stop until you type <tt>d&lt;Enter&gt;</tt>
+
:'''Workaround:''' First, use <code>hg -v incoming</code> (see below; <code>-v</code> means "verbose"). No need to log this since it makes no change to the repository. If it tells you "No changes found", no need to do anything more at the moment. Otherwise, it will tell you which files will be changed if you pull. Then if <code>runtime/doc/tags</code> is included, you know that fetch may stop until you type <code>d&lt;Enter&gt;</code>
 
:— If there are many new changesets, and you want to exceptionally use (just this once) vim as a pager, repeat the command like this (all on one line):
 
:— If there are many new changesets, and you want to exceptionally use (just this once) vim as a pager, repeat the command like this (all on one line):
::<tt>hg -v --config 'extensions.hgext.pager=' --config 'pager.pager=vim -' --config 'pager.attend=incoming' incoming</tt>
+
::<code>hg -v --config 'extensions.hgext.pager=' --config 'pager.pager=view -' --config 'pager.attend=incoming' incoming</code>
:where the three <tt>--config</tt> arguments mean that '''this single command''' will be run as if your hgrc included the following (in addition tothe other lines already there):
+
:where the three <code>--config</code> arguments mean that '''this single command''' will be run as if your hgrc included the following (in addition tothe other lines already there):
 
<pre>[extensions]
 
<pre>[extensions]
 
hgext.pager=
 
hgext.pager=
Line 162: Line 171:
 
pager=view -
 
pager=view -
 
attend=incoming</pre>
 
attend=incoming</pre>
:i.e. enable the <tt>pager</tt> extension, use "'''<tt>view -</tt>'''" i.e. Vim read-only from stdin, as a pager, and enable the pager for the <tt>hg incoming</tt> command. — [[User:Tonymec|Tonymec]] 21:42, July 7, 2010 (UTC)
+
:i.e. enable the <code>pager</code> extension, use "'''<code>view -</code>'''" i.e. Vim read-only from stdin, as a pager, and enable the pager for the <code>hg incoming</code> command. — [[User:Tonymec|Tonymec]] 21:42, July 7, 2010 (UTC)
 
----
 
----
  +
I finally found how to force Python programs (including Mercurial, which is written in Python) to always use '''unbuffered''' I/O on stdin, stdout and stderr. Simple: '''set the environment variable <tt>PYTHONUNBUFFERED</tt> to some nonempty string.'''
  +
  +
Example (for the <tt>bash</tt> shell on Unix-like systems):
 
<pre>
  +
cd ~/.build/hg/vim
  +
PYTHONUNBUFFERED='unbuffered' (date && hg fetch --switch-parent) 2>&1 |tee -a ../hg-vim.log
 
</pre>
  +
  +
<div style="background-color: #FFFFCC; border: 2px dashed grey; padding: 1ex">'''CAUTION:''' It might be unwise to do this in your permanent environment, since unbuffering means more frequent and smaller transfers, thus reducing throughput. You may want to do it '''only''' when logging via <tt>|tee</tt></div>
 
— [[User:Tonymec|Tonymec]] ([[User talk:Tonymec|talk]]) 02:56, July 16, 2012 (UTC)
   
 
===Useful commands to "get information"===
 
===Useful commands to "get information"===
* <tt>hg help</tt>
+
*<code>hg -v help</code>
* <tt>hg help |less</tt>
+
*<code>hg -v help |less</code>
 
::what are the basic hg commands, and what do they do?
 
::what are the basic hg commands, and what do they do?
* <tt>hg help <u>command</u></tt>
+
*<code>hg -v help <u>command</u></code>
::(where <u>command</u> is a Mercurial command) what are the possible arguments to that command (and what do they mean)?
+
::(where <u>command</u> is a Mercurial command) what are the possible arguments to that command (and what do they mean)?<br>(<code>-v</code> or <code>--verbose</code> is necessary to get the full text of the concerned help section)
* <tt>hg status</tt>
+
*<code>hg status</code>
::are there local files waiting for a disposition (<tt>commit</tt> possibly preceded by <tt>add</tt> and/or <tt>forget</tt>)? The reply is one filename per line, preceded by A (added to the list of tracked files), M (merged), D (deleted i.e. specifically not tracked), ? (new file, neither "tracked" nor "not tracked" yet).
+
::are there local files waiting for a disposition (<code>commit</code> possibly preceded by <code>add</code> and/or <code>forget</code>)? The reply is one filename per line, preceded by A (added to the list of tracked files), M (merged), D (deleted i.e. specifically not tracked), ? (new file, neither "tracked" nor "not tracked" yet).
* <tt>hg heads</tt>
+
*<code>hg heads</code>
 
::what are all the "tree leaves" ? (commits which are not a parent to a later commit)
 
::what are all the "tree leaves" ? (commits which are not a parent to a later commit)
* <tt>hg log -l <u>N</u></tt>
+
*<code>hg log -l <u>N</u></code>
 
::(where <u>N</u> is a number): show the <u>N</u> latest commits, with relative number and short hash, branch name if any, tags if any, parent(s) if not, or not only, the immediately older commit, and description (commit message)
 
::(where <u>N</u> is a number): show the <u>N</u> latest commits, with relative number and short hash, branch name if any, tags if any, parent(s) if not, or not only, the immediately older commit, and description (commit message)
* <tt>hg log -l <u>N</u> -f</tt>
+
*<code>hg log -l <u>N</u> -f</code>
 
::same as above, but only for the current tip and its parents and ancestors.
 
::same as above, but only for the current tip and its parents and ancestors.
* <tt>hg incoming</tt>
+
*<code>hg incoming</code>
::tells you (in the same format as <tt>hg log</tt>) which changesets (if any) are waiting for you to pull them.
+
::tells you (in the same format as <code>hg log</code>) which changesets (if any) are waiting for you to pull them.
* <tt>hg diff -r ''xxxxxxxxxxxx'' [-r ''yyyyyyyyyyyy''] [<u>file</u> ...]</tt>
+
*<code>hg diff -r ''xxxxxxxxxxxx'' [-r ''yyyyyyyyyyyy''] [<u>file</u> ...]</code>
 
::where ''xxxxxxxxxxxx'' (and ''yyyyyyyyyyyy'' if present) are revision IDs: Produce a diff of the file(s) named, as they changed between the named revisions. With only one revision: compare it to the current tip. With no filenames: give <u>all</u> differences between these revisions.
 
::where ''xxxxxxxxxxxx'' (and ''yyyyyyyyyyyy'' if present) are revision IDs: Produce a diff of the file(s) named, as they changed between the named revisions. With only one revision: compare it to the current tip. With no filenames: give <u>all</u> differences between these revisions.
 
::'''Notes:'''
 
::'''Notes:'''
 
:# Contrary to what is said in the manpage, with no revision there is no output.
 
:# Contrary to what is said in the manpage, with no revision there is no output.
:# I find it useful to use <span style="background-color: #CFC"><tt>|view -</tt></span> as a pager for the output of this command. Then a simple <tt>:saveas <u>patchname</u>.diff</tt> will, if you want to, create the patch file after you review it.
+
:# I find it useful to use <span style="background-color: #CFC"><code>|view -</code></span> as a pager for the output of this command. Then a simple <code>:saveas <u>patchname</u>.diff</code> will, if you want to, create the patch file after you review it.
:# To always use <tt>view</tt> as pager for the more "bulky" output-producing Mercurial commands, add the following to your <tt>~/.hgrc</tt> file (or, on Windows, your <tt>%USERPROFILE%\Mercurial.ini</tt>):
+
:# To always use <code>view</code> as pager for the more "bulky" output-producing Mercurial commands, add the following to your <code>~/.hgrc</code> file (or, on Windows, your <code>%USERPROFILE%\Mercurial.ini</code>):
 
<pre>
 
<pre>
 
[extensions]
 
[extensions]
Line 195: Line 214:
 
</pre>
 
</pre>
 
— [[User:Tonymec|Tonymec]] 09:43, May 24, 2010 (UTC)
 
— [[User:Tonymec|Tonymec]] 09:43, May 24, 2010 (UTC)
----
 
   
 
===Changing branches===
 
===Changing branches===
Changing branches is one of the functions of the <tt>hg update</tt> command (which has <tt>up</tt> as an alias) — in general, its function is to "update" the files in the current repository (the "working copy" as Mercurial names it) to any revision you specify. So:
+
Changing branches, or going to a "tagged" revision, are two of the functions of the <code>hg update</code> command (which has <code>up</code> as an alias) — in general, its function is to "update" the files in the current repository (the "working copy" as Mercurial names it) to any revision you specify. So:
====To go to the Vim 7.3 source====
+
====To go to the Vim 7.2 source====
<pre>hg up vim73</pre>
+
<pre>hg up vim72</pre>
  +
====To go back to Vim 7.2====
+
====To go back to the latest sources====
 
<pre>hg up default</pre>
 
<pre>hg up default</pre>
====To clone a new repository and immediately set it up for Vim 7.3====
 
<pre>
 
hg clone -U https://vim.googlecode.com/hg/ vim73a
 
cd vim73a
 
hg update vim73
 
</pre>
 
The <tt>-U</tt> switch avoids an unnecessary pull of the Vim 7.2 source.<br>
 
— [[User:Tonymec|Tonymec]] 23:08, May 23, 2010 (UTC)
 
----
 
Tony: I haven't had an opportunity to seriously read this, but as part of my normal "standard format" I notice that there are unexpected trailing spaces. They don't matter, but I like to get the stuff I can understand sorted... I'm pretty sure the space after <tt>hgext.fetch =</tt> is redundant, and nearly all the spaces in the "Patch your <tt>.hgignore</tt> file" section can be deleted. But then I noticed that the leading spaces look a bit odd. There's no need to explain it to me, but I don't understand the "diff -r 2bd29808d1f6 -r a5e628a08c4e .hgignore" line (but it's ignored by the patch), and I expected two spaces in front of most the diff lines. Anyway, if there is anything which needs fixing (like redundant trailing spaces, or the leading two characters in the patch), please do so. Use <tt>&amp;nbsp;</tt> for the last trailing space on any lines which require leading spaces so I don't accidentally remove them later. Thanks. [[User:JohnBeckett|JohnBeckett]] 01:56, May 24, 2010 (UTC)
 
 
:The trailing spaces in the patch come from copy-pasting from konsole, I've removed them. The diff -r (etc.) line is part of the output of hg diff (as I got that patch by doing an hg diff between .hgignore before and after I changed it). The patch program will consider that line as what its manpage names "leading garbage" as it does the "Problem" "Solution" and "Files" headers in Bram's patches -- IOW, it is not necessary but doesn't hurt. The problem with &amp;nbsp; on the otherwise empty lines of a patch is that the patch program needs a true space (0x20), not a no-break space (0xA0). — [[User:Tonymec|Tonymec]] 09:13, May 24, 2010 (UTC)
 
   
  +
====To go to a specific patchlevel====
:P.S. One of the differences between "unified diff" (as produced by hg diff and by diff -u, with added and removed lines in a single section) and "traditional" context diffs (as produced by diff -c, with separate sections relating to the "old" and the "new" file) is that traditional context diffs have one space between the initial ! (changed), + (added), - (removed), space (unchanged) and the line text, while in unified diffs the line text immediately follows the initial + - or space. — [[User:Tonymec|Tonymec]] 09:25, May 24, 2010 (UTC)
 
  +
(only for 7.3.142 or later)
::OK but have a look at [[Cscope#Generating the database]]: That patch contains <tt>&amp;nbsp;</tt> for trailing spaces and three browsers I have tried copy 0x20 out of the rendered window. Are you saying that some browsers will copy the trailing spaces on that page as 0xA0? If you now think <tt>&amp;nbsp;</tt> is ok, please just make the change and delete these comments as redundant. [[User:JohnBeckett|JohnBeckett]] 05:06, May 26, 2010 (UTC)
 
  +
<pre>hg up v7-3-155</pre>
:::Ah, sorry, I hadn't checked. This "no-break" space indeed gets pasted into gvim as 0x20. Don't know if it's my browser (SeaMonkey 2.1a1pre) or the Wikimedia software that does it. — [[User:Tonymec|Tonymec]] 09:39, May 26, 2010 (UTC)
 

Revision as of 10:58, 23 February 2014

Tip 1653 Printable Monobook Previous Next

created May 14, 2010 · complexity basic · author Tonymec · version 7.0


This tip describes how to get the Vim source from the new Mercurial repository. It assumes that you know how to compile Vim once you have the source. Examples are for Linux but it shouldn't be hard to adapt them to whatever OS you're running on (provided of course that there exists a version of Mercurial that runs on your OS). Also, the examples are written for GNU make: in case of doubt, try replacing make by gmake everywhere.

First time only: Creating your repository

Make sure that Mercurial and Python are installed on your system

For example, check there is a program named hg and another named python in your PATH. If you haven't got Mercurial, install it, either (if available) by installing the Mercurial package from your distro, or else from the Mercurial site. As of May 2010 the Python version required by the Mercurial package is Python 2.4, but it seems to work fine with later versions like Python 2.6.2.

If you're uncomfortable with a command-line interface (or simply prefer a GUI), there are options available such as TortoiseHg to simplify common tasks with an easy-to-use GUI front-end. On Windows, the installer even includes Python and a command-line hg tool, so that you get everything you need in one package.

Install a copy of Bram's latest source, runtime and ancillary files

1. Set up a directory head "for building" and cd to it, e.g. (on Linux)

mkdir -p ~/.build/hg
cd ~/.build/hg

2. Clone Bram's repository (this may take some time, depending on the speed of your CPU and Internet connection):

(date && hg clone https://vim.googlecode.com/hg/ vim) 2>&1 |tee hg-vim.log

The above is slightly more complicated than absolutely necessary because it can be useful to keep a running log. The important part starts with hg and ends immediately before the right parenthesis. Similarly for other hg commands below.

Simple case: Getting new patches

This applies if all of the following are true:

  • You have no local changes to the Vim source, ancillary and runtime files (including the Makefile; you can easily compile a custom Vim with no Makefile changes, as detailed in the compiling "how to" pages below)
  • You compile only one Vim and therefore don't use a shadow directory
  • You don't build a cscope database inside the Vim source tree

In this case, all you need to check for (and, if necessary, get) any changes to the Vim source is:

cd ~/.build/hg/vim
(date && hg pull -u) 2>&1 |tee -a ../hg-vim.log

Complex case: You have local changes and/or compile several Vim versions

Enable the fetch extension

Add the following to the .hg/hgrc file in your repository (it was created by the clone process, with Bram's repository as the default remote source):

[extensions]
hgext.fetch =

No need to add anything after the equal sign, this extension comes packed with Mercurial (but disabled by default)

Patch your .hgignore file

It is found at the top level of your repository. This step is unnecessary if you have neither additional help files nor additional Vim versions and you don't add a cscope database inside the Vim source tree. Copy the following patch and apply it with patch -p1 < hgignore.diff from the top directory where the file resides.

diff -r 2bd29808d1f6 -r a5e628a08c4e .hgignore
--- a/.hgignore Fri May 14 18:56:38 2010 +0200
+++ b/.hgignore Fri May 14 20:05:50 2010 +0200
@@ -30,12 +30,25 @@ src/auto/pathdef.c
 *.res
 *.RES
 src/pathdef.c
 src/Obj*/pathdef.c
 gvimext.dll
 gvimext.lib
 
 # All platforms
+runtime/doc/tags
 *.rej
 *.orig
 *.mo
 *~
+
+# shadow directories
+# the directory names could be anything but we restrict them
+# to shadow (the default) or shadow-*
+src/shadow
+src/shadow-*
+# src/runtime and src/pixmaps are softlinks needed for proper 'make install'
+# when in a shadow directory
+src/runtime
+src/pixmaps
+# avoid tracking cscope.out even if built here
+src/cscope.out

Then commit this change:

(date && hg commit -m 'Ignore shadow directories and help tag changes') 2>&1 |tee -a ../hg-vim.log

Create shadow directories

If you want to compile more than one version of Vim, create shadow directories to avoid conflicts between them. We create them with names starting with shadow- so .hgignore (after applying the above patch) will see them. Here is an example:

cd ~/.build/hg/vim/src
(date && SHADOWDIR='shadow-huge' make -e shadow) 2>&1 |tee -a ../../hg-vim.log
(date && SHADOWDIR='shadow-tiny' make -e shadow) 2>&1 |tee -a ../../hg-vim.log

The -e command-line switch is necessary so that make won't override our SHADOWDIR names with the default which is just shadow

Apply your local changes and commit them

You do this by editing the sources in the src directory. The case where you want to compile different versions of Vim with not only different configuration options but even different changes to the sources is not covered by the present tip, and neither is the case when your changes could conflict with Bram's (the changes I have consist of added sections in out-of-the-way parts of Makefile and feature.h plus Bill McCarthy's extra float functions).

Also, check that your "nonstandard" patches are mentioned in src/version.c so that they will appear in the :version output of your home-compiled Vim: here is the relevant part of mine, normally you would add one line (with a string followed by a comma) per extra patch with a /**/ comment between each of them:

static char *(extra_patches[]) =
{   /* Add your patch description below this line */
/**/
#ifdef FEAT_FLOAT
    "Extra float functions (Bill McCarthy)",
#endif
/**/
    NULL
};

Then, commit your local changes with

(date && hg commit -m 'Local source changes') 2>&1 |tee -a ../hg-vim.log

Get any new official patches and merge them with your local ones

cd ~/.build/hg/vim
(date && hg fetch --switch-parent) 2>&1 |tee -a ../hg-vim.log

The --switch-parent switch places the local directory (where changes are few and far between) as the "first" parent of any resulting merge, so that the local changes won't be removed and added back every time: this reduces the number of source files which make will see as "modified".

Before compiling, you may want to check any files listed as "merged" (possibly with the help of the hg diff function) to make sure that the changes are what you would expect.

See also

Manpages

  • man hg
  • man hgrc
  • man hgignore

The Mercurial online help

In my experience, second only to the Vim help itself. It includes the whole contents of the manpages, and more.

  • hg help
  • hg help subject

where subject is a Mercurial command (e.g. pull) or other help subject (e.g. extensions).

Note: The full text of the help is only obtained with -v or --verbose, or when the [ui] section of your hgrc (or, on Windows, Mercurial.ini) contains the line verbose=1

In this wiki

External links

Comments

Known bug: Logging and interactive merge

A problem which I haven't solved about the above method of keeping a running log, is that is doesn't mesh well with Mercurial's "interactive merge tool": if the interactive merge asks a question, you don't see it, and you will have to blind-type a guessed response.

In my experience, questions are about runtime/doc/tags being deleted locally, reintroduced on the remote repository, and the question is "Use (c)changed version or leave (d)eleted?" -- in that case I reply d and the fetch goes on. I get this on the first non-null fetch after a "make install".

If you hit Ctrl-C to break the run, you won't see what Mercurial has output so far: it is not in the log; and your local repository is left in an uncertain state: once I did this, but then "hg status" replied nothing and "hg fetch" gave an error saying local files needed update -C or merge. Finally "hg merge" (with no logging) gave me the c/d question again so I could bring back my local repo to a "sane" state by replying d then manually committing the merge (with a -m message inspired by the "description" on the remote head, as obtained with "hg heads").

Tonymec 04:39, May 18, 2010 (UTC)
Workaround: First, use hg -v incoming (see below; -v means "verbose"). No need to log this since it makes no change to the repository. If it tells you "No changes found", no need to do anything more at the moment. Otherwise, it will tell you which files will be changed if you pull. Then if runtime/doc/tags is included, you know that fetch may stop until you type d<Enter>
— If there are many new changesets, and you want to exceptionally use (just this once) vim as a pager, repeat the command like this (all on one line):
hg -v --config 'extensions.hgext.pager=' --config 'pager.pager=view -' --config 'pager.attend=incoming' incoming
where the three --config arguments mean that this single command will be run as if your hgrc included the following (in addition tothe other lines already there):
[extensions]
hgext.pager=
[pager]
pager=view -
attend=incoming
i.e. enable the pager extension, use "view -" i.e. Vim read-only from stdin, as a pager, and enable the pager for the hg incoming command. — Tonymec 21:42, July 7, 2010 (UTC)

I finally found how to force Python programs (including Mercurial, which is written in Python) to always use unbuffered I/O on stdin, stdout and stderr. Simple: set the environment variable PYTHONUNBUFFERED to some nonempty string.

Example (for the bash shell on Unix-like systems):

cd ~/.build/hg/vim
PYTHONUNBUFFERED='unbuffered' (date && hg fetch --switch-parent) 2>&1 |tee -a ../hg-vim.log
CAUTION: It might be unwise to do this in your permanent environment, since unbuffering means more frequent and smaller transfers, thus reducing throughput. You may want to do it only when logging via |tee

Tonymec (talk) 02:56, July 16, 2012 (UTC)

Useful commands to "get information"

  • hg -v help
  • hg -v help |less
what are the basic hg commands, and what do they do?
  • hg -v help command
(where command is a Mercurial command) what are the possible arguments to that command (and what do they mean)?
(-v or --verbose is necessary to get the full text of the concerned help section)
  • hg status
are there local files waiting for a disposition (commit possibly preceded by add and/or forget)? The reply is one filename per line, preceded by A (added to the list of tracked files), M (merged), D (deleted i.e. specifically not tracked), ? (new file, neither "tracked" nor "not tracked" yet).
  • hg heads
what are all the "tree leaves" ? (commits which are not a parent to a later commit)
  • hg log -l N
(where N is a number): show the N latest commits, with relative number and short hash, branch name if any, tags if any, parent(s) if not, or not only, the immediately older commit, and description (commit message)
  • hg log -l N -f
same as above, but only for the current tip and its parents and ancestors.
  • hg incoming
tells you (in the same format as hg log) which changesets (if any) are waiting for you to pull them.
  • hg diff -r xxxxxxxxxxxx [-r yyyyyyyyyyyy] [file ...]
where xxxxxxxxxxxx (and yyyyyyyyyyyy if present) are revision IDs: Produce a diff of the file(s) named, as they changed between the named revisions. With only one revision: compare it to the current tip. With no filenames: give all differences between these revisions.
Notes:
  1. Contrary to what is said in the manpage, with no revision there is no output.
  2. I find it useful to use |view - as a pager for the output of this command. Then a simple :saveas patchname.diff will, if you want to, create the patch file after you review it.
  3. To always use view as pager for the more "bulky" output-producing Mercurial commands, add the following to your ~/.hgrc file (or, on Windows, your %USERPROFILE%\Mercurial.ini):
[extensions]
hgext.pager=
[pager]
pager = view -
attend = annotate, cat, diff, export, glog, log, qdiff

Tonymec 09:43, May 24, 2010 (UTC)

Changing branches

Changing branches, or going to a "tagged" revision, are two of the functions of the hg update command (which has up as an alias) — in general, its function is to "update" the files in the current repository (the "working copy" as Mercurial names it) to any revision you specify. So:

To go to the Vim 7.2 source

hg up vim72

To go back to the latest sources

hg up default

To go to a specific patchlevel

(only for 7.3.142 or later)

hg up v7-3-155