mercurial/node.py
author Matt Harbison <matt_harbison@yahoo.com>
Sun, 24 Jun 2018 01:13:09 -0400
changeset 38483 3efadf2317c7
parent 37448 d7114f883505
child 39145 b623c7b23695
permissions -rw-r--r--
windows: add a method to convert Unix style command lines to Windows style This started as a copy/paste of `os.path.expandvars()`, but limited to a given dictionary of variables, converting `foo = foo + bar` to `foo += bar`, and adding 'b' string prefixes. Then code was added to make sure that a value being substituted in wouldn't itself be expanded by cmd.exe. But that left inconsistent results between `$var1` and `%var1%` when its value was '%foo%'- since neither were touched, `$var1` wouldn't expand but `%var1%` would. So instead, this just converts the Unix style to Windows style (if the variable exists, because Windows will leave `%missing%` as-is), and lets cmd.exe do its thing. I then dropped the %% -> % conversion (because Windows doesn't do this), and added the ability to escape the '$' with '\'. The escape character is dropped, for consistency with shell handling. After everything seemed stable and working, running the whole test suite flagged a problem near the end of test-bookmarks.t:1069. The problem is cmd.exe won't pass empty variables to its child, so defined but empty variables are now skipped. I can't think of anything better, and it seems like a pre-existing violation of the documentation, which calls out that HG_OLDNODE is empty on bookmark creation. Future additions could potentially be replacing strong quotes with double quotes (cmd.exe doesn't know what to do with the former), escaping a double quote, and some tilde expansion via os.path.expanduser(). I've got some doubts about replacing the strong quotes in case sh.exe is run, but it seems like the right thing to do the vast majority of the time. The original form of this was discussed about a year ago[1]. [1] https://www.mercurial-scm.org/pipermail/mercurial-devel/2017-July/100735.html
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8226
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
     1
# node.py - basic nodeid manipulation for mercurial
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
     2
#
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
     3
# Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
     4
#
8b2cd04a6e97 put license and copyright info into comment blocks
Martin Geisler <mg@lazybytes.net>
parents: 8225
diff changeset
     5
# This software may be used and distributed according to the terms of the
10263
25e572394f5c Update license to GPLv2+
Matt Mackall <mpm@selenic.com>
parents: 8226
diff changeset
     6
# GNU General Public License version 2 or any later version.
1089
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
     7
25962
738314da6c75 node: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25737
diff changeset
     8
from __future__ import absolute_import
738314da6c75 node: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25737
diff changeset
     9
3877
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 3578
diff changeset
    10
import binascii
1089
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
    11
26980
18f50b8cbf1e node: add 'nullhex', hex-encoded nullid
Siddharth Agarwal <sid0@fb.com>
parents: 25962
diff changeset
    12
# This ugly style has a noticeable effect in manifest parsing
18f50b8cbf1e node: add 'nullhex', hex-encoded nullid
Siddharth Agarwal <sid0@fb.com>
parents: 25962
diff changeset
    13
hex = binascii.hexlify
36238
f574cc00831a node: make bin() be a wrapper instead of just an alias
Augie Fackler <augie@google.com>
parents: 32684
diff changeset
    14
# Adapt to Python 3 API changes. If this ends up showing up in
f574cc00831a node: make bin() be a wrapper instead of just an alias
Augie Fackler <augie@google.com>
parents: 32684
diff changeset
    15
# profiles, we can use this version only on Python 3, and forward
f574cc00831a node: make bin() be a wrapper instead of just an alias
Augie Fackler <augie@google.com>
parents: 32684
diff changeset
    16
# binascii.unhexlify like we used to on Python 2.
f574cc00831a node: make bin() be a wrapper instead of just an alias
Augie Fackler <augie@google.com>
parents: 32684
diff changeset
    17
def bin(s):
f574cc00831a node: make bin() be a wrapper instead of just an alias
Augie Fackler <augie@google.com>
parents: 32684
diff changeset
    18
    try:
