hg history (was: Re: Strange changeset in kernel repo)

Thomas Arendsen Hein thomas at intevation.de
Fri Jul 1 02:56:41 CDT 2005


* Matt Mackall <mpm at selenic.com> [20050628 09:14]:
> > * Matt Mackall <mpm at selenic.com> [20050628 08:08]:
> > > hg history               -> everything
> > > hg history -r <x>        -> show one entry
> > > hg history -r <x> -r <x> -> show a range, inclusive
> 
>  0---1---2---3---4---5
>   <d> <d> <d> <d> <d>
> 
> Then 'hg history -r 0 -r 5' shows you the points on the history, while
> 'hg diff -r 0 -r 5' shows you the deltas between the points.

Ok, you convinced me, patch attached and pullable.

Giving longer lists is still possible with more than two -r
arguments, e.g. displaying only tip and 0.6 with:

hg log -r tip -r tip -r 0.6
       \___range___/

While "hg log -r tip -r 0.6" would yield in listing all changesets
between tip and 0.6 (inclusive, descending).


RFD (I don't know if this is good):
 Somebody mentioned that there are too many hg commands.
 Should 'hg tip' be removed in favour of 'hg log -rtip'?
 There also is 'hg heads' which always includes tip, too.

Thomas

-- 
Email: thomas at intevation.de
http://intevation.de/~thomas/
-------------- next part --------------
# HG changeset patch
# User Thomas Arendsen Hein <thomas at intevation.de>
# Node ID 2204311609a08017171372e6be13304222dccaa1
# Parent  4fc63e22b1fe707bb542ab1149403daa9a77cdf8

Allow specifying revisions in 'hg log' like with 'hg diff'.

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Allow specifying revisions in 'hg log' like with 'hg diff'.

manifest hash: 62d48dbaa0213b36f08dc15bc3b1a1f35ecd89f0
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFCxPbeW7P1GVgWeRoRApOgAJsFYCQ8EEpYDQz8t53bRXfrP/MXwwCfWDV5
dLv6zwG6/I++SyChFkTPfAY=
=cg0V
-----END PGP SIGNATURE-----

diff -r 4fc63e22b1fe -r 2204311609a0 doc/hg.1.txt
--- a/doc/hg.1.txt	Fri Jul  1 07:28:16 2005
+++ b/doc/hg.1.txt	Fri Jul  1 07:55:10 2005
@@ -167,13 +167,18 @@
 init::
     Initialize a new repository in the current directory.
 
-log [file]::
+log [-r revision ...] [file]::
     Print the revision history of the specified file or the entire project.
 
     By default this command outputs: changeset id and hash, tags,
     parents, user, date and time, and a summary for each commit. The
     -v switch adds some more detail, such as changed files, manifest
     hashes or message signatures.
+
+    When a revision argument is given, only this file or changelog revision
+    is displayed. With two revision arguments all revisions in this range
+    are listed. Additional revision arguments may be given repeating the above
+    cycle.
 
     aliases: history
 
diff -r 4fc63e22b1fe -r 2204311609a0 mercurial/commands.py
--- a/mercurial/commands.py	Fri Jul  1 07:28:16 2005
+++ b/mercurial/commands.py	Fri Jul  1 07:55:10 2005
@@ -515,16 +515,28 @@
         sys.exit(1)
     repo = hg.repository(ui, ".", create=1)
 
-def log(ui, repo, f = None):
+def log(ui, repo, f=None, **opts):
     """show the revision history of the repository or a single file"""
     if f:
-        f = relpath(repo, [f])[0]
-        r = repo.file(f)
-        for i in range(r.count() - 1, -1, -1):
-            show_changeset(ui, repo, filelog=r, rev=i)
-    else:
-        for i in range(repo.changelog.count() - 1, -1, -1):
-            show_changeset(ui, repo, rev=i)
+        filelog = repo.file(relpath(repo, [f])[0])
+        log = filelog
+        lookup = filelog.lookup
+    else:
+        filelog = None
+        log = repo.changelog
+        lookup = repo.lookup
+    revlist = []
+    revs = [log.rev(lookup(rev)) for rev in opts['rev']]
+    while revs:
+        if len(revs) == 1:
+            revlist.append(revs.pop(0))
+        else:
+            a = revs.pop(0)
+            b = revs.pop(0)
+            off = a > b and -1 or 1
+            revlist.extend(range(a, b + off, off))
+    for i in revlist or range(log.count() - 1, -1, -1):
+        show_changeset(ui, repo, filelog=filelog, rev=i)
 
 def manifest(ui, repo, rev = []):
     """output the latest or given revision of the project manifest"""
@@ -765,7 +777,9 @@
                       ('b', 'base', "", 'base path')],
                      "hg import [options] <patches>"),
     "init": (init, [], 'hg init'),
-    "log|history": (log, [], 'hg log [file]'),
+    "log|history": (log,
+                    [('r', 'rev', [], 'revision')],
+                    'hg log [-r A] [-r B] [file]'),
     "manifest": (manifest, [], 'hg manifest [rev]'),
     "parents": (parents, [], 'hg parents [node]'),
     "pull": (pull,


More information about the Mercurial mailing list