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

Unified Diff: tools/grit/pak_util.py

Issue 2969123002: Add deduplication logic to .pak files (Closed)
Patch Set: sizeof() 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
« no previous file with comments | « tools/grit/grit/format/data_pack_unittest.py ('k') | ui/base/BUILD.gn » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/grit/pak_util.py
diff --git a/tools/grit/pak_util.py b/tools/grit/pak_util.py
index e98f9bd39005ec58200d0aa7c19a2a9d7025644b..dd98049b1521fa3c91d89d878fdbfd1e86fb849b 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')
« no previous file with comments | « tools/grit/grit/format/data_pack_unittest.py ('k') | ui/base/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698