This file is indexed.

/usr/lib/python2.7/dist-packages/hgnested/__init__.py is in mercurial-nested 0.7-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# This file is part of hgnested.  The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
'''commands to manage nested repositories.

This extension provides commands that apply to all the nested repositories.

It was inspired by the forest extension by Robin Farine.
'''

testedwith = '2.9 3.0 3.1 3.2 3.3 3.4 3.5'
buglink = 'https://bitbucket.org/cedk/hgnested/issues'

import os
import time
from functools import partial
from mercurial import hg
from mercurial import commands, localrepo, hgweb
from mercurial import util
from mercurial import cmdutil
from mercurial import wireproto
from mercurial.error import CapabilityError
from mercurial.scmutil import walkrepos
from mercurial.i18n import _

try:
    from mercurial import sshpeer, httppeer
except ImportError:
    from mercurial import sshrepo, httprepo
    sshpeer, httppeer = None, None

__version__ = '0.7'

_nested_cache = {}
_nested_refreshinterval = 20

_capabilities_parent = wireproto.capabilities


def capabilities(repo, proto):
    caps = _capabilities_parent(repo, proto).split()
    caps.append('nested')
    return ' '.join(caps)
wireproto.capabilities = capabilities
wireproto.commands['capabilities'] = ((capabilities,) +
        wireproto.commands['capabilities'][1:])


def nested(repo, proto):
    '''Return a list of nested repositories.'''
    return "\n".join(repo.nested)

wireproto.commands['nested'] = (nested, '')


@property
def _localrepo_nested(self):
    '''Return a list of nested repositories.'''
    cache = _nested_cache.setdefault(self.root, {
        'lastrefresh': 0,
        'nested': None,
        })
    if cache['lastrefresh'] + _nested_refreshinterval > time.time():
        return cache['nested']
    res = {}
    paths = [self.root]
    while paths:
        path = paths.pop()
        if os.path.realpath(path) in res:
            continue
        for root, dirs, files in os.walk(path):
            for dir in dirs[:]:
                if dir == '.hg':
                    res[os.path.realpath(root)] = os.path.abspath(root)
                    proot = os.path.join(root, '.hg', 'patches')
                    if os.path.isdir(os.path.join(proot, '.hg')):
                        res[os.path.realpath(proot)] = os.path.abspath(proot)
                    dirs.remove('.hg')  # Don't visit .hg directory
                else:
                    path = os.path.join(root, dir)
                    if (os.path.islink(path)
                            and os.path.realpath(path) not in res):
                        paths.append(path)
    prefix = len(self.root) + 1
    res = [x[prefix:] or '.' for x in res.itervalues()]
    res.sort()
    cache['nested'] = res
    cache['lastrefresh'] = time.time()
    return res

localrepo.localrepository.nested = _localrepo_nested


@property
def _sshpeer_nested(self):
    '''Return a list of nested repositories.'''
    if hasattr(self, 'capable'):
        test = self.capable('nested')
    else:
        test = 'nested' in self.capabilities
    if not test:
        raise util.Abort(_("Remote repository doesn't support "
            "the nested extension."))
    if hasattr(self, '_call'):
        return self._call('nested').splitlines()
    return self.call('nested').splitlines()

if sshpeer:
    sshpeer.sshpeer.nested = _sshpeer_nested
else:
    sshrepo.sshrepository.nested = _sshpeer_nested


@property
def _httppeer_nested(self):
    '''Return a list of nested repositories.'''
    if hasattr(self, 'capable'):
        test = self.capable('nested')
    else:
        test = 'nested' in self.capabilities
    if not test:
        raise util.Abort(_("Remote repository doesn't support "
            "the nested extension."))
    if hasattr(self, '_call'):
        return self._call('nested').split()
    return self.do_read('nested').split()

if httppeer:
    httppeer.httppeer.nested = _httppeer_nested
else:
    httprepo.httprepository.nested = _httppeer_nested


_hgwebdir_refresh_parent = hgweb.hgwebdir_mod.hgwebdir.refresh


def _hgwebdir_refresh(self):
    if self.lastrefresh + self.refreshinterval > time.time():
        return
    _hgwebdir_refresh_parent(self)
    for prefix, root in self.ui.configitems('collections'):
        prefix = util.pconvert(prefix)
        for path in walkrepos(root, followsym=True):
            repo = hg.repository(self.ui, path)
            for npath in repo.nested:
                npath = os.path.normpath(os.path.join(path, npath))
                name = util.pconvert(npath)
                if name.startswith(prefix):
                    name = name[len(prefix):]
                repo = (name.lstrip('/'), npath)
                if repo not in self.repos:
                    self.repos.append(repo)
    self.lastrefresh = time.time()

