~ubuntu-branches/debian/sid/tortoisehg/sid

« back to all changes in this revision

Viewing changes to tortoisehg/util/hglib.py

  • Committer: Package Import Robot
  • Author(s): Ludovico Cavedon
  • Date: 2012-05-29 00:59:17 UTC
  • mfrom: (1.2.9)
  • Revision ID: package-import@ubuntu.com-20120529005917-ae1mdohuiimxxkc0
Tags: 2.4-1
* Imported Upstream version 2.4 (Closes: #671473).
* Re-add Nautilus extension (LP: #990527).
* Update Standards-Version to 3.9.3.
* Update copyright format.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
import urllib
13
13
 
14
14
from mercurial import ui, util, extensions, match, bundlerepo, cmdutil
15
 
from mercurial import encoding, templatefilters, filemerge, error
16
 
from mercurial import demandimport, revset
 
15
from mercurial import encoding, templatefilters, filemerge, error, scmutil
17
16
from mercurial import dispatch as hgdispatch
18
17
 
19
 
 
20
 
demandimport.disable()
21
 
try:
22
 
    # hg >= 1.9
23
 
    from mercurial.scmutil import canonpath, userrcpath
24
 
    user_rcpath = userrcpath
25
 
except (ImportError, AttributeError):
26
 
    # hg <= 1.8
27
 
    from mercurial.util import canonpath, user_rcpath
28
 
try:
29
 
    # hg >= 1.9
30
 
    from mercurial.util import localpath
31
 
except (ImportError, AttributeError):
32
 
    # hg <= 1.8
33
 
    from mercurial.hg import localpath
34
 
try:
35
 
    # hg >= 1.9
36
 
    from mercurial.util import hidepassword, removeauth
37
 
except (ImportError, AttributeError):
38
 
    # hg <= 1.8
39
 
    from mercurial.url import hidepassword, removeauth
40
 
try:
41
 
    # hg >= 1.9
42
 
    from mercurial.httpconnection import readauthforuri as hgreadauthforuri
43
 
except (ImportError, AttributeError):
44
 
    # hg <= 1.8
45
 
    from mercurial.url import readauthforuri as hgreadauthforuri
46
 
try:
47
 
    # hg >= 1.9
48
 
    from mercurial.scmutil import revrange, expandpats, revpair, match, matchall
49
 
except (ImportError, AttributeError):
50
 
    # hg <= 1.8
51
 
    from mercurial.cmdutil import revrange, expandpats, revpair, match, matchall
52
 
try:
53
 
    # hg >= 2.1 (0bd17a4bed88)
54
 
    from mercurial.copies import mergecopies, pathcopies
55
 
except (ImportError, AttributeError):
56
 
    from mercurial.copies import copies as mergecopies
57
 
    def pathcopies(c1, c2):
58
 
        return mergecopies(c1._repo, c1, c2, c1._repo[-1], False)[0]
59
 
demandimport.enable()
60
 
 
61
 
def readauthforuri(ui, uri, user):
62
 
    try:
63
 
        return hgreadauthforuri(ui, uri, user)
64
 
    except TypeError:
65
 
        return hgreadauthforuri(ui, uri)
66
 
 
67
 
def revsetmatch(ui, pattern):
68
 
    try:
69
 
        # hg >= 1.9
70
 
        return revset.match(ui, pattern)
71
 
    except TypeError:
72
 
        # hg <= 1.8
73
 
        return revset.match(pattern)
74
 
 
75
18
_encoding = encoding.encoding
76
19
_encodingmode = encoding.encodingmode
77
20
_fallbackencoding = encoding.fallbackencoding
394
337
    root = paths.find_root(cwd)
395
338
    for f in list:
396
339
        try:
397
 
            canonpats.append(canonpath(root, cwd, f))
 
340
            canonpats.append(scmutil.canonpath(root, cwd, f))
398
341
        except util.Abort:
399
342
            # Attempt to resolve case folding conflicts.
400
343
            fu = f.upper()
401
344
            cwdu = cwd.upper()
402
345
            if fu.startswith(cwdu):
403
 
                canonpats.append(canonpath(root, cwd, f[len(cwd+os.sep):]))
 
346
                canonpats.append(scmutil.canonpath(root, cwd,
 
347
                                                   f[len(cwd+os.sep):]))
404
348
            else:
405
349
                # May already be canonical
406
350
                canonpats.append(f)
500
444
    _difftools = tools
501
445
    return tools
502
446
 
 
447
def tortoisehgtools(ui, selectedlocation=None):
 
448
    '''
 
449
    Parse 'tortoisehg-tools' section of ini file. Changes:
 
450
    
 
451
    [tortoisehg-tools]
 
452
    update_to_tip.icon = hg-update
 
453
    update_to_tip.command = hg update tip
 
454
    update_to_tip.tooltip = Update to tip
 
455
    update_to_tip.location = workbench,repowidget
 
456
    
 
457
    into following dictionary
 
458
    
 
459
    {'update_to_tip': 
 
460
        {'icon': 'hg-update', 
 
461
         'command': 'hg update tip', 
 
462
         'tooltip': 'Update to tip',
 
463
         'location': 'workbench,repowidget'}
 
464
    }
 
465
    
 
466
    If selectedlocation is set, only return those tools whose
 
467
    location matches the selected location.
 
468
    If a tool has no location set, it will be assumed that it must be
 
469
    shown on the 'workbench' toolbar
 
470
    '''
 
471
    tools = {}
 
472
    toolnames = []
 
473
    for key, value in ui.configitems('tortoisehg-tools'):
 
474
        toolname, field = key.split('.')
 
475
        if toolname not in tools:
 
476
            tools[toolname] = {}
 
477
            toolnames.append(toolname)
 
478
        bvalue = util.parsebool(value)
 
479
        if bvalue is not None:
 
480
            value = bvalue
 
481
        tools[toolname][field] = value
 
482
    
 
483
    if selectedlocation is None:
 
484
        return tools, toolnames
 
485
    # Only return the tools that are linked to the selected location
 
486
    selectedtools = {}
 
487
    selectedtoolnames = []
 
488
    for name in toolnames:
 
489
        info = tools[name]
 
490
        location = info.get('location', 'workbench').replace(' ', '').split(',')
 
491
        if selectedlocation in location:
 
492
            selectedtools[name] = info
 
493
            selectedtoolnames.append(name)
 
494
    return selectedtools, selectedtoolnames
503
495
 
504
496
def hgcmd_toq(q, label, args):
505
497
    '''
622
614
    for alias, path_aux in repo.ui.configitems('paths'):
623
615
        if path == alias:
624
616
            return_path = path_aux
625
 
        elif path == hidepassword(path_aux):
 
617
        elif path == util.hidepassword(path_aux):
626
618
            return_path = path_aux
627
619
    return return_path
628
620