f574cc00831a node: make bin() be a wrapper instead of just an alias
Augie Fackler <augie@google.com>
parents: 32684
diff changeset
    19
        return binascii.unhexlify(s)
f574cc00831a node: make bin() be a wrapper instead of just an alias
Augie Fackler <augie@google.com>
parents: 32684
diff changeset
    20
    except binascii.Error as e:
f574cc00831a node: make bin() be a wrapper instead of just an alias
Augie Fackler <augie@google.com>
parents: 32684
diff changeset
    21
        raise TypeError(e)
26980
18f50b8cbf1e node: add 'nullhex', hex-encoded nullid
Siddharth Agarwal <sid0@fb.com>
parents: 25962
diff changeset
    22
3578
3b4e00cba57a Define and use nullrev (revision of nullid) instead of -1.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 2859
diff changeset
    23
nullrev = -1
28585
a3f3fdac8433 node: use byte literals to construct nullid and wdirid
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26980
diff changeset
    24
nullid = b"\0" * 20
26980
18f50b8cbf1e node: add 'nullhex', hex-encoded nullid
Siddharth Agarwal <sid0@fb.com>
parents: 25962
diff changeset
    25
nullhex = hex(nullid)
1089
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
    26
30360
0298a07f64d9 dirstate: change placeholder hash length to 20 bytes
Durham Goode <durham@fb.com>
parents: 28585
diff changeset
    27
# Phony node value to stand-in for new files in some uses of
0298a07f64d9 dirstate: change placeholder hash length to 20 bytes
Durham Goode <durham@fb.com>
parents: 28585
diff changeset
    28
# manifests.
0298a07f64d9 dirstate: change placeholder hash length to 20 bytes
Durham Goode <durham@fb.com>
parents: 28585
diff changeset
    29
newnodeid = '!' * 20
30361
1070df141718 dirstate: change added/modified placeholder hash length to 20 bytes
Durham Goode <durham@fb.com>
parents: 30360
diff changeset
    30
addednodeid = ('0' * 15) + 'added'
1070df141718 dirstate: change added/modified placeholder hash length to 20 bytes
Durham Goode <durham@fb.com>
parents: 30360
diff changeset
    31
modifiednodeid = ('0' * 12) + 'modified'
30360
0298a07f64d9 dirstate: change placeholder hash length to 20 bytes
Durham Goode <durham@fb.com>
parents: 28585
diff changeset
    32
37448
d7114f883505 node: rename wdirnodes to clarify they are for manifest/filelogs
Yuya Nishihara <yuya@tcha.org>
parents: 36238
diff changeset
    33
wdirfilenodeids = {newnodeid, addednodeid, modifiednodeid}
30360
0298a07f64d9 dirstate: change placeholder hash length to 20 bytes
Durham Goode <durham@fb.com>
parents: 28585
diff changeset
    34
25737
1a5211f2f87f node: define experimental identifiers for working directory
Yuya Nishihara <yuya@tcha.org>
parents: 10263
diff changeset
    35
# pseudo identifiers for working directory
1a5211f2f87f node: define experimental identifiers for working directory
Yuya Nishihara <yuya@tcha.org>
parents: 10263
diff changeset
    36
# (they are experimental, so don't add too many dependencies on them)
1a5211f2f87f node: define experimental identifiers for working directory
Yuya Nishihara <yuya@tcha.org>
parents: 10263
diff changeset
    37
wdirrev = 0x7fffffff
28585
a3f3fdac8433 node: use byte literals to construct nullid and wdirid
Gregory Szorc <gregory.szorc@gmail.com>
parents: 26980
diff changeset
    38
wdirid = b"\xff" * 20
32684
af854b1b36f8 revlog: add support for partial matching of wdir node id
Yuya Nishihara <yuya@tcha.org>
parents: 32291
diff changeset
    39
wdirhex = hex(wdirid)
25737
1a5211f2f87f node: define experimental identifiers for working directory
Yuya Nishihara <yuya@tcha.org>
parents: 10263
diff changeset
    40
1089
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
    41
def short(node):
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
    42
    return hex(node[:6])