Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(43)

Unified Diff: tools/grit/pak_util.py

Issue 2969123002: Add deduplication logic to .pak files (Closed)
Patch Set: fix resource_sizes computation Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tools/grit/pak_util.py
diff --git a/tools/grit/pak_util.py b/tools/grit/pak_util.py
index ec43f33afddae2c0d22756bb76e8903a7b40f3a2..97f70647c497c4fd405a0ae780d8606172d371d3 100755
--- a/tools/grit/pak_util.py
+++ b/tools/grit/pak_util.py
@@ -33,6 +33,7 @@ def _ExtractMain(args):
def _PrintMain(args):
pak = data_pack.ReadDataPack(args.pak_file)
+ id_map = {id(v): k for k, v in sorted(pak.resources.items(), reverse=True)}
encoding = 'binary'
if pak.encoding == 1:
encoding = 'utf-8'
@@ -57,8 +58,13 @@ def _PrintMain(args):
except UnicodeDecodeError:
pass
sha1 = hashlib.sha1(data).hexdigest()[:10]
- line = u'Entry(id={}, len={}, sha1={}): {}'.format(
- resource_id, len(data), sha1, desc)
+ canonical_id = id_map[id(data)]
+ if resource_id == canonical_id:
+ line = u'Entry(id={}, len={}, sha1={}): {}'.format(
+ resource_id, len(data), sha1, desc)
+ else:
+ line = u'Entry(id={}, alias_of={}): {}'.format(
+ resource_id, canonical_id, desc)
print line.encode('utf-8')

Powered by Google App Engine
This is Rietveld 408576698