annotate tracext/hg/backend.py @ 17:32fd17a943f7 1.0

Merge from 0.12
author cboos
date Mon, 17 Sep 2012 20:49:05 +0200
parents 62e59cafa3de 2706330d90cb
children 985671b91ce4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
2 #
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
3 # Copyright (C) 2005-2012 Edgewall Software
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
4 # Copyright (C) 2005-2012 Christian Boos <cboos@edgewall.org>
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
5 # All rights reserved.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
6 #
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
7 # This software may be used and distributed according to the terms
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
8 # of the GNU General Public License, incorporated herein by reference.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
9 #
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
10 # This software consists of voluntary contributions made by many
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
11 # individuals. For the exact contribution history, see the revision
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
12 # history and logs, available at http://trac.edgewall.org/log/.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
13 #
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
14 # Author: Christian Boos <cboos@edgewall.org>
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
15
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
16 from bisect import bisect
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
17 from datetime import datetime
3
8af21bda2b3e #10515: rework the way we retrieve the last change on directories.
Christian Boos <christian.boos@free.fr>
parents: 2
diff changeset
18 from heapq import heappop, heappush
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
19 import os
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
20 import time
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
21 import posixpath
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
22 import re
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
23 import sys
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
24
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
25 import pkg_resources
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
26
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
27 from genshi.builder import tag
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
28
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
29 from trac.core import *
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
30 from trac.config import BoolOption, ChoiceOption, ListOption, PathOption
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
31 from trac.env import ISystemInfoProvider
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
32 from trac.util import arity
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
33 from trac.util.datefmt import FixedOffset, utc
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
34 from trac.util.text import exception_to_unicode, shorten_line, to_unicode
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
35 from trac.util.translation import domain_functions
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
36 from trac.versioncontrol.api import Changeset, Node, Repository, \
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
37 IRepositoryConnector, RepositoryManager, \
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
38 NoSuchChangeset, NoSuchNode
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
39 from trac.versioncontrol.web_ui import IPropertyRenderer, RenderedProperty
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
40 from trac.wiki import IWikiSyntaxProvider
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
41
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
42 # -- plugin i18n
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
43
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
44 gettext, _, tag_, N_, add_domain = \
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
45 domain_functions('tracmercurial',
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
46 ('gettext', '_', 'tag_', 'N_', 'add_domain'))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
47
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
48 # -- Using internal Mercurial API, see:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
49 # * http://mercurial.selenic.com/wiki/MercurialApi
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
50 # * http://mercurial.selenic.com/wiki/ApiChanges
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
51
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
52 hg_import_error = []
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
53 try:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
54 # The new `demandimport` mechanism doesn't play well with code relying
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
55 # on the `ImportError` exception being caught.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
56 # OTOH, we can't disable `demandimport` because mercurial relies on it
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
57 # (circular reference issue). So for now, we activate `demandimport`
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
58 # before loading mercurial modules, and desactivate it afterwards.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
59 #
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
60 # See http://www.selenic.com/mercurial/bts/issue605
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
61
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
62 try:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
63 from mercurial import demandimport
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
64 demandimport.enable();
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
65 except ImportError, hg_import_error:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
66 demandimport = None
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
67
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
68 from mercurial import hg
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
69 from mercurial.context import filectx
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
70 from mercurial.ui import ui
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
71 from mercurial.node import hex, short, nullid, nullrev
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
72 from mercurial.util import pathto, cachefunc
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
73 from mercurial import cmdutil
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
74 from mercurial import encoding
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
75 from mercurial import extensions
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
76 from mercurial.extensions import loadall
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
77 from mercurial.error import RepoLookupError
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
78
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
79 # Note: due to the nature of demandimport, there will be no actual
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
80 # import error until those symbols get accessed, so here we go:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
81 for sym in ("filectx ui hex short nullid pathto "
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
82 "cachefunc loadall".split()):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
83 if repr(globals()[sym]) == "<unloaded module '%s'>" % sym:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
84 hg_import_error.append(sym)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
85 if hg_import_error:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
86 hg_import_error = "Couldn't import symbols: "+','.join(hg_import_error)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
87
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
88 # Mercurial versions >= 1.2 won't have mercurial.repo.RepoError anymore
11
45f04cd0ada8 Add support for Mercurial 2.3+ (post- hg:1ac628cd7113)
Christian Boos <cboos@edgewall.org>
parents: 0
diff changeset
89 try:
45f04cd0ada8 Add support for Mercurial 2.3+ (post- hg:1ac628cd7113)
Christian Boos <cboos@edgewall.org>
parents: 0
diff changeset
90 from mercurial.repo import RepoError
45f04cd0ada8 Add support for Mercurial 2.3+ (post- hg:1ac628cd7113)
Christian Boos <cboos@edgewall.org>
parents: 0
diff changeset
91 except ImportError: # Mercurial 2.3.1 doesn't even have mercurial.repo!
45f04cd0ada8 Add support for Mercurial 2.3+ (post- hg:1ac628cd7113)
Christian Boos <cboos@edgewall.org>
parents: 0
diff changeset
92 RepoError = None
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
93 from mercurial.revlog import LookupError as HgLookupError
11
45f04cd0ada8 Add support for Mercurial 2.3+ (post- hg:1ac628cd7113)
Christian Boos <cboos@edgewall.org>
parents: 0
diff changeset
94 if RepoError is None or repr(RepoError) == "<unloaded module 'RepoError'>":
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
95 from mercurial.error import RepoError, LookupError as HgLookupError
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
96
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
97 # Force local encoding to be non-lossy (#7217)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
98 os.environ['HGENCODING'] = 'utf-8'
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
99 encoding.tolocal = str
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
100
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
101 if demandimport:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
102 demandimport.disable()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
103
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
104 # API compatibility (watch http://mercurial.selenic.com/wiki/ApiChanges)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
105
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
106 if hasattr(cmdutil, 'match'):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
107 def match(ctx, *args, **kwargs):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
108 return cmdutil.match(ctx._repo, *args, **kwargs)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
109 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
110 from mercurial.scmutil import match
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
111
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
112
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
113 except ImportError, e:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
114 hg_import_error = e
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
115 ui = object
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
116
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
117
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
118 ### Helpers
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
119
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
120 def checked_encode(u, encodings, check):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
121 """Convert `unicode` to `str` trying several encodings until a
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
122 condition is met.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
123
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
124 :param u: the `unicode` input
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
125 :param encodings: the list of possible encodings
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
126 :param check: the predicate to satisfy
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
127
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
128 :return: the first converted `str` if `check(s)` is `True`,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
129 otherwise `None`. Note that if no encoding is able to
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
130 successfully convert the input, the empty string will be
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
131 given to `check`, which can accept it as valid or not.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
132 """
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
133 s = u
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
134 if isinstance(u, unicode):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
135 for enc in encodings:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
136 try:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
137 s = u.encode(enc)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
138 if check(s):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
139 return s
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
140 except UnicodeEncodeError:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
141 pass
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
142 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
143 s = ''
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
144 if check(s):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
145 return s
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
146
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
147
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
148 class trac_ui(ui):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
149 # Note: will be dropped in 0.13, see MercurialConnector._setup_ui
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
150 def __init__(self, *args, **kwargs):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
151 ui.__init__(self, *args)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
152 self.setconfig('ui', 'interactive', 'off')
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
153 self.log = kwargs.get('log', args and args[0].log or None)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
154
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
155 def write(self, *args, **opts):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
156 for a in args:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
157 self.log.info('(mercurial status) %s', a)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
158
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
159 def write_err(self, *args, **opts):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
160 for a in args:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
161 self.log.warn('(mercurial warning) %s', a)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
162
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
163 def plain(self, *args, **kw):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
164 return False # so that '[hg] hgrc' file can specify [ui] options
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
165
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
166 def interactive(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
167 return False
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
168
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
169 def readline(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
170 raise TracError('*** Mercurial ui.readline called ***')
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
171
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
172
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
173 ### Components
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
174
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
175 class CsetPropertyRenderer(Component):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
176
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
177 implements(IPropertyRenderer)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
178
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
179 def match_property(self, name, mode):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
180 return (name.startswith('hg-') and
4
f261cc084df2 #10527: add bookmark support, shown as properties.
Christian Boos <cboos@edgewall.org>
parents: 3
diff changeset
181 name[3:] in ('Parents', 'Children', 'Tags', 'Branch',
f261cc084df2 #10527: add bookmark support, shown as properties.
Christian Boos <cboos@edgewall.org>
parents: 3
diff changeset
182 'Bookmarks') and
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
183 mode == 'revprop') and 4 or 0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
184
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
185 def render_property(self, name, mode, context, props):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
186 return RenderedProperty(name=gettext(name[3:] + ':'),
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
187 name_attributes=[("class", "property")],
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
188 content=self._render_property(name, mode, context, props))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
189
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
190 def _render_property(self, name, mode, context, props):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
191 repos, revs = props[name]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
192
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
193 if name in ('hg-Parents', 'hg-Children'):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
194 label = repos.display_rev
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
195 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
196 label = lambda rev: rev
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
197
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
198 def link(rev):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
199 chgset = repos.get_changeset(rev)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
200 return tag.a(label(rev), class_="changeset",
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
201 title=shorten_line(chgset.message),
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
202 href=context.href.changeset(rev, repos.reponame))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
203
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
204 if name == 'hg-Parents' and len(revs) == 2: # merge
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
205 new = context.resource.id
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
206 parent_links = [
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
207 (link(rev), ' (',
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
208 tag.a('diff', title=_("Diff against this parent "
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
209 "(show the changes merged from the other parents)"),
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
210 href=context.href.changeset(new, repos.reponame,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
211 old=rev)), ')')
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
212 for rev in revs]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
213 return tag([(parent, ', ') for parent in parent_links[:-1]],
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
214 parent_links[-1], tag.br(),
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
215 tag.span(tag_("Note: this is a %(merge)s changeset, "
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
216 "the changes displayed below correspond "
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
217 "to the merge itself.",
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
218 merge=tag.strong('merge')),
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
219 class_='hint'), tag.br(),
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
220 # TODO: only keep chunks present in both parents
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
221 # (conflicts) or in none (extra changes)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
222 # tag.span('No changes means the merge was clean.',
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
223 # class_='hint'), tag.br(),
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
224 tag.span(tag_("Use the %(diff)s links above to see all "
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
225 "the changes relative to each parent.",
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
226 diff=tag.tt('(diff)')),
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
227 class_='hint'))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
228 return tag([tag(link(rev), ', ') for rev in revs[:-1]],
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
229 link(revs[-1]))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
230
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
231
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
232 class HgExtPropertyRenderer(Component):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
233
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
234 implements(IPropertyRenderer)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
235
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
236 def match_property(self, name, mode):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
237 return name in ('hg-transplant_source', 'hg-convert_revision') and \
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
238 mode == 'revprop' and 4 or 0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
239
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
240 def render_property(self, name, mode, context, props):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
241 repos, value = props[name]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
242 if name == 'hg-transplant_source':
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
243 try:
16
2706330d90cb Fix transplant property renderer
cboos
parents: 14
diff changeset
244 ctx = repos.changectx(value)
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
245 chgset = MercurialChangeset(repos, ctx)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
246 href = context.href.changeset(ctx.hex(), repos.reponame)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
247 link = tag.a(repos._display(ctx), class_="changeset",
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
248 title=shorten_line(chgset.message), href=href)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
249 except NoSuchChangeset:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
250 link = tag.a(hex(value), class_="missing changeset",
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
251 title=_("no such changeset"), rel="nofollow")
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
252 return RenderedProperty(name=_("Transplant:"), content=link,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
253 name_attributes=[("class", "property")])
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
254
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
255 elif name == 'hg-convert_revision':
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
256 text = repos.to_u(value)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
257 if value.startswith('svn:'):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
258 # e.g. 'svn:af82e41b-90c4-0310-8c96-b1721e28e2e2/trunk@9517'
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
259 uuid = value[:40]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
260 rev = value.rsplit('@', 1)[-1]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
261 for r in RepositoryManager(self.env).get_real_repositories():
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
262 if r.name.startswith(uuid + ':'):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
263 path = r.reponame
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
264 href = context.href.changeset(rev, path or None)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
265 text = tag.a('[%s%s]' % (rev, path and '/' + path),
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
266 class_='changeset', href=href,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
267 title=_('Changeset in source repository'))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
268 break
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
269 return RenderedProperty(name=_('Convert:'), content=text,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
270 name_attributes=[("class", "property")])
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
271
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
272
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
273 class HgDefaultPropertyRenderer(Component):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
274
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
275 implements(IPropertyRenderer)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
276
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
277 def match_property(self, name, mode):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
278 return name.startswith('hg-') and mode == 'revprop' and 1 or 0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
279
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
280 def render_property(self, name, mode, context, props):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
281 return RenderedProperty(name=name[3:] + ':',
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
282 name_attributes=[("class", "property")],
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
283 content=self._render_property(name, mode,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
284 context, props))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
285
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
286 def _render_property(self, name, mode, context, props):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
287 repos, value = props[name]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
288 try:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
289 return unicode(value)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
290 except UnicodeDecodeError:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
291 if len(value) <= 100:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
292 return tag.tt(''.join(("%02x" % ord(c)) for c in value))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
293 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
294 return tag.em(_("(binary, size greater than 100 bytes)"))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
295
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
296
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
297 class MercurialConnector(Component):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
298
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
299 implements(ISystemInfoProvider, IRepositoryConnector, IWikiSyntaxProvider)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
300
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
301 encoding = ListOption('hg', 'encoding', 'utf-8', doc="""
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
302 Encoding that should be used to decode filenames, file
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
303 content, and changeset metadata. If multiple encodings are
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
304 used for these different situations (or even multiple
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
305 encodings were used for filenames), simply specify a list of
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
306 encodings which will be tried in turn (''since 0.12.0.24'').
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
307 """)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
308
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
309 show_rev = BoolOption('hg', 'show_rev', True, doc="""
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
310 Show decimal revision in front of the commit SHA1 hash. While
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
311 this number is specific to the particular clone used to browse
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
312 the repository, this can sometimes give an useful hint about
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
313 the relative "age" of a revision.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
314 """)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
315
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
316 node_format = ChoiceOption('hg', 'node_format', ['short', 'hex'], doc="""
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
317 Specify how the commit SHA1 hashes should be
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
318 displayed. Possible choices are: 'short', the SHA1 hash is
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
319 abbreviated to its first 12 digits, or 'hex', the hash is
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
320 shown in full.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
321 """)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
322
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
323 hgrc = PathOption('hg', 'hgrc', '', doc="""
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
324 Optional path to an hgrc file which will be used to specify
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
325 extra Mercurial configuration options (see
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
326 http://www.selenic.com/mercurial/hgrc.5.html).
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
327 """)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
328
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
329 def __init__(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
330 self.ui = None
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
331 locale_dir = pkg_resources.resource_filename(__name__, 'locale')
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
332 add_domain(self.env.path, locale_dir)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
333 self._version = self._version_info = None
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
334 if not hg_import_error:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
335 try:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
336 from mercurial.version import get_version
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
337 self._version = get_version()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
338 except ImportError: # gone in Mercurial 1.2 (hg:9626819b2e3d)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
339 from mercurial.util import version
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
340 self._version = version()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
341 # development version assumed to be always the ''newest'' one,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
342 # i.e. old development version won't be supported
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
343 self._version_info = (999, 0, 0)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
344 m = re.match(r'(\d+)\.(\d+)(?:\.(\d+))?', self._version or '')
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
345 if m:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
346 self._version_info = tuple([int(n or 0) for n in m.groups()])
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
347
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
348 def _setup_ui(self, hgrc_path):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
349 # Starting with Mercurial 1.3 we can probably do simply:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
350 #
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
351 # ui = baseui.copy() # there's no longer a parent/child concept
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
352 # ui.setconfig('ui', 'interactive', 'off')
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
353 #
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
354 self.ui = trac_ui(log=self.log)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
355
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
356 # (code below adapted from mercurial.dispatch._dispatch)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
357
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
358 # read the local repository .hgrc into a local ui object
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
359 if hgrc_path:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
360 if not os.path.exists(hgrc_path):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
361 self.log.warn("'[hg] hgrc' file (%s) not found ", hgrc_path)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
362 try:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
363 self.ui = trac_ui(self.ui, log=self.log)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
364 self.ui.check_trusted = False
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
365 self.ui.readconfig(hgrc_path)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
366 except IOError, e:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
367 self.log.warn("'[hg] hgrc' file (%s) can't be read: %s",
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
368 hgrc_path, e)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
369
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
370 extensions.loadall(self.ui)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
371 if hasattr(extensions, 'extensions'):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
372 for name, module in extensions.extensions():
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
373 # setup extensions
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
374 extsetup = getattr(module, 'extsetup', None)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
375 if extsetup:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
376 if arity(extsetup) == 1:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
377 extsetup(self.ui)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
378 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
379 extsetup()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
380
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
381 # ISystemInfoProvider methods
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
382
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
383 def get_system_info(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
384 if self._version is not None:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
385 yield 'Mercurial', self._version
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
386
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
387 # IRepositoryConnector methods
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
388
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
389 def get_supported_types(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
390 """Support for `repository_type = hg`"""
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
391 if hg_import_error:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
392 self.error = hg_import_error
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
393 yield ("hg", -1)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
394 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
395 yield ("hg", 8)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
396
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
397 def get_repository(self, type, dir, params):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
398 """Return a `MercurialRepository`"""
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
399 if not self.ui:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
400 self._setup_ui(self.hgrc)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
401 repos = MercurialRepository(dir, params, self.log, self)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
402 repos.version_info = self._version_info
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
403 return repos
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
404
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
405 # IWikiSyntaxProvider methods
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
406
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
407 def get_wiki_syntax(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
408 yield (r'!?(?P<hgrev>[0-9a-f]{12,40})(?P<hgpath>/\S+\b)?',
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
409 lambda formatter, label, match:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
410 self._format_link(formatter, 'cset', match.group(0),
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
411 match.group(0), match))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
412
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
413 def get_link_resolvers(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
414 yield ('cset', self._format_link)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
415 yield ('chgset', self._format_link)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
416 yield ('branch', self._format_link) # go to the corresponding head
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
417 yield ('tag', self._format_link)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
418
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
419 def _format_link(self, formatter, ns, rev, label, fullmatch=None):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
420 reponame = path = ''
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
421 repos = None
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
422 rm = RepositoryManager(self.env)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
423 try:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
424 if fullmatch:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
425 rev = fullmatch.group('hgrev')
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
426 path = fullmatch.group('hgpath')
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
427 if path:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
428 reponame, repos, path = \
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
429 rm.get_repository_by_path(path.strip('/'))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
430 if not repos:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
431 context = formatter.context
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
432 while context:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
433 if context.resource.realm in ('source', 'changeset'):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
434 reponame = context.resource.parent.id
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
435 break
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
436 context = context.parent
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
437 repos = rm.get_repository(reponame)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
438 if repos:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
439 if ns == 'branch':
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
440 for b, n in repos.repo.branchtags().items():
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
441 if repos.to_u(b) == rev:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
442 rev = repos.repo.changelog.rev(n)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
443 break
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
444 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
445 raise NoSuchChangeset(rev)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
446 chgset = repos.get_changeset(rev)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
447 return tag.a(label, class_="changeset",
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
448 title=shorten_line(chgset.message),
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
449 href=formatter.href.changeset(rev, reponame,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
450 path))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
451 raise TracError("Repository not found")
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
452 except NoSuchChangeset, e:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
453 errmsg = to_unicode(e)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
454 except TracError:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
455 errmsg = _("Repository '%(repo)s' not found", repo=reponame)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
456 return tag.a(label, class_="missing changeset",
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
457 title=errmsg, rel="nofollow")
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
458
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
459
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
460
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
461 ### Version Control API
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
462
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
463 class MercurialRepository(Repository):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
464 """Repository implementation based on the mercurial API.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
465
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
466 This wraps an hg.repository object. The revision navigation
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
467 follows the branches, and defaults to the first parent/child in
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
468 case there are many. The eventual other parents/children are
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
469 listed as additional changeset properties.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
470 """
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
471
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
472 def __init__(self, path, params, log, connector):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
473 self.ui = connector.ui
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
474 self._show_rev = connector.show_rev
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
475 self._node_fmt = connector.node_format
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
476 # TODO 0.13: per repository ui and options
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
477
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
478 # -- encoding
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
479 encoding = connector.encoding
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
480 if not encoding:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
481 encoding = ['utf-8']
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
482 # verify given encodings
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
483 for enc in encoding:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
484 try:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
485 u''.encode(enc)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
486 except LookupError, e:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
487 log.warning("'[hg] encoding' (%r) not valid", e)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
488 if 'latin1' not in encoding:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
489 encoding.append('latin1')
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
490 self.encoding = encoding
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
491
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
492 def to_u(s):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
493 if isinstance(s, unicode):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
494 return s
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
495 for enc in encoding:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
496 try:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
497 return unicode(s, enc)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
498 except UnicodeDecodeError:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
499 pass
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
500 def to_s(u):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
501 if isinstance(u, str):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
502 return u
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
503 for enc in encoding:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
504 try:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
505 return u.encode(enc)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
506 except UnicodeEncodeError:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
507 pass
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
508 self.to_u = to_u
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
509 self.to_s = to_s
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
510
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
511 # -- repository path
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
512 self.path = str_path = path
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
513 # Note: `path` is a filesystem path obtained either from the
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
514 # trac.ini file or from the `repository` table, so it's
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
515 # normally an `unicode` instance. '[hg] encoding'
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
516 # shouldn't play a role here, but we can nevertheless
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
517 # use that as secondary choices.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
518 fsencoding = [sys.getfilesystemencoding() or 'utf-8'] + encoding
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
519 str_path = checked_encode(path, fsencoding, os.path.exists)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
520 if str_path is None:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
521 raise TracError(_("Repository path '%(path)s' does not exist.",
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
522 path=path))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
523 try:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
524 self.repo = hg.repository(ui=self.ui, path=str_path)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
525 except RepoError, e:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
526 version = connector._version
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
527 error = exception_to_unicode(e)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
528 log.error("Mercurial %s can't open repository (%s)", version, error)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
529 raise TracError(_("'%(path)s' does not appear to contain a"
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
530 " repository (Mercurial %(version)s says "
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
531 "%(error)s)",
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
532 path=path, version=version, error=error))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
533 Repository.__init__(self, 'hg:%s' % path, params, log)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
534
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
535 def from_hg_time(self, timeinfo):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
536 time, tz = timeinfo
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
537 tzinfo = FixedOffset(tz / 60, 'GMT %d:00' % (tz / 3600))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
538 return datetime.fromtimestamp(time, tzinfo)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
539
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
540 def changectx(self, rev=None):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
541 """Produce a Mercurial `context.changectx` from given Trac revision."""
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
542 return self.repo[self.short_rev(rev)]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
543
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
544 def close(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
545 self.repo = None
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
546
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
547 def normalize_path(self, path):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
548 """Remove leading "/" (even at root)"""
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
549 return path and path.strip('/') or ''
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
550
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
551 def normalize_rev(self, rev):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
552 """Return the full hash for the specified rev."""
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
553 return self.changectx(rev).hex()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
554
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
555 def short_rev(self, rev):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
556 """Find Mercurial revision number corresponding to given Trac revision.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
557
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
558 :param rev: any kind of revision specification, either an
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
559 `unicode` string, or a revision number. If `None`
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
560 or '', latest revision will be returned.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
561
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
562 :return: an integer revision
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
563 """
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
564 repo = self.repo
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
565 if rev == 0:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
566 return rev
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
567 if not rev:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
568 return len(repo) - 1
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
569 if isinstance(rev, (long, int)):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
570 return rev
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
571 if rev[0] != "'": # "'11:11'" can be a tag name?
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
572 rev = rev.split(':', 1)[0]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
573 if rev == '-1':
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
574 return nullrev
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
575 if rev.isdigit():
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
576 r = int(rev)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
577 if 0 <= r < len(repo):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
578 return r
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
579 try:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
580 return repo[repo.lookup(self.to_s(rev))].rev()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
581 except (HgLookupError, RepoError):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
582 raise NoSuchChangeset(rev)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
583
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
584 def display_rev(self, rev):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
585 return self._display(self.changectx(rev))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
586
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
587 def _display(self, ctx):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
588 """Return user-readable revision information for node `n`.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
589
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
590 The specific format depends on the `node_format` and
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
591 `show_rev` options.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
592 """
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
593 nodestr = self._node_fmt == "hex" and ctx.hex() or str(ctx)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
594 if self._show_rev:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
595 return '%s:%s' % (ctx.rev(), nodestr)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
596 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
597 return nodestr
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
598
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
599 def get_quickjump_entries(self, rev):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
600 # map ctx to (unicode) branch
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
601 branches = {}
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
602 closed_branches = {}
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
603 for b, n in self.repo.branchtags().items():
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
604 b = self.to_u(b)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
605 ctx = self.repo[n]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
606 if 'close' in ctx.extra():
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
607 closed_branches[ctx] = b
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
608 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
609 branches[ctx] = b
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
610 # map node to tag names
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
611 tags = {}
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
612 tagslist = self.repo.tagslist()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
613 for tag, n in tagslist:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
614 tags.setdefault(n, []).append(self.to_u(tag))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
615 def taginfo(ctx):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
616 t = tags.get(ctx.node())
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
617 if t:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
618 return ' (%s)' % ', '.join(t)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
619 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
620 return ''
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
621 # branches
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
622 for ctx, b in sorted(branches.items(), reverse=True,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
623 key=lambda (ctx, b): ctx.rev()):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
624 yield ('branches', b + taginfo(ctx), '/', self._display(ctx))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
625 # heads
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
626 for n in self.repo.heads():
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
627 ctx = self.repo[n]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
628 if ctx not in branches and ctx not in closed_branches:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
629 h = self._display(ctx)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
630 yield ('extra heads', h + taginfo(ctx), '/', h)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
631 # tags
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
632 for t, n in reversed(tagslist):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
633 try:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
634 yield ('tags', ', '.join(tags.pop(n)), # FIXME: pop?
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
635 '/', self._display(self.repo[n]))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
636 except (KeyError, RepoLookupError):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
637 pass
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
638 # closed branches
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
639 for ctx, b in sorted(closed_branches.items(), reverse=True,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
640 key=lambda (ctx, b): ctx.rev()):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
641 yield ('closed branches', b + taginfo(ctx), '/', self._display(ctx))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
642
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
643 def get_path_url(self, path, rev):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
644 url = self.params.get('url')
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
645 if url and (not path or path == '/'):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
646 if not rev:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
647 return url
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
648 branch = self.changectx(rev).branch()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
649 if branch == 'default':
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
650 return url
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
651 return url + '#' + self.to_u(branch) # URL for cloning that branch
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
652
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
653 # Note: link to matching location in Mercurial's file browser
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
654 #rev = rev is not None and short(n) or 'tip'
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
655 #return '/'.join([url, 'file', rev, path])
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
656
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
657 def get_changeset(self, rev):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
658 return MercurialChangeset(self, self.changectx(rev))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
659
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
660 def get_changeset_uid(self, rev):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
661 return self.changectx(rev).hex()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
662
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
663 def get_changesets(self, start, stop):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
664 """Follow each head and parents in order to get all changesets
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
665
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
666 FIXME: this can only be handled correctly and efficiently by
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
667 using the db repository cache.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
668
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
669 The code below is only an heuristic, and doesn't work in the
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
670 general case. E.g. look at the mercurial repository timeline
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
671 for 2006-10-18, you need to give ''38'' daysback in order to
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
672 see the changesets from 2006-10-17...
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
673
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
674 This is because of the following '''linear''' sequence of csets:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
675 - 3445:233c733e4af5 10/18/2006 9:08:36 AM mpm
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
676 - 3446:0b450267cf47 9/10/2006 3:25:06 AM hopper
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
677 - 3447:ef1032c223e7 9/10/2006 3:25:06 AM hopper
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
678 - 3448:6ca49c5fe268 9/10/2006 3:25:07 AM hopper
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
679 - 3449:c8686e3f0291 10/18/2006 9:14:26 AM hopper
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
680
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
681 This is most probably because [3446:3448] correspond to old
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
682 changesets that have been ''hg import''ed, with their
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
683 original dates.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
684 """
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
685 seen = {nullrev: 1}
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
686 seeds = [self.repo[n] for n in self.repo.heads()]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
687 while seeds:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
688 ctx = seeds.pop(0)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
689 time = self.from_hg_time(ctx.date())
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
690 if time < start:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
691 continue # assume no ancestor is younger and use next seed
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
692 # (and that assumption is wrong for 3448 in the example above)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
693 elif time < stop:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
694 yield MercurialChangeset(self, ctx)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
695 for p in ctx.parents():
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
696 if p.rev() not in seen:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
697 seen[p.rev()] = 1
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
698 seeds.append(p)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
699
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
700 def get_node(self, path, rev=None):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
701 return MercurialNode(self, self.normalize_path(path),
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
702 self.changectx(rev))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
703
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
704 def get_oldest_rev(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
705 return 0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
706
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
707 def get_youngest_rev(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
708 return self.changectx().hex()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
709
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
710 def previous_rev(self, rev, path=''): # FIXME: path ignored for now
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
711 for p in self.changectx(rev).parents():
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
712 if p:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
713 return p.hex() # always follow first parent
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
714
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
715 def next_rev(self, rev, path=''):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
716 ctx = self.changectx(rev)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
717 if path: # might be a file
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
718 fc = filectx(self.repo, self.to_s(path), ctx.node())
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
719 # Note: the simpler form below raises an HgLookupError for a dir
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
720 # fc = ctx.filectx(self.to_s(path))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
721 if fc: # it is a file
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
722 for c in fc.children():
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
723 return c.hex()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
724 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
725 return None
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
726 # it might be a directory (not supported for now) FIXME
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
727 for c in ctx.children():
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
728 return c.hex() # always follow first child
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
729
1
b30690538379 initialize branch:0.13 from svn
Christian Boos <christian.boos@free.fr>
parents: 0
diff changeset
730 def parent_revs(self, rev):
b30690538379 initialize branch:0.13 from svn
Christian Boos <christian.boos@free.fr>
parents: 0
diff changeset
731 return [p.hex() for p in self.changectx(rev).parents()]
b30690538379 initialize branch:0.13 from svn
Christian Boos <christian.boos@free.fr>
parents: 0
diff changeset
732
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
733 def rev_older_than(self, rev1, rev2):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
734 # FIXME use == and ancestors?
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
735 return self.short_rev(rev1) < self.short_rev(rev2)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
736
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
737 # def get_path_history(self, path, rev=None, limit=None):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
738 # (not really relevant for Mercurial)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
739
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
740 def get_changes(self, old_path, old_rev, new_path, new_rev,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
741 ignore_ancestry=1):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
742 """Generates changes corresponding to generalized diffs.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
743
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
744 Generator that yields change tuples (old_node, new_node, kind,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
745 change) for each node change between the two arbitrary
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
746 (path,rev) pairs.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
747
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
748 The old_node is assumed to be None when the change is an ADD,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
749 the new_node is assumed to be None when the change is a
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
750 DELETE.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
751 """
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
752 old_node = new_node = None
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
753 old_node = self.get_node(old_path, old_rev)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
754 new_node = self.get_node(new_path, new_rev)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
755 # check kind, both should be same.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
756 if new_node.kind != old_node.kind:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
757 raise TracError(
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
758 _("Diff mismatch: "
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
759 "Base is a %(okind)s (%(opath)s in revision %(orev)s) "
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
760 "and Target is a %(nkind)s (%(npath)s in revision %(nrev)s).",
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
761 okind=old_node.kind, opath=old_path, orev=old_rev,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
762 nkind=new_node.kind, npath=new_path, nrev=new_rev))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
763 # Correct change info from changelog(revlog)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
764 # Finding changes between two revs requires tracking back
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
765 # several routes.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
766
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
767 if new_node.isdir:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
768 # TODO: Should we follow rename and copy?
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
769 # As temporary workaround, simply compare entry names.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
770 changes = []
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
771 str_new_path = self.to_s(new_path)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
772 str_old_path = self.to_s(old_path)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
773 # additions and edits
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
774 for str_path in new_node.manifest:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
775 # changes out of scope
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
776 if str_new_path and not str_path.startswith(str_new_path + '/'):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
777 continue
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
778 # 'added' if not present in old manifest
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
779 str_op = str_old_path + str_path[len(str_new_path):]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
780 if str_op not in old_node.manifest:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
781 changes.append((str_path, None, new_node.subnode(str_path),
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
782 Node.FILE, Changeset.ADD))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
783 elif old_node.manifest[str_op] != new_node.manifest[str_path]:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
784 changes.append((str_path, old_node.subnode(str_op),
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
785 new_node.subnode(str_path),
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
786 Node.FILE, Changeset.EDIT))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
787 # deletions
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
788 for str_path in old_node.manifest:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
789 # changes out of scope
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
790 if str_old_path and not str_path.startswith(str_old_path + '/'):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
791 continue
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
792 # 'deleted' if not present in new manifest
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
793 str_np = str_new_path + str_path[len(str_old_path):]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
794 if str_np not in new_node.manifest:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
795 changes.append((str_path, old_node.subnode(str_np), None,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
796 Node.FILE, Changeset.DELETE))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
797 # Note: `str_path` only used as a key, no need to convert to_u
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
798 for change in sorted(changes, key=lambda c: c[0]):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
799 yield(change[1], change[2], change[3], change[4])
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
800 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
801 if old_node.manifest[old_node.str_path] != \
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
802 new_node.manifest[new_node.str_path]:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
803 yield(old_node, new_node, Node.FILE, Changeset.EDIT)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
804
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
805
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
806 class MercurialNode(Node):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
807 """A path in the repository, at a given revision.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
808
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
809 It encapsulates the repository manifest for the given revision.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
810
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
811 As directories are not first-class citizens in Mercurial,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
812 retrieving revision information for directory can be much slower
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
813 than for files, except when created as a `subnode()` of an
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
814 existing MercurialNode.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
815 """
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
816
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
817 filectx = dirnode = None
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
818
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
819 def __init__(self, repos, path, changectx,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
820 manifest=None, dirctx=None, str_entry=None):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
821 """
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
822 :param repos: the `MercurialRepository`
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
823 :param path: the `unicode` path corresponding to this node
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
824 :param rev: requested revision (i.e. "browsing at")
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
825 :param changectx: the `changectx` for the "requested" revision
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
826
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
827 The following parameters are passed when creating a subnode
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
828 instance:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
829
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
830 :param manifest: `manifest` object from parent `MercurialNode`
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
831 :param dirctx: `changectx` for a directory determined by
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
832 parent `MercurialNode`
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
833 :param str_entry: entry name if node created from parent node
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
834 """
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
835 repo = repos.repo
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
836 self.repos = repos
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
837 self.changectx = changectx
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
838 self.manifest = manifest or changectx.manifest()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
839 str_entries = []
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
840
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
841 if path == '' or path == '/':
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
842 str_path = ''
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
843 elif dirctx:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
844 str_path = str_entry
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
845 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
846 # Fast path: check for existing file
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
847 str_path = checked_encode(path, repos.encoding,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
848 lambda s: s in self.manifest)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
849 if str_path is None:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
850 # Slow path: this might be a directory node
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
851 str_files = sorted(self.manifest)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
852 idx = [-1]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
853 def has_dir_node(str_dir):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
854 if not str_dir: # no encoding matched, i.e. not existing
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
855 return False
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
856 idx[0] = lo = bisect(str_files, str_dir)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
857 return lo < len(str_files) \
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
858 and str_files[lo].startswith(str_dir)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
859 str_path = checked_encode(path + '/', repos.encoding,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
860 has_dir_node)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
861 if str_path is None:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
862 raise NoSuchNode(path, changectx.hex())
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
863 lo = idx[0]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
864 for hi in xrange(lo, len(str_files)):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
865 if not str_files[hi].startswith(str_path):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
866 break
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
867 str_path = str_path[:-1]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
868 str_entries = str_files[lo:hi]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
869 self.str_path = str_path
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
870
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
871 # Determine `kind`, `rev` (requested rev) and `created_rev`
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
872 # (last changed revision before requested rev)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
873
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
874 kind = None
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
875 rev = changectx.rev()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
876 if str_path == '':
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
877 kind = Node.DIRECTORY
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
878 dirctx = changectx
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
879 elif str_path in self.manifest: # then it's a file
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
880 kind = Node.FILE
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
881 self.filectx = changectx.filectx(str_path)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
882 created_rev = self.filectx.linkrev()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
883 # FIXME (0.13) this is a hack, we should fix that at the
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
884 # Trac level, which should really show the
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
885 # created_rev value for files in the browser.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
886 rev = created_rev
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
887 else: # we already know it's a dir
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
888 kind = Node.DIRECTORY
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
889 if not dirctx:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
890 # we need to find the most recent change for a file below dir
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
891 str_dir = str_path + '/'
2
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
892 dirctxs = self._find_dirctx(changectx.rev(), [str_dir,],
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
893 {str_dir: str_entries})
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
894 dirctx = dirctxs.values()[0]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
895
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
896 if not kind:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
897 if repo.changelog.tip() == nullid or \
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
898 not (self.manifest or str_path):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
899 # empty or emptied repository
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
900 kind = Node.DIRECTORY
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
901 dirctx = changectx
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
902 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
903 raise NoSuchNode(path, changectx.hex())
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
904
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
905 self.time = self.repos.from_hg_time(changectx.date())
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
906 if dirctx is not None:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
907 # FIXME (0.13) same remark as above
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
908 rev = created_rev = dirctx.rev()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
909 Node.__init__(self, self.repos, path, rev or '0', kind)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
910 self.created_path = path
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
911 self.created_rev = created_rev
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
912 self.data = None
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
913
2
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
914 def _find_dirctx(self, max_rev, str_dirnames, str_entries):
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
915 """Find most recent modification for each given directory path.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
916
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
917 :param max_rev: find no revision more recent than this one
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
918 :param str_dirnames: directory paths to consider
2
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
919 (list of `str` ending with '/')
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
920 :param str_entries: maps each directory to the files it contains
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
921
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
922 :return: a `dict` with `str_dirnames` as keys, `changectx` as values
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
923
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
924 As directories are not first-class citizens in Mercurial, this
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
925 operation is not trivial. There are basically two strategies:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
926
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
927 - for each file below the given directories, retrieve the
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
928 linkrev (most recent modification for this file), and take
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
929 the max; this approach is very inefficient for repositories
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
930 containing many files (#7746)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
931
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
932 - retrieve the files modified when going backward through the
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
933 changelog and detect the first occurrence of a change in
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
934 each directory; this is much faster but can still be slow
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
935 if some folders are only modified in the distant past
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
936
2
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
937 It is possible to combine both approaches, and this can
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
938 produce excellent results in some cases, for example browsing
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
939 the root of the Hg mirror of the Linux repository (at revision
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
940 118733) takes several minutes with the first approach, 11s
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
941 with the second, but only 1.2s with the hybrid approach.
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
942
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
943 Note that the specialized scan of the changelog we do below is
2
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
944 more efficient than the general cmdutil.walkchangerevs.
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
945 """
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
946 str_dirctxs = {}
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
947 repo = self.repos.repo
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
948 max_ctx = repo[max_rev]
3
8af21bda2b3e #10515: rework the way we retrieve the last change on directories.
Christian Boos <christian.boos@free.fr>
parents: 2
diff changeset
949 orevs = [-max_rev]
8af21bda2b3e #10515: rework the way we retrieve the last change on directories.
Christian Boos <christian.boos@free.fr>
parents: 2
diff changeset
950 revs = set(orevs)
8af21bda2b3e #10515: rework the way we retrieve the last change on directories.
Christian Boos <christian.boos@free.fr>
parents: 2
diff changeset
951 while orevs:
8af21bda2b3e #10515: rework the way we retrieve the last change on directories.
Christian Boos <christian.boos@free.fr>
parents: 2
diff changeset
952 r = -heappop(orevs)
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
953 ctx = repo[r]
3
8af21bda2b3e #10515: rework the way we retrieve the last change on directories.
Christian Boos <christian.boos@free.fr>
parents: 2
diff changeset
954 for p in ctx.parents():
8af21bda2b3e #10515: rework the way we retrieve the last change on directories.
Christian Boos <christian.boos@free.fr>
parents: 2
diff changeset
955 if p and p.rev() not in revs:
8af21bda2b3e #10515: rework the way we retrieve the last change on directories.
Christian Boos <christian.boos@free.fr>
parents: 2
diff changeset
956 revs.add(p.rev())
8af21bda2b3e #10515: rework the way we retrieve the last change on directories.
Christian Boos <christian.boos@free.fr>
parents: 2
diff changeset
957 heappush(orevs, -p.rev())
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
958 # lookup changes to str_dirnames in current cset
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
959 for str_file in ctx.files():
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
960 for str_dir in str_dirnames[:]:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
961 if str_file.startswith(str_dir):
2
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
962 # rev for str_dir was found using first strategy
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
963 str_dirctxs[str_dir] = ctx
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
964 str_dirnames.remove(str_dir)
2
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
965 if not str_dirnames: # nothing left to find
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
966 return str_dirctxs
2
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
967
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
968 # In parallel, try the filelog strategy (the 463, 2, 40
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
969 # values below look a bit like magic numbers; actually
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
970 # they were selected by testing the plugin on the Linux
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
971 # and NetBeans repositories)
2
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
972
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
973 # only use the filelog strategy every `n` revs
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
974 n = 463
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
975
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
976 # k, the number of files to examine per directory,
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
977 # will be comprised between `min_files` and `max_files`
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
978 min_files = 2
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
979 max_files = 40 # (will be the max if there's only one dir left)
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
980
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
981 if r % n == 0:
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
982 k = max(min_files, max_files / len(str_dirnames))
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
983 for str_dir in str_dirnames[:]:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
984 str_files = str_entries[str_dir]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
985 dr = str_dirctxs.get(str_dir, 0)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
986 for f in str_files[:k]:
3
8af21bda2b3e #10515: rework the way we retrieve the last change on directories.
Christian Boos <christian.boos@free.fr>
parents: 2
diff changeset
987 dr = max(dr, max_ctx.filectx(f).linkrev())
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
988 str_files = str_files[k:]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
989 if str_files:
2
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
990 # not all files for str_dir seen yet,
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
991 # store max rev found so far
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
992 str_entries[str_dir] = str_files
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
993 str_dirctxs[str_dir] = dr
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
994 else:
2
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
995 # all files for str_dir were examined,
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
996 # rev found using filelog strategy
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
997 str_dirctxs[str_dir] = repo[dr]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
998 str_dirnames.remove(str_dir)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
999 if not str_dirnames:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1000 return str_dirctxs
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1001
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1002
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1003 def subnode(self, str_path, subctx=None):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1004 """Return a node with the same revision information but for
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1005 another path
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1006
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1007 :param str_path: should be the an existing entry in the manifest
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1008 """
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1009 return MercurialNode(self.repos, self.repos.to_u(str_path),
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1010 self.changectx, self.manifest, subctx, str_path)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1011
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1012 def get_content(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1013 if self.isdir:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1014 return None
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1015 self.pos = 0 # reset the read()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1016 return self # something that can be `read()` ...
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1017
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1018 def read(self, size=None):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1019 if self.isdir:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1020 return TracError(_("Can't read from directory %(path)s",
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1021 path=self.path))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1022 if self.data is None:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1023 self.data = self.filectx.data()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1024 self.pos = 0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1025 if size:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1026 prev_pos = self.pos
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1027 self.pos += size
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1028 return self.data[prev_pos:self.pos]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1029 return self.data
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1030
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1031 def get_entries(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1032 if self.isfile:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1033 return
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1034
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1035 # dirnames are entries which are sub-directories
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1036 str_entries = {}
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1037 str_dirnames = []
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1038 def add_entry(str_file, idx):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1039 str_entry = str_file
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1040 if idx > -1: # directory
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1041 str_entry = str_file[:idx + 1]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1042 str_files = str_entries.setdefault(str_entry, [])
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1043 if not str_files:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1044 str_dirnames.append(str_entry)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1045 str_files.append(str_file)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1046 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1047 str_entries[str_entry] = 1
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1048
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1049 if self.str_path:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1050 str_dir = self.str_path + '/'
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1051 for str_file in self.manifest:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1052 if str_file.startswith(str_dir):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1053 add_entry(str_file, str_file.find('/', len(str_dir)))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1054 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1055 for str_file in self.manifest:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1056 add_entry(str_file, str_file.find('/'))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1057
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1058 # pre-computing the changectx for the last change in each sub-directory
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1059 if str_dirnames:
2
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
1060 dirctxs = self._find_dirctx(self.created_rev, str_dirnames,
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
1061 str_entries)
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1062 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1063 dirctxs = {}
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1064
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1065 for str_entry in str_entries:
2
bbb6e28dc488 Add documentation to `MercurialNode` `find_dirctx`.
Christian Boos <christian.boos@free.fr>
parents: 1
diff changeset
1066 yield self.subnode(str_entry.rstrip('/'), dirctxs.get(str_entry))
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1067
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1068 def get_history(self, limit=None):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1069 repo = self.repos.repo
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1070 pats = []
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1071 if self.str_path:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1072 pats.append('path:' + self.str_path)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1073 opts = {'rev': ['%s:0' % self.changectx.hex()]}
14
89d0599cbded #10719: don't use follow mode for file log, for Mercurial version >= 2.1.1
Christian Boos <cboos@edgewall.org>
parents: 11
diff changeset
1074 if self.isfile and self.repos.version_info < (2, 1, 1):
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1075 opts['follow'] = True
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1076 if arity(cmdutil.walkchangerevs) == 4:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1077 return self._get_history_1_4(repo, pats, opts, limit)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1078 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1079 return self._get_history_1_3(repo, pats, opts, limit)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1080
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1081 def _get_history_1_4(self, repo, pats, opts, limit):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1082 matcher = match(repo[None], pats, opts)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1083 if self.isfile:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1084 fncache = {}
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1085 def prep(ctx, fns):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1086 if self.isfile:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1087 fncache[ctx.rev()] = self.repos.to_u(fns[0])
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1088 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1089 def prep(ctx, fns):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1090 pass
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1091
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1092 # keep one lookahead entry so that we can detect renames
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1093 path = self.path
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1094 entry = None
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1095 count = 0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1096 for ctx in cmdutil.walkchangerevs(repo, matcher, opts, prep):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1097 if self.isfile and entry:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1098 path = fncache[ctx.rev()]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1099 if path != entry[0]:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1100 entry = entry[0:2] + (Changeset.COPY,)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1101 if entry:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1102 yield entry
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1103 count += 1
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1104 if limit is not None and count >= limit:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1105 return
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1106 entry = (path, ctx.hex(), Changeset.EDIT)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1107 if entry:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1108 if limit is None or count < limit:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1109 entry = entry[0:2] + (Changeset.ADD,)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1110 yield entry
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1111
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1112 def _get_history_1_3(self, repo, pats, opts, limit):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1113 if self.repos.version_info > (1, 3, 999):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1114 changefn = lambda r: repo[r]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1115 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1116 changefn = lambda r: repo[r].changeset()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1117 get = cachefunc(changefn)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1118 if self.isfile:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1119 fncache = {}
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1120 chgiter, matchfn = cmdutil.walkchangerevs(self.repos.ui, repo, pats,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1121 get, opts)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1122 # keep one lookahead entry so that we can detect renames
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1123 path = self.path
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1124 entry = None
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1125 count = 0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1126 for st, rev, fns in chgiter:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1127 if st == 'add' and self.isfile:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1128 fncache[rev] = self.repos.to_u(fns[0])
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1129 elif st == 'iter':
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1130 if self.isfile and entry:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1131 path = fncache[rev]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1132 if path != entry[0]:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1133 entry = entry[0:2] + (Changeset.COPY,)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1134 if entry:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1135 yield entry
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1136 count += 1
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1137 if limit is not None and count >= limit:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1138 return
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1139 n = repo.changelog.node(rev)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1140 entry = (path, hex(n), Changeset.EDIT)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1141 if entry:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1142 if limit is None or count < limit:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1143 entry = entry[0:2] + (Changeset.ADD,)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1144 yield entry
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1145
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1146 def get_annotations(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1147 annotations = []
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1148 if self.filectx:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1149 for fc, line in self.filectx.annotate(follow=True):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1150 annotations.append(fc.rev() or '0')
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1151 return annotations
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1152
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1153 def get_properties(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1154 if self.isfile and 'x' in self.manifest.flags(self.str_path):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1155 return {'exe': '*'}
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1156 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1157 return {}
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1158
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1159 def get_content_length(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1160 if self.isdir:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1161 return None
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1162 return self.filectx.size()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1163
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1164 def get_content_type(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1165 if self.isdir:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1166 return None
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1167 if 'mq' in self.repos.params: # FIXME
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1168 if self.str_path not in ('.hgignore', 'series'):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1169 return 'text/x-diff'
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1170 return ''
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1171
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1172 def get_last_modified(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1173 return self.time
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1174
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1175
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1176 class MercurialChangeset(Changeset):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1177 """A changeset in the repository.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1178
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1179 This wraps the corresponding information from the changelog. The
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1180 files changes are obtained by comparing the current manifest to
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1181 the parent manifest(s).
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1182 """
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1183
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1184 def __init__(self, repos, ctx):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1185 self.repos = repos
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1186 self.ctx = ctx
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1187 self.branch = self.repos.to_u(ctx.branch())
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1188 # Note: desc and time are already processed by hg's
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1189 # `encoding.tolocal`; by setting $HGENCODING to latin1, we are
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1190 # however guaranteed to get back the bytes as they were
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1191 # stored.
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1192 desc = repos.to_u(ctx.description())
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1193 user = repos.to_u(ctx.user())
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1194 time = repos.from_hg_time(ctx.date())
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1195 Changeset.__init__(self, repos, ctx.hex(), desc, user, time)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1196
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1197 hg_properties = [
5
852043605ea2 i18n: new extraction, update of french translation
Christian Boos <cboos@edgewall.org>
parents: 4
diff changeset
1198 N_("Parents:"), N_("Children:"), N_("Branch:"), N_("Tags:"),
852043605ea2 i18n: new extraction, update of french translation
Christian Boos <cboos@edgewall.org>
parents: 4
diff changeset
1199 N_("Bookmarks:")
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1200 ]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1201
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1202 def get_properties(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1203 properties = {}
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1204 parents = self.ctx.parents()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1205 if len(parents) > 1:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1206 properties['hg-Parents'] = (self.repos,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1207 [p.hex() for p in parents if p])
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1208 children = self.ctx.children()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1209 if len(children) > 1:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1210 properties['hg-Children'] = (self.repos,
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1211 [c.hex() for c in children])
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1212 if self.branch:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1213 properties['hg-Branch'] = (self.repos, [self.branch])
1
b30690538379 initialize branch:0.13 from svn
Christian Boos <christian.boos@free.fr>
parents: 0
diff changeset
1214 tags = self.get_tags()
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1215 if len(tags):
1
b30690538379 initialize branch:0.13 from svn
Christian Boos <christian.boos@free.fr>
parents: 0
diff changeset
1216 properties['hg-Tags'] = (self.repos, tags)
4
f261cc084df2 #10527: add bookmark support, shown as properties.
Christian Boos <cboos@edgewall.org>
parents: 3
diff changeset
1217 bookmarks = self.ctx.bookmarks()
f261cc084df2 #10527: add bookmark support, shown as properties.
Christian Boos <cboos@edgewall.org>
parents: 3
diff changeset
1218 if len(bookmarks):
f261cc084df2 #10527: add bookmark support, shown as properties.
Christian Boos <cboos@edgewall.org>
parents: 3
diff changeset
1219 properties['hg-Bookmarks'] = (self.repos, bookmarks)
0
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1220 for k, v in self.ctx.extra().iteritems():
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1221 if k != 'branch':
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1222 properties['hg-' + k] = (self.repos, v)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1223 return properties
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1224
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1225 def get_changes(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1226 u = self.repos.to_u
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1227 repo = self.repos.repo
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1228 manifest = self.ctx.manifest()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1229 parents = self.ctx.parents()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1230
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1231 renames = []
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1232 str_deletions = {}
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1233 changes = []
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1234 for str_file in self.ctx.files(): # added, edited and deleted files
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1235 f = u(str_file)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1236 # TODO: find a way to detect conflicts and show how they were
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1237 # solved (kind of 3-way diff - theirs/mine/merged)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1238 edits = [p for p in parents if str_file in p.manifest()]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1239
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1240 if str_file not in manifest:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1241 str_deletions[str_file] = edits[0]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1242 elif edits:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1243 for p in edits:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1244 changes.append((f, Node.FILE, Changeset.EDIT, f, p.rev()))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1245 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1246 renamed = repo.file(str_file).renamed(manifest[str_file])
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1247 if renamed:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1248 renames.append((f, renamed))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1249 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1250 changes.append((f, Node.FILE, Changeset.ADD, '', None))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1251 # distinguish between move and copy
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1252 for f, (str_base_path, base_filenode) in renames:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1253 base_ctx = repo.filectx(str_base_path, fileid=base_filenode)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1254 if str_base_path in str_deletions:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1255 del str_deletions[str_base_path]
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1256 action = Changeset.MOVE
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1257 else:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1258 action = Changeset.COPY
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1259 changes.append((f, Node.FILE, action, u(str_base_path),
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1260 base_ctx.rev()))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1261 # remaining str_deletions are real deletions
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1262 for str_file, p in str_deletions.items():
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1263 f = u(str_file)
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1264 changes.append((f, Node.FILE, Changeset.DELETE, f, p.rev()))
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1265 changes.sort()
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1266 for change in changes:
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1267 yield change
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1268
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1269 def get_branches(self):
a97b17f1bac7 TracMercurial: started new Mercurial repository
Christian Boos <christian.boos@free.fr>
parents:
diff changeset
1270 """Yield branch names to which this changeset belong."""
1
b30690538379 initialize branch:0.13 from svn
Christian Boos <christian.boos@free.fr>
parents: 0
diff changeset
1271 if self.branch:
b30690538379 initialize branch:0.13 from svn
Christian Boos <christian.boos@free.fr>
parents: 0
diff changeset
1272 yield (self.branch, len(self.ctx.children()) == 0)
b30690538379 initialize branch:0.13 from svn
Christian Boos <christian.boos@free.fr>
parents: 0
diff changeset
1273
b30690538379 initialize branch:0.13 from svn
Christian Boos <christian.boos@free.fr>
parents: 0
diff changeset
1274 def get_tags(self):
b30690538379 initialize branch:0.13 from svn
Christian Boos <christian.boos@free.fr>
parents: 0
diff changeset
1275 """Yield tag names to which this changeset belong."""
b30690538379 initialize branch:0.13 from svn
Christian Boos <christian.boos@free.fr>
parents: 0
diff changeset
1276 return [self.repos.to_u(t) for t in self.ctx.tags()]