Rev 333: Use checksums for the path in case the file id is too long (fixes #77453). in http://people.samba.org/bzr/jelmer/bzr-svn/bzr.dev

Jelmer Vernooij jelmer at samba.org
Fri Dec 29 23:22:51 GMT 2006


------------------------------------------------------------
revno: 333
revision-id: jelmer at samba.org-20061229231829-2rwwhu07q2u774k8
parent: jelmer at samba.org-20061229211551-5f6dzb5dk7z59iqg
committer: Jelmer Vernooij <jelmer at samba.org>
branch nick: main
timestamp: Sat 2006-12-30 00:18:29 +0100
message:
  Use checksums for the path in case the file id is too long (fixes #77453). 
modified:
  fileids.py                     fileids.py-20060714013623-u5iiyqqnko11grcf-1
  mapping.txt                    mapping.txt-20060625151311-9ghaqrm71ajq593n-1
  tests/test_fileids.py          test_fileids.py-20060622131341-19gyrlgqy8yl2od5-1
=== modified file 'fileids.py'
--- a/fileids.py	2006-12-29 19:21:54 +0000
+++ b/fileids.py	2006-12-29 23:18:29 +0000
@@ -24,6 +24,7 @@
 from warnings import warn
 
 import os
+import sha
 
 import logwalker
 from repository import (escape_svn_path, generate_svn_revision_id, 
@@ -35,12 +36,19 @@
     :param uuid: UUID of the repository
     :param revnu: Revision number at which the file was introduced.
     :param branch: Branch path of the branch in which the file was introduced.
-    :param path: Original path of the file.
+    :param path: Original path of the file within the branch
     """
     if path == "":
         return ROOT_ID
     introduced_revision_id = generate_svn_revision_id(uuid, revnum, branch)
-    return "%s-%s" % (introduced_revision_id, escape_svn_path(path))
+    ret = "%s-%s" % (introduced_revision_id, escape_svn_path(path))
+    if len(ret) > 250:
+        basename = os.path.basename(path)
+        parent = path[:-len(basename)]
+        ret = "%s-%s-%s" % (introduced_revision_id, 
+                            sha.new(parent).hexdigest(),
+                            escape_svn_path(basename))
+    return ret
 
 
 def generate_file_id(revid, path):

=== modified file 'mapping.txt'
--- a/mapping.txt	2006-12-26 00:12:31 +0000
+++ b/mapping.txt	2006-12-29 23:18:29 +0000
@@ -83,6 +83,13 @@
 If a file is being replaced by a copy of itself in an older revision it will 
 receive a new file id.
 
+If the file id generated is longer than 250 bytes, the following format will 
+be used:
+
+<REVID>-<SHA1>-<FILENAME>
+
+where <SHA1> is the sha1 of the path to the directory name.
+
 NEXT VERSION: Special rules are applied to make sure that renames are tracked.
 
 == Properties ==

=== modified file 'tests/test_fileids.py'
--- a/tests/test_fileids.py	2006-12-29 19:21:54 +0000
+++ b/tests/test_fileids.py	2006-12-29 23:18:29 +0000
@@ -21,6 +21,8 @@
 from bzrlib.trace import mutter
 from bzrlib.tests import TestSkipped, TestCase
 
+import sha
+
 import format
 from fileids import SimpleFileIdMap, generate_file_id
 from repository import MAPPING_VERSION
@@ -147,6 +149,19 @@
                 "svn-v%d:1@%s-trunk" % (MAPPING_VERSION, repository.uuid), 
                 revid)
 
+def sha1(str):
+    return sha.new(str).hexdigest()
+
+class TestFileIdGenerator(TestCase):
+    def test_generate_file_id_path(self):
+        self.assertEqual("svn-v2:2 at uuid-bp-mypath", 
+                         generate_file_id("svn-v2:2 at uuid-bp", "mypath"))
+
+    def test_generate_file_id_long(self):
+        dir = "this/is/a" + ("/very"*40) + "/long/path/"
+        self.assertEqual("svn-v2:2 at uuid-bp-" + sha1(dir) + "-filename", 
+                         generate_file_id("svn-v2:2 at uuid-bp", dir+"filename"))
+
 class TestFileMapping(TestCase):
     def apply_mappings(self, mappings, find_children=None):
         map = {}




More information about the bazaar-commits mailing list