hgweb.hgwebdir_mod.hgwebdir.refresh = _hgwebdir_refresh


def _nested_apply(ui, repo, function, status, *args, **kwargs):
    'Apply function to all nested repositories'
    for npath in repo.nested:
        if npath == '.':
            nrepo = repo
            lui = ui
        else:
            lpath = os.path.join(repo.root, npath)
            nrepo = hg.repository(ui, lpath)
            lui = nrepo.ui
            if function is _nested_diff:
                kwargs['prefix'] = npath
        if status:
            lui.status('[%s]\n' % npath)
        function(lui, nrepo, *args, **kwargs)
        if status:
            lui.status('\n')


def _nested_diff(ui, repo, *pats, **opts):
    diffordiffstat = cmdutil.diffordiffstat
    cmdutil.diffordiffstat = partial(diffordiffstat,
        prefix=opts.get('prefix') or '')
    commands.diff(ui, repo, *pats, **opts)
    cmdutil.diffordiffstat = diffordiffstat


def ndiff(ui, repo, *pats, **opts):
    '''diff nested repositories (or selected files)

    Show differences between revisions for the specified files.

    Look at the help of diff command for more informations.'''
    _nested_apply(ui, repo, _nested_diff, False, *pats, **opts)


def nclone(ui, source, dest=None, **opts):
    '''make a copy of an existing repository and all nested repositories

    Create a copy of an existing repository in a new directory.

    Look at the help of clone command for more informations.'''
    origsource = ui.expandpath(source)
    remotesource, remotebranch = hg.parseurl(origsource, opts.get('branch'))
    if hasattr(hg, 'peer'):
        remoterepo = hg.peer(ui, opts, remotesource)
        localrepo = remoterepo.local()
        if localrepo:
            remoterepo = localrepo
    else:
        remoterepo = hg.repository(hg.remoteui(ui, opts), remotesource)
    if dest is None:
        dest = hg.defaultdest(source)
        ui.status(_("destination directory: %s\n") % dest)
    for npath in remoterepo.nested:
        if npath == '.':
            npath = ''
        u = util.url(source)
        if u.scheme:
            nsource = '%s/%s' % (source, npath)
        else:
            nsource = os.path.join(source, npath)
        ndest = os.path.join(dest, npath)
        ui.status('[%s]\n' % os.path.normpath(
            os.path.join(os.path.basename(dest),
                ndest[len(dest) + 1:])))
        commands.clone(ui, nsource, dest=ndest, **opts)
        ui.status('\n')


def nshare(ui, source, dest=None, noupdate=False):
    '''create a new shared repository and all nested repositories
    '''
    sourcerepo = hg.repository(ui, source)
    if dest is None:
        dest = hg.defaultdest(source)
        ui.status(_("destination directory: %s\n") % dest)
    for npath in sourcerepo.nested:
        if npath == '.':
            npath = ''
        u = util.url(source)
        if u.scheme:
            nsource = '%s/%s' % (source, npath)
        else:
            nsource = os.path.join(source, npath)
        ndest = os.path.join(dest, npath)
        ui.status('[%s]\n' % os.path.normpath(
            os.path.join(os.path.basename(dest),
                ndest[len(dest) + 1:])))
        hg.share(ui, nsource, ndest, not noupdate)
        ui.status('\n')


def nincoming(ui, repo, dest=None, **opts):
    '''show changest not found in repository and all nested repositories

    Look at the help of incoming command for more informations.'''
    _nested_apply(ui, repo, commands.incoming, True, dest=dest, **opts)


def noutgoing(ui, repo, dest=None, **opts):
    '''show changesest not found in the destination and all nested repositories

    Look at the help of outgoing command for more informations.'''
    _nested_apply(ui, repo, commands.outgoing, True, dest=dest, **opts)


