mercurial/mdiff.py
changeset 35890 079b27b5a869
parent 35584 6f62a1c3e11d
child 35891 a9d07bd8f758
equal deleted inserted replaced
35889:5cfdf6137af8 35890:079b27b5a869
   232                 if old == new:
   232                 if old == new:
   233                     type = '~'
   233                     type = '~'
   234             yield s, type
   234             yield s, type
   235         yield s1, '='
   235         yield s1, '='
   236 
   236 
   237 def unidiff(a, ad, b, bd, fn1, fn2, opts=defaultopts):
   237 def unidiff(a, ad, b, bd, fn1, fn2, opts=defaultopts, check_binary=True):
   238     """Return a unified diff as a (headers, hunks) tuple.
   238     """Return a unified diff as a (headers, hunks) tuple.
   239 
   239 
   240     If the diff is not null, `headers` is a list with unified diff header
   240     If the diff is not null, `headers` is a list with unified diff header
   241     lines "--- <original>" and "+++ <new>" and `hunks` is a generator yielding
   241     lines "--- <original>" and "+++ <new>" and `hunks` is a generator yielding
   242     (hunkrange, hunklines) coming from _unidiff().
   242     (hunkrange, hunklines) coming from _unidiff().
   243     Otherwise, `headers` and `hunks` are empty.
   243     Otherwise, `headers` and `hunks` are empty.
       
   244 
       
   245     Setting `check_binary` to false will skip the binary check, i.e. when
       
   246     it has been done in advance. Files are expected to be text in this case.
   244     """
   247     """
   245     def datetag(date, fn=None):
   248     def datetag(date, fn=None):
   246         if not opts.git and not opts.nodates:
   249         if not opts.git and not opts.nodates:
   247             return '\t%s' % date
   250             return '\t%s' % date
   248         if fn and ' ' in fn:
   251         if fn and ' ' in fn:
   268         for text in lines:
   271         for text in lines:
   269             if text[-1:] != '\n':
   272             if text[-1:] != '\n':
   270                 text += "\n\ No newline at end of file\n"
   273                 text += "\n\ No newline at end of file\n"
   271             yield text
   274             yield text
   272 
   275 
   273     if not opts.text and (util.binary(a) or util.binary(b)):
   276     if not opts.text and check_binary and (util.binary(a) or util.binary(b)):
   274         if a and b and len(a) == len(b) and a == b:
   277         if a and b and len(a) == len(b) and a == b:
   275             return sentinel
   278             return sentinel
   276         headerlines = []
   279         headerlines = []
   277         hunks = (None, ['Binary file %s has changed\n' % fn1]),
   280         hunks = (None, ['Binary file %s has changed\n' % fn1]),
   278     elif not a:
   281     elif not a: