Rev 2239: merge bencode licence, branch todo in http://sourcefrog.net/bzr/tags

Martin Pool mbp at sourcefrog.net
Tue Feb 20 05:41:14 GMT 2007


At http://sourcefrog.net/bzr/tags

------------------------------------------------------------
revno: 2239
revision-id: mbp at sourcefrog.net-20070220054112-5ch1jqmy9m5zbk72
parent: mbp at sourcefrog.net-20070215012807-d5ocuw66i5j8dclk
parent: mbp at sourcefrog.net-20070220052557-e3jtl3uan4ynrtot
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: tags
timestamp: Tue 2007-02-20 16:41:12 +1100
message:
  merge bencode licence, branch todo
removed:
  bzrlib/util/bencode.py         bencode.py-20070213121732-eo93j33urnoog9ml-1
added:
  bzrlib/util/bencode.py         bencode.py-20070220044742-sltr28q21w2wzlxi-1
modified:
  BRANCH.TODO                    BRANCH.TODO-20060103052123-79ac4969351c03a9
    ------------------------------------------------------------
    revno: 2230.1.2
    merged: mbp at sourcefrog.net-20070220052557-e3jtl3uan4ynrtot
    parent: mbp at sourcefrog.net-20070220044754-ptovhd212hs4vkkf
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: tags
    timestamp: Tue 2007-02-20 16:25:57 +1100
    message:
      add branch todo notes
    ------------------------------------------------------------
    revno: 2230.1.1
    merged: mbp at sourcefrog.net-20070220044754-ptovhd212hs4vkkf
    parent: mbp at sourcefrog.net-20070212071826-5x37ixz8r6cylk75
    committer: Martin Pool <mbp at sourcefrog.net>
    branch nick: tags
    timestamp: Tue 2007-02-20 15:47:54 +1100
    message:
      add bencode utility
