[MERGE] gen_file_ids() should create more filesystem friendly file ids.
Martin Pool
mbp at canonical.com
Thu Jul 20 02:56:57 BST 2006
On 18 Jul 2006, John Arbash Meinel <john at arbash-meinel.com> wrote:
> The attached patch fixes bug:
> https://launchpad.net/products/bzr/+bug/43801
+1 for 0.9, thankyou.
> def test_gen_file_id(self):
> - self.assertStartsWith(bzrlib.workingtree.gen_file_id('bar'), 'bar-')
> - self.assertStartsWith(bzrlib.workingtree.gen_file_id('Mwoo oof\t m'), 'Mwoooofm-')
> - self.assertStartsWith(bzrlib.workingtree.gen_file_id('..gam.py'), 'gam.py-')
> - self.assertStartsWith(bzrlib.workingtree.gen_file_id('..Mwoo oof\t m'), 'Mwoooofm-')
> + gen_file_id = bzrlib.workingtree.gen_file_id
> +
> + # We try to use the filename if possible
> + self.assertStartsWith(gen_file_id('bar'), 'bar-')
> +
> + # but we squash capitalization, and remove non word characters
> + self.assertStartsWith(gen_file_id('Mwoo oof\t m'), 'mwoooofm-')
> +
> + # We also remove leading '.' characters to prevent hidden file-ids
> + self.assertStartsWith(gen_file_id('..gam.py'), 'gam.py-')
> + self.assertStartsWith(gen_file_id('..Mwoo oof\t m'), 'mwoooofm-')
> +
> + # we remove unicode characters, and still don't end up with a
> + # hidden file id
> + self.assertStartsWith(gen_file_id(u'\xe5\xb5.txt'), 'txt-')
> +
> + # We truncate long filenames to be friendly to OS. This is
> + # less important with case squashing, because we do less escaping
> + # (A long all-caps filename used to create a *huge* filename on disk)
> + fid = gen_file_id('A'*50 + '.txt')
> + self.assertStartsWith(fid, 'a'*20 + '-')
Perhaps it would be more to the point of your comment to assert that the
result is less than ~60 characters (or whatever)
> +
> + # restricting length happens after the other actions, so
> + # we preserv as much as possible
> + fid = gen_file_id('\xe5\xb5..aBcd\tefGhijKLMnop\tqrstuvwxyz')
> + self.assertStartsWith(fid, 'abcdefghijklmnopqrst-')
and again here.
I realize they'll both pass but I'm just thinking about making sure to
test the right requirement.
Thanks for adding the tests.
--
Martin
More information about the bazaar
mailing list