[PATCH] commands: add more robust support for 'hg log -b' (issue2078)
Steve Losh
steve at stevelosh.com
Sun Apr 18 17:53:08 CDT 2010
On Apr 18, 2010, at 6:50 PM, Steve Losh wrote:
> # HG changeset patch
> # User Steve Losh <steve at stevelosh.com>
> # Date 1271115205 14400
> # Node ID a9a1f76c20d5192aad7175626ed616b49b6f9cb8
> # Parent 3e9dee04cab9fc58388ff87c588f37b1fd15d11f
> commands: add more robust support for 'hg log -b' (issue2078)
>
> Fixes issue2078 and adds tests to cover various 'hg log -b' uses.
>
> This change adds a localrepo.lookupbranch(key, remote=None) function. This
> will look up the branch of the revision with the given key. The algorithm
> works like this:
>
> * If a remote repo is given and KEY is the name of a branch in that repo,
> return KEY.
> * If no remote repo is given and KEY is the name of a branch in the local
> repo object, return KEY.
> * Otherwise look up the revision with the identifier KEY in the local repo
> and return its branch.
>
> This change also makes 'hg log -b' use this new functionality and adds a few
> tests for it.
I forgot to mention -- this changes the behavior of 'hg log -b 'non-existant-branch-or-rev' to raise an error if the given key is not the name of a branch or revision. Previously 'hg log -b 'non-existant-branch-or-rev' would simply print nothing.
This new behavior is consistent with the behavior of 'hg log -r non-existant-rev'.
>
> diff --git a/mercurial/commands.py b/mercurial/commands.py
> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -2151,20 +2151,21 @@
>
> endrev = None
> if opts.get('copies') and opts.get('rev'):
> endrev = max(cmdutil.revrange(repo, opts.get('rev'))) + 1
>
> df = False
> if opts["date"]:
> df = util.matchdate(opts["date"])
>
> opts['branch'] += opts.get('only_branch')
> + opts['branch'] = [repo.lookupbranch(b) for b in opts['branch']]
>
> displayer = cmdutil.show_changeset(ui, repo, opts, True, matchfn)
> def prep(ctx, fns):
> rev = ctx.rev()
> parents = [p for p in repo.changelog.parentrevs(rev)
> if p != nullrev]
> if opts.get('no_merges') and len(parents) == 2:
> return
> if opts.get('only_merges') and len(parents) != 2:
> return
> diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
> --- a/mercurial/localrepo.py
> +++ b/mercurial/localrepo.py
> @@ -448,20 +448,28 @@
> if key in self.dirstate.parents():
> raise error.Abort(_("working directory has unknown parent '%s'!")
> % short(key))
> try:
> if len(key) == 20:
> key = hex(key)
> except:
> pass
> raise error.RepoLookupError(_("unknown revision '%s'") % key)
>
> + def lookupbranch(self, key, remote=None):
> + repo = remote or self
> + if key in repo.branchmap():
> + return key
> +
> + repo = (remote and remote.local()) and remote or self
> + return repo[key].branch()
> +
> def local(self):
> return True
>
> def join(self, f):
> return os.path.join(self.path, f)
>
> def wjoin(self, f):
> return os.path.join(self.root, f)
>
> def rjoin(self, f):
> diff --git a/tests/test-log b/tests/test-log
> --- a/tests/test-log
> +++ b/tests/test-log
> @@ -155,14 +155,26 @@
>
> echo '% log -b default'
> hg log -b default
>
> echo '% log -b test'
> hg log -b test
>
> echo '% log -b dummy'
> hg log -b dummy
>
> +echo '% log -b .'
> +hg log -b .
> +
> echo '% log -b default -b test'
> hg log -b default -b test
>
> +echo '% log -b default -b .'
> +hg log -b default -b .
> +
> +echo '% log -b . -b test'
> +hg log -b . -b test
> +
> +echo '% log -b 2'
> +hg log -b 2
> +
> exit 0
> diff --git a/tests/test-log.out b/tests/test-log.out
> --- a/tests/test-log.out
> +++ b/tests/test-log.out
> @@ -353,20 +353,36 @@
> date: Thu Jan 01 00:00:00 1970 +0000
> summary: commit on test
>
> changeset: 1:d32277701ccb
> branch: test
> user: test
> date: Thu Jan 01 00:00:00 1970 +0000
> summary: commit on test
>
> % log -b dummy
> +abort: unknown revision 'dummy'!
> +% log -b .
> +changeset: 3:f5d8de11c2e2
> +branch: test
> +tag: tip
> +parent: 1:d32277701ccb
> +user: test
> +date: Thu Jan 01 00:00:00 1970 +0000
> +summary: commit on test
> +
> +changeset: 1:d32277701ccb
> +branch: test
> +user: test
> +date: Thu Jan 01 00:00:00 1970 +0000
> +summary: commit on test
> +
> % log -b default -b test
> changeset: 3:f5d8de11c2e2
> branch: test
> tag: tip
> parent: 1:d32277701ccb
> user: test
> date: Thu Jan 01 00:00:00 1970 +0000
> summary: commit on test
>
> changeset: 2:c3a4f03cc9a7
> @@ -379,10 +395,63 @@
> branch: test
> user: test
> date: Thu Jan 01 00:00:00 1970 +0000
> summary: commit on test
>
> changeset: 0:24427303d56f
> user: test
> date: Thu Jan 01 00:00:00 1970 +0000
> summary: commit on default
>
> +% log -b default -b .
> +changeset: 3:f5d8de11c2e2
> +branch: test
> +tag: tip
> +parent: 1:d32277701ccb
> +user: test
> +date: Thu Jan 01 00:00:00 1970 +0000
> +summary: commit on test
> +
> +changeset: 2:c3a4f03cc9a7
> +parent: 0:24427303d56f
> +user: test
> +date: Thu Jan 01 00:00:00 1970 +0000
> +summary: commit on default
> +
> +changeset: 1:d32277701ccb
> +branch: test
> +user: test
> +date: Thu Jan 01 00:00:00 1970 +0000
> +summary: commit on test
> +
> +changeset: 0:24427303d56f
> +user: test
> +date: Thu Jan 01 00:00:00 1970 +0000
> +summary: commit on default
> +
> +% log -b . -b test
> +changeset: 3:f5d8de11c2e2
> +branch: test
> +tag: tip
> +parent: 1:d32277701ccb
> +user: test
> +date: Thu Jan 01 00:00:00 1970 +0000
> +summary: commit on test
> +
> +changeset: 1:d32277701ccb
> +branch: test
> +user: test
> +date: Thu Jan 01 00:00:00 1970 +0000
> +summary: commit on test
> +
> +% log -b 2
> +changeset: 2:c3a4f03cc9a7
> +parent: 0:24427303d56f
> +user: test
> +date: Thu Jan 01 00:00:00 1970 +0000
> +summary: commit on default
> +
> +changeset: 0:24427303d56f
> +user: test
> +date: Thu Jan 01 00:00:00 1970 +0000
> +summary: commit on default
> +
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list