Hex Artifact Content
Not logged in

Artifact 20363d7b427f5bf53b08dcaa552ca255cddde101:

File src/diffcmd.c part of check-in [fe8bb01d38] - Add the ability to diff to arbitrary versions of a single file. by drh on 2009-11-06 14:00:38.

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 29 3b 0a 20 20 64 69 66 66 5f 66 69 6c 65 28  t);.  diff_file(
16b0: 26 63 6f 6e 74 65 6e 74 2c 20 67 2e 61 72 67 76  &content, g.argv
16c0: 5b 32 5d 2c 20 67 2e 61 72 67 76 5b 32 5d 2c 20  [2], g.argv[2], 
16d0: 7a 44 69 66 66 43 6d 64 29 3b 0a 20 20 62 6c 6f  zDiffCmd);.  blo
16e0: 62 5f 72 65 73 65 74 28 26 63 6f 6e 74 65 6e 74  b_reset(&content
16f0: 29 3b 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74 28  );.  blob_reset(
1700: 26 66 6e 61 6d 65 29 3b 0a 7d 0a 0a 2f 2a 0a 2a  &fname);.}../*.*
1710: 2a 20 52 75 6e 20 61 20 64 69 66 66 20 62 65 74  * Run a diff bet
1720: 77 65 65 6e 20 74 68 65 20 76 65 72 73 69 6f 6e  ween the version
1730: 20 7a 46 72 6f 6d 20 61 6e 64 20 66 69 6c 65 73   zFrom and files
1740: 20 6f 6e 20 64 69 73 6b 2e 20 20 7a 46 72 6f 6d   on disk.  zFrom
1750: 20 6d 69 67 68 74 0a 2a 2a 20 62 65 20 4e 55 4c   might.** be NUL
1760: 4c 20 77 68 69 63 68 20 6d 65 61 6e 73 20 74 6f  L which means to
1770: 20 73 69 6d 70 6c 79 20 73 68 6f 77 20 74 68 65   simply show the
1780: 20 64 69 66 66 65 72 65 6e 63 65 20 62 65 74 77   difference betw
1790: 65 65 6e 20 74 68 65 20 65 64 69 74 65 64 0a 2a  een the edited.*
17a0: 2a 20 66 69 6c 65 73 20 6f 6e 20 64 69 73 6b 20  * files on disk 
17b0: 61 6e 64 20 74 68 65 20 63 68 65 63 6b 2d 6f 75  and the check-ou
17c0: 74 20 6f 6e 20 77 68 69 63 68 20 74 68 65 79 20  t on which they 
17d0: 61 72 65 20 62 61 73 65 64 2e 0a 2a 2f 0a 73 74  are based..*/.st
17e0: 61 74 69 63 20 76 6f 69 64 20 64 69 66 66 5f 61  atic void diff_a
17f0: 6c 6c 5f 61 67 61 69 6e 73 74 5f 64 69 73 6b 28  ll_against_disk(
1800: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 46 72 6f  const char *zFro
1810: 6d 2c 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  m, const char *z
1820: 44 69 66 66 43 6d 64 29 7b 0a 20 20 69 6e 74 20  DiffCmd){.  int 
1830: 76 69 64 3b 0a 20 20 42 6c 6f 62 20 73 71 6c 3b  vid;.  Blob sql;
1840: 0a 20 20 53 74 6d 74 20 71 3b 0a 0a 20 20 76 69  .  Stmt q;..  vi
1850: 64 20 3d 20 64 62 5f 6c 67 65 74 5f 69 6e 74 28  d = db_lget_int(
1860: 22 63 68 65 63 6b 6f 75 74 22 2c 20 30 29 3b 0a  "checkout", 0);.
1870: 20 20 76 66 69 6c 65 5f 63 68 65 63 6b 5f 73 69    vfile_check_si
1880: 67 6e 61 74 75 72 65 28 76 69 64 29 3b 0a 20 20  gnature(vid);.  
1890: 62 6c 6f 62 5f 7a 65 72 6f 28 26 73 71 6c 29 3b  blob_zero(&sql);
18a0: 0a 20 20 64 62 5f 62 65 67 69 6e 5f 74 72 61 6e  .  db_begin_tran
18b0: 73 61 63 74 69 6f 6e 28 29 3b 0a 20 20 69 66 28  saction();.  if(
18c0: 20 7a 46 72 6f 6d 20 29 7b 0a 20 20 20 20 69 6e   zFrom ){.    in
18d0: 74 20 72 69 64 20 3d 20 6e 61 6d 65 5f 74 6f 5f  t rid = name_to_
18e0: 72 69 64 28 7a 46 72 6f 6d 29 3b 0a 20 20 20 20  rid(zFrom);.    
18f0: 69 66 28 20 21 69 73 5f 61 5f 76 65 72 73 69 6f  if( !is_a_versio
1900: 6e 28 72 69 64 29 20 29 7b 0a 20 20 20 20 20 20  n(rid) ){.      
1910: 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28 22 6e 6f  fossil_fatal("no
1920: 20 73 75 63 68 20 63 68 65 63 6b 2d 69 6e 3a 20   such check-in: 
1930: 25 73 22 2c 20 7a 46 72 6f 6d 29 3b 0a 20 20 20  %s", zFrom);.   
1940: 20 7d 0a 20 20 20 20 6c 6f 61 64 5f 76 66 69 6c   }.    load_vfil
1950: 65 5f 66 72 6f 6d 5f 72 69 64 28 72 69 64 29 3b  e_from_rid(rid);
1960: 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64  .    blob_append
1970: 66 28 26 73 71 6c 2c 0a 20 20 20 20 20 20 22 53  f(&sql,.      "S
1980: 45 4c 45 43 54 20 76 32 2e 70 61 74 68 6e 61 6d  ELECT v2.pathnam
1990: 65 2c 20 76 32 2e 64 65 6c 65 74 65 64 2c 20 76  e, v2.deleted, v
19a0: 32 2e 63 68 6e 67 65 64 2c 20 76 32 2e 72 69 64  2.chnged, v2.rid
19b0: 3d 3d 30 2c 20 76 31 2e 72 69 64 22 0a 20 20 20  ==0, v1.rid".   
19c0: 20 20 20 22 20 20 46 52 4f 4d 20 76 66 69 6c 65     "  FROM vfile
19d0: 20 76 31 2c 20 76 66 69 6c 65 20 76 32 20 22 0a   v1, vfile v2 ".
19e0: 20 20 20 20 20 20 22 20 57 48 45 52 45 20 76 31        " WHERE v1
19f0: 2e 70 61 74 68 6e 61 6d 65 3d 76 32 2e 70 61 74  .pathname=v2.pat
1a00: 68 6e 61 6d 65 20 41 4e 44 20 76 31 2e 76 69 64  hname AND v1.vid
1a10: 3d 25 64 20 41 4e 44 20 76 32 2e 76 69 64 3d 25  =%d AND v2.vid=%
1a20: 64 22 0a 20 20 20 20 20 20 22 20 20 20 41 4e 44  d".      "   AND
1a30: 20 28 76 32 2e 64 65 6c 65 74 65 64 20 4f 52 20   (v2.deleted OR 
1a40: 76 32 2e 63 68 6e 67 65 64 20 4f 52 20 76 31 2e  v2.chnged OR v1.
1a50: 72 69 64 21 3d 76 32 2e 72 69 64 29 22 0a 20 20  rid!=v2.rid)".  
1a60: 20 20 20 20 22 55 4e 49 4f 4e 20 22 0a 20 20 20      "UNION ".   
1a70: 20 20 20 22 53 45 4c 45 43 54 20 70 61 74 68 6e     "SELECT pathn
1a80: 61 6d 65 2c 20 31 2c 20 30 2c 20 30 2c 20 30 22  ame, 1, 0, 0, 0"
1a90: 0a 20 20 20 20 20 20 22 20 20 46 52 4f 4d 20 76  .      "  FROM v
1aa0: 66 69 6c 65 20 76 31 22 0a 20 20 20 20 20 20 22  file v1".      "
1ab0: 20 57 48 45 52 45 20 76 31 2e 76 69 64 3d 25 64   WHERE v1.vid=%d
1ac0: 22 0a 20 20 20 20 20 20 22 20 20 20 41 4e 44 20  ".      "   AND 
1ad0: 4e 4f 54 20 45 58 49 53 54 53 28 53 45 4c 45 43  NOT EXISTS(SELEC
1ae0: 54 20 31 20 46 52 4f 4d 20 76 66 69 6c 65 20 76  T 1 FROM vfile v
1af0: 32 22 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  2".             
1b00: 20 20 20 20 20 20 20 20 20 20 20 22 20 57 48 45             " WHE
1b10: 52 45 20 76 32 2e 76 69 64 3d 25 64 20 41 4e 44  RE v2.vid=%d AND
1b20: 20 76 32 2e 70 61 74 68 6e 61 6d 65 3d 76 31 2e   v2.pathname=v1.
1b30: 70 61 74 68 6e 61 6d 65 29 22 0a 20 20 20 20 20  pathname)".     
1b40: 20 22 55 4e 49 4f 4e 20 22 0a 20 20 20 20 20 20   "UNION ".      
1b50: 22 53 45 4c 45 43 54 20 70 61 74 68 6e 61 6d 65  "SELECT pathname
1b60: 2c 20 30 2c 20 30 2c 20 31 2c 20 30 22 0a 20 20  , 0, 0, 1, 0".  
1b70: 20 20 20 20 22 20 20 46 52 4f 4d 20 76 66 69 6c      "  FROM vfil
1b80: 65 20 76 32 22 0a 20 20 20 20 20 20 22 20 57 48  e v2".      " WH
1b90: 45 52 45 20 76 32 2e 76 69 64 3d 25 64 22 0a 20  ERE v2.vid=%d". 
1ba0: 20 20 20 20 20 22 20 20 20 41 4e 44 20 4e 4f 54       "   AND NOT
1bb0: 20 45 58 49 53 54 53 28 53 45 4c 45 43 54 20 31   EXISTS(SELECT 1
1bc0: 20 46 52 4f 4d 20 76 66 69 6c 65 20 76 31 22 0a   FROM vfile v1".
1bd0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1be0: 20 20 20 20 20 20 20 20 22 20 57 48 45 52 45 20          " WHERE 
1bf0: 76 31 2e 76 69 64 3d 25 64 20 41 4e 44 20 76 31  v1.vid=%d AND v1
1c00: 2e 70 61 74 68 6e 61 6d 65 3d 76 32 2e 70 61 74  .pathname=v2.pat
1c10: 68 6e 61 6d 65 29 22 0a 20 20 20 20 20 20 22 20  hname)".      " 
1c20: 4f 52 44 45 52 20 42 59 20 31 22 2c 0a 20 20 20  ORDER BY 1",.   
1c30: 20 20 20 72 69 64 2c 20 76 69 64 2c 20 72 69 64     rid, vid, rid
1c40: 2c 20 76 69 64 2c 20 76 69 64 2c 20 72 69 64 0a  , vid, vid, rid.
1c50: 20 20 20 20 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a      );.  }else{.
1c60: 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 66      blob_appendf
1c70: 28 26 73 71 6c 2c 0a 20 20 20 20 20 20 22 53 45  (&sql,.      "SE
1c80: 4c 45 43 54 20 70 61 74 68 6e 61 6d 65 2c 20 64  LECT pathname, d
1c90: 65 6c 65 74 65 64 2c 20 63 68 6e 67 65 64 20 2c  eleted, chnged ,
1ca0: 20 72 69 64 3d 3d 30 2c 20 72 69 64 22 0a 20 20   rid==0, rid".  
1cb0: 20 20 20 20 22 20 20 46 52 4f 4d 20 76 66 69 6c      "  FROM vfil
1cc0: 65 22 0a 20 20 20 20 20 20 22 20 57 48 45 52 45  e".      " WHERE
1cd0: 20 76 69 64 3d 25 64 22 0a 20 20 20 20 20 20 22   vid=%d".      "
1ce0: 20 20 20 41 4e 44 20 28 64 65 6c 65 74 65 64 20     AND (deleted 
1cf0: 4f 52 20 63 68 6e 67 65 64 20 4f 52 20 72 69 64  OR chnged OR rid
1d00: 3d 3d 30 29 22 0a 20 20 20 20 20 20 22 20 4f 52  ==0)".      " OR
1d10: 44 45 52 20 42 59 20 70 61 74 68 6e 61 6d 65 22  DER BY pathname"
1d20: 2c 0a 20 20 20 20 20 20 76 69 64 0a 20 20 20 20  ,.      vid.    
1d30: 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 70 72 65 70  );.  }.  db_prep
1d40: 61 72 65 28 26 71 2c 20 62 6c 6f 62 5f 73 74 72  are(&q, blob_str
1d50: 28 26 73 71 6c 29 29 3b 0a 20 20 77 68 69 6c 65  (&sql));.  while
1d60: 28 20 64 62 5f 73 74 65 70 28 26 71 29 3d 3d 53  ( db_step(&q)==S
1d70: 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a 20 20 20  QLITE_ROW ){.   
1d80: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 50 61   const char *zPa
1d90: 74 68 6e 61 6d 65 20 3d 20 64 62 5f 63 6f 6c 75  thname = db_colu
1da0: 6d 6e 5f 74 65 78 74 28 26 71 2c 30 29 3b 0a 20  mn_text(&q,0);. 
1db0: 20 20 20 69 6e 74 20 69 73 44 65 6c 65 74 65 64     int isDeleted
1dc0: 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74   = db_column_int
1dd0: 28 26 71 2c 20 31 29 3b 0a 20 20 20 20 69 6e 74  (&q, 1);.    int
1de0: 20 69 73 43 68 6e 67 65 64 20 3d 20 64 62 5f 63   isChnged = db_c
1df0: 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 32 29 3b  olumn_int(&q,2);
1e00: 0a 20 20 20 20 69 6e 74 20 69 73 4e 65 77 20 3d  .    int isNew =
1e10: 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26   db_column_int(&
1e20: 71 2c 33 29 3b 0a 20 20 20 20 63 68 61 72 20 2a  q,3);.    char *
1e30: 7a 46 75 6c 6c 4e 61 6d 65 20 3d 20 6d 70 72 69  zFullName = mpri
1e40: 6e 74 66 28 22 25 73 25 73 22 2c 20 67 2e 7a 4c  ntf("%s%s", g.zL
1e50: 6f 63 61 6c 52 6f 6f 74 2c 20 7a 50 61 74 68 6e  ocalRoot, zPathn
1e60: 61 6d 65 29 3b 0a 20 20 20 20 69 66 28 20 69 73  ame);.    if( is
1e70: 44 65 6c 65 74 65 64 20 29 7b 0a 20 20 20 20 20  Deleted ){.     
1e80: 20 70 72 69 6e 74 66 28 22 44 45 4c 45 54 45 44   printf("DELETED
1e90: 20 20 25 73 5c 6e 22 2c 20 7a 50 61 74 68 6e 61    %s\n", zPathna
1ea0: 6d 65 29 3b 0a 20 20 20 20 7d 65 6c 73 65 20 69  me);.    }else i
1eb0: 66 28 20 61 63 63 65 73 73 28 7a 46 75 6c 6c 4e  f( access(zFullN
1ec0: 61 6d 65 2c 20 30 29 20 29 7b 0a 20 20 20 20 20  ame, 0) ){.     
1ed0: 20 70 72 69 6e 74 66 28 22 4d 49 53 53 49 4e 47   printf("MISSING
1ee0: 20 20 25 73 5c 6e 22 2c 20 7a 50 61 74 68 6e 61    %s\n", zPathna
1ef0: 6d 65 29 3b 0a 20 20 20 20 7d 65 6c 73 65 20 69  me);.    }else i
1f00: 66 28 20 69 73 4e 65 77 20 29 7b 0a 20 20 20 20  f( isNew ){.    
1f10: 20 20 70 72 69 6e 74 66 28 22 41 44 44 45 44 20    printf("ADDED 
1f20: 20 20 20 25 73 5c 6e 22 2c 20 7a 50 61 74 68 6e     %s\n", zPathn
1f30: 61 6d 65 29 3b 0a 20 20 20 20 7d 65 6c 73 65 20  ame);.    }else 
1f40: 69 66 28 20 69 73 44 65 6c 65 74 65 64 20 29 7b  if( isDeleted ){
1f50: 0a 20 20 20 20 20 20 70 72 69 6e 74 66 28 22 44  .      printf("D
1f60: 45 4c 45 54 45 44 20 20 25 73 5c 6e 22 2c 20 7a  ELETED  %s\n", z
1f70: 50 61 74 68 6e 61 6d 65 29 3b 0a 20 20 20 20 7d  Pathname);.    }
1f80: 65 6c 73 65 20 69 66 28 20 69 73 43 68 6e 67 65  else if( isChnge
1f90: 64 3d 3d 33 20 29 7b 0a 20 20 20 20 20 20 70 72  d==3 ){.      pr
1fa0: 69 6e 74 66 28 22 41 44 44 45 44 5f 42 59 5f 4d  intf("ADDED_BY_M
1fb0: 45 52 47 45 20 25 73 5c 6e 22 2c 20 7a 50 61 74  ERGE %s\n", zPat
1fc0: 68 6e 61 6d 65 29 3b 0a 20 20 20 20 7d 65 6c 73  hname);.    }els
1fd0: 65 7b 0a 20 20 20 20 20 20 69 6e 74 20 73 72 63  e{.      int src
1fe0: 69 64 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69  id = db_column_i
1ff0: 6e 74 28 26 71 2c 20 34 29 3b 0a 20 20 20 20 20  nt(&q, 4);.     
2000: 20 42 6c 6f 62 20 63 6f 6e 74 65 6e 74 3b 0a 20   Blob content;. 
2010: 20 20 20 20 20 63 6f 6e 74 65 6e 74 5f 67 65 74       content_get
2020: 28 73 72 63 69 64 2c 20 26 63 6f 6e 74 65 6e 74  (srcid, &content
2030: 29 3b 0a 20 20 20 20 20 20 70 72 69 6e 74 66 28  );.      printf(
2040: 22 49 6e 64 65 78 3a 20 25 73 5c 6e 3d 3d 3d 3d  "Index: %s\n====
2050: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
2060: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
2070: 3d 3d 3d 22 0a 20 20 20 20 20 20 20 20 20 20 20  ===".           
2080: 20 20 22 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d    "=============
2090: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 5c  ===============\
20a0: 6e 22 2c 0a 20 20 20 20 20 20 20 20 20 20 20 20  n",.            
20b0: 20 7a 50 61 74 68 6e 61 6d 65 0a 20 20 20 20 20   zPathname.     
20c0: 20 29 3b 0a 20 20 20 20 20 20 64 69 66 66 5f 66   );.      diff_f
20d0: 69 6c 65 28 26 63 6f 6e 74 65 6e 74 2c 20 7a 46  ile(&content, zF
20e0: 75 6c 6c 4e 61 6d 65 2c 20 7a 50 61 74 68 6e 61  ullName, zPathna
20f0: 6d 65 2c 20 7a 44 69 66 66 43 6d 64 29 3b 0a 20  me, zDiffCmd);. 
2100: 20 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28       blob_reset(
2110: 26 63 6f 6e 74 65 6e 74 29 3b 0a 20 20 20 20 7d  &content);.    }
2120: 0a 20 20 20 20 66 72 65 65 28 7a 46 75 6c 6c 4e  .    free(zFullN
2130: 61 6d 65 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 66  ame);.  }.  db_f
2140: 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a 20 20 64  inalize(&q);.  d
2150: 62 5f 65 6e 64 5f 74 72 61 6e 73 61 63 74 69 6f  b_end_transactio
2160: 6e 28 31 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 4f  n(1);.}../*.** O
2170: 75 74 70 75 74 20 74 68 65 20 64 69 66 66 65 72  utput the differ
2180: 65 6e 63 65 73 20 62 65 74 77 65 65 6e 20 74 77  ences between tw
2190: 6f 20 76 65 72 73 69 6f 6e 73 20 6f 66 20 61 20  o versions of a 
21a0: 73 69 6e 67 6c 65 20 66 69 6c 65 2e 0a 2a 2a 20  single file..** 
21b0: 7a 46 72 6f 6d 20 61 6e 64 20 7a 54 6f 20 61 72  zFrom and zTo ar
21c0: 65 20 74 68 65 20 63 68 65 63 6b 2d 69 6e 73 20  e the check-ins 
21d0: 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 74  containing the t
21e0: 77 6f 20 66 69 6c 65 20 76 65 72 73 69 6f 6e 73  wo file versions
21f0: 2e 0a 2a 2a 20 54 68 65 20 66 69 6c 65 6e 61 6d  ..** The filenam
2200: 65 20 69 73 20 63 6f 6e 74 61 69 6e 65 64 20 69  e is contained i
2210: 6e 20 67 2e 61 72 67 76 5b 32 5d 2e 0a 2a 2f 0a  n g.argv[2]..*/.
2220: 73 74 61 74 69 63 20 76 6f 69 64 20 64 69 66 66  static void diff
2230: 5f 6f 6e 65 5f 74 77 6f 5f 76 65 72 73 69 6f 6e  _one_two_version
2240: 73 28 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20  s(.  const char 
2250: 2a 7a 46 72 6f 6d 2c 0a 20 20 63 6f 6e 73 74 20  *zFrom,.  const 
2260: 63 68 61 72 20 2a 7a 54 6f 2c 0a 20 20 63 6f 6e  char *zTo,.  con
2270: 73 74 20 63 68 61 72 20 2a 7a 44 69 66 66 43 6d  st char *zDiffCm
2280: 64 0a 29 7b 0a 20 20 63 68 61 72 20 2a 7a 4e 61  d.){.  char *zNa
2290: 6d 65 3b 0a 20 20 42 6c 6f 62 20 66 6e 61 6d 65  me;.  Blob fname
22a0: 3b 0a 20 20 42 6c 6f 62 20 76 31 2c 20 76 32 3b  ;.  Blob v1, v2;
22b0: 0a 20 20 66 69 6c 65 5f 74 72 65 65 5f 6e 61 6d  .  file_tree_nam
22c0: 65 28 67 2e 61 72 67 76 5b 32 5d 2c 20 26 66 6e  e(g.argv[2], &fn
22d0: 61 6d 65 2c 20 31 29 3b 0a 20 20 7a 4e 61 6d 65  ame, 1);.  zName
22e0: 20 3d 20 62 6c 6f 62 5f 73 74 72 28 26 66 6e 61   = blob_str(&fna
22f0: 6d 65 29 3b 0a 20 20 68 69 73 74 6f 72 69 63 61  me);.  historica
2300: 6c 5f 76 65 72 73 69 6f 6e 5f 6f 66 5f 66 69 6c  l_version_of_fil
2310: 65 28 7a 46 72 6f 6d 2c 20 7a 4e 61 6d 65 2c 20  e(zFrom, zName, 
2320: 26 76 31 29 3b 0a 20 20 68 69 73 74 6f 72 69 63  &v1);.  historic
2330: 61 6c 5f 76 65 72 73 69 6f 6e 5f 6f 66 5f 66 69  al_version_of_fi
2340: 6c 65 28 7a 54 6f 2c 20 7a 4e 61 6d 65 2c 20 26  le(zTo, zName, &
2350: 76 32 29 3b 0a 20 20 64 69 66 66 5f 66 69 6c 65  v2);.  diff_file
2360: 5f 6d 65 6d 28 26 76 31 2c 20 26 76 32 2c 20 7a  _mem(&v1, &v2, z
2370: 4e 61 6d 65 2c 20 7a 44 69 66 66 43 6d 64 29 3b  Name, zDiffCmd);
2380: 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 76  .  blob_reset(&v
2390: 31 29 3b 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74  1);.  blob_reset
23a0: 28 26 76 32 29 3b 0a 20 20 62 6c 6f 62 5f 72 65  (&v2);.  blob_re
23b0: 73 65 74 28 26 66 6e 61 6d 65 29 3b 0a 7d 0a 0a  set(&fname);.}..
23c0: 2f 2a 0a 2a 2a 20 4f 75 74 70 75 74 20 74 68 65  /*.** Output the
23d0: 20 64 69 66 66 65 72 65 6e 63 65 73 20 62 65 74   differences bet
23e0: 77 65 65 6e 20 74 77 6f 20 63 68 65 63 6b 2d 69  ween two check-i
23f0: 6e 73 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f  ns..*/.static vo
2400: 69 64 20 64 69 66 66 5f 61 6c 6c 5f 74 77 6f 5f  id diff_all_two_
2410: 76 65 72 73 69 6f 6e 73 28 0a 20 20 63 6f 6e 73  versions(.  cons
2420: 74 20 63 68 61 72 20 2a 7a 46 72 6f 6d 2c 0a 20  t char *zFrom,. 
2430: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 54 6f   const char *zTo
2440: 2c 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a  ,.  const char *
2450: 7a 44 69 66 66 43 6d 64 0a 29 7b 0a 7d 0a 0a 2f  zDiffCmd.){.}../
2460: 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 64 69  *.** COMMAND: di
2470: 66 66 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 67  ff.** COMMAND: g
2480: 64 69 66 66 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65  diff.**.** Usage
2490: 3a 20 25 66 6f 73 73 69 6c 20 64 69 66 66 7c 67  : %fossil diff|g
24a0: 64 69 66 66 20 3f 6f 70 74 69 6f 6e 73 3f 20 3f  diff ?options? ?
24b0: 46 49 4c 45 3f 0a 2a 2a 0a 2a 2a 20 53 68 6f 77  FILE?.**.** Show
24c0: 20 74 68 65 20 64 69 66 66 65 72 65 6e 63 65 20   the difference 
24d0: 62 65 74 77 65 65 6e 20 74 68 65 20 63 75 72 72  between the curr
24e0: 65 6e 74 20 76 65 72 73 69 6f 6e 20 6f 66 20 46  ent version of F
24f0: 49 4c 45 20 28 61 73 20 69 74 0a 2a 2a 20 65 78  ILE (as it.** ex
2500: 69 73 74 73 20 6f 6e 20 64 69 73 6b 29 20 61 6e  ists on disk) an
2510: 64 20 74 68 61 74 20 73 61 6d 65 20 66 69 6c 65  d that same file
2520: 20 61 73 20 69 74 20 77 61 73 20 63 68 65 63 6b   as it was check
2530: 65 64 20 6f 75 74 2e 20 20 4f 72 0a 2a 2a 20 69  ed out.  Or.** i
2540: 66 20 74 68 65 20 46 49 4c 45 20 61 72 67 75 6d  f the FILE argum
2550: 65 6e 74 20 69 73 20 6f 6d 69 74 74 65 64 2c 20  ent is omitted, 
2560: 73 68 6f 77 20 74 68 65 20 75 6e 73 61 76 65 64  show the unsaved
2570: 20 63 68 61 6e 67 65 64 20 63 75 72 72 65 6e 74   changed current
2580: 6c 79 0a 2a 2a 20 69 6e 20 74 68 65 20 77 6f 72  ly.** in the wor
2590: 6b 69 6e 67 20 63 68 65 63 6b 2d 6f 75 74 2e 0a  king check-out..
25a0: 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 22 2d 2d  **.** If the "--
25b0: 66 72 6f 6d 20 56 45 52 53 49 4f 4e 22 20 6f 72  from VERSION" or
25c0: 20 22 2d 72 20 56 45 52 53 49 4f 4e 22 20 6f 70   "-r VERSION" op
25d0: 74 69 6f 6e 20 69 73 20 75 73 65 64 20 69 74 20  tion is used it 
25e0: 73 70 65 63 69 66 69 65 73 0a 2a 2a 20 74 68 65  specifies.** the
25f0: 20 73 6f 75 72 63 65 20 63 68 65 63 6b 2d 69 6e   source check-in
2600: 20 66 6f 72 20 74 68 65 20 64 69 66 66 20 6f 70   for the diff op
2610: 65 72 61 74 69 6f 6e 2e 20 20 49 66 20 6e 6f 74  eration.  If not
2620: 20 73 70 65 63 69 66 69 65 64 2c 20 74 68 65 20   specified, the 
2630: 0a 2a 2a 20 73 6f 75 72 63 65 20 63 68 65 63 6b  .** source check
2640: 2d 69 6e 20 69 73 20 74 68 65 20 62 61 73 65 20  -in is the base 
2650: 63 68 65 63 6b 2d 69 6e 20 66 6f 72 20 74 68 65  check-in for the
2660: 20 63 75 72 72 65 6e 74 20 63 68 65 63 6b 2d 6f   current check-o
2670: 75 74 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65  ut..**.** If the
2680: 20 22 2d 2d 74 6f 20 56 45 52 53 49 4f 4e 22 20   "--to VERSION" 
2690: 6f 70 74 69 6f 6e 20 61 70 70 65 61 72 73 2c 20  option appears, 
26a0: 69 74 20 73 70 65 63 69 66 69 65 73 20 74 68 65  it specifies the
26b0: 20 63 68 65 63 6b 2d 69 6e 20 66 72 6f 6d 0a 2a   check-in from.*
26c0: 2a 20 77 68 69 63 68 20 74 68 65 20 73 65 63 6f  * which the seco
26d0: 6e 64 20 76 65 72 73 69 6f 6e 20 6f 66 20 74 68  nd version of th
26e0: 65 20 66 69 6c 65 20 6f 72 20 66 69 6c 65 73 20  e file or files 
26f0: 69 73 20 74 61 6b 65 6e 2e 20 20 49 66 20 74 68  is taken.  If th
2700: 65 72 65 20 69 73 0a 2a 2a 20 6e 6f 20 22 2d 2d  ere is.** no "--
2710: 74 6f 22 20 6f 70 74 69 6f 6e 20 74 68 65 6e 20  to" option then 
2720: 74 68 65 20 28 70 6f 73 73 69 62 6c 79 20 65 64  the (possibly ed
2730: 69 74 65 64 29 20 66 69 6c 65 73 20 69 6e 20 74  ited) files in t
2740: 68 65 20 63 75 72 72 65 6e 74 20 63 68 65 63 6b  he current check
2750: 2d 6f 75 74 0a 2a 2a 20 61 72 65 20 75 73 65 64  -out.** are used
2760: 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 22 2d 69 22  ..**.** The "-i"
2770: 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 20 6f 70   command-line op
2780: 74 69 6f 6e 20 66 6f 72 63 65 73 20 74 68 65 20  tion forces the 
2790: 75 73 65 20 6f 66 20 74 68 65 20 69 6e 74 65 72  use of the inter
27a0: 6e 61 6c 20 64 69 66 66 20 6c 6f 67 69 63 0a 2a  nal diff logic.*
27b0: 2a 20 72 61 74 68 65 72 20 74 68 61 6e 20 61 6e  * rather than an
27c0: 79 20 65 78 74 65 72 6e 61 6c 20 64 69 66 66 20  y external diff 
27d0: 70 72 6f 67 72 61 6d 20 74 68 61 74 20 6d 69 67  program that mig
27e0: 68 74 20 62 65 20 63 6f 6e 66 69 67 75 72 65 64  ht be configured
27f0: 20 75 73 69 6e 67 0a 2a 2a 20 74 68 65 20 22 73   using.** the "s
2800: 65 74 74 69 6e 67 22 20 63 6f 6d 6d 61 6e 64 2e  etting" command.
2810: 20 20 49 66 20 6e 6f 20 65 78 74 65 72 6e 61 6c    If no external
2820: 20 64 69 66 66 20 70 72 6f 67 72 61 6d 20 69 73   diff program is
2830: 20 63 6f 6e 66 69 67 75 72 65 64 2c 20 74 68 65   configured, the
2840: 6e 0a 2a 2a 20 74 68 65 20 22 2d 69 22 20 6f 70  n.** the "-i" op
2850: 74 69 6f 6e 20 69 73 20 61 20 6e 6f 2d 6f 70 2e  tion is a no-op.
2860: 20 20 54 68 65 20 22 2d 69 22 20 6f 70 74 69 6f    The "-i" optio
2870: 6e 20 63 6f 6e 76 65 72 74 73 20 22 67 64 69 66  n converts "gdif
2880: 66 22 20 69 6e 74 6f 20 22 64 69 66 66 22 2e 0a  f" into "diff"..
2890: 2a 2f 0a 76 6f 69 64 20 64 69 66 66 5f 63 6d 64  */.void diff_cmd
28a0: 28 76 6f 69 64 29 7b 0a 20 20 69 6e 74 20 69 73  (void){.  int is
28b0: 47 44 69 66 66 3b 20 20 20 20 20 20 20 20 20 20  GDiff;          
28c0: 20 20 20 20 20 2f 2a 20 54 72 75 65 20 66 6f 72       /* True for
28d0: 20 67 64 69 66 66 2e 20 20 46 61 6c 73 65 20 66   gdiff.  False f
28e0: 6f 72 20 6e 6f 72 6d 61 6c 20 64 69 66 66 20 2a  or normal diff *
28f0: 2f 0a 20 20 69 6e 74 20 69 73 49 6e 74 65 72 6e  /.  int isIntern
2900: 44 69 66 66 3b 20 20 20 20 20 20 20 20 20 20 2f  Diff;          /
2910: 2a 20 54 72 75 65 20 66 6f 72 20 69 6e 74 65 72  * True for inter
2920: 6e 61 6c 20 64 69 66 66 20 2a 2f 0a 20 20 63 6f  nal diff */.  co
2930: 6e 73 74 20 63 68 61 72 20 2a 7a 46 72 6f 6d 3b  nst char *zFrom;
2940: 20 20 20 20 20 20 20 20 20 2f 2a 20 53 6f 75 72           /* Sour
2950: 63 65 20 76 65 72 73 69 6f 6e 20 6e 75 6d 62 65  ce version numbe
2960: 72 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61  r */.  const cha
2970: 72 20 2a 7a 54 6f 3b 20 20 20 20 20 20 20 20 20  r *zTo;         
2980: 20 20 2f 2a 20 54 61 72 67 65 74 20 76 65 72 73    /* Target vers
2990: 69 6f 6e 20 6e 75 6d 62 65 72 20 2a 2f 0a 20 20  ion number */.  
29a0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 44 69 66  const char *zDif
29b0: 66 43 6d 64 20 3d 20 30 3b 20 20 2f 2a 20 45 78  fCmd = 0;  /* Ex
29c0: 74 65 72 6e 61 6c 20 64 69 66 66 20 63 6f 6d 6d  ternal diff comm
29d0: 61 6e 64 2e 20 4e 55 4c 4c 20 66 6f 72 20 69 6e  and. NULL for in
29e0: 74 65 72 6e 61 6c 20 64 69 66 66 20 2a 2f 0a 0a  ternal diff */..
29f0: 20 20 69 73 47 44 69 66 66 20 3d 20 67 2e 61 72    isGDiff = g.ar
2a00: 67 76 5b 31 5d 5b 30 5d 3d 3d 27 67 27 3b 0a 20  gv[1][0]=='g';. 
2a10: 20 69 73 49 6e 74 65 72 6e 44 69 66 66 20 3d 20   isInternDiff = 
2a20: 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 69 6e 74  find_option("int
2a30: 65 72 6e 61 6c 22 2c 22 69 22 2c 30 29 21 3d 30  ernal","i",0)!=0
2a40: 3b 0a 20 20 7a 46 72 6f 6d 20 3d 20 66 69 6e 64  ;.  zFrom = find
2a50: 5f 6f 70 74 69 6f 6e 28 22 66 72 6f 6d 22 2c 20  _option("from", 
2a60: 22 72 22 2c 20 31 29 3b 0a 20 20 7a 54 6f 20 3d  "r", 1);.  zTo =
2a70: 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 74 6f   find_option("to
2a80: 22 2c 20 30 2c 20 31 29 3b 0a 0a 20 20 69 66 28  ", 0, 1);..  if(
2a90: 20 7a 54 6f 3d 3d 30 20 29 7b 0a 20 20 20 20 64   zTo==0 ){.    d
2aa0: 62 5f 6d 75 73 74 5f 62 65 5f 77 69 74 68 69 6e  b_must_be_within
2ab0: 5f 74 72 65 65 28 29 3b 0a 20 20 20 20 76 65 72  _tree();.    ver
2ac0: 69 66 79 5f 61 6c 6c 5f 6f 70 74 69 6f 6e 73 28  ify_all_options(
2ad0: 29 3b 0a 20 20 20 20 69 66 28 20 21 69 73 49 6e  );.    if( !isIn
2ae0: 74 65 72 6e 44 69 66 66 20 26 26 20 67 2e 61 72  ternDiff && g.ar
2af0: 67 63 3d 3d 33 20 29 7b 0a 20 20 20 20 20 20 7a  gc==3 ){.      z
2b00: 44 69 66 66 43 6d 64 20 3d 20 64 62 5f 67 65 74  DiffCmd = db_get
2b10: 28 69 73 47 44 69 66 66 20 3f 20 22 67 64 69 66  (isGDiff ? "gdif
2b20: 66 2d 63 6f 6d 6d 61 6e 64 22 20 3a 20 22 64 69  f-command" : "di
2b30: 66 66 2d 63 6f 6d 6d 61 6e 64 22 2c 20 30 29 3b  ff-command", 0);
2b40: 0a 20 20 20 20 7d 0a 20 20 20 20 69 66 28 20 67  .    }.    if( g
2b50: 2e 61 72 67 63 3d 3d 33 20 29 7b 0a 20 20 20 20  .argc==3 ){.    
2b60: 20 20 64 69 66 66 5f 6f 6e 65 5f 61 67 61 69 6e    diff_one_again
2b70: 73 74 5f 64 69 73 6b 28 7a 46 72 6f 6d 2c 20 7a  st_disk(zFrom, z
2b80: 44 69 66 66 43 6d 64 29 3b 0a 20 20 20 20 7d 65  DiffCmd);.    }e
2b90: 6c 73 65 7b 0a 20 20 20 20 20 20 64 69 66 66 5f  lse{.      diff_
2ba0: 61 6c 6c 5f 61 67 61 69 6e 73 74 5f 64 69 73 6b  all_against_disk
2bb0: 28 7a 46 72 6f 6d 2c 20 7a 44 69 66 66 43 6d 64  (zFrom, zDiffCmd
2bc0: 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 65 6c 73 65  );.    }.  }else
2bd0: 20 69 66 28 20 7a 46 72 6f 6d 3d 3d 30 20 29 7b   if( zFrom==0 ){
2be0: 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61  .    fossil_fata
2bf0: 6c 28 22 6d 75 73 74 20 75 73 65 20 2d 2d 66 72  l("must use --fr
2c00: 6f 6d 20 69 66 20 2d 2d 74 6f 20 69 73 20 70 72  om if --to is pr
2c10: 65 73 65 6e 74 22 29 3b 0a 20 20 7d 65 6c 73 65  esent");.  }else
2c20: 7b 0a 20 20 20 20 64 62 5f 66 69 6e 64 5f 61 6e  {.    db_find_an
2c30: 64 5f 6f 70 65 6e 5f 72 65 70 6f 73 69 74 6f 72  d_open_repositor
2c40: 79 28 31 29 3b 0a 20 20 20 20 76 65 72 69 66 79  y(1);.    verify
2c50: 5f 61 6c 6c 5f 6f 70 74 69 6f 6e 73 28 29 3b 0a  _all_options();.
2c60: 20 20 20 20 69 66 28 20 21 69 73 49 6e 74 65 72      if( !isInter
2c70: 6e 44 69 66 66 20 26 26 20 67 2e 61 72 67 63 3d  nDiff && g.argc=
2c80: 3d 33 20 29 7b 0a 20 20 20 20 20 20 7a 44 69 66  =3 ){.      zDif
2c90: 66 43 6d 64 20 3d 20 64 62 5f 67 65 74 28 69 73  fCmd = db_get(is
2ca0: 47 44 69 66 66 20 3f 20 22 67 64 69 66 66 2d 63  GDiff ? "gdiff-c
2cb0: 6f 6d 6d 61 6e 64 22 20 3a 20 22 64 69 66 66 2d  ommand" : "diff-
2cc0: 63 6f 6d 6d 61 6e 64 22 2c 20 30 29 3b 0a 20 20  command", 0);.  
2cd0: 20 20 7d 0a 20 20 20 20 69 66 28 20 67 2e 61 72    }.    if( g.ar
2ce0: 67 63 3d 3d 33 20 29 7b 0a 20 20 20 20 20 20 64  gc==3 ){.      d
2cf0: 69 66 66 5f 6f 6e 65 5f 74 77 6f 5f 76 65 72 73  iff_one_two_vers
2d00: 69 6f 6e 73 28 7a 46 72 6f 6d 2c 20 7a 54 6f 2c  ions(zFrom, zTo,
2d10: 20 7a 44 69 66 66 43 6d 64 29 3b 0a 20 20 20 20   zDiffCmd);.    
2d20: 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 66 6f 73  }else{.      fos
2d30: 73 69 6c 5f 66 61 74 61 6c 28 22 2d 2d 74 6f 20  sil_fatal("--to 
2d40: 6f 6e 20 63 6f 6d 70 6c 65 74 65 20 63 68 65 63  on complete chec
2d50: 6b 2d 69 6e 73 20 6e 6f 74 20 79 65 74 20 69 6d  k-ins not yet im
2d60: 70 6c 65 6d 65 6e 74 65 64 22 29 3b 0a 20 20 20  plemented");.   
2d70: 20 20 20 64 69 66 66 5f 61 6c 6c 5f 74 77 6f 5f     diff_all_two_
2d80: 76 65 72 73 69 6f 6e 73 28 7a 46 72 6f 6d 2c 20  versions(zFrom, 
2d90: 7a 54 6f 2c 20 7a 44 69 66 66 43 6d 64 29 3b 0a  zTo, zDiffCmd);.
2da0: 20 20 20 20 7d 0a 20 20 7d 0a 7d 0a                  }.  }.}.