|
@@ -30,6 +30,9 @@ import stat
|
|
|
from dulwich.errors import (
|
|
|
ObjectFormatException,
|
|
|
)
|
|
|
+from dulwich.misc import (
|
|
|
+ permutations,
|
|
|
+ )
|
|
|
from dulwich.objects import (
|
|
|
Blob,
|
|
|
Tree,
|
|
@@ -64,40 +67,6 @@ tree_sha = '70c190eb48fa8bbb50ddc692a17b44cb781af7f6'
|
|
|
tag_sha = '71033db03a03c6a36721efcf1968dd8f8e0cf023'
|
|
|
|
|
|
|
|
|
-try:
|
|
|
- from itertools import permutations
|
|
|
-except ImportError:
|
|
|
- # Implementation of permutations from Python 2.6 documentation:
|
|
|
- # http://docs.python.org/2.6/library/itertools.html#itertools.permutations
|
|
|
- # Copyright (c) 2001-2010 Python Software Foundation; All Rights Reserved
|
|
|
- # Modified syntax slightly to run under Python 2.4.
|
|
|
- def permutations(iterable, r=None):
|
|
|
- # permutations('ABCD', 2) --> AB AC AD BA BC BD CA CB CD DA DB DC
|
|
|
- # permutations(range(3)) --> 012 021 102 120 201 210
|
|
|
- pool = tuple(iterable)
|
|
|
- n = len(pool)
|
|
|
- if r is None:
|
|
|
- r = n
|
|
|
- if r > n:
|
|
|
- return
|
|
|
- indices = range(n)
|
|
|
- cycles = range(n, n-r, -1)
|
|
|
- yield tuple(pool[i] for i in indices[:r])
|
|
|
- while n:
|
|
|
- for i in reversed(range(r)):
|
|
|
- cycles[i] -= 1
|
|
|
- if cycles[i] == 0:
|
|
|
- indices[i:] = indices[i+1:] + indices[i:i+1]
|
|
|
- cycles[i] = n - i
|
|
|
- else:
|
|
|
- j = cycles[i]
|
|
|
- indices[i], indices[-j] = indices[-j], indices[i]
|
|
|
- yield tuple(pool[i] for i in indices[:r])
|
|
|
- break
|
|
|
- else:
|
|
|
- return
|
|
|
-
|
|
|
-
|
|
|
class TestHexToSha(TestCase):
|
|
|
|
|
|
def test_simple(self):
|