=== removed file 'bzrlib/util/bencode.py'
--- a/bzrlib/util/bencode.py	2007-02-13 13:01:00 +0000
+++ b/bzrlib/util/bencode.py	1970-01-01 00:00:00 +0000
@@ -1,307 +0,0 @@
-# Written by Petru Paler
-# see LICENSE.txt for license information
-
-def decode_int(x, f):
-    f += 1
-    newf = x.index('e', f)
-    try:
-        n = int(x[f:newf])
-    except (OverflowError, ValueError):
-        n = long(x[f:newf])
-    if x[f] == '-':
-        if x[f + 1] == '0':
-            raise ValueError
-    elif x[f] == '0' and newf != f+1:
-        raise ValueError
-    return (n, newf+1)
-
-def decode_string(x, f):
-    colon = x.index(':', f)
-    try:
-        n = int(x[f:colon])
-    except (OverflowError, ValueError):
-        n = long(x[f:colon])
-    if x[f] == '0' and colon != f+1:
-        raise ValueError
-    colon += 1
-    return (x[colon:colon+n], colon+n)
-
-def decode_list(x, f):
-    r, f = [], f+1
-    while x[f] != 'e':
-        v, f = decode_func[x[f]](x, f)
-        r.append(v)
-    return (r, f + 1)
-
-def decode_dict(x, f):
-    r, f = {}, f+1
-    lastkey = None
-    while x[f] != 'e':
-        k, f = decode_string(x, f)
-        if lastkey >= k:
-            raise ValueError
-        lastkey = k
-        r[k], f = decode_func[x[f]](x, f)
-    return (r, f + 1)
-
-decode_func = {}
-decode_func['l'] = decode_list
-decode_func['d'] = decode_dict
-decode_func['i'] = decode_int
-decode_func['0'] = decode_string
-decode_func['1'] = decode_string
-decode_func['2'] = decode_string
-decode_func['3'] = decode_string
-decode_func['4'] = decode_string
-decode_func['5'] = decode_string
-decode_func['6'] = decode_string
-decode_func['7'] = decode_string
-decode_func['8'] = decode_string
-decode_func['9'] = decode_string
-
-def bdecode(x):
-    try:
-        r, l = decode_func[x[0]](x, 0)
-    except (IndexError, KeyError):
-        raise ValueError
-    if l != len(x):
-        raise ValueError
-    return r
-
-def test_bdecode():
-    try:
-        bdecode('0:0:')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('ie')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('i341foo382e')
-        assert 0
-    except ValueError:
-        pass
-    assert bdecode('i4e') == 4L
-    assert bdecode('i0e') == 0L
-    assert bdecode('i123456789e') == 123456789L
-    assert bdecode('i-10e') == -10L
-    try:
-        bdecode('i-0e')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('i123')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('i6easd')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('35208734823ljdahflajhdf')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('2:abfdjslhfld')
-        assert 0
-    except ValueError:
-        pass
-    assert bdecode('0:') == ''
-    assert bdecode('3:abc') == 'abc'
-    assert bdecode('10:1234567890') == '1234567890'
-    try:
-        bdecode('02:xy')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('l')
-        assert 0
-    except ValueError:
-        pass
-    assert bdecode('le') == []
-    try:
-        bdecode('leanfdldjfh')
-        assert 0
-    except ValueError:
-        pass
-    assert bdecode('l0:0:0:e') == ['', '', '']
-    try:
-        bdecode('relwjhrlewjh')
-        assert 0
-    except ValueError:
-        pass
-    assert bdecode('li1ei2ei3ee') == [1, 2, 3]
-    assert bdecode('l3:asd2:xye') == ['asd', 'xy']
-    assert bdecode('ll5:Alice3:Bobeli2ei3eee') == [['Alice', 'Bob'], [2, 3]]
-    try:
-        bdecode('d')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('defoobar')
-        assert 0
-    except ValueError:
-        pass
-    assert bdecode('de') == {}
-    assert bdecode('d3:agei25e4:eyes4:bluee') == {'age': 25, 'eyes': 'blue'}
-    assert bdecode('d8:spam.mp3d6:author5:Alice6:lengthi100000eee') == {'spam.mp3': {'author': 'Alice', 'length': 100000}}
-    try:
-        bdecode('d3:fooe')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('di1e0:e')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('d1:b0:1:a0:e')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('d1:a0:1:a0:e')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('i03e')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('l01:ae')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('9999:x')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('l0:')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('d0:0:')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('d0:')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('00:')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('l-3:e')
-        assert 0
-    except ValueError:
-        pass
-    try:
-        bdecode('i-03e')
-        assert 0
-    except ValueError:
-        pass
-    bdecode('d0:i3ee')
-
-from types import StringType, IntType, LongType, DictType, ListType, TupleType
-
-class Bencached(object):
-    __slots__ = ['bencoded']
-
-    def __init__(self, s):
-        self.bencoded = s
-
-def encode_bencached(x,r):
-    r.append(x.bencoded)
-
-def encode_int(x, r):
-    r.extend(('i', str(x), 'e'))
-
-def encode_string(x, r):
-    r.extend((str(len(x)), ':', x))
-
-def encode_list(x, r):
-    r.append('l')
-    for i in x:
-        encode_func[type(i)](i, r)
-    r.append('e')
-
-def encode_dict(x,r):
-    r.append('d')
-    ilist = x.items()
-    ilist.sort()
-    for k, v in ilist:
-        r.extend((str(len(k)), ':', k))
-        encode_func[type(v)](v, r)
-    r.append('e')
-
-encode_func = {}
-encode_func[type(Bencached(0))] = encode_bencached
-encode_func[IntType] = encode_int
-encode_func[LongType] = encode_int
-encode_func[StringType] = encode_string
-encode_func[ListType] = encode_list
-encode_func[TupleType] = encode_list
-encode_func[DictType] = encode_dict
-
-try:
-    from types import BooleanType
-    encode_func[BooleanType] = encode_int
-except ImportError:
-    pass
-
-def bencode(x):
-    r = []
-    encode_func[type(x)](x, r)
-    return ''.join(r)
-
-def test_bencode():
-    assert bencode(4) == 'i4e'
-    assert bencode(0) == 'i0e'
-    assert bencode(-10) == 'i-10e'
-    assert bencode(12345678901234567890L) == 'i12345678901234567890e'
-    assert bencode('') == '0:'
-    assert bencode('abc') == '3:abc'
-    assert bencode('1234567890') == '10:1234567890'
-    assert bencode([]) == 'le'
-    assert bencode([1, 2, 3]) == 'li1ei2ei3ee'
-    assert bencode([['Alice', 'Bob'], [2, 3]]) == 'll5:Alice3:Bobeli2ei3eee'
-    assert bencode({}) == 'de'
-    assert bencode({'age': 25, 'eyes': 'blue'}) == 'd3:agei25e4:eyes4:bluee'
-    assert bencode({'spam.mp3': {'author': 'Alice', 'length': 100000}}) == 'd8:spam.mp3d6:author5:Alice6:lengthi100000eee'
-    assert bencode(Bencached(bencode(3))) == 'i3e'
-    try:
-        bencode({1: 'foo'})
-    except TypeError:
-        return
-    assert 0
-
-try:
-    import psyco
-    psyco.bind(bdecode)
-    psyco.bind(bencode)
-except ImportError:
-    pass

