mercurial/node.py
author Manuel Jacob <me@manueljacob.de>
Mon, 07 Aug 2023 23:12:02 +0200
branchstable
changeset 50767 9ed281bbf864
parent 49263 63fd0282ad40
permissions -rw-r--r--
hgweb: encode WSGI environment using the ISO-8859-1 codec The WSGI specification (PEP 3333) specifies that on Python 3 all strings passed by the server must be of type str with code points encodable using the ISO 8859-1 codec. For some reason, I introduced a bug in 2632c1ed8f34 by applying the reverse change. Maybe I got confused because PEP 3333 says that arbitrary operating system environment variables may be contained in the WSGI environment and therefore we need to handle the WSGI environment variables like we would handle operating system environment variables. The bug mentioned in the previous paragraph and fixed by this changeset manifested e.g. in the path of the URL being encoded in the wrong way. Browsers encode non-ASCII bytes with the percent-encoding. WSGI servers will decode the percent-encoded bytes and pass them to the application as strings where each byte is mapped to the corresponding code point with the same ordinal (i.e. it is decoded using the ISO-8859-1 codec). Mercurial uses the bytes type for these strings (which makes much more sense), so we need to encode it again using the ISO-8859-1 codec. If we use another codec, it can result in nonsense.
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
#
46819
d4ba4d51f85f contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents: 46793
diff changeset
     3
# Copyright 2005, 2006 Olivia Mackall <olivia@selenic.com>
8226
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
3877
abaee83ce0a6 Replace demandload with new demandimport
Matt Mackall <mpm@selenic.com>
parents: 3578
diff changeset
     9
import binascii
1089
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
    10
26980
18f50b8cbf1e node: add 'nullhex', hex-encoded nullid
Siddharth Agarwal <sid0@fb.com>
parents: 25962
diff changeset
    11
# 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
    12
hex = binascii.hexlify
49263
63fd0282ad40 node: stop converting binascii.Error to TypeError in bin()
Manuel Jacob <me@manueljacob.de>
parents: 49037
diff changeset
    13
bin = binascii.unhexlify
26980
18f50b8cbf1e node: add 'nullhex', hex-encoded nullid
Siddharth Agarwal <sid0@fb.com>
parents: 25962
diff changeset
    14
43075
57875cf423c9 style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents: 39227
diff changeset
    15
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    16
def short(node):
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    17
    return hex(node[:6])
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    18
1089
142b5d5ec9cc Break apart hg.py
mpm@selenic.com
parents:
diff changeset
    19
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    20
nullrev = -1
30370
0298a07f64d9 dirstate: change placeholder hash length to 20 bytes
Durham Goode <durham@fb.com>
parents: 28585
diff changeset
    21
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    22
# pseudo identifier for working directory
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    23
# (experimental, so don't add too many dependencies on it)
43075
57875cf423c9 style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents: 39227
diff changeset
    24
wdirrev = 0x7FFFFFFF
25737
1a5211f2f87f node: define experimental identifiers for working directory
Yuya Nishihara <yuya@tcha.org>
parents: 10263
diff changeset
    25
43075
57875cf423c9 style: run a patched black on a subset of mercurial
Augie Fackler <augie@google.com>
parents: 39227
diff changeset
    26
49037
642e31cb55f0 py3: use class X: instead of class X(object):
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
    27
class sha1nodeconstants:
46793
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    28
    nodelen = 20
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    29
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    30
    # In hex, this is '0000000000000000000000000000000000000000'
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    31
    nullid = b"\0" * nodelen
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    32
    nullhex = hex(nullid)
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    33
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    34
    # Phony node value to stand-in for new files in some uses of
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    35
    # manifests.
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    36
    # In hex, this is '2121212121212121212121212121212121212121'
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    37
    newnodeid = b'!!!!!!!!!!!!!!!!!!!!'
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    38
    # In hex, this is '3030303030303030303030303030306164646564'
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    39
    addednodeid = b'000000000000000added'
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    40
    # In hex, this is '3030303030303030303030306d6f646966696564'
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    41
    modifiednodeid = b'000000000000modified'
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    42
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    43
    wdirfilenodeids = {newnodeid, addednodeid, modifiednodeid}
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    44
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    45
    # pseudo identifier for working directory
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    46
    # (experimental, so don't add too many dependencies on it)
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    47
    # In hex, this is 'ffffffffffffffffffffffffffffffffffffffff'
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    48
    wdirid = b"\xff" * nodelen
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    49
    wdirhex = hex(wdirid)
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    50
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    51
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    52
# legacy starting point for porting modules
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    53
nullid = sha1nodeconstants.nullid
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    54
nullhex = sha1nodeconstants.nullhex
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    55
newnodeid = sha1nodeconstants.newnodeid
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    56
addednodeid = sha1nodeconstants.addednodeid
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    57
modifiednodeid = sha1nodeconstants.modifiednodeid
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    58
wdirfilenodeids = sha1nodeconstants.wdirfilenodeids
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    59
wdirid = sha1nodeconstants.wdirid
6266d19556ad node: introduce nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 43077
diff changeset
    60
wdirhex = sha1nodeconstants.wdirhex