Rev 3131: (jam) allow _patience_diff_c to support any object that supports in file:///home/pqm/archives/thelove/bzr/%2Btrunk/
Canonical.com Patch Queue Manager
pqm at pqm.ubuntu.com
Wed Dec 19 23:40:50 GMT 2007
At file:///home/pqm/archives/thelove/bzr/%2Btrunk/
------------------------------------------------------------
revno: 3131
revision-id:pqm at pqm.ubuntu.com-20071219234039-462zdjboqfg4lcr1
parent: pqm at pqm.ubuntu.com-20071219211725-mgnpnt2keboqflwi
parent: john at arbash-meinel.com-20071219224427-iovj1ha49yuo2rjf
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Wed 2007-12-19 23:40:39 +0000
message:
(jam) allow _patience_diff_c to support any object that supports
hash()
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/_patiencediff_c.c _patiencediff_c.c-20070721205602-q3imkipwlgagp3cy-1
bzrlib/tests/test_diff.py testdiff.py-20050727164403-d1a3496ebb12e339
------------------------------------------------------------
revno: 3074.2.12
revision-id:john at arbash-meinel.com-20071219224427-iovj1ha49yuo2rjf
parent: john at arbash-meinel.com-20071219223929-l239ac2atqdcapb8
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: patience_tuples
timestamp: Wed 2007-12-19 16:44:27 -0600
message:
NEWS
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
------------------------------------------------------------
revno: 3074.2.11
revision-id:john at arbash-meinel.com-20071219223929-l239ac2atqdcapb8
parent: john at arbash-meinel.com-20071219164503-dxzdtrm0i3jet9ea
parent: pqm at pqm.ubuntu.com-20071219091053-81xgp971m1pgmccf
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: patience_tuples
timestamp: Wed 2007-12-19 16:39:29 -0600
message:
[merge] bzr.dev 3129
removed:
doc/en/user-reference/index.txt index.txt-20070830033353-ud9e03xsh24053oo-1
added:
bzrlib/help_topics/ help_topics-20071211013603-qz0sojhgxhiujm6a-1
bzrlib/help_topics/en/ bzrlibhelp-20071209214431-xzg3moksichjwyts-1
bzrlib/version_info_formats/format_custom.py format_custom.py-20071029100350-ajovqhbpb5khf6gu-1
doc/en/quick-reference/quick-start-summary.pdf quickstartsummary.pd-20071207005239-it6xmdjml8nxvzgt-1
doc/en/quick-reference/quick-start-summary.png quickstartsummary.pn-20071203142852-hsiybkmh37q5owwe-1
doc/en/user-guide/adv_merging.txt adv_merging.txt-20071213070245-d7u7150lb2hhnvby-1
doc/en/user-reference/readme.txt readme.txt-20071211133352-guencaey6fpesv4j-1
index.txt index.txt-20071121073725-0corxykv5irjal00-1
renamed:
bzrlib/help_topics.py => bzrlib/help_topics/__init__.py help_topics.py-20060920210027-rnim90q9e0bwxvy4-1
doc/en/user-guide/authentication_conf.txt => bzrlib/help_topics/en/authentication.txt authentication_conf.-20071104135035-glfv0ri355tyg1nf-1
doc/en/user-guide/configuration.txt => bzrlib/help_topics/en/configuration.txt configuration.txt-20060314161707-868350809502af01
doc/en/user-guide/conflicts.txt => bzrlib/help_topics/en/conflicts.txt conflicts.txt-20070723221841-ns3jvwxdb4okn6fk-1
doc/en/user-reference/hooks.txt => bzrlib/help_topics/en/hooks.txt hooks.txt-20070830033044-xxu2rced13f72dka-1
modified:
.bzrignore bzrignore-20050311232317-81f7b71efa2db11a
Makefile Makefile-20050805140406-d96e3498bb61c5bb
NEWS NEWS-20050323055033-4e00b5db738777ff
README README-20050309040720-8f368abf9f346b9d
bzr bzr.py-20050313053754-5485f144c7006fa6
bzrlib/__init__.py __init__.py-20050309040759-33e65acf91bbcd5d
bzrlib/branch.py branch.py-20050309040759-e4baf4e0d046576e
bzrlib/bugtracker.py bugtracker.py-20070410073305-vu1vu1qosjurg8kb-1
bzrlib/builtins.py builtins.py-20050830033751-fc01482b9ca23183
bzrlib/bundle/serializer/v4.py v10.py-20070611062757-5ggj7k18s9dej0fr-1
bzrlib/bzrdir.py bzrdir.py-20060131065624-156dfea39c4387cb
bzrlib/cmd_version_info.py __init__.py-20051228204928-697d01fdca29c99b
bzrlib/config.py config.py-20051011043216-070c74f4e9e338e8
bzrlib/debug.py debug.py-20061102062349-vdhrw9qdpck8cl35-1
bzrlib/diff.py diff.py-20050309040759-26944fbbf2ebbf36
bzrlib/dirstate.py dirstate.py-20060728012006-d6mvoihjb3je9peu-1
bzrlib/errors.py errors.py-20050309040759-20512168c4e14fbd
bzrlib/graph.py graph_walker.py-20070525030359-y852guab65d4wtn0-1
bzrlib/index.py index.py-20070712131115-lolkarso50vjr64s-1
bzrlib/inventory.py inventory.py-20050309040759-6648b84ca2005b37
bzrlib/lockable_files.py control_files.py-20051111201905-bb88546e799d669f
bzrlib/log.py log.py-20050505065812-c40ce11702fe5fb1
bzrlib/merge.py merge.py-20050513021216-953b65a438527106
bzrlib/merge_directive.py merge_directive.py-20070228184838-ja62280spt1g7f4x-1
bzrlib/osutils.py osutils.py-20050309040759-eeaff12fbf77ac86
bzrlib/plugins/launchpad/lp_indirect.py lp_indirect.py-20070126012204-de5rugwlt22c7u7e-1
bzrlib/plugins/launchpad/test_lp_indirect.py test_lp_indirect.py-20070126002743-oyle362tzv9cd8mi-1
bzrlib/reconfigure.py reconfigure.py-20070908040425-6ykgo7escxhyrg9p-1
bzrlib/remote.py remote.py-20060720103555-yeeg2x51vn0rbtdp-1
bzrlib/repofmt/knitrepo.py knitrepo.py-20070206081537-pyy4a00xdas0j4pf-1
bzrlib/repofmt/pack_repo.py pack_repo.py-20070813041115-gjv5ma7ktfqwsjgn-1
bzrlib/repository.py rev_storage.py-20051111201905-119e9401e46257e3
bzrlib/revision.py revision.py-20050309040759-e77802c08f3999d5
bzrlib/smart/medium.py medium.py-20061103051856-rgu2huy59fkz902q-1
bzrlib/switch.py switch.py-20071116011000-v5lnw7d2wkng9eux-1
bzrlib/symbol_versioning.py symbol_versioning.py-20060105104851-9ecf8af605d15a80
bzrlib/tests/HttpServer.py httpserver.py-20061012142527-m1yxdj1xazsf8d7s-1
bzrlib/tests/TestUtil.py TestUtil.py-20050824080200-5f70140a2d938694
bzrlib/tests/__init__.py selftest.py-20050531073622-8d0e3c8845c97a64
bzrlib/tests/blackbox/test_bound_branches.py test_bound_branches.py-20051109215527-2373188ad566c205
bzrlib/tests/blackbox/test_cat.py test_cat.py-20051201162916-f0937e4e19ea24b3
bzrlib/tests/blackbox/test_commit.py test_commit.py-20060212094538-ae88fc861d969db0
bzrlib/tests/blackbox/test_diff.py test_diff.py-20060110203741-aa99ac93e633d971
bzrlib/tests/blackbox/test_exceptions.py test_exceptions.py-20060604211237-yi2cxg0ose3xk4id-1
bzrlib/tests/blackbox/test_info.py test_info.py-20060215045507-bbdd2d34efab9e0a
bzrlib/tests/blackbox/test_log.py test_log.py-20060112090212-78f6ea560c868e24
bzrlib/tests/blackbox/test_non_ascii.py test_non_ascii.py-20060105214030-68010be784a5d854
bzrlib/tests/blackbox/test_outside_wt.py test_outside_wt.py-20060116200058-98edd33e7db8bdde
bzrlib/tests/blackbox/test_push.py test_push.py-20060329002750-929af230d5d22663
bzrlib/tests/blackbox/test_send.py test_bundle.py-20060616222707-c21c8b7ea5ef57b1
bzrlib/tests/blackbox/test_split.py test_split.py-20061008023421-qy0vdpzysh5rriu8-1
bzrlib/tests/blackbox/test_uncommit.py test_uncommit.py-20051027212835-84944b63adae51be
bzrlib/tests/branch_implementations/test_branch.py testbranch.py-20050711070244-121d632bc37d7253
bzrlib/tests/repository_implementations/__init__.py __init__.py-20060131092037-9564957a7d4a841b
bzrlib/tests/repository_implementations/test_repository.py test_repository.py-20060131092128-ad07f494f5c9d26c
bzrlib/tests/test_ancestry.py test_ancestry.py-20050913023709-69768e94848312c6
bzrlib/tests/test_bugtracker.py test_bugtracker.py-20070410073305-vu1vu1qosjurg8kb-2
bzrlib/tests/test_config.py testconfig.py-20051011041908-742d0c15d8d8c8eb
bzrlib/tests/test_diff.py testdiff.py-20050727164403-d1a3496ebb12e339
bzrlib/tests/test_errors.py test_errors.py-20060210110251-41aba2deddf936a8
bzrlib/tests/test_extract.py test_extract.py-20061002214140-qdnnm67q1ov6x6pd-1
bzrlib/tests/test_graph.py test_graph_walker.py-20070525030405-enq4r60hhi9xrujc-1
bzrlib/tests/test_help.py test_help.py-20070419045354-6q6rq15j9e2n5fna-1
bzrlib/tests/test_http.py testhttp.py-20051018020158-b2eef6e867c514d9
bzrlib/tests/test_http_response.py test_http_response.py-20060628233143-950b2a482a32505d
bzrlib/tests/test_lockable_files.py test_lockable_files.py-20051225183927-365c7fd99591caf1
bzrlib/tests/test_log.py testlog.py-20050728115707-1a514809d7d49309
bzrlib/tests/test_merge_directive.py test_merge_directive-20070228184838-ja62280spt1g7f4x-2
bzrlib/tests/test_msgeditor.py test_msgeditor.py-20051202041359-920315ec6011ee51
bzrlib/tests/test_osutils.py test_osutils.py-20051201224856-e48ee24c12182989
bzrlib/tests/test_reconfigure.py test_reconfigure.py-20070908040425-6ykgo7escxhyrg9p-2
bzrlib/tests/test_repository.py test_repository.py-20060131075918-65c555b881612f4d
bzrlib/tests/test_revision.py testrevision.py-20050804210559-46f5e1eb67b01289
bzrlib/tests/test_selftest.py test_selftest.py-20051202044319-c110a115d8c0456a
bzrlib/tests/test_switch.py test_switch.py-20071116011000-v5lnw7d2wkng9eux-2
bzrlib/tests/test_transform.py test_transaction.py-20060105172520-b3ffb3946550e6c4
bzrlib/tests/test_transport.py testtransport.py-20050718175618-e5cdb99f4555ddce
bzrlib/tests/test_transport_implementations.py test_transport_implementations.py-20051227111451-f97c5c7d5c49fce7
bzrlib/tests/test_version_info.py test_version_info.py-20051228204928-2c364e30b702b41b
bzrlib/tests/tree_implementations/test_inv.py test_inv.py-20070312023226-0cdvk5uwhutis9vg-1
bzrlib/trace.py trace.py-20050309040759-c8ed824bdcd4748a
bzrlib/transform.py transform.py-20060105172343-dd99e54394d91687
bzrlib/transport/__init__.py transport.py-20050711165921-4978aa7ce1285ad5
bzrlib/transport/http/__init__.py http_transport.py-20050711212304-506c5fd1059ace96
bzrlib/transport/http/_pycurl.py pycurlhttp.py-20060110060940-4e2a705911af77a6
bzrlib/transport/http/_urllib.py _urlgrabber.py-20060113083826-0bbf7d992fbf090c
bzrlib/transport/http/_urllib2_wrappers.py _urllib2_wrappers.py-20060913231729-ha9ugi48ktx481ao-1
bzrlib/transport/http/response.py _response.py-20060613154423-a2ci7hd4iw5c7fnt-1
bzrlib/version_info_formats/__init__.py generate_version_info.py-20051228204928-8358edabcddcd97e
bzrlib/workingtree.py workingtree.py-20050511021032-29b6ec0a681e02e3
doc/developers/bundles.txt bundles.txt-20070621030528-qkjnugd7iyud6ow3-1
doc/developers/index.txt index.txt-20070508041241-qznziunkg0nffhiw-1
doc/developers/packrepo.txt knitpack.txt-20071023074744-q0g5u8me8gk5zbtb-1
doc/en/mini-tutorial/index.txt index.txt-20070813141352-2u64ooqzo0or4hss-2
doc/en/quick-reference/quick-start-summary.svg quickstartsummary.sv-20070813143223-5i7bgw7w8s7l3ae2-3
doc/en/user-guide/browsing_history.txt browsing_history.txt-20071121073725-0corxykv5irjal00-2
doc/en/user-guide/bug_trackers.txt bug_trackers.txt-20070713223459-khxdlcudraii95uv-1
doc/en/user-guide/configuring_bazaar.txt configuring_bazaar.t-20071128000722-ncxiua259xwbdbg7-1
doc/en/user-guide/core_concepts.txt core_concepts.txt-20071114035000-q36a9h57ps06uvnl-2
doc/en/user-guide/hooks.txt hooks.txt-20070829200551-7nr6e5a1io6x78uf-1
doc/en/user-guide/http_smart_server.txt fastcgi.txt-20061005091552-rz8pva0olkxv0sd8-3
doc/en/user-guide/index.txt index.txt-20060622101119-tgwtdci8z769bjb9-2
doc/en/user-guide/installing_bazaar.txt installing_bazaar.tx-20071114035000-q36a9h57ps06uvnl-4
doc/en/user-guide/introducing_bazaar.txt introducing_bazaar.t-20071114035000-q36a9h57ps06uvnl-5
doc/en/user-guide/merging_changes.txt merging_changes.txt-20071122141511-0knao2lklsdsvb1q-3
doc/en/user-guide/plugins.txt plugins.txt-20060314145616-525099a747f3ffdd
doc/en/user-guide/publishing_a_branch.txt publishing_a_branch.-20071123055134-k5x4ekduci2lbn36-2
doc/en/user-guide/resolving_conflicts.txt resolving_conflicts.-20071122141511-0knao2lklsdsvb1q-5
doc/en/user-guide/reusing_a_checkout.txt reusing_a_checkout.t-20071123055134-k5x4ekduci2lbn36-3
doc/en/user-guide/sending_changes.txt sending_changes.txt-20071123154453-dk2mjhrg1vpjm5w2-4
doc/en/user-guide/server.txt server.txt-20060913044801-h939fvbwzz39gf7g-1
doc/en/user-guide/setting_up_email.txt setting_up_email.txt-20060314161707-fd242c8944346173
doc/en/user-guide/specifying_revisions.txt specifying_revisions.txt-20060314161707-19deb139101bea33
doc/en/user-guide/undoing_mistakes.txt undoing_mistakes.txt-20071121092300-8fyacngt1w98e5mp-1
doc/en/user-guide/version_info.txt version_info.txt-20060921215543-gju6o5xdic8w25np-1
doc/en/user-guide/working_offline_central.txt working_offline_cent-20071123055134-k5x4ekduci2lbn36-5
doc/index.txt index.txt-20070813101924-07gd9i9d2jt124bf-1
setup.py setup.py-20050314065409-02f8a0a6e3f9bc70
tools/doc_generate/autodoc_rstx.py autodoc_rstx.py-20060420024836-3e0d4a526452193c
tools/rst2html.py rst2html.py-20060817120932-gn177u8v0008txhu-1
bzrlib/help_topics/__init__.py help_topics.py-20060920210027-rnim90q9e0bwxvy4-1
bzrlib/help_topics/en/authentication.txt authentication_conf.-20071104135035-glfv0ri355tyg1nf-1
bzrlib/help_topics/en/configuration.txt configuration.txt-20060314161707-868350809502af01
bzrlib/help_topics/en/conflicts.txt conflicts.txt-20070723221841-ns3jvwxdb4okn6fk-1
bzrlib/help_topics/en/hooks.txt hooks.txt-20070830033044-xxu2rced13f72dka-1
------------------------------------------------------------
revno: 3074.2.10
revision-id:john at arbash-meinel.com-20071219164503-dxzdtrm0i3jet9ea
parent: john at arbash-meinel.com-20071219154004-wjlljom34fzjw8ws
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: patience_tuples
timestamp: Wed 2007-12-19 10:45:03 -0600
message:
Cleanup the test cases (Andrew)
modified:
bzrlib/tests/test_diff.py testdiff.py-20050727164403-d1a3496ebb12e339
------------------------------------------------------------
revno: 3074.2.9
revision-id:john at arbash-meinel.com-20071219154004-wjlljom34fzjw8ws
parent: john at arbash-meinel.com-20071219151157-stcd2kh9chb4qo61
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: patience_tuples
timestamp: Wed 2007-12-19 09:40:04 -0600
message:
Large simplification by ignoring len() and just sticking with py objects.
modified:
bzrlib/_patiencediff_c.c _patiencediff_c.c-20070721205602-q3imkipwlgagp3cy-1
------------------------------------------------------------
revno: 3074.2.8
revision-id:john at arbash-meinel.com-20071219151157-stcd2kh9chb4qo61
parent: john at arbash-meinel.com-20071205140908-d02s0wgd2wssygwv
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: patience_tuples
timestamp: Wed 2007-12-19 09:11:57 -0600
message:
Stop using const, since PyObject_Compare doesn't like it. (Lukáš)
modified:
bzrlib/_patiencediff_c.c _patiencediff_c.c-20070721205602-q3imkipwlgagp3cy-1
------------------------------------------------------------
revno: 3074.2.7
revision-id:john at arbash-meinel.com-20071205140908-d02s0wgd2wssygwv
parent: john at arbash-meinel.com-20071205140005-aexhlajexv5r1w3l
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: patience_tuples
timestamp: Wed 2007-12-05 08:09:08 -0600
message:
Using just PyObject_Compare: 3.6s-3.9s
modified:
bzrlib/_patiencediff_c.c _patiencediff_c.c-20070721205602-q3imkipwlgagp3cy-1
------------------------------------------------------------
revno: 3074.2.6
revision-id:john at arbash-meinel.com-20071205140005-aexhlajexv5r1w3l
parent: john at arbash-meinel.com-20071205134925-4s1wo9k920cbnavb
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: patience_tuples
timestamp: Wed 2007-12-05 08:00:05 -0600
message:
The numbers are a bit noisy...
Using djb2 hash and memcmp/PyObject_Compare ranges from: 3.5s-4.1s
Using original code ranges from: 3.9s-4.1s
modified:
bzrlib/_patiencediff_c.c _patiencediff_c.c-20070721205602-q3imkipwlgagp3cy-1
------------------------------------------------------------
revno: 3074.2.5
revision-id:john at arbash-meinel.com-20071205134925-4s1wo9k920cbnavb
parent: john at arbash-meinel.com-20071204170735-1l5oc5vt7w473qds
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: patience_tuples
timestamp: Wed 2007-12-05 07:49:25 -0600
message:
using PyObject_Hash, but memcmp if both sides are strings
Using original djb2 hash and only handling strings: 4.340s
With PyObject_Hash and memcmp/PyObject_Compare: 5.550s :(
modified:
bzrlib/_patiencediff_c.c _patiencediff_c.c-20070721205602-q3imkipwlgagp3cy-1
------------------------------------------------------------
revno: 3074.2.4
revision-id:john at arbash-meinel.com-20071204170735-1l5oc5vt7w473qds
parent: john at arbash-meinel.com-20071204162828-chfnl5ylzkh0y2ll
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: patience_tuples
timestamp: Tue 2007-12-04 11:07:35 -0600
message:
Don't leak references to the sequence object.
modified:
bzrlib/_patiencediff_c.c _patiencediff_c.c-20070721205602-q3imkipwlgagp3cy-1
------------------------------------------------------------
revno: 3074.2.3
revision-id:john at arbash-meinel.com-20071204162828-chfnl5ylzkh0y2ll
parent: john at arbash-meinel.com-20071204160709-mmzmchn2daf0quma
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: patience_tuples
timestamp: Tue 2007-12-04 10:28:28 -0600
message:
Enable some error checking, and small amount of code cleanup.
If PyObject_Hash() or PyObject_Length() fails, we should raise an exception, not
silently swallow it.
modified:
bzrlib/_patiencediff_c.c _patiencediff_c.c-20070721205602-q3imkipwlgagp3cy-1
bzrlib/tests/test_diff.py testdiff.py-20050727164403-d1a3496ebb12e339
------------------------------------------------------------
revno: 3074.2.2
revision-id:john at arbash-meinel.com-20071204160709-mmzmchn2daf0quma
parent: john at arbash-meinel.com-20071204152439-hlj4y6a8a2fb6nkz
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: patience_tuples
timestamp: Tue 2007-12-04 10:07:09 -0600
message:
Simple cleanup.
modified:
bzrlib/_patiencediff_c.c _patiencediff_c.c-20070721205602-q3imkipwlgagp3cy-1
------------------------------------------------------------
revno: 3074.2.1
revision-id:john at arbash-meinel.com-20071204152439-hlj4y6a8a2fb6nkz
parent: pqm at pqm.ubuntu.com-20071204035213-2kot5u403spjchen
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: patience_tuples
timestamp: Tue 2007-12-04 09:24:39 -0600
message:
Change the C PatienceDiff implementation to support arbitrary objects.
modified:
bzrlib/_patiencediff_c.c _patiencediff_c.c-20070721205602-q3imkipwlgagp3cy-1
bzrlib/tests/test_diff.py testdiff.py-20050727164403-d1a3496ebb12e339
=== modified file 'NEWS'
--- a/NEWS 2007-12-19 21:17:25 +0000
+++ b/NEWS 2007-12-19 23:40:39 +0000
@@ -83,6 +83,9 @@
dictionary instead of ``get_parents`` returning a list.
``get_parents`` is now considered deprecated. (John Arbash Meinel)
+ * Patience Diff now supports arbitrary python objects, as long as they
+ support ``hash()``. (John Arbash Meinel)
+
API BREAKS:
TESTING:
=== modified file 'bzrlib/_patiencediff_c.c'
--- a/bzrlib/_patiencediff_c.c 2007-09-04 09:10:35 +0000
+++ b/bzrlib/_patiencediff_c.c 2007-12-19 15:40:04 +0000
@@ -70,11 +70,10 @@
struct line {
- int hash; /* hash code of the string */
+ long hash; /* hash code of the string/object */
Py_ssize_t next; /* next line from the same equivalence class */
Py_ssize_t equiv; /* equivalence class */
- Py_ssize_t len;
- const char *data;
+ PyObject *data;
};
@@ -151,8 +150,8 @@
static inline int
compare_lines(struct line *a, struct line *b)
{
- return ((a->hash != b->hash) || (a->len != b->len) ||
- memcmp(a->data, b->data, a->len));
+ return ((a->hash != b->hash)
+ || PyObject_Compare(a->data, b->data));
}
@@ -545,9 +544,7 @@
static Py_ssize_t
load_lines(PyObject *orig, struct line **lines)
{
- Py_ssize_t size, i, j;
- int h;
- char *p;
+ Py_ssize_t size, i;
struct line *line;
PyObject *seq, *item;
@@ -571,29 +568,18 @@
for (i = 0; i < size; i++) {
item = PySequence_Fast_GET_ITEM(seq, i);
- if (!PyString_Check(item)){
- PyErr_Format(PyExc_TypeError,
- "sequence item %zd: expected string,"
- " %.80s found",
- i, item->ob_type->tp_name);
- Py_DECREF(seq);
- return -1;
+ line->data = item;
+ line->hash = PyObject_Hash(item);
+ if (line->hash == (-1)) {
+ /* Propogate the hash exception */
+ size = -1;
+ goto cleanup;
}
- line->len = PyString_GET_SIZE(item);
- line->data = p = PyString_AS_STRING(item);
- /* 'djb2' hash. This gives us a nice compromise between fast hash
- function and a hash with less collisions. The algorithm doesn't
- use the hash for actual lookups, only for building the table
- so a better hash function wouldn't bring us much benefit, but
- would make this loading code slower. */
- h = 5381;
- for (j = 0; j < line->len; j++)
- h = ((h << 5) + h) + *p++;
- line->hash = h;
line->next = SENTINEL;
line++;
}
+ cleanup:
Py_DECREF(seq);
return size;
}
=== modified file 'bzrlib/tests/test_diff.py'
--- a/bzrlib/tests/test_diff.py 2007-12-18 04:15:34 +0000
+++ b/bzrlib/tests/test_diff.py 2007-12-19 23:40:39 +0000
@@ -783,37 +783,43 @@
# This is what it currently gives:
test_one('aBccDe', 'abccde', [(0,0), (5,5)])
+ def assertDiffBlocks(self, a, b, expected_blocks):
+ """Check that the sequence matcher returns the correct blocks.
+
+ :param a: A sequence to match
+ :param b: Another sequence to match
+ :param expected_blocks: The expected output, not including the final
+ matching block (len(a), len(b), 0)
+ """
+ matcher = self._PatienceSequenceMatcher(None, a, b)
+ blocks = matcher.get_matching_blocks()
+ last = blocks.pop()
+ self.assertEqual((len(a), len(b), 0), last)
+ self.assertEqual(expected_blocks, blocks)
+
def test_matching_blocks(self):
- def chk_blocks(a, b, expected_blocks):
- # difflib always adds a signature of the total
- # length, with no matching entries at the end
- s = self._PatienceSequenceMatcher(None, a, b)
- blocks = s.get_matching_blocks()
- self.assertEquals((len(a), len(b), 0), blocks[-1])
- self.assertEquals(expected_blocks, blocks[:-1])
-
# Some basic matching tests
- chk_blocks('', '', [])
- chk_blocks([], [], [])
- chk_blocks('abc', '', [])
- chk_blocks('', 'abc', [])
- chk_blocks('abcd', 'abcd', [(0, 0, 4)])
- chk_blocks('abcd', 'abce', [(0, 0, 3)])
- chk_blocks('eabc', 'abce', [(1, 0, 3)])
- chk_blocks('eabce', 'abce', [(1, 0, 4)])
- chk_blocks('abcde', 'abXde', [(0, 0, 2), (3, 3, 2)])
- chk_blocks('abcde', 'abXYZde', [(0, 0, 2), (3, 5, 2)])
- chk_blocks('abde', 'abXYZde', [(0, 0, 2), (2, 5, 2)])
- # This may check too much, but it checks to see that
+ self.assertDiffBlocks('', '', [])
+ self.assertDiffBlocks([], [], [])
+ self.assertDiffBlocks('abc', '', [])
+ self.assertDiffBlocks('', 'abc', [])
+ self.assertDiffBlocks('abcd', 'abcd', [(0, 0, 4)])
+ self.assertDiffBlocks('abcd', 'abce', [(0, 0, 3)])
+ self.assertDiffBlocks('eabc', 'abce', [(1, 0, 3)])
+ self.assertDiffBlocks('eabce', 'abce', [(1, 0, 4)])
+ self.assertDiffBlocks('abcde', 'abXde', [(0, 0, 2), (3, 3, 2)])
+ self.assertDiffBlocks('abcde', 'abXYZde', [(0, 0, 2), (3, 5, 2)])
+ self.assertDiffBlocks('abde', 'abXYZde', [(0, 0, 2), (2, 5, 2)])
+ # This may check too much, but it checks to see that
# a copied block stays attached to the previous section,
# not the later one.
# difflib would tend to grab the trailing longest match
# which would make the diff not look right
- chk_blocks('abcdefghijklmnop', 'abcdefxydefghijklmnop',
- [(0, 0, 6), (6, 11, 10)])
+ self.assertDiffBlocks('abcdefghijklmnop', 'abcdefxydefghijklmnop',
+ [(0, 0, 6), (6, 11, 10)])
# make sure it supports passing in lists
- chk_blocks(
+ self.assertDiffBlocks(
['hello there\n',
'world\n',
'how are you today?\n'],
@@ -823,21 +829,45 @@
# non unique lines surrounded by non-matching lines
# won't be found
- chk_blocks('aBccDe', 'abccde', [(0,0,1), (5,5,1)])
+ self.assertDiffBlocks('aBccDe', 'abccde', [(0,0,1), (5,5,1)])
# But they only need to be locally unique
- chk_blocks('aBcDec', 'abcdec', [(0,0,1), (2,2,1), (4,4,2)])
+ self.assertDiffBlocks('aBcDec', 'abcdec', [(0,0,1), (2,2,1), (4,4,2)])
# non unique blocks won't be matched
- chk_blocks('aBcdEcdFg', 'abcdecdfg', [(0,0,1), (8,8,1)])
+ self.assertDiffBlocks('aBcdEcdFg', 'abcdecdfg', [(0,0,1), (8,8,1)])
# but locally unique ones will
- chk_blocks('aBcdEeXcdFg', 'abcdecdfg', [(0,0,1), (2,2,2),
+ self.assertDiffBlocks('aBcdEeXcdFg', 'abcdecdfg', [(0,0,1), (2,2,2),
(5,4,1), (7,5,2), (10,8,1)])
- chk_blocks('abbabbXd', 'cabbabxd', [(7,7,1)])
- chk_blocks('abbabbbb', 'cabbabbc', [])
- chk_blocks('bbbbbbbb', 'cbbbbbbc', [])
+ self.assertDiffBlocks('abbabbXd', 'cabbabxd', [(7,7,1)])
+ self.assertDiffBlocks('abbabbbb', 'cabbabbc', [])
+ self.assertDiffBlocks('bbbbbbbb', 'cbbbbbbc', [])
+
+ def test_matching_blocks_tuples(self):
+ # Some basic matching tests
+ self.assertDiffBlocks([], [], [])
+ self.assertDiffBlocks([('a',), ('b',), ('c,')], [], [])
+ self.assertDiffBlocks([], [('a',), ('b',), ('c,')], [])
+ self.assertDiffBlocks([('a',), ('b',), ('c,')],
+ [('a',), ('b',), ('c,')],
+ [(0, 0, 3)])
+ self.assertDiffBlocks([('a',), ('b',), ('c,')],
+ [('a',), ('b',), ('d,')],
+ [(0, 0, 2)])
+ self.assertDiffBlocks([('d',), ('b',), ('c,')],
+ [('a',), ('b',), ('c,')],
+ [(1, 1, 2)])
+ self.assertDiffBlocks([('d',), ('a',), ('b',), ('c,')],
+ [('a',), ('b',), ('c,')],
+ [(1, 0, 3)])
+ self.assertDiffBlocks([('a', 'b'), ('c', 'd'), ('e', 'f')],
+ [('a', 'b'), ('c', 'X'), ('e', 'f')],
+ [(0, 0, 1), (2, 2, 1)])
+ self.assertDiffBlocks([('a', 'b'), ('c', 'd'), ('e', 'f')],
+ [('a', 'b'), ('c', 'dX'), ('e', 'f')],
+ [(0, 0, 1), (2, 2, 1)])
def test_opcodes(self):
def chk_ops(a, b, expected_codes):
@@ -955,25 +985,16 @@
def test_multiple_ranges(self):
# There was an earlier bug where we used a bad set of ranges,
# this triggers that specific bug, to make sure it doesn't regress
- def chk_blocks(a, b, expected_blocks):
- # difflib always adds a signature of the total
- # length, with no matching entries at the end
- s = self._PatienceSequenceMatcher(None, a, b)
- blocks = s.get_matching_blocks()
- x = blocks.pop()
- self.assertEquals(x, (len(a), len(b), 0))
- self.assertEquals(expected_blocks, blocks)
-
- chk_blocks('abcdefghijklmnop'
- , 'abcXghiYZQRSTUVWXYZijklmnop'
- , [(0, 0, 3), (6, 4, 3), (9, 20, 7)])
-
- chk_blocks('ABCd efghIjk L'
- , 'AxyzBCn mo pqrstuvwI1 2 L'
- , [(0,0,1), (1, 4, 2), (9, 19, 1), (12, 23, 3)])
+ self.assertDiffBlocks('abcdefghijklmnop',
+ 'abcXghiYZQRSTUVWXYZijklmnop',
+ [(0, 0, 3), (6, 4, 3), (9, 20, 7)])
+
+ self.assertDiffBlocks('ABCd efghIjk L',
+ 'AxyzBCn mo pqrstuvwI1 2 L',
+ [(0,0,1), (1, 4, 2), (9, 19, 1), (12, 23, 3)])
# These are rot13 code snippets.
- chk_blocks('''\
+ self.assertDiffBlocks('''\
trg nqqrq jura lbh nqq n svyr va gur qverpgbel.
"""
gnxrf_netf = ['svyr*']
@@ -1086,6 +1107,19 @@
self._PatienceSequenceMatcher = \
bzrlib._patiencediff_c.PatienceSequenceMatcher_c
+ def test_unhashable(self):
+ """We should get a proper exception here."""
+ # We need to be able to hash items in the sequence, lists are
+ # unhashable, and thus cannot be diffed
+ e = self.assertRaises(TypeError, self._PatienceSequenceMatcher,
+ None, [[]], [])
+ e = self.assertRaises(TypeError, self._PatienceSequenceMatcher,
+ None, ['valid', []], [])
+ e = self.assertRaises(TypeError, self._PatienceSequenceMatcher,
+ None, ['valid'], [[]])
+ e = self.assertRaises(TypeError, self._PatienceSequenceMatcher,
+ None, ['valid'], ['valid', []])
+
class TestPatienceDiffLibFiles(TestCaseInTempDir):
More information about the bazaar-commits
mailing list