=== added file 'bzrlib/util/bencode.py'
--- a/bzrlib/util/bencode.py	1970-01-01 00:00:00 +0000
+++ b/bzrlib/util/bencode.py	2007-02-20 04:47:54 +0000
@@ -0,0 +1,328 @@
+# bencode structured encoding
+#
+# Written by Petru Paler
+#
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation files
+# (the "Software"), to deal in the Software without restriction,
+# including without limitation the rights to use, copy, modify, merge,
+# publish, distribute, sublicense, and/or sell copies of the Software,
+# and to permit persons to whom the Software is furnished to do so,
+# subject to the following conditions:
+# 
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+# 
+# The Software is provided "AS IS", without warranty of any kind,
+# express or implied, including but not limited to the warranties of
+# merchantability,  fitness for a particular purpose and
+# noninfringement. In no event shall the  authors or copyright holders
+# be liable for any claim, damages or other liability, whether in an
+# action of contract, tort or otherwise, arising from, out of or in
+# connection with the Software or the use or other dealings in the
+# Software.
+
+def decode_int(x, f):
+    f += 1
+    newf = x.index('e', f)
+    try:
+        n = int(x[f:newf])
+    except (OverflowError, ValueError):
+        n = long(x[f:newf])
+    if x[f] == '-':
+        if x[f + 1] == '0':
+            raise ValueError
+    elif x[f] == '0' and newf != f+1:
+        raise ValueError
+    return (n, newf+1)
+
+def decode_string(x, f):
+    colon = x.index(':', f)
+    try:
+        n = int(x[f:colon])
+    except (OverflowError, ValueError):
+        n = long(x[f:colon])
+    if x[f] == '0' and colon != f+1:
+        raise ValueError
+    colon += 1
+    return (x[colon:colon+n], colon+n)
+
+def decode_list(x, f):
+    r, f = [], f+1
+    while x[f] != 'e':
+        v, f = decode_func[x[f]](x, f)
+        r.append(v)
+    return (r, f + 1)
+
+def decode_dict(x, f):
+    r, f = {}, f+1
+    lastkey = None
+    while x[f] != 'e':
+        k, f = decode_string(x, f)
+        if lastkey >= k:
+            raise ValueError
+        lastkey = k
+        r[k], f = decode_func[x[f]](x, f)
+    return (r, f + 1)
+
+decode_func = {}
+decode_func['l'] = decode_list
+decode_func['d'] = decode_dict
+decode_func['i'] = decode_int
+decode_func['0'] = decode_string
+decode_func['1'] = decode_string
+decode_func['2'] = decode_string
+decode_func['3'] = decode_string
+decode_func['4'] = decode_string
+decode_func['5'] = decode_string
+decode_func['6'] = decode_string
+decode_func['7'] = decode_string
+decode_func['8'] = decode_string
+decode_func['9'] = decode_string
+
+def bdecode(x):
+    try:
+        r, l = decode_func[x[0]](x, 0)
+    except (IndexError, KeyError):
+        raise ValueError
+    if l != len(x):
+        raise ValueError
+    return r
+
+def test_bdecode():
+    try:
+        bdecode('0:0:')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('ie')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('i341foo382e')
+        assert 0
+    except ValueError:
+        pass
+    assert bdecode('i4e') == 4L
+    assert bdecode('i0e') == 0L
+    assert bdecode('i123456789e') == 123456789L
+    assert bdecode('i-10e') == -10L
+    try:
+        bdecode('i-0e')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('i123')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('i6easd')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('35208734823ljdahflajhdf')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('2:abfdjslhfld')
+        assert 0
+    except ValueError:
+        pass
+    assert bdecode('0:') == ''
+    assert bdecode('3:abc') == 'abc'
+    assert bdecode('10:1234567890') == '1234567890'
+    try:
+        bdecode('02:xy')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('l')
+        assert 0
+    except ValueError:
+        pass
+    assert bdecode('le') == []
+    try:
+        bdecode('leanfdldjfh')
+        assert 0
+    except ValueError:
+        pass
+    assert bdecode('l0:0:0:e') == ['', '', '']
+    try:
+        bdecode('relwjhrlewjh')
+        assert 0
+    except ValueError:
+        pass
+    assert bdecode('li1ei2ei3ee') == [1, 2, 3]
+    assert bdecode('l3:asd2:xye') == ['asd', 'xy']
+    assert bdecode('ll5:Alice3:Bobeli2ei3eee') == [['Alice', 'Bob'], [2, 3]]
+    try:
+        bdecode('d')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('defoobar')
+        assert 0
+    except ValueError:
+        pass
+    assert bdecode('de') == {}
+    assert bdecode('d3:agei25e4:eyes4:bluee') == {'age': 25, 'eyes': 'blue'}
+    assert bdecode('d8:spam.mp3d6:author5:Alice6:lengthi100000eee') == {'spam.mp3': {'author': 'Alice', 'length': 100000}}
+    try:
+        bdecode('d3:fooe')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('di1e0:e')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('d1:b0:1:a0:e')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('d1:a0:1:a0:e')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('i03e')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('l01:ae')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('9999:x')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('l0:')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('d0:0:')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('d0:')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('00:')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('l-3:e')
+        assert 0
+    except ValueError:
+        pass
+    try:
+        bdecode('i-03e')
+        assert 0
+    except ValueError:
+        pass
+    bdecode('d0:i3ee')
+
+from types import StringType, IntType, LongType, DictType, ListType, TupleType
+
+class Bencached(object):
+    __slots__ = ['bencoded']
+
+    def __init__(self, s):
+        self.bencoded = s
+
+def encode_bencached(x,r):
+    r.append(x.bencoded)
+
+def encode_int(x, r):
+    r.extend(('i', str(x), 'e'))
+
+def encode_string(x, r):
+    r.extend((str(len(x)), ':', x))
+
+def encode_list(x, r):
+    r.append('l')
+    for i in x:
+        encode_func[type(i)](i, r)
+    r.append('e')
+
+def encode_dict(x,r):
+    r.append('d')
+    ilist = x.items()
+    ilist.sort()
+    for k, v in ilist:
+        r.extend((str(len(k)), ':', k))
+        encode_func[type(v)](v, r)
+    r.append('e')
+
+encode_func = {}
+encode_func[type(Bencached(0))] = encode_bencached
+encode_func[IntType] = encode_int
+encode_func[LongType] = encode_int
+encode_func[StringType] = encode_string
+encode_func[ListType] = encode_list
+encode_func[TupleType] = encode_list
+encode_func[DictType] = encode_dict
+
+try:
+    from types import BooleanType
+    encode_func[BooleanType] = encode_int
+except ImportError:
+    pass
+
+def bencode(x):
+    r = []
+    encode_func[type(x)](x, r)
+    return ''.join(r)
+
+def test_bencode():
+    assert bencode(4) == 'i4e'
+    assert bencode(0) == 'i0e'
+    assert bencode(-10) == 'i-10e'
+    assert bencode(12345678901234567890L) == 'i12345678901234567890e'
+    assert bencode('') == '0:'
+    assert bencode('abc') == '3:abc'
+    assert bencode('1234567890') == '10:1234567890'
+    assert bencode([]) == 'le'
+    assert bencode([1, 2, 3]) == 'li1ei2ei3ee'
+    assert bencode([['Alice', 'Bob'], [2, 3]]) == 'll5:Alice3:Bobeli2ei3eee'
+    assert bencode({}) == 'de'
+    assert bencode({'age': 25, 'eyes': 'blue'}) == 'd3:agei25e4:eyes4:bluee'
+    assert bencode({'spam.mp3': {'author': 'Alice', 'length': 100000}}) == 'd8:spam.mp3d6:author5:Alice6:lengthi100000eee'
+    assert bencode(Bencached(bencode(3))) == 'i3e'
+    try:
+        bencode({1: 'foo'})
+    except TypeError:
+        return
+    assert 0
+
+try:
+    import psyco
+    psyco.bind(bdecode)
+    psyco.bind(bencode)
+except ImportError:
+    pass

