Teach annotate about binary files
authormpm@selenic.com
Tue, 23 Aug 2005 20:21:52 -0700
changeset 1016 836667830fee
parent 1015 22571b8d35d3
child 1017 cbc3d3d39d7d
child 1030 28e2f13ca7c4
Teach annotate about binary files
doc/hg.1.txt
mercurial/commands.py
--- a/doc/hg.1.txt	Tue Aug 23 19:58:46 2005 -0700
+++ b/doc/hg.1.txt	Tue Aug 23 20:21:52 2005 -0700
@@ -71,8 +71,13 @@
     
     This command is useful to discover who did a change or when a change took
     place.
+
+    Without the -a option, annotate will avoid processing files it
+    detects as binary. With -a, annotate will generate an annotation
+    anyway, probably with undesirable results.
     
     options:
+    -a, --text            treat all files as text
     -I, --include <pat>   include names matching the given patterns
     -X, --exclude <pat>   exclude names matching the given patterns
     -r, --revision <rev>  annotate the specified revision
--- a/mercurial/commands.py	Tue Aug 23 19:58:46 2005 -0700
+++ b/mercurial/commands.py	Tue Aug 23 20:21:52 2005 -0700
@@ -433,12 +433,18 @@
         node = repo.dirstate.parents()[0]
     change = repo.changelog.read(node)
     mmap = repo.manifest.read(change[0])
+
     for src, abs, rel, exact in walk(repo, pats, opts):
         if abs not in mmap:
             ui.warn("warning: %s is not in the repository!\n" % rel)
             continue
 
-        lines = repo.file(abs).annotate(mmap[abs])
+        f = repo.file(abs)
+        if not opts['text'] and util.binary(f.read(mmap[abs])):
+            ui.write("%s: binary file\n" % rel)
+            continue
+
+        lines = f.annotate(mmap[abs])
         pieces = []
 
         for o, f in opmap:
@@ -1285,6 +1291,7 @@
     "^annotate":
         (annotate,
          [('r', 'rev', '', 'revision'),
+          ('a', 'text', None, 'treat all files as text'),
           ('u', 'user', None, 'show user'),
           ('n', 'number', None, 'show revision number'),
           ('c', 'changeset', None, 'show changeset'),