Hex Artifact Content
Not logged in

Artifact 6b2be81037608261703d3f2e0314c6f638e344bd:

File src/diffcmd.c part of check-in [76f169fca6] - Detect when the check-out contains missing files and filesystem objects that ought to be files but are not. Issue reasonable warnings. by drh on 2009-12-18 00:29:51. Also file src/diffcmd.c part of check-in [76bc05d739] - merge with trunk by btheado on 2009-12-30 20:33:59.

0000: 2f 2a 0a 2a 2a 20 43 6f 70 79 72 69 67 68 74 20  /*.** Copyright 
0010: 28 63 29 20 32 30 30 37 20 44 2e 20 52 69 63 68  (c) 2007 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 0a 2a 2a 20 54  ard Hipp.**.** T
0030: 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 66  his program is f
0040: 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 79 6f  ree software; yo
0050: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75  u can redistribu
0060: 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a 2a 2a 20  te it and/or.** 
0070: 6d 6f 64 69 66 79 20 69 74 20 75 6e 64 65 72 20  modify it under 
0080: 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 65  the terms of the
0090: 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62   GNU General Pub
00a0: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 76  lic.** License v
00b0: 65 72 73 69 6f 6e 20 32 20 61 73 20 70 75 62 6c  ersion 2 as publ
00c0: 69 73 68 65 64 20 62 79 20 74 68 65 20 46 72 65  ished by the Fre
00d0: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
00e0: 61 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 69  ation..**.** Thi
00f0: 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73  s program is dis
0100: 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20  tributed in the 
0110: 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c  hope that it wil
0120: 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a 20  l be useful,.** 
0130: 62 75 74 20 57 49 54 48 4f 55 54 20 41 4e 59 20  but WITHOUT ANY 
0140: 57 41 52 52 41 4e 54 59 3b 20 77 69 74 68 6f 75  WARRANTY; withou
0150: 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69  t even the impli
0160: 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 2a  ed warranty of.*
0170: 2a 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54  * MERCHANTABILIT
0180: 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52  Y or FITNESS FOR
0190: 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 50 55   A PARTICULAR PU
01a0: 52 50 4f 53 45 2e 20 20 53 65 65 20 74 68 65 20  RPOSE.  See the 
01b0: 47 4e 55 0a 2a 2a 20 47 65 6e 65 72 61 6c 20 50  GNU.** General P
01c0: 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 66 6f  ublic License fo
01d0: 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 2e 0a  r more details..
01e0: 2a 2a 0a 2a 2a 20 59 6f 75 20 73 68 6f 75 6c 64  **.** You should
01f0: 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20 61   have received a
0200: 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e 55   copy of the GNU
0210: 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63 0a   General Public.
0220: 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f 6e 67  ** License along
0230: 20 77 69 74 68 20 74 68 69 73 20 6c 69 62 72 61   with this libra
0240: 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72 69 74  ry; if not, writ
0250: 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72 65 65  e to the.** Free
0260: 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64 61   Software Founda
0270: 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39 20 54  tion, Inc., 59 T
0280: 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20 53 75  emple Place - Su
0290: 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f 73 74  ite 330,.** Bost
02a0: 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d 31 33  on, MA  02111-13
02b0: 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a 20 41  07, USA..**.** A
02c0: 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69 6e  uthor contact in
02d0: 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20 20  formation:.**   
02e0: 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a 2a  drh@hwaci.com.**
02f0: 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68 77     http://www.hw
0300: 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a 0a  aci.com/drh/.**.
0310: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0320: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0330: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0340: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0350: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a  ***************.
0360: 2a 2a 0a 2a 2a 20 54 68 69 73 20 66 69 6c 65 20  **.** This file 
0370: 63 6f 6e 74 61 69 6e 73 20 63 6f 64 65 20 75 73  contains code us
0380: 65 64 20 74 6f 20 69 6d 70 6c 65 6d 65 6e 74 20  ed to implement 
0390: 74 68 65 20 22 64 69 66 66 22 20 63 6f 6d 6d 61  the "diff" comma
03a0: 6e 64 0a 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 22  nd.*/.#include "
03b0: 63 6f 6e 66 69 67 2e 68 22 0a 23 69 6e 63 6c 75  config.h".#inclu
03c0: 64 65 20 22 64 69 66 66 63 6d 64 2e 68 22 0a 23  de "diffcmd.h".#
03d0: 69 6e 63 6c 75 64 65 20 3c 61 73 73 65 72 74 2e  include <assert.
03e0: 68 3e 0a 0a 2f 2a 0a 2a 2a 20 53 68 65 6c 6c 2d  h>../*.** Shell-
03f0: 65 73 63 61 70 65 20 74 68 65 20 67 69 76 65 6e  escape the given
0400: 20 73 74 72 69 6e 67 2e 20 20 41 70 70 65 6e 64   string.  Append
0410: 20 74 68 65 20 72 65 73 75 6c 74 20 74 6f 20 61   the result to a
0420: 20 62 6c 6f 62 2e 0a 2a 2f 0a 73 74 61 74 69 63   blob..*/.static
0430: 20 76 6f 69 64 20 73 68 65 6c 6c 5f 65 73 63 61   void shell_esca
0440: 70 65 28 42 6c 6f 62 20 2a 70 42 6c 6f 62 2c 20  pe(Blob *pBlob, 
0450: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 49 6e 29  const char *zIn)
0460: 7b 0a 20 20 69 6e 74 20 6e 20 3d 20 62 6c 6f 62  {.  int n = blob
0470: 5f 73 69 7a 65 28 70 42 6c 6f 62 29 3b 0a 20 20  _size(pBlob);.  
0480: 69 6e 74 20 6b 20 3d 20 73 74 72 6c 65 6e 28 7a  int k = strlen(z
0490: 49 6e 29 3b 0a 20 20 69 6e 74 20 69 2c 20 63 3b  In);.  int i, c;
04a0: 0a 20 20 63 68 61 72 20 2a 7a 3b 0a 20 20 66 6f  .  char *z;.  fo
04b0: 72 28 69 3d 30 3b 20 28 63 20 3d 20 7a 49 6e 5b  r(i=0; (c = zIn[
04c0: 69 5d 29 21 3d 30 3b 20 69 2b 2b 29 7b 0a 20 20  i])!=0; i++){.  
04d0: 20 20 69 66 28 20 69 73 73 70 61 63 65 28 63 29    if( isspace(c)
04e0: 20 7c 7c 20 63 3d 3d 27 22 27 20 7c 7c 20 28 63   || c=='"' || (c
04f0: 3d 3d 27 5c 5c 27 20 26 26 20 7a 49 6e 5b 69 2b  =='\\' && zIn[i+
0500: 31 5d 21 3d 30 29 20 29 7b 0a 20 20 20 20 20 20  1]!=0) ){.      
0510: 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 70 42 6c  blob_appendf(pBl
0520: 6f 62 2c 20 22 5c 22 25 73 5c 22 22 2c 20 7a 49  ob, "\"%s\"", zI
0530: 6e 29 3b 0a 20 20 20 20 20 20 7a 20 3d 20 62 6c  n);.      z = bl
0540: 6f 62 5f 62 75 66 66 65 72 28 70 42 6c 6f 62 29  ob_buffer(pBlob)
0550: 3b 0a 20 20 20 20 20 20 66 6f 72 28 69 3d 6e 2b  ;.      for(i=n+
0560: 31 3b 20 69 3c 3d 6e 2b 6b 3b 20 69 2b 2b 29 7b  1; i<=n+k; i++){
0570: 0a 20 20 20 20 20 20 20 20 69 66 28 20 7a 5b 69  .        if( z[i
0580: 5d 3d 3d 27 22 27 20 29 20 7a 5b 69 5d 20 3d 20  ]=='"' ) z[i] = 
0590: 27 5f 27 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20  '_';.      }.   
05a0: 20 20 20 72 65 74 75 72 6e 3b 0a 20 20 20 20 7d     return;.    }
05b0: 0a 20 20 7d 0a 20 20 62 6c 6f 62 5f 61 70 70 65  .  }.  blob_appe
05c0: 6e 64 28 70 42 6c 6f 62 2c 20 7a 49 6e 2c 20 2d  nd(pBlob, zIn, -
05d0: 31 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 68 69  1);.}../*.** Thi
05e0: 73 20 66 75 6e 63 74 69 6f 6e 20 69 6d 70 6c 65  s function imple
05f0: 6d 65 6e 74 73 20 61 20 63 72 6f 73 73 2d 70 6c  ments a cross-pl
0600: 61 74 66 6f 72 6d 20 22 73 79 73 74 65 6d 28 29  atform "system()
0610: 22 20 69 6e 74 65 72 66 61 63 65 2e 0a 2a 2f 0a  " interface..*/.
0620: 69 6e 74 20 70 6f 72 74 61 62 6c 65 5f 73 79 73  int portable_sys
0630: 74 65 6d 28 63 68 61 72 20 2a 7a 4f 72 69 67 43  tem(char *zOrigC
0640: 6d 64 29 7b 0a 20 20 69 6e 74 20 72 63 3b 0a 23  md){.  int rc;.#
0650: 69 66 64 65 66 20 5f 5f 4d 49 4e 47 57 33 32 5f  ifdef __MINGW32_
0660: 5f 0a 20 20 2f 2a 20 4f 6e 20 77 69 6e 64 6f 77  _.  /* On window
0670: 73 2c 20 77 65 20 68 61 76 65 20 74 6f 20 70 75  s, we have to pu
0680: 74 20 64 6f 75 62 6c 65 2d 71 75 6f 74 65 73 20  t double-quotes 
0690: 61 72 6f 75 6e 64 20 74 68 65 20 65 6e 74 69 72  around the entir
06a0: 65 20 63 6f 6d 6d 61 6e 64 2e 0a 20 20 2a 2a 20  e command..  ** 
06b0: 57 68 6f 20 6b 6e 6f 77 73 20 77 68 79 20 2d 20  Who knows why - 
06c0: 74 68 69 73 20 69 73 20 6a 75 73 74 20 74 68 65  this is just the
06d0: 20 77 61 79 20 77 69 6e 64 6f 77 73 20 77 6f 72   way windows wor
06e0: 6b 73 2e 0a 20 20 2a 2f 0a 20 20 63 68 61 72 20  ks..  */.  char 
06f0: 2a 7a 4e 65 77 43 6d 64 20 3d 20 6d 70 72 69 6e  *zNewCmd = mprin
0700: 74 66 28 22 5c 22 25 73 5c 22 22 2c 20 7a 4f 72  tf("\"%s\"", zOr
0710: 69 67 43 6d 64 29 3b 0a 20 20 72 63 20 3d 20 73  igCmd);.  rc = s
0720: 79 73 74 65 6d 28 7a 4e 65 77 43 6d 64 29 3b 0a  ystem(zNewCmd);.
0730: 20 20 66 72 65 65 28 7a 4e 65 77 43 6d 64 29 3b    free(zNewCmd);
0740: 0a 23 65 6c 73 65 0a 20 20 2f 2a 20 4f 6e 20 75  .#else.  /* On u
0750: 6e 69 78 2c 20 65 76 61 6c 75 61 74 65 20 74 68  nix, evaluate th
0760: 65 20 63 6f 6d 6d 61 6e 64 20 64 69 72 65 63 74  e command direct
0770: 6c 79 2e 0a 20 20 2a 2f 0a 20 20 72 63 20 3d 20  ly..  */.  rc = 
0780: 73 79 73 74 65 6d 28 7a 4f 72 69 67 43 6d 64 29  system(zOrigCmd)
0790: 3b 0a 23 65 6e 64 69 66 20 0a 20 20 72 65 74 75  ;.#endif .  retu
07a0: 72 6e 20 72 63 3b 20 0a 7d 0a 0a 2f 2a 0a 2a 2a  rn rc; .}../*.**
07b0: 20 53 68 6f 77 20 74 68 65 20 64 69 66 66 65 72   Show the differ
07c0: 65 6e 63 65 20 62 65 74 77 65 65 6e 20 74 77 6f  ence between two
07d0: 20 66 69 6c 65 73 2c 20 6f 6e 65 20 69 6e 20 6d   files, one in m
07e0: 65 6d 6f 72 79 20 61 6e 64 20 6f 6e 65 20 6f 6e  emory and one on
07f0: 20 64 69 73 6b 2e 0a 2a 2a 0a 2a 2a 20 54 68 65   disk..**.** The
0800: 20 64 69 66 66 65 72 65 6e 63 65 20 69 73 20 74   difference is t
0810: 68 65 20 73 65 74 20 6f 66 20 65 64 69 74 73 20  he set of edits 
0820: 6e 65 65 64 65 64 20 74 6f 20 74 72 61 6e 73 66  needed to transf
0830: 6f 72 6d 20 70 46 69 6c 65 31 20 69 6e 74 6f 0a  orm pFile1 into.
0840: 2a 2a 20 7a 46 69 6c 65 32 2e 20 20 54 68 65 20  ** zFile2.  The 
0850: 63 6f 6e 74 65 6e 74 20 6f 66 20 70 46 69 6c 65  content of pFile
0860: 31 20 69 73 20 69 6e 20 6d 65 6d 6f 72 79 2e 20  1 is in memory. 
0870: 20 7a 46 69 6c 65 32 20 65 78 69 73 74 73 20 6f   zFile2 exists o
0880: 6e 20 64 69 73 6b 2e 0a 2a 2a 0a 2a 2a 20 55 73  n disk..**.** Us
0890: 65 20 74 68 65 20 69 6e 74 65 72 6e 61 6c 20 64  e the internal d
08a0: 69 66 66 20 6c 6f 67 69 63 20 69 66 20 7a 44 69  iff logic if zDi
08b0: 66 66 43 6d 64 20 69 73 20 4e 55 4c 4c 2e 20 20  ffCmd is NULL.  
08c0: 4f 74 68 65 72 77 69 73 65 20 63 61 6c 6c 20 74  Otherwise call t
08d0: 68 65 0a 2a 2a 20 63 6f 6d 6d 61 6e 64 20 7a 44  he.** command zD
08e0: 69 66 66 43 6d 64 20 74 6f 20 64 6f 20 74 68 65  iffCmd to do the
08f0: 20 64 69 66 66 69 6e 67 2e 0a 2a 2f 0a 73 74 61   diffing..*/.sta
0900: 74 69 63 20 76 6f 69 64 20 64 69 66 66 5f 66 69  tic void diff_fi
0910: 6c 65 28 0a 20 20 42 6c 6f 62 20 2a 70 46 69 6c  le(.  Blob *pFil
0920: 65 31 2c 20 20 20 20 20 20 20 20 20 20 20 20 20  e1,             
0930: 2f 2a 20 49 6e 20 6d 65 6d 6f 72 79 20 63 6f 6e  /* In memory con
0940: 74 65 6e 74 20 74 6f 20 63 6f 6d 70 61 72 65 20  tent to compare 
0950: 66 72 6f 6d 20 2a 2f 0a 20 20 63 6f 6e 73 74 20  from */.  const 
0960: 63 68 61 72 20 2a 7a 46 69 6c 65 32 2c 20 20 20  char *zFile2,   
0970: 20 20 20 20 2f 2a 20 4f 6e 20 64 69 73 6b 20 63      /* On disk c
0980: 6f 6e 74 65 6e 74 20 74 6f 20 63 6f 6d 70 61 72  ontent to compar
0990: 65 20 74 6f 20 2a 2f 0a 20 20 63 6f 6e 73 74 20  e to */.  const 
09a0: 63 68 61 72 20 2a 7a 4e 61 6d 65 2c 20 20 20 20  char *zName,    
09b0: 20 20 20 20 2f 2a 20 44 69 73 70 6c 61 79 20 6e      /* Display n
09c0: 61 6d 65 20 6f 66 20 74 68 65 20 66 69 6c 65 20  ame of the file 
09d0: 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20  */.  const char 
09e0: 2a 7a 44 69 66 66 43 6d 64 20 20 20 20 20 20 2f  *zDiffCmd      /
09f0: 2a 20 43 6f 6d 6d 61 6e 64 20 66 6f 72 20 63 6f  * Command for co
0a00: 6d 70 61 72 69 73 6f 6e 20 2a 2f 0a 29 7b 0a 20  mparison */.){. 
0a10: 20 69 66 28 20 7a 44 69 66 66 43 6d 64 3d 3d 30   if( zDiffCmd==0
0a20: 20 29 7b 0a 20 20 20 20 42 6c 6f 62 20 6f 75 74   ){.    Blob out
0a30: 3b 20 20 20 20 20 20 2f 2a 20 44 69 66 66 20 6f  ;      /* Diff o
0a40: 75 74 70 75 74 20 74 65 78 74 20 2a 2f 0a 20 20  utput text */.  
0a50: 20 20 42 6c 6f 62 20 66 69 6c 65 32 3b 20 20 20    Blob file2;   
0a60: 20 2f 2a 20 43 6f 6e 74 65 6e 74 20 6f 66 20 7a   /* Content of z
0a70: 46 69 6c 65 32 20 2a 2f 0a 0a 20 20 20 20 2f 2a  File2 */..    /*
0a80: 20 52 65 61 64 20 63 6f 6e 74 65 6e 74 20 6f 66   Read content of
0a90: 20 7a 46 69 6c 65 32 20 69 6e 74 6f 20 6d 65 6d   zFile2 into mem
0aa0: 6f 72 79 20 2a 2f 0a 20 20 20 20 62 6c 6f 62 5f  ory */.    blob_
0ab0: 7a 65 72 6f 28 26 66 69 6c 65 32 29 3b 0a 20 20  zero(&file2);.  
0ac0: 20 20 62 6c 6f 62 5f 72 65 61 64 5f 66 72 6f 6d    blob_read_from
0ad0: 5f 66 69 6c 65 28 26 66 69 6c 65 32 2c 20 7a 46  _file(&file2, zF
0ae0: 69 6c 65 32 29 3b 0a 0a 20 20 20 20 2f 2a 20 43  ile2);..    /* C
0af0: 6f 6d 70 75 74 65 20 61 6e 64 20 6f 75 74 70 75  ompute and outpu
0b00: 74 20 74 68 65 20 64 69 66 66 65 72 65 6e 63 65  t the difference
0b10: 73 20 2a 2f 0a 20 20 20 20 62 6c 6f 62 5f 7a 65  s */.    blob_ze
0b20: 72 6f 28 26 6f 75 74 29 3b 0a 20 20 20 20 74 65  ro(&out);.    te
0b30: 78 74 5f 64 69 66 66 28 70 46 69 6c 65 31 2c 20  xt_diff(pFile1, 
0b40: 26 66 69 6c 65 32 2c 20 26 6f 75 74 2c 20 35 29  &file2, &out, 5)
0b50: 3b 0a 20 20 20 20 70 72 69 6e 74 66 28 22 2d 2d  ;.    printf("--
0b60: 2d 20 25 73 5c 6e 2b 2b 2b 20 25 73 5c 6e 22 2c  - %s\n+++ %s\n",
0b70: 20 7a 4e 61 6d 65 2c 20 7a 4e 61 6d 65 29 3b 0a   zName, zName);.
0b80: 20 20 20 20 70 72 69 6e 74 66 28 22 25 73 5c 6e      printf("%s\n
0b90: 22 2c 20 62 6c 6f 62 5f 73 74 72 28 26 6f 75 74  ", blob_str(&out
0ba0: 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 52 65 6c 65  ));..    /* Rele
0bb0: 61 73 65 20 6d 65 6d 6f 72 79 20 72 65 73 6f 75  ase memory resou
0bc0: 72 63 65 73 20 2a 2f 0a 20 20 20 20 62 6c 6f 62  rces */.    blob
0bd0: 5f 72 65 73 65 74 28 26 66 69 6c 65 32 29 3b 0a  _reset(&file2);.
0be0: 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26      blob_reset(&
0bf0: 6f 75 74 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20  out);.  }else{. 
0c00: 20 20 20 69 6e 74 20 63 6e 74 20 3d 20 30 3b 0a     int cnt = 0;.
0c10: 20 20 20 20 42 6c 6f 62 20 6e 61 6d 65 46 69 6c      Blob nameFil
0c20: 65 31 3b 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f  e1;    /* Name o
0c30: 66 20 74 65 6d 70 6f 72 61 72 79 20 66 69 6c 65  f temporary file
0c40: 20 74 6f 20 6f 6c 64 20 70 46 69 6c 65 31 20 63   to old pFile1 c
0c50: 6f 6e 74 65 6e 74 20 2a 2f 0a 20 20 20 20 42 6c  ontent */.    Bl
0c60: 6f 62 20 63 6d 64 3b 20 20 20 20 20 20 20 20 20  ob cmd;         
0c70: 20 2f 2a 20 54 65 78 74 20 6f 66 20 63 6f 6d 6d   /* Text of comm
0c80: 61 6e 64 20 74 6f 20 72 75 6e 20 2a 2f 0a 0a 20  and to run */.. 
0c90: 20 20 20 2f 2a 20 43 6f 6e 73 74 72 75 63 74 20     /* Construct 
0ca0: 61 20 74 65 6d 70 6f 72 61 72 79 20 66 69 6c 65  a temporary file
0cb0: 20 74 6f 20 68 6f 6c 64 20 70 46 69 6c 65 31 20   to hold pFile1 
0cc0: 62 61 73 65 64 20 6f 6e 20 74 68 65 20 6e 61 6d  based on the nam
0cd0: 65 20 6f 66 0a 20 20 20 20 2a 2a 20 7a 46 69 6c  e of.    ** zFil
0ce0: 65 32 20 2a 2f 0a 20 20 20 20 62 6c 6f 62 5f 7a  e2 */.    blob_z
0cf0: 65 72 6f 28 26 6e 61 6d 65 46 69 6c 65 31 29 3b  ero(&nameFile1);
0d00: 0a 20 20 20 20 64 6f 7b 0a 20 20 20 20 20 20 62  .    do{.      b
0d10: 6c 6f 62 5f 72 65 73 65 74 28 26 6e 61 6d 65 46  lob_reset(&nameF
0d20: 69 6c 65 31 29 3b 0a 20 20 20 20 20 20 62 6c 6f  ile1);.      blo
0d30: 62 5f 61 70 70 65 6e 64 66 28 26 6e 61 6d 65 46  b_appendf(&nameF
0d40: 69 6c 65 31 2c 20 22 25 73 7e 25 64 22 2c 20 7a  ile1, "%s~%d", z
0d50: 46 69 6c 65 32 2c 20 63 6e 74 2b 2b 29 3b 0a 20  File2, cnt++);. 
0d60: 20 20 20 7d 77 68 69 6c 65 28 20 61 63 63 65 73     }while( acces
0d70: 73 28 62 6c 6f 62 5f 73 74 72 28 26 6e 61 6d 65  s(blob_str(&name
0d80: 46 69 6c 65 31 29 2c 30 29 3d 3d 30 20 29 3b 0a  File1),0)==0 );.
0d90: 20 20 20 20 62 6c 6f 62 5f 77 72 69 74 65 5f 74      blob_write_t
0da0: 6f 5f 66 69 6c 65 28 70 46 69 6c 65 31 2c 20 62  o_file(pFile1, b
0db0: 6c 6f 62 5f 73 74 72 28 26 6e 61 6d 65 46 69 6c  lob_str(&nameFil
0dc0: 65 31 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 43 6f  e1));..    /* Co
0dd0: 6e 73 74 72 75 63 74 20 74 68 65 20 65 78 74 65  nstruct the exte
0de0: 72 6e 61 6c 20 64 69 66 66 20 63 6f 6d 6d 61 6e  rnal diff comman
0df0: 64 20 2a 2f 0a 20 20 20 20 62 6c 6f 62 5f 7a 65  d */.    blob_ze
0e00: 72 6f 28 26 63 6d 64 29 3b 0a 20 20 20 20 62 6c  ro(&cmd);.    bl
0e10: 6f 62 5f 61 70 70 65 6e 64 66 28 26 63 6d 64 2c  ob_appendf(&cmd,
0e20: 20 22 25 73 20 22 2c 20 7a 44 69 66 66 43 6d 64   "%s ", zDiffCmd
0e30: 29 3b 0a 20 20 20 20 73 68 65 6c 6c 5f 65 73 63  );.    shell_esc
0e40: 61 70 65 28 26 63 6d 64 2c 20 62 6c 6f 62 5f 73  ape(&cmd, blob_s
0e50: 74 72 28 26 6e 61 6d 65 46 69 6c 65 31 29 29 3b  tr(&nameFile1));
0e60: 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64  .    blob_append
0e70: 28 26 63 6d 64 2c 20 22 20 22 2c 20 31 29 3b 0a  (&cmd, " ", 1);.
0e80: 20 20 20 20 73 68 65 6c 6c 5f 65 73 63 61 70 65      shell_escape
0e90: 28 26 63 6d 64 2c 20 7a 46 69 6c 65 32 29 3b 0a  (&cmd, zFile2);.
0ea0: 0a 20 20 20 20 2f 2a 20 52 75 6e 20 74 68 65 20  .    /* Run the 
0eb0: 65 78 74 65 72 6e 61 6c 20 64 69 66 66 20 63 6f  external diff co
0ec0: 6d 6d 61 6e 64 20 2a 2f 0a 20 20 20 20 70 6f 72  mmand */.    por
0ed0: 74 61 62 6c 65 5f 73 79 73 74 65 6d 28 62 6c 6f  table_system(blo
0ee0: 62 5f 73 74 72 28 26 63 6d 64 29 29 3b 0a 0a 20  b_str(&cmd));.. 
0ef0: 20 20 20 2f 2a 20 44 65 6c 65 74 65 20 74 68 65     /* Delete the
0f00: 20 74 65 6d 70 6f 72 61 72 79 20 66 69 6c 65 20   temporary file 
0f10: 61 6e 64 20 63 6c 65 61 6e 20 75 70 20 6d 65 6d  and clean up mem
0f20: 6f 72 79 20 75 73 65 64 20 2a 2f 0a 20 20 20 20  ory used */.    
0f30: 75 6e 6c 69 6e 6b 28 62 6c 6f 62 5f 73 74 72 28  unlink(blob_str(
0f40: 26 6e 61 6d 65 46 69 6c 65 31 29 29 3b 0a 20 20  &nameFile1));.  
0f50: 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 6e 61    blob_reset(&na
0f60: 6d 65 46 69 6c 65 31 29 3b 0a 20 20 20 20 62 6c  meFile1);.    bl
0f70: 6f 62 5f 72 65 73 65 74 28 26 63 6d 64 29 3b 0a  ob_reset(&cmd);.
0f80: 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 53 68 6f    }.}../*.** Sho
0f90: 77 20 74 68 65 20 64 69 66 66 65 72 65 6e 63 65  w the difference
0fa0: 20 62 65 74 77 65 65 6e 20 74 77 6f 20 66 69 6c   between two fil
0fb0: 65 73 2c 20 62 6f 74 68 20 69 6e 20 6d 65 6d 6f  es, both in memo
0fc0: 72 79 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 64 69  ry..**.** The di
0fd0: 66 66 65 72 65 6e 63 65 20 69 73 20 74 68 65 20  fference is the 
0fe0: 73 65 74 20 6f 66 20 65 64 69 74 73 20 6e 65 65  set of edits nee
0ff0: 64 65 64 20 74 6f 20 74 72 61 6e 73 66 6f 72 6d  ded to transform
1000: 20 70 46 69 6c 65 31 20 69 6e 74 6f 0a 2a 2a 20   pFile1 into.** 
1010: 70 46 69 6c 65 32 2e 0a 2a 2a 0a 2a 2a 20 55 73  pFile2..**.** Us
1020: 65 20 74 68 65 20 69 6e 74 65 72 6e 61 6c 20 64  e the internal d
1030: 69 66 66 20 6c 6f 67 69 63 20 69 66 20 7a 44 69  iff logic if zDi
1040: 66 66 43 6d 64 20 69 73 20 4e 55 4c 4c 2e 20 20  ffCmd is NULL.  
1050: 4f 74 68 65 72 77 69 73 65 20 63 61 6c 6c 20 74  Otherwise call t
1060: 68 65 0a 2a 2a 20 63 6f 6d 6d 61 6e 64 20 7a 44  he.** command zD
1070: 69 66 66 43 6d 64 20 74 6f 20 64 6f 20 74 68 65  iffCmd to do the
1080: 20 64 69 66 66 69 6e 67 2e 0a 2a 2f 0a 73 74 61   diffing..*/.sta
1090: 74 69 63 20 76 6f 69 64 20 64 69 66 66 5f 66 69  tic void diff_fi
10a0: 6c 65 5f 6d 65 6d 28 0a 20 20 42 6c 6f 62 20 2a  le_mem(.  Blob *
10b0: 70 46 69 6c 65 31 2c 20 20 20 20 20 20 20 20 20  pFile1,         
10c0: 20 20 20 20 2f 2a 20 49 6e 20 6d 65 6d 6f 72 79      /* In memory
10d0: 20 63 6f 6e 74 65 6e 74 20 74 6f 20 63 6f 6d 70   content to comp
10e0: 61 72 65 20 66 72 6f 6d 20 2a 2f 0a 20 20 42 6c  are from */.  Bl
10f0: 6f 62 20 2a 70 46 69 6c 65 32 2c 20 20 20 20 20  ob *pFile2,     
1100: 20 20 20 20 20 20 20 20 2f 2a 20 49 6e 20 6d 65          /* In me
1110: 6d 6f 72 79 20 63 6f 6e 74 65 6e 74 20 74 6f 20  mory content to 
1120: 63 6f 6d 70 61 72 65 20 74 6f 20 2a 2f 0a 20 20  compare to */.  
1130: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d  const char *zNam
1140: 65 2c 20 20 20 20 20 20 20 20 2f 2a 20 44 69 73  e,        /* Dis
1150: 70 6c 61 79 20 6e 61 6d 65 20 6f 66 20 74 68 65  play name of the
1160: 20 66 69 6c 65 20 2a 2f 0a 20 20 63 6f 6e 73 74   file */.  const
1170: 20 63 68 61 72 20 2a 7a 44 69 66 66 43 6d 64 20   char *zDiffCmd 
1180: 20 20 20 20 20 2f 2a 20 43 6f 6d 6d 61 6e 64 20       /* Command 
1190: 66 6f 72 20 63 6f 6d 70 61 72 69 73 6f 6e 20 2a  for comparison *
11a0: 2f 0a 29 7b 0a 20 20 69 66 28 20 7a 44 69 66 66  /.){.  if( zDiff
11b0: 43 6d 64 3d 3d 30 20 29 7b 0a 20 20 20 20 42 6c  Cmd==0 ){.    Bl
11c0: 6f 62 20 6f 75 74 3b 20 20 20 20 20 20 2f 2a 20  ob out;      /* 
11d0: 44 69 66 66 20 6f 75 74 70 75 74 20 74 65 78 74  Diff output text
11e0: 20 2a 2f 0a 0a 20 20 20 20 62 6c 6f 62 5f 7a 65   */..    blob_ze
11f0: 72 6f 28 26 6f 75 74 29 3b 0a 20 20 20 20 74 65  ro(&out);.    te
1200: 78 74 5f 64 69 66 66 28 70 46 69 6c 65 31 2c 20  xt_diff(pFile1, 
1210: 70 46 69 6c 65 32 2c 20 26 6f 75 74 2c 20 35 29  pFile2, &out, 5)
1220: 3b 0a 20 20 20 20 70 72 69 6e 74 66 28 22 2d 2d  ;.    printf("--
1230: 2d 20 25 73 5c 6e 2b 2b 2b 20 25 73 5c 6e 22 2c  - %s\n+++ %s\n",
1240: 20 7a 4e 61 6d 65 2c 20 7a 4e 61 6d 65 29 3b 0a   zName, zName);.
1250: 20 20 20 20 70 72 69 6e 74 66 28 22 25 73 5c 6e      printf("%s\n
1260: 22 2c 20 62 6c 6f 62 5f 73 74 72 28 26 6f 75 74  ", blob_str(&out
1270: 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 52 65 6c 65  ));..    /* Rele
1280: 61 73 65 20 6d 65 6d 6f 72 79 20 72 65 73 6f 75  ase memory resou
1290: 72 63 65 73 20 2a 2f 0a 20 20 20 20 62 6c 6f 62  rces */.    blob
12a0: 5f 72 65 73 65 74 28 26 6f 75 74 29 3b 0a 20 20  _reset(&out);.  
12b0: 7d 65 6c 73 65 7b 0a 20 20 20 20 42 6c 6f 62 20  }else{.    Blob 
12c0: 63 6d 64 3b 0a 20 20 20 20 63 68 61 72 20 7a 54  cmd;.    char zT
12d0: 65 6d 70 31 5b 33 30 30 5d 3b 0a 20 20 20 20 63  emp1[300];.    c
12e0: 68 61 72 20 7a 54 65 6d 70 32 5b 33 30 30 5d 3b  har zTemp2[300];
12f0: 0a 0a 20 20 20 20 2f 2a 20 43 6f 6e 73 74 72 75  ..    /* Constru
1300: 63 74 20 61 20 74 65 6d 70 6f 72 61 72 79 20 66  ct a temporary f
1310: 69 6c 65 20 6e 61 6d 65 73 20 2a 2f 0a 20 20 20  ile names */.   
1320: 20 66 69 6c 65 5f 74 65 6d 70 6e 61 6d 65 28 73   file_tempname(s
1330: 69 7a 65 6f 66 28 7a 54 65 6d 70 31 29 2c 20 7a  izeof(zTemp1), z
1340: 54 65 6d 70 31 29 3b 0a 20 20 20 20 66 69 6c 65  Temp1);.    file
1350: 5f 74 65 6d 70 6e 61 6d 65 28 73 69 7a 65 6f 66  _tempname(sizeof
1360: 28 7a 54 65 6d 70 32 29 2c 20 7a 54 65 6d 70 32  (zTemp2), zTemp2
1370: 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 77 72 69 74  );.    blob_writ
1380: 65 5f 74 6f 5f 66 69 6c 65 28 70 46 69 6c 65 31  e_to_file(pFile1
1390: 2c 20 7a 54 65 6d 70 31 29 3b 0a 20 20 20 20 62  , zTemp1);.    b
13a0: 6c 6f 62 5f 77 72 69 74 65 5f 74 6f 5f 66 69 6c  lob_write_to_fil
13b0: 65 28 70 46 69 6c 65 32 2c 20 7a 54 65 6d 70 32  e(pFile2, zTemp2
13c0: 29 3b 0a 0a 20 20 20 20 2f 2a 20 43 6f 6e 73 74  );..    /* Const
13d0: 72 75 63 74 20 74 68 65 20 65 78 74 65 72 6e 61  ruct the externa
13e0: 6c 20 64 69 66 66 20 63 6f 6d 6d 61 6e 64 20 2a  l diff command *
13f0: 2f 0a 20 20 20 20 62 6c 6f 62 5f 7a 65 72 6f 28  /.    blob_zero(
1400: 26 63 6d 64 29 3b 0a 20 20 20 20 62 6c 6f 62 5f  &cmd);.    blob_
1410: 61 70 70 65 6e 64 66 28 26 63 6d 64 2c 20 22 25  appendf(&cmd, "%
1420: 73 20 22 2c 20 7a 44 69 66 66 43 6d 64 29 3b 0a  s ", zDiffCmd);.
1430: 20 20 20 20 73 68 65 6c 6c 5f 65 73 63 61 70 65      shell_escape
1440: 28 26 63 6d 64 2c 20 7a 54 65 6d 70 31 29 3b 0a  (&cmd, zTemp1);.
1450: 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28      blob_append(
1460: 26 63 6d 64 2c 20 22 20 22 2c 20 31 29 3b 0a 20  &cmd, " ", 1);. 
1470: 20 20 20 73 68 65 6c 6c 5f 65 73 63 61 70 65 28     shell_escape(
1480: 26 63 6d 64 2c 20 7a 54 65 6d 70 32 29 3b 0a 0a  &cmd, zTemp2);..
1490: 20 20 20 20 2f 2a 20 52 75 6e 20 74 68 65 20 65      /* Run the e
14a0: 78 74 65 72 6e 61 6c 20 64 69 66 66 20 63 6f 6d  xternal diff com
14b0: 6d 61 6e 64 20 2a 2f 0a 20 20 20 20 70 6f 72 74  mand */.    port
14c0: 61 62 6c 65 5f 73 79 73 74 65 6d 28 62 6c 6f 62  able_system(blob
14d0: 5f 73 74 72 28 26 63 6d 64 29 29 3b 0a 0a 20 20  _str(&cmd));..  
14e0: 20 20 2f 2a 20 44 65 6c 65 74 65 20 74 68 65 20    /* Delete the 
14f0: 74 65 6d 70 6f 72 61 72 79 20 66 69 6c 65 20 61  temporary file a
1500: 6e 64 20 63 6c 65 61 6e 20 75 70 20 6d 65 6d 6f  nd clean up memo
1510: 72 79 20 75 73 65 64 20 2a 2f 0a 20 20 20 20 75  ry used */.    u
1520: 6e 6c 69 6e 6b 28 7a 54 65 6d 70 31 29 3b 0a 20  nlink(zTemp1);. 
1530: 20 20 20 75 6e 6c 69 6e 6b 28 7a 54 65 6d 70 32     unlink(zTemp2
1540: 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 72 65 73 65  );.    blob_rese
1550: 74 28 26 63 6d 64 29 3b 0a 20 20 7d 0a 7d 0a 0a  t(&cmd);.  }.}..
1560: 2f 2a 0a 2a 2a 20 44 6f 20 61 20 64 69 66 66 20  /*.** Do a diff 
1570: 61 67 61 69 6e 73 74 20 61 20 73 69 6e 67 6c 65  against a single
1580: 20 66 69 6c 65 20 6e 61 6d 65 64 20 69 6e 20 67   file named in g
1590: 2e 61 72 67 76 5b 32 5d 20 66 72 6f 6d 20 76 65  .argv[2] from ve
15a0: 72 73 69 6f 6e 20 7a 46 72 6f 6d 0a 2a 2a 20 61  rsion zFrom.** a
15b0: 67 61 69 6e 73 74 20 74 68 65 20 73 61 6d 65 20  gainst the same 
15c0: 66 69 6c 65 20 6f 6e 20 64 69 73 6b 2e 0a 2a 2f  file on disk..*/
15d0: 0a 73 74 61 74 69 63 20 76 6f 69 64 20 64 69 66  .static void dif
15e0: 66 5f 6f 6e 65 5f 61 67 61 69 6e 73 74 5f 64 69  f_one_against_di
15f0: 73 6b 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  sk(const char *z
1600: 46 72 6f 6d 2c 20 63 6f 6e 73 74 20 63 68 61 72  From, const char
1610: 20 2a 7a 44 69 66 66 43 6d 64 29 7b 0a 20 20 42   *zDiffCmd){.  B
1620: 6c 6f 62 20 66 6e 61 6d 65 3b 0a 20 20 42 6c 6f  lob fname;.  Blo
1630: 62 20 63 6f 6e 74 65 6e 74 3b 0a 20 20 66 69 6c  b content;.  fil
1640: 65 5f 74 72 65 65 5f 6e 61 6d 65 28 67 2e 61 72  e_tree_name(g.ar
1650: 67 76 5b 32 5d 2c 20 26 66 6e 61 6d 65 2c 20 31  gv[2], &fname, 1
1660: 29 3b 0a 20 20 68 69 73 74 6f 72 69 63 61 6c 5f  );.  historical_
1670: 76 65 72 73 69 6f 6e 5f 6f 66 5f 66 69 6c 65 28  version_of_file(
1680: 7a 46 72 6f 6d 2c 20 62 6c 6f 62 5f 73 74 72 28  zFrom, blob_str(
1690: 26 66 6e 61 6d 65 29 2c 20 26 63 6f 6e 74 65 6e  &fname), &conten
16a0: 74 2c 20 30 29 3b 0a 20 20 64 69 66 66 5f 66 69  t, 0);.  diff_fi
16b0: 6c 65 28 26 63 6f 6e 74 65 6e 74 2c 20 67 2e 61  le(&content, g.a
16c0: 72 67 76 5b 32 5d 2c 20 67 2e 61 72 67 76 5b 32  rgv[2], g.argv[2
16d0: 5d 2c 20 7a 44 69 66 66 43 6d 64 29 3b 0a 20 20  ], zDiffCmd);.  
16e0: 62 6c 6f 62 5f 72 65 73 65 74 28 26 63 6f 6e 74  blob_reset(&cont
16f0: 65 6e 74 29 3b 0a 20 20 62 6c 6f 62 5f 72 65 73  ent);.  blob_res
1700: 65 74 28 26 66 6e 61 6d 65 29 3b 0a 7d 0a 0a 2f  et(&fname);.}../
1710: 2a 0a 2a 2a 20 52 75 6e 20 61 20 64 69 66 66 20  *.** Run a diff 
1720: 62 65 74 77 65 65 6e 20 74 68 65 20 76 65 72 73  between the vers
1730: 69 6f 6e 20 7a 46 72 6f 6d 20 61 6e 64 20 66 69  ion zFrom and fi
1740: 6c 65 73 20 6f 6e 20 64 69 73 6b 2e 20 20 7a 46  les on disk.  zF
1750: 72 6f 6d 20 6d 69 67 68 74 0a 2a 2a 20 62 65 20  rom might.** be 
1760: 4e 55 4c 4c 20 77 68 69 63 68 20 6d 65 61 6e 73  NULL which means
1770: 20 74 6f 20 73 69 6d 70 6c 79 20 73 68 6f 77 20   to simply show 
1780: 74 68 65 20 64 69 66 66 65 72 65 6e 63 65 20 62  the difference b
1790: 65 74 77 65 65 6e 20 74 68 65 20 65 64 69 74 65  etween the edite
17a0: 64 0a 2a 2a 20 66 69 6c 65 73 20 6f 6e 20 64 69  d.** files on di
17b0: 73 6b 20 61 6e 64 20 74 68 65 20 63 68 65 63 6b  sk and the check
17c0: 2d 6f 75 74 20 6f 6e 20 77 68 69 63 68 20 74 68  -out on which th
17d0: 65 79 20 61 72 65 20 62 61 73 65 64 2e 0a 2a 2f  ey are based..*/
17e0: 0a 73 74 61 74 69 63 20 76 6f 69 64 20 64 69 66  .static void dif
17f0: 66 5f 61 6c 6c 5f 61 67 61 69 6e 73 74 5f 64 69  f_all_against_di
1800: 73 6b 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  sk(const char *z
1810: 46 72 6f 6d 2c 20 63 6f 6e 73 74 20 63 68 61 72  From, const char
1820: 20 2a 7a 44 69 66 66 43 6d 64 29 7b 0a 20 20 69   *zDiffCmd){.  i
1830: 6e 74 20 76 69 64 3b 0a 20 20 42 6c 6f 62 20 73  nt vid;.  Blob s
1840: 71 6c 3b 0a 20 20 53 74 6d 74 20 71 3b 0a 0a 20  ql;.  Stmt q;.. 
1850: 20 76 69 64 20 3d 20 64 62 5f 6c 67 65 74 5f 69   vid = db_lget_i
1860: 6e 74 28 22 63 68 65 63 6b 6f 75 74 22 2c 20 30  nt("checkout", 0
1870: 29 3b 0a 20 20 76 66 69 6c 65 5f 63 68 65 63 6b  );.  vfile_check
1880: 5f 73 69 67 6e 61 74 75 72 65 28 76 69 64 2c 20  _signature(vid, 
1890: 31 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28  1);.  blob_zero(
18a0: 26 73 71 6c 29 3b 0a 20 20 64 62 5f 62 65 67 69  &sql);.  db_begi
18b0: 6e 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 29 3b  n_transaction();
18c0: 0a 20 20 69 66 28 20 7a 46 72 6f 6d 20 29 7b 0a  .  if( zFrom ){.
18d0: 20 20 20 20 69 6e 74 20 72 69 64 20 3d 20 6e 61      int rid = na
18e0: 6d 65 5f 74 6f 5f 72 69 64 28 7a 46 72 6f 6d 29  me_to_rid(zFrom)
18f0: 3b 0a 20 20 20 20 69 66 28 20 21 69 73 5f 61 5f  ;.    if( !is_a_
1900: 76 65 72 73 69 6f 6e 28 72 69 64 29 20 29 7b 0a  version(rid) ){.
1910: 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74        fossil_fat
1920: 61 6c 28 22 6e 6f 20 73 75 63 68 20 63 68 65 63  al("no such chec
1930: 6b 2d 69 6e 3a 20 25 73 22 2c 20 7a 46 72 6f 6d  k-in: %s", zFrom
1940: 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 6c 6f 61  );.    }.    loa
1950: 64 5f 76 66 69 6c 65 5f 66 72 6f 6d 5f 72 69 64  d_vfile_from_rid
1960: 28 72 69 64 29 3b 0a 20 20 20 20 62 6c 6f 62 5f  (rid);.    blob_
1970: 61 70 70 65 6e 64 66 28 26 73 71 6c 2c 0a 20 20  appendf(&sql,.  
1980: 20 20 20 20 22 53 45 4c 45 43 54 20 76 32 2e 70      "SELECT v2.p
1990: 61 74 68 6e 61 6d 65 2c 20 76 32 2e 64 65 6c 65  athname, v2.dele
19a0: 74 65 64 2c 20 76 32 2e 63 68 6e 67 65 64 2c 20  ted, v2.chnged, 
19b0: 76 32 2e 72 69 64 3d 3d 30 2c 20 76 31 2e 72 69  v2.rid==0, v1.ri
19c0: 64 22 0a 20 20 20 20 20 20 22 20 20 46 52 4f 4d  d".      "  FROM
19d0: 20 76 66 69 6c 65 20 76 31 2c 20 76 66 69 6c 65   vfile v1, vfile
19e0: 20 76 32 20 22 0a 20 20 20 20 20 20 22 20 57 48   v2 ".      " WH
19f0: 45 52 45 20 76 31 2e 70 61 74 68 6e 61 6d 65 3d  ERE v1.pathname=
1a00: 76 32 2e 70 61 74 68 6e 61 6d 65 20 41 4e 44 20  v2.pathname AND 
1a10: 76 31 2e 76 69 64 3d 25 64 20 41 4e 44 20 76 32  v1.vid=%d AND v2
1a20: 2e 76 69 64 3d 25 64 22 0a 20 20 20 20 20 20 22  .vid=%d".      "
1a30: 20 20 20 41 4e 44 20 28 76 32 2e 64 65 6c 65 74     AND (v2.delet
1a40: 65 64 20 4f 52 20 76 32 2e 63 68 6e 67 65 64 20  ed OR v2.chnged 
1a50: 4f 52 20 76 31 2e 72 69 64 21 3d 76 32 2e 72 69  OR v1.rid!=v2.ri
1a60: 64 29 22 0a 20 20 20 20 20 20 22 55 4e 49 4f 4e  d)".      "UNION
1a70: 20 22 0a 20 20 20 20 20 20 22 53 45 4c 45 43 54   ".      "SELECT
1a80: 20 70 61 74 68 6e 61 6d 65 2c 20 31 2c 20 30 2c   pathname, 1, 0,
1a90: 20 30 2c 20 30 22 0a 20 20 20 20 20 20 22 20 20   0, 0".      "  
1aa0: 46 52 4f 4d 20 76 66 69 6c 65 20 76 31 22 0a 20  FROM vfile v1". 
1ab0: 20 20 20 20 20 22 20 57 48 45 52 45 20 76 31 2e       " WHERE v1.
1ac0: 76 69 64 3d 25 64 22 0a 20 20 20 20 20 20 22 20  vid=%d".      " 
1ad0: 20 20 41 4e 44 20 4e 4f 54 20 45 58 49 53 54 53    AND NOT EXISTS
1ae0: 28 53 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 76  (SELECT 1 FROM v
1af0: 66 69 6c 65 20 76 32 22 0a 20 20 20 20 20 20 20  file v2".       
1b00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1b10: 20 22 20 57 48 45 52 45 20 76 32 2e 76 69 64 3d   " WHERE v2.vid=
1b20: 25 64 20 41 4e 44 20 76 32 2e 70 61 74 68 6e 61  %d AND v2.pathna
1b30: 6d 65 3d 76 31 2e 70 61 74 68 6e 61 6d 65 29 22  me=v1.pathname)"
1b40: 0a 20 20 20 20 20 20 22 55 4e 49 4f 4e 20 22 0a  .      "UNION ".
1b50: 20 20 20 20 20 20 22 53 45 4c 45 43 54 20 70 61        "SELECT pa
1b60: 74 68 6e 61 6d 65 2c 20 30 2c 20 30 2c 20 31 2c  thname, 0, 0, 1,
1b70: 20 30 22 0a 20 20 20 20 20 20 22 20 20 46 52 4f   0".      "  FRO
1b80: 4d 20 76 66 69 6c 65 20 76 32 22 0a 20 20 20 20  M vfile v2".    
1b90: 20 20 22 20 57 48 45 52 45 20 76 32 2e 76 69 64    " WHERE v2.vid
1ba0: 3d 25 64 22 0a 20 20 20 20 20 20 22 20 20 20 41  =%d".      "   A
1bb0: 4e 44 20 4e 4f 54 20 45 58 49 53 54 53 28 53 45  ND NOT EXISTS(SE
1bc0: 4c 45 43 54 20 31 20 46 52 4f 4d 20 76 66 69 6c  LECT 1 FROM vfil
1bd0: 65 20 76 31 22 0a 20 20 20 20 20 20 20 20 20 20  e v1".          
1be0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 20                " 
1bf0: 57 48 45 52 45 20 76 31 2e 76 69 64 3d 25 64 20  WHERE v1.vid=%d 
1c00: 41 4e 44 20 76 31 2e 70 61 74 68 6e 61 6d 65 3d  AND v1.pathname=
1c10: 76 32 2e 70 61 74 68 6e 61 6d 65 29 22 0a 20 20  v2.pathname)".  
1c20: 20 20 20 20 22 20 4f 52 44 45 52 20 42 59 20 31      " ORDER BY 1
1c30: 22 2c 0a 20 20 20 20 20 20 72 69 64 2c 20 76 69  ",.      rid, vi
1c40: 64 2c 20 72 69 64 2c 20 76 69 64 2c 20 76 69 64  d, rid, vid, vid
1c50: 2c 20 72 69 64 0a 20 20 20 20 29 3b 0a 20 20 7d  , rid.    );.  }
1c60: 65 6c 73 65 7b 0a 20 20 20 20 62 6c 6f 62 5f 61  else{.    blob_a
1c70: 70 70 65 6e 64 66 28 26 73 71 6c 2c 0a 20 20 20  ppendf(&sql,.   
1c80: 20 20 20 22 53 45 4c 45 43 54 20 70 61 74 68 6e     "SELECT pathn
1c90: 61 6d 65 2c 20 64 65 6c 65 74 65 64 2c 20 63 68  ame, deleted, ch
1ca0: 6e 67 65 64 20 2c 20 72 69 64 3d 3d 30 2c 20 72  nged , rid==0, r
1cb0: 69 64 22 0a 20 20 20 20 20 20 22 20 20 46 52 4f  id".      "  FRO
1cc0: 4d 20 76 66 69 6c 65 22 0a 20 20 20 20 20 20 22  M vfile".      "
1cd0: 20 57 48 45 52 45 20 76 69 64 3d 25 64 22 0a 20   WHERE vid=%d". 
1ce0: 20 20 20 20 20 22 20 20 20 41 4e 44 20 28 64 65       "   AND (de
1cf0: 6c 65 74 65 64 20 4f 52 20 63 68 6e 67 65 64 20  leted OR chnged 
1d00: 4f 52 20 72 69 64 3d 3d 30 29 22 0a 20 20 20 20  OR rid==0)".    
1d10: 20 20 22 20 4f 52 44 45 52 20 42 59 20 70 61 74    " ORDER BY pat
1d20: 68 6e 61 6d 65 22 2c 0a 20 20 20 20 20 20 76 69  hname",.      vi
1d30: 64 0a 20 20 20 20 29 3b 0a 20 20 7d 0a 20 20 64  d.    );.  }.  d
1d40: 62 5f 70 72 65 70 61 72 65 28 26 71 2c 20 62 6c  b_prepare(&q, bl
1d50: 6f 62 5f 73 74 72 28 26 73 71 6c 29 29 3b 0a 20  ob_str(&sql));. 
1d60: 20 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28   while( db_step(
1d70: 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20  &q)==SQLITE_ROW 
1d80: 29 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61  ){.    const cha
1d90: 72 20 2a 7a 50 61 74 68 6e 61 6d 65 20 3d 20 64  r *zPathname = d
1da0: 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71  b_column_text(&q
1db0: 2c 30 29 3b 0a 20 20 20 20 69 6e 74 20 69 73 44  ,0);.    int isD
1dc0: 65 6c 65 74 65 64 20 3d 20 64 62 5f 63 6f 6c 75  eleted = db_colu
1dd0: 6d 6e 5f 69 6e 74 28 26 71 2c 20 31 29 3b 0a 20  mn_int(&q, 1);. 
1de0: 20 20 20 69 6e 74 20 69 73 43 68 6e 67 65 64 20     int isChnged 
1df0: 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28  = db_column_int(
1e00: 26 71 2c 32 29 3b 0a 20 20 20 20 69 6e 74 20 69  &q,2);.    int i
1e10: 73 4e 65 77 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e  sNew = db_column
1e20: 5f 69 6e 74 28 26 71 2c 33 29 3b 0a 20 20 20 20  _int(&q,3);.    
1e30: 63 68 61 72 20 2a 7a 46 75 6c 6c 4e 61 6d 65 20  char *zFullName 
1e40: 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 25 73 22  = mprintf("%s%s"
1e50: 2c 20 67 2e 7a 4c 6f 63 61 6c 52 6f 6f 74 2c 20  , g.zLocalRoot, 
1e60: 7a 50 61 74 68 6e 61 6d 65 29 3b 0a 20 20 20 20  zPathname);.    
1e70: 69 66 28 20 69 73 44 65 6c 65 74 65 64 20 29 7b  if( isDeleted ){
1e80: 0a 20 20 20 20 20 20 70 72 69 6e 74 66 28 22 44  .      printf("D
1e90: 45 4c 45 54 45 44 20 20 25 73 5c 6e 22 2c 20 7a  ELETED  %s\n", z
1ea0: 50 61 74 68 6e 61 6d 65 29 3b 0a 20 20 20 20 7d  Pathname);.    }
1eb0: 65 6c 73 65 20 69 66 28 20 61 63 63 65 73 73 28  else if( access(
1ec0: 7a 46 75 6c 6c 4e 61 6d 65 2c 20 30 29 20 29 7b  zFullName, 0) ){
1ed0: 0a 20 20 20 20 20 20 70 72 69 6e 74 66 28 22 4d  .      printf("M
1ee0: 49 53 53 49 4e 47 20 20 25 73 5c 6e 22 2c 20 7a  ISSING  %s\n", z
1ef0: 50 61 74 68 6e 61 6d 65 29 3b 0a 20 20 20 20 7d  Pathname);.    }
1f00: 65 6c 73 65 20 69 66 28 20 69 73 4e 65 77 20 29  else if( isNew )
1f10: 7b 0a 20 20 20 20 20 20 70 72 69 6e 74 66 28 22  {.      printf("
1f20: 41 44 44 45 44 20 20 20 20 25 73 5c 6e 22 2c 20  ADDED    %s\n", 
1f30: 7a 50 61 74 68 6e 61 6d 65 29 3b 0a 20 20 20 20  zPathname);.    
1f40: 7d 65 6c 73 65 20 69 66 28 20 69 73 44 65 6c 65  }else if( isDele
1f50: 74 65 64 20 29 7b 0a 20 20 20 20 20 20 70 72 69  ted ){.      pri
1f60: 6e 74 66 28 22 44 45 4c 45 54 45 44 20 20 25 73  ntf("DELETED  %s
1f70: 5c 6e 22 2c 20 7a 50 61 74 68 6e 61 6d 65 29 3b  \n", zPathname);
1f80: 0a 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20 69  .    }else if( i
1f90: 73 43 68 6e 67 65 64 3d 3d 33 20 29 7b 0a 20 20  sChnged==3 ){.  
1fa0: 20 20 20 20 70 72 69 6e 74 66 28 22 41 44 44 45      printf("ADDE
1fb0: 44 5f 42 59 5f 4d 45 52 47 45 20 25 73 5c 6e 22  D_BY_MERGE %s\n"
1fc0: 2c 20 7a 50 61 74 68 6e 61 6d 65 29 3b 0a 20 20  , zPathname);.  
1fd0: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 69    }else{.      i
1fe0: 6e 74 20 73 72 63 69 64 20 3d 20 64 62 5f 63 6f  nt srcid = db_co
1ff0: 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 34 29 3b  lumn_int(&q, 4);
2000: 0a 20 20 20 20 20 20 42 6c 6f 62 20 63 6f 6e 74  .      Blob cont
2010: 65 6e 74 3b 0a 20 20 20 20 20 20 63 6f 6e 74 65  ent;.      conte
2020: 6e 74 5f 67 65 74 28 73 72 63 69 64 2c 20 26 63  nt_get(srcid, &c
2030: 6f 6e 74 65 6e 74 29 3b 0a 20 20 20 20 20 20 70  ontent);.      p
2040: 72 69 6e 74 66 28 22 49 6e 64 65 78 3a 20 25 73  rintf("Index: %s
2050: 5c 6e 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  \n==============
2060: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
2070: 3d 3d 3d 3d 3d 3d 3d 3d 3d 22 0a 20 20 20 20 20  =========".     
2080: 20 20 20 20 20 20 20 20 22 3d 3d 3d 3d 3d 3d 3d          "=======
2090: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
20a0: 3d 3d 3d 3d 3d 5c 6e 22 2c 0a 20 20 20 20 20 20  =====\n",.      
20b0: 20 20 20 20 20 20 20 7a 50 61 74 68 6e 61 6d 65         zPathname
20c0: 0a 20 20 20 20 20 20 29 3b 0a 20 20 20 20 20 20  .      );.      
20d0: 64 69 66 66 5f 66 69 6c 65 28 26 63 6f 6e 74 65  diff_file(&conte
20e0: 6e 74 2c 20 7a 46 75 6c 6c 4e 61 6d 65 2c 20 7a  nt, zFullName, z
20f0: 50 61 74 68 6e 61 6d 65 2c 20 7a 44 69 66 66 43  Pathname, zDiffC
2100: 6d 64 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f  md);.      blob_
2110: 72 65 73 65 74 28 26 63 6f 6e 74 65 6e 74 29 3b  reset(&content);
2120: 0a 20 20 20 20 7d 0a 20 20 20 20 66 72 65 65 28  .    }.    free(
2130: 7a 46 75 6c 6c 4e 61 6d 65 29 3b 0a 20 20 7d 0a  zFullName);.  }.
2140: 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71    db_finalize(&q
2150: 29 3b 0a 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e  );.  db_end_tran
2160: 73 61 63 74 69 6f 6e 28 31 29 3b 0a 7d 0a 0a 2f  saction(1);.}../
2170: 2a 0a 2a 2a 20 4f 75 74 70 75 74 20 74 68 65 20  *.** Output the 
2180: 64 69 66 66 65 72 65 6e 63 65 73 20 62 65 74 77  differences betw
2190: 65 65 6e 20 74 77 6f 20 76 65 72 73 69 6f 6e 73  een two versions
21a0: 20 6f 66 20 61 20 73 69 6e 67 6c 65 20 66 69 6c   of a single fil
21b0: 65 2e 0a 2a 2a 20 7a 46 72 6f 6d 20 61 6e 64 20  e..** zFrom and 
21c0: 7a 54 6f 20 61 72 65 20 74 68 65 20 63 68 65 63  zTo are the chec
21d0: 6b 2d 69 6e 73 20 63 6f 6e 74 61 69 6e 69 6e 67  k-ins containing
21e0: 20 74 68 65 20 74 77 6f 20 66 69 6c 65 20 76 65   the two file ve
21f0: 72 73 69 6f 6e 73 2e 0a 2a 2a 20 54 68 65 20 66  rsions..** The f
2200: 69 6c 65 6e 61 6d 65 20 69 73 20 63 6f 6e 74 61  ilename is conta
2210: 69 6e 65 64 20 69 6e 20 67 2e 61 72 67 76 5b 32  ined in g.argv[2
2220: 5d 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69  ]..*/.static voi
2230: 64 20 64 69 66 66 5f 6f 6e 65 5f 74 77 6f 5f 76  d diff_one_two_v
2240: 65 72 73 69 6f 6e 73 28 0a 20 20 63 6f 6e 73 74  ersions(.  const
2250: 20 63 68 61 72 20 2a 7a 46 72 6f 6d 2c 0a 20 20   char *zFrom,.  
2260: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 54 6f 2c  const char *zTo,
2270: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  .  const char *z
2280: 44 69 66 66 43 6d 64 0a 29 7b 0a 20 20 63 68 61  DiffCmd.){.  cha
2290: 72 20 2a 7a 4e 61 6d 65 3b 0a 20 20 42 6c 6f 62  r *zName;.  Blob
22a0: 20 66 6e 61 6d 65 3b 0a 20 20 42 6c 6f 62 20 76   fname;.  Blob v
22b0: 31 2c 20 76 32 3b 0a 20 20 66 69 6c 65 5f 74 72  1, v2;.  file_tr
22c0: 65 65 5f 6e 61 6d 65 28 67 2e 61 72 67 76 5b 32  ee_name(g.argv[2
22d0: 5d 2c 20 26 66 6e 61 6d 65 2c 20 31 29 3b 0a 20  ], &fname, 1);. 
22e0: 20 7a 4e 61 6d 65 20 3d 20 62 6c 6f 62 5f 73 74   zName = blob_st
22f0: 72 28 26 66 6e 61 6d 65 29 3b 0a 20 20 68 69 73  r(&fname);.  his
2300: 74 6f 72 69 63 61 6c 5f 76 65 72 73 69 6f 6e 5f  torical_version_
2310: 6f 66 5f 66 69 6c 65 28 7a 46 72 6f 6d 2c 20 7a  of_file(zFrom, z
2320: 4e 61 6d 65 2c 20 26 76 31 2c 20 30 29 3b 0a 20  Name, &v1, 0);. 
2330: 20 68 69 73 74 6f 72 69 63 61 6c 5f 76 65 72 73   historical_vers
2340: 69 6f 6e 5f 6f 66 5f 66 69 6c 65 28 7a 54 6f 2c  ion_of_file(zTo,
2350: 20 7a 4e 61 6d 65 2c 20 26 76 32 2c 20 30 29 3b   zName, &v2, 0);
2360: 0a 20 20 64 69 66 66 5f 66 69 6c 65 5f 6d 65 6d  .  diff_file_mem
2370: 28 26 76 31 2c 20 26 76 32 2c 20 7a 4e 61 6d 65  (&v1, &v2, zName
2380: 2c 20 7a 44 69 66 66 43 6d 64 29 3b 0a 20 20 62  , zDiffCmd);.  b
2390: 6c 6f 62 5f 72 65 73 65 74 28 26 76 31 29 3b 0a  lob_reset(&v1);.
23a0: 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 76 32    blob_reset(&v2
23b0: 29 3b 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74 28  );.  blob_reset(
23c0: 26 66 6e 61 6d 65 29 3b 0a 7d 0a 0a 2f 2a 0a 2a  &fname);.}../*.*
23d0: 2a 20 4f 75 74 70 75 74 20 74 68 65 20 64 69 66  * Output the dif
23e0: 66 65 72 65 6e 63 65 73 20 62 65 74 77 65 65 6e  ferences between
23f0: 20 74 77 6f 20 63 68 65 63 6b 2d 69 6e 73 2e 0a   two check-ins..
2400: 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20 64  */.static void d
2410: 69 66 66 5f 61 6c 6c 5f 74 77 6f 5f 76 65 72 73  iff_all_two_vers
2420: 69 6f 6e 73 28 0a 20 20 63 6f 6e 73 74 20 63 68  ions(.  const ch
2430: 61 72 20 2a 7a 46 72 6f 6d 2c 0a 20 20 63 6f 6e  ar *zFrom,.  con
2440: 73 74 20 63 68 61 72 20 2a 7a 54 6f 2c 0a 20 20  st char *zTo,.  
2450: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 44 69 66  const char *zDif
2460: 66 43 6d 64 0a 29 7b 0a 7d 0a 0a 2f 2a 0a 2a 2a  fCmd.){.}../*.**
2470: 20 43 4f 4d 4d 41 4e 44 3a 20 64 69 66 66 0a 2a   COMMAND: diff.*
2480: 2a 20 43 4f 4d 4d 41 4e 44 3a 20 67 64 69 66 66  * COMMAND: gdiff
2490: 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 3a 20 25 66  .**.** Usage: %f
24a0: 6f 73 73 69 6c 20 64 69 66 66 7c 67 64 69 66 66  ossil diff|gdiff
24b0: 20 3f 6f 70 74 69 6f 6e 73 3f 20 3f 46 49 4c 45   ?options? ?FILE
24c0: 3f 0a 2a 2a 0a 2a 2a 20 53 68 6f 77 20 74 68 65  ?.**.** Show the
24d0: 20 64 69 66 66 65 72 65 6e 63 65 20 62 65 74 77   difference betw
24e0: 65 65 6e 20 74 68 65 20 63 75 72 72 65 6e 74 20  een the current 
24f0: 76 65 72 73 69 6f 6e 20 6f 66 20 46 49 4c 45 20  version of FILE 
2500: 28 61 73 20 69 74 0a 2a 2a 20 65 78 69 73 74 73  (as it.** exists
2510: 20 6f 6e 20 64 69 73 6b 29 20 61 6e 64 20 74 68   on disk) and th
2520: 61 74 20 73 61 6d 65 20 66 69 6c 65 20 61 73 20  at same file as 
2530: 69 74 20 77 61 73 20 63 68 65 63 6b 65 64 20 6f  it was checked o
2540: 75 74 2e 20 20 4f 72 0a 2a 2a 20 69 66 20 74 68  ut.  Or.** if th
2550: 65 20 46 49 4c 45 20 61 72 67 75 6d 65 6e 74 20  e FILE argument 
2560: 69 73 20 6f 6d 69 74 74 65 64 2c 20 73 68 6f 77  is omitted, show
2570: 20 74 68 65 20 75 6e 73 61 76 65 64 20 63 68 61   the unsaved cha
2580: 6e 67 65 64 20 63 75 72 72 65 6e 74 6c 79 0a 2a  nged currently.*
2590: 2a 20 69 6e 20 74 68 65 20 77 6f 72 6b 69 6e 67  * in the working
25a0: 20 63 68 65 63 6b 2d 6f 75 74 2e 0a 2a 2a 0a 2a   check-out..**.*
25b0: 2a 20 49 66 20 74 68 65 20 22 2d 2d 66 72 6f 6d  * If the "--from
25c0: 20 56 45 52 53 49 4f 4e 22 20 6f 72 20 22 2d 72   VERSION" or "-r
25d0: 20 56 45 52 53 49 4f 4e 22 20 6f 70 74 69 6f 6e   VERSION" option
25e0: 20 69 73 20 75 73 65 64 20 69 74 20 73 70 65 63   is used it spec
25f0: 69 66 69 65 73 0a 2a 2a 20 74 68 65 20 73 6f 75  ifies.** the sou
2600: 72 63 65 20 63 68 65 63 6b 2d 69 6e 20 66 6f 72  rce check-in for
2610: 20 74 68 65 20 64 69 66 66 20 6f 70 65 72 61 74   the diff operat
2620: 69 6f 6e 2e 20 20 49 66 20 6e 6f 74 20 73 70 65  ion.  If not spe
2630: 63 69 66 69 65 64 2c 20 74 68 65 20 0a 2a 2a 20  cified, the .** 
2640: 73 6f 75 72 63 65 20 63 68 65 63 6b 2d 69 6e 20  source check-in 
2650: 69 73 20 74 68 65 20 62 61 73 65 20 63 68 65 63  is the base chec
2660: 6b 2d 69 6e 20 66 6f 72 20 74 68 65 20 63 75 72  k-in for the cur
2670: 72 65 6e 74 20 63 68 65 63 6b 2d 6f 75 74 2e 0a  rent check-out..
2680: 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 22 2d 2d  **.** If the "--
2690: 74 6f 20 56 45 52 53 49 4f 4e 22 20 6f 70 74 69  to VERSION" opti
26a0: 6f 6e 20 61 70 70 65 61 72 73 2c 20 69 74 20 73  on appears, it s
26b0: 70 65 63 69 66 69 65 73 20 74 68 65 20 63 68 65  pecifies the che
26c0: 63 6b 2d 69 6e 20 66 72 6f 6d 0a 2a 2a 20 77 68  ck-in from.** wh
26d0: 69 63 68 20 74 68 65 20 73 65 63 6f 6e 64 20 76  ich the second v
26e0: 65 72 73 69 6f 6e 20 6f 66 20 74 68 65 20 66 69  ersion of the fi
26f0: 6c 65 20 6f 72 20 66 69 6c 65 73 20 69 73 20 74  le or files is t
2700: 61 6b 65 6e 2e 20 20 49 66 20 74 68 65 72 65 20  aken.  If there 
2710: 69 73 0a 2a 2a 20 6e 6f 20 22 2d 2d 74 6f 22 20  is.** no "--to" 
2720: 6f 70 74 69 6f 6e 20 74 68 65 6e 20 74 68 65 20  option then the 
2730: 28 70 6f 73 73 69 62 6c 79 20 65 64 69 74 65 64  (possibly edited
2740: 29 20 66 69 6c 65 73 20 69 6e 20 74 68 65 20 63  ) files in the c
2750: 75 72 72 65 6e 74 20 63 68 65 63 6b 2d 6f 75 74  urrent check-out
2760: 0a 2a 2a 20 61 72 65 20 75 73 65 64 2e 0a 2a 2a  .** are used..**
2770: 0a 2a 2a 20 54 68 65 20 22 2d 69 22 20 63 6f 6d  .** The "-i" com
2780: 6d 61 6e 64 2d 6c 69 6e 65 20 6f 70 74 69 6f 6e  mand-line option
2790: 20 66 6f 72 63 65 73 20 74 68 65 20 75 73 65 20   forces the use 
27a0: 6f 66 20 74 68 65 20 69 6e 74 65 72 6e 61 6c 20  of the internal 
27b0: 64 69 66 66 20 6c 6f 67 69 63 0a 2a 2a 20 72 61  diff logic.** ra
27c0: 74 68 65 72 20 74 68 61 6e 20 61 6e 79 20 65 78  ther than any ex
27d0: 74 65 72 6e 61 6c 20 64 69 66 66 20 70 72 6f 67  ternal diff prog
27e0: 72 61 6d 20 74 68 61 74 20 6d 69 67 68 74 20 62  ram that might b
27f0: 65 20 63 6f 6e 66 69 67 75 72 65 64 20 75 73 69  e configured usi
2800: 6e 67 0a 2a 2a 20 74 68 65 20 22 73 65 74 74 69  ng.** the "setti
2810: 6e 67 22 20 63 6f 6d 6d 61 6e 64 2e 20 20 49 66  ng" command.  If
2820: 20 6e 6f 20 65 78 74 65 72 6e 61 6c 20 64 69 66   no external dif
2830: 66 20 70 72 6f 67 72 61 6d 20 69 73 20 63 6f 6e  f program is con
2840: 66 69 67 75 72 65 64 2c 20 74 68 65 6e 0a 2a 2a  figured, then.**
2850: 20 74 68 65 20 22 2d 69 22 20 6f 70 74 69 6f 6e   the "-i" option
2860: 20 69 73 20 61 20 6e 6f 2d 6f 70 2e 20 20 54 68   is a no-op.  Th
2870: 65 20 22 2d 69 22 20 6f 70 74 69 6f 6e 20 63 6f  e "-i" option co
2880: 6e 76 65 72 74 73 20 22 67 64 69 66 66 22 20 69  nverts "gdiff" i
2890: 6e 74 6f 20 22 64 69 66 66 22 2e 0a 2a 2f 0a 76  nto "diff"..*/.v
28a0: 6f 69 64 20 64 69 66 66 5f 63 6d 64 28 76 6f 69  oid diff_cmd(voi
28b0: 64 29 7b 0a 20 20 69 6e 74 20 69 73 47 44 69 66  d){.  int isGDif
28c0: 66 3b 20 20 20 20 20 20 20 20 20 20 20 20 20 20  f;              
28d0: 20 2f 2a 20 54 72 75 65 20 66 6f 72 20 67 64 69   /* True for gdi
28e0: 66 66 2e 20 20 46 61 6c 73 65 20 66 6f 72 20 6e  ff.  False for n
28f0: 6f 72 6d 61 6c 20 64 69 66 66 20 2a 2f 0a 20 20  ormal diff */.  
2900: 69 6e 74 20 69 73 49 6e 74 65 72 6e 44 69 66 66  int isInternDiff
2910: 3b 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72  ;          /* Tr
2920: 75 65 20 66 6f 72 20 69 6e 74 65 72 6e 61 6c 20  ue for internal 
2930: 64 69 66 66 20 2a 2f 0a 20 20 63 6f 6e 73 74 20  diff */.  const 
2940: 63 68 61 72 20 2a 7a 46 72 6f 6d 3b 20 20 20 20  char *zFrom;    
2950: 20 20 20 20 20 2f 2a 20 53 6f 75 72 63 65 20 76       /* Source v
2960: 65 72 73 69 6f 6e 20 6e 75 6d 62 65 72 20 2a 2f  ersion number */
2970: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  .  const char *z
2980: 54 6f 3b 20 20 20 20 20 20 20 20 20 20 20 2f 2a  To;           /*
2990: 20 54 61 72 67 65 74 20 76 65 72 73 69 6f 6e 20   Target version 
29a0: 6e 75 6d 62 65 72 20 2a 2f 0a 20 20 63 6f 6e 73  number */.  cons
29b0: 74 20 63 68 61 72 20 2a 7a 44 69 66 66 43 6d 64  t char *zDiffCmd
29c0: 20 3d 20 30 3b 20 20 2f 2a 20 45 78 74 65 72 6e   = 0;  /* Extern
29d0: 61 6c 20 64 69 66 66 20 63 6f 6d 6d 61 6e 64 2e  al diff command.
29e0: 20 4e 55 4c 4c 20 66 6f 72 20 69 6e 74 65 72 6e   NULL for intern
29f0: 61 6c 20 64 69 66 66 20 2a 2f 0a 0a 20 20 69 73  al diff */..  is
2a00: 47 44 69 66 66 20 3d 20 67 2e 61 72 67 76 5b 31  GDiff = g.argv[1
2a10: 5d 5b 30 5d 3d 3d 27 67 27 3b 0a 20 20 69 73 49  ][0]=='g';.  isI
2a20: 6e 74 65 72 6e 44 69 66 66 20 3d 20 66 69 6e 64  nternDiff = find
2a30: 5f 6f 70 74 69 6f 6e 28 22 69 6e 74 65 72 6e 61  _option("interna
2a40: 6c 22 2c 22 69 22 2c 30 29 21 3d 30 3b 0a 20 20  l","i",0)!=0;.  
2a50: 7a 46 72 6f 6d 20 3d 20 66 69 6e 64 5f 6f 70 74  zFrom = find_opt
2a60: 69 6f 6e 28 22 66 72 6f 6d 22 2c 20 22 72 22 2c  ion("from", "r",
2a70: 20 31 29 3b 0a 20 20 7a 54 6f 20 3d 20 66 69 6e   1);.  zTo = fin
2a80: 64 5f 6f 70 74 69 6f 6e 28 22 74 6f 22 2c 20 30  d_option("to", 0
2a90: 2c 20 31 29 3b 0a 0a 20 20 69 66 28 20 7a 54 6f  , 1);..  if( zTo
2aa0: 3d 3d 30 20 29 7b 0a 20 20 20 20 64 62 5f 6d 75  ==0 ){.    db_mu
2ab0: 73 74 5f 62 65 5f 77 69 74 68 69 6e 5f 74 72 65  st_be_within_tre
2ac0: 65 28 29 3b 0a 20 20 20 20 76 65 72 69 66 79 5f  e();.    verify_
2ad0: 61 6c 6c 5f 6f 70 74 69 6f 6e 73 28 29 3b 0a 20  all_options();. 
2ae0: 20 20 20 69 66 28 20 21 69 73 49 6e 74 65 72 6e     if( !isIntern
2af0: 44 69 66 66 20 26 26 20 67 2e 61 72 67 63 3d 3d  Diff && g.argc==
2b00: 33 20 29 7b 0a 20 20 20 20 20 20 7a 44 69 66 66  3 ){.      zDiff
2b10: 43 6d 64 20 3d 20 64 62 5f 67 65 74 28 69 73 47  Cmd = db_get(isG
2b20: 44 69 66 66 20 3f 20 22 67 64 69 66 66 2d 63 6f  Diff ? "gdiff-co
2b30: 6d 6d 61 6e 64 22 20 3a 20 22 64 69 66 66 2d 63  mmand" : "diff-c
2b40: 6f 6d 6d 61 6e 64 22 2c 20 30 29 3b 0a 20 20 20  ommand", 0);.   
2b50: 20 7d 0a 20 20 20 20 69 66 28 20 67 2e 61 72 67   }.    if( g.arg
2b60: 63 3d 3d 33 20 29 7b 0a 20 20 20 20 20 20 64 69  c==3 ){.      di
2b70: 66 66 5f 6f 6e 65 5f 61 67 61 69 6e 73 74 5f 64  ff_one_against_d
2b80: 69 73 6b 28 7a 46 72 6f 6d 2c 20 7a 44 69 66 66  isk(zFrom, zDiff
2b90: 43 6d 64 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b  Cmd);.    }else{
2ba0: 0a 20 20 20 20 20 20 64 69 66 66 5f 61 6c 6c 5f  .      diff_all_
2bb0: 61 67 61 69 6e 73 74 5f 64 69 73 6b 28 7a 46 72  against_disk(zFr
2bc0: 6f 6d 2c 20 7a 44 69 66 66 43 6d 64 29 3b 0a 20  om, zDiffCmd);. 
2bd0: 20 20 20 7d 0a 20 20 7d 65 6c 73 65 20 69 66 28     }.  }else if(
2be0: 20 7a 46 72 6f 6d 3d 3d 30 20 29 7b 0a 20 20 20   zFrom==0 ){.   
2bf0: 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 6d   fossil_fatal("m
2c00: 75 73 74 20 75 73 65 20 2d 2d 66 72 6f 6d 20 69  ust use --from i
2c10: 66 20 2d 2d 74 6f 20 69 73 20 70 72 65 73 65 6e  f --to is presen
2c20: 74 22 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20  t");.  }else{.  
2c30: 20 20 64 62 5f 66 69 6e 64 5f 61 6e 64 5f 6f 70    db_find_and_op
2c40: 65 6e 5f 72 65 70 6f 73 69 74 6f 72 79 28 31 29  en_repository(1)
2c50: 3b 0a 20 20 20 20 76 65 72 69 66 79 5f 61 6c 6c  ;.    verify_all
2c60: 5f 6f 70 74 69 6f 6e 73 28 29 3b 0a 20 20 20 20  _options();.    
2c70: 69 66 28 20 21 69 73 49 6e 74 65 72 6e 44 69 66  if( !isInternDif
2c80: 66 20 26 26 20 67 2e 61 72 67 63 3d 3d 33 20 29  f && g.argc==3 )
2c90: 7b 0a 20 20 20 20 20 20 7a 44 69 66 66 43 6d 64  {.      zDiffCmd
2ca0: 20 3d 20 64 62 5f 67 65 74 28 69 73 47 44 69 66   = db_get(isGDif
2cb0: 66 20 3f 20 22 67 64 69 66 66 2d 63 6f 6d 6d 61  f ? "gdiff-comma
2cc0: 6e 64 22 20 3a 20 22 64 69 66 66 2d 63 6f 6d 6d  nd" : "diff-comm
2cd0: 61 6e 64 22 2c 20 30 29 3b 0a 20 20 20 20 7d 0a  and", 0);.    }.
2ce0: 20 20 20 20 69 66 28 20 67 2e 61 72 67 63 3d 3d      if( g.argc==
2cf0: 33 20 29 7b 0a 20 20 20 20 20 20 64 69 66 66 5f  3 ){.      diff_
2d00: 6f 6e 65 5f 74 77 6f 5f 76 65 72 73 69 6f 6e 73  one_two_versions
2d10: 28 7a 46 72 6f 6d 2c 20 7a 54 6f 2c 20 7a 44 69  (zFrom, zTo, zDi
2d20: 66 66 43 6d 64 29 3b 0a 20 20 20 20 7d 65 6c 73  ffCmd);.    }els
2d30: 65 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f  e{.      fossil_
2d40: 66 61 74 61 6c 28 22 2d 2d 74 6f 20 6f 6e 20 63  fatal("--to on c
2d50: 6f 6d 70 6c 65 74 65 20 63 68 65 63 6b 2d 69 6e  omplete check-in
2d60: 73 20 6e 6f 74 20 79 65 74 20 69 6d 70 6c 65 6d  s not yet implem
2d70: 65 6e 74 65 64 22 29 3b 0a 20 20 20 20 20 20 64  ented");.      d
2d80: 69 66 66 5f 61 6c 6c 5f 74 77 6f 5f 76 65 72 73  iff_all_two_vers
2d90: 69 6f 6e 73 28 7a 46 72 6f 6d 2c 20 7a 54 6f 2c  ions(zFrom, zTo,
2da0: 20 7a 44 69 66 66 43 6d 64 29 3b 0a 20 20 20 20   zDiffCmd);.    
2db0: 7d 0a 20 20 7d 0a 7d 0a                          }.  }.}.