=== modified file 'BRANCH.TODO'
--- a/BRANCH.TODO	2006-10-05 10:23:20 +0000
+++ b/BRANCH.TODO	2007-02-20 05:25:57 +0000
@@ -2,9 +2,97 @@
 # It should ALWAYS be empty in the mainline or in integration branches.
 # 
 
-Security: it should be impossible, by default, to access files above the base of
-the backing transport of the SmartServerRequestHandler.  Currently '..' and the
-like are not vetted, however.
-
-Similarly, the SmartWSGIApp should also be careful to disallow '..' and the
-like.
+Short-and-sweet implementation of tags for bzr
+
+Key features:
+
+Tags are stored in a repository.  Tags are pointers from names to revision
+ids.  Normally there should be a single universal definition for any tag
+name, though reality diverges from this in several important cases,
+including:
+
+ * A new tag has been added in a repository, but not yet propagated to its 
+   mirrors.
+
+There is a single set of tag definitions visible by all operations within
+that repository.  The history of tags is not recorded (though we could
+perhaps record who made the tags and when, just for human reference).
+
+This patch modifies RepositoryFormatKnit2 to add tag support.  This 
+should be ok as this format is marked as experimental, though it has 
+shipped in previous releases.  If people are using it, and use an old 
+client to copy a repository it may lose the tag information.
+
+
+Done
+----
+
+ - method to get tags from a repository - there are none at present
+ - this should return nothing (or None) on old formats, or say that
+   it's not supported
+ - add a new repository format which does have tags 
+ - get a single tag, or complain if it's not defined
+ - add a tag command which tags a revision, by adding an entry into the 
+   repository's tag dictionary
+ - add tag:foo revision spec, and make sure it can be used 
+ - separate tag storage into a strategy object?
+ - raise TagsNotSupported on repositories that don't
+ - make tag on arbitrary revisions
+ - copy tags when cloning the repository
+ - copy tags on push and pull
+
+Plan
+----
+
+ - move tag operations onto branch
+ - store tags in bencode format - or nul-delimited
+ - test use of unicode tags
+ - delete tags, and mark as deleted
+ - record who set tags, when, why
+ - tests that -d accepts urls, etc
+ - copy only selected tags
+ - if tags conflict when copying
+   - return them and give a warning
+   - option to override this and copy anyhow
+ - give a nice message when trying to copy tags if it can't be done
+ - when fetching revisions, also copy tags
+   - give a warning if the tags differ, and don't override them
+   - allow this to be forced
+ - raise an exception if the tag name is unreasonable
+ - refuse to add tags if the tag is already present, but allow it to 
+   be forced
+ - command to show all tags
+ - command to remove a tag
+ - show tags in log
+ - test copying tags between different repository formats?  a 
+   bit hard as there's only one at the moment...
+ - include tags in bundles?
+
+
+Also to do
+----------
+
+Are LockableFiles still really useful, rather than just?  Being lockable is
+perhaps not the point - rather that they have common conventions for how we
+treat our control files...
+
+Split repository.py into separate files for different formats?
+
+Have a single 'Experimental' format containing all work that's not yet
+released?
+
+A single method to get the contents of a (small) file as bytes of utf8 -- on
+Transport, I think, since many Transports can do that more efficiently than
+returning a file-like object.
+
+Keep the lock while constructing the Repository, so that we can call
+things that expect the lock to be held, and avoid taking or releasing it,
+or someone else seeing the half-constructed Repository.
+
+put_bytes_nonatomic may fairly often have the case of writing no content
+(and only creating the file) - we could test for and avoid one roundtrip.
+
+Split builtin commands into separate files, lazily loaded. 
+
+ - Change commands to use a standard Registry.
+ - Register commands lazily.




More information about the bazaar-commits mailing list