def npull(ui, repo, source="default", **opts):
    '''pull changes from the specified source and all nested repositories

    Pull changes from a remote repository to a local one.

    Look at the help of pull command for more informations.'''
    def test(ui, repo, source, **opts):
        source, branches = hg.parseurl(ui.expandpath(source),
                opts.get('branch'))
        other = hg.repository(hg.remoteui(repo, opts), source)
        revs, checkout = hg.addbranchrevs(repo, other, branches,
                opts.get('rev'))
        if revs:
            try:
                revs = [other.lookup(rev) for rev in revs]
            except CapabilityError:
                err = _("Other repository doesn't support revision lookup, "
                        "so a rev cannot be specified.")
                raise util.Abort(err)
    if (source != 'default'
            or opts.get('branch')
            or opts.get('rev')):
        _nested_apply(ui, repo, test, False, source=source, **opts)
    _nested_apply(ui, repo, commands.pull, True, source=source, **opts)


def npush(ui, repo, dest=None, **opts):
    '''push changes to the specified destination and all nested repositories

    Push changes from the local repository to the specified destination.

    Look at the help of status command for more informations.'''
    def test(ui, repo, dest=None, **opts):
        dest = ui.expandpath(dest or 'default-push', dest or 'default')
        dest, branches = hg.parseurl(dest, opts.get('branch'))
        revs, checkout = hg.addbranchrevs(repo, repo, branches,
                opts.get('rev'))
        if hasattr(hg, 'peer'):
            other = hg.peer(ui, opts, dest)
            localother = other.local()
            if localother:
                other = localother
        else:
            other = hg.repository(hg.remoteui(repo, opts), dest)
        if revs:
            revs = [other.lookup(rev) for rev in revs]
    _nested_apply(ui, repo, test, False, dest=dest, **opts)
    _nested_apply(ui, repo, commands.push, True, dest=dest, **opts)


def nstatus(ui, repo, *pats, **opts):
    '''show changed files in the working directory and all nested repositories

    Show status of files in the repository.

    Look at the help of status command for more informations.'''
    _nested_apply(ui, repo, commands.status, True, *pats, **opts)


def nupdate(ui, repo, node=None, rev=None, clean=False, date=None, check=False,
        **opts):
    '''update working directory and all nested repositories

    Update the repository's working directory to the specified changeset.

    Look at the help of update command for more informations.'''
    def test(ui, repo, node=None, rev=None, date=None, check=False):
        if rev and node:
            raise util.Abort(_("please specify just one revision"))

        if not rev:
            rev = node

        if check:
            c = repo[None]
            if c.modified() or c.added() or c.removed():
                raise util.Abort(_("uncommitted local changes"))

        if date:
            rev = cmdutil.finddate(ui, repo, date)
    _nested_apply(ui, repo, test, False, node=node, rev=rev, date=date,
            check=check)
    _nested_apply(ui, repo, commands.update, True, node=node, rev=rev,
            clean=clean, date=date, check=check)

cmdtable = {
    '^ndiff': (ndiff,
        cmdutil.findcmd('diff', commands.table)[1][1],
        _('[OPTION]... ([-c REV] | [-r REV1 [-r REV2]]) [FILE]...')),
    '^nclone': (nclone,
        cmdutil.findcmd('clone', commands.table)[1][1],
        _('[OPTION]... SOURCE [DEST]')),
    '^nshare': (nshare,
        [('U', 'noupdate', None, _('do not create a working copy'))],
        ('[-U] SOURCE [DEST]')),
    'nincoming|nin': (nincoming,
        cmdutil.findcmd('incoming', commands.table)[1][1],
        _('[-p] [-n] [-M] [-f] [-r REV]... [--bundle FILENAME] [SOURCE]')),
    'noutgoing|nout': (noutgoing,
        cmdutil.findcmd('outgoing', commands.table)[1][1],
        _('[-M] [-p] [-n] [-f] [-r REV]... [DEST]')),
    'npull': (npull,
        cmdutil.findcmd('pull', commands.table)[1][1],
        _('[-u] [-f] [-r REV]... [-e CMD] [--remotecmd CMD] [SOURCE]')),
    '^npush': (npush,
        cmdutil.findcmd('push', commands.table)[1][1],
        _('[-f] [-r REV]... [-e CMD] [--remotecmd CMD] [DEST]')),
    '^nstatus|nst': (nstatus,
        cmdutil.findcmd('status', commands.table)[1][1],
        _('[OPTION]... [FILE]...')),
    '^nupdate|nup': (nupdate,
        cmdutil.findcmd('update', commands.table)[1][1],
        _('[-c] [-C] [-d DATE] [[-r] REV]')),
}
commands.norepo += " nclone nshare"