Hex Artifact Content
Not logged in

Artifact 5083153aeebaca0a66ee6e1dd67b66461cec2639:

File src/diffcmd.c part of check-in [149945beea] - Because the "vfile" signatures are now used by "diff", be sure to recompute them before running the diff. by drh on 2009-11-06 04:05:13.

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 44 6f 20    }.}../*.** Do 
0f90: 61 20 64 69 66 66 20 61 67 61 69 6e 73 74 20 61  a diff against a
0fa0: 20 73 69 6e 67 6c 65 20 66 69 6c 65 20 6e 61 6d   single file nam
0fb0: 65 64 20 69 6e 20 67 2e 61 72 67 76 5b 32 5d 20  ed in g.argv[2] 
0fc0: 66 72 6f 6d 20 76 65 72 73 69 6f 6e 20 7a 46 72  from version zFr
0fd0: 6f 6d 0a 2a 2a 20 61 67 61 69 6e 73 74 20 74 68  om.** against th
0fe0: 65 20 73 61 6d 65 20 66 69 6c 65 20 6f 6e 20 64  e same file on d
0ff0: 69 73 6b 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76  isk..*/.static v
1000: 6f 69 64 20 64 69 66 66 5f 6f 6e 65 5f 61 67 61  oid diff_one_aga
1010: 69 6e 73 74 5f 64 69 73 6b 28 63 6f 6e 73 74 20  inst_disk(const 
1020: 63 68 61 72 20 2a 7a 46 72 6f 6d 2c 20 63 6f 6e  char *zFrom, con
1030: 73 74 20 63 68 61 72 20 2a 7a 44 69 66 66 43 6d  st char *zDiffCm
1040: 64 29 7b 0a 20 20 42 6c 6f 62 20 66 6e 61 6d 65  d){.  Blob fname
1050: 3b 0a 20 20 42 6c 6f 62 20 63 6f 6e 74 65 6e 74  ;.  Blob content
1060: 3b 0a 20 20 66 69 6c 65 5f 74 72 65 65 5f 6e 61  ;.  file_tree_na
1070: 6d 65 28 67 2e 61 72 67 76 5b 32 5d 2c 20 26 66  me(g.argv[2], &f
1080: 6e 61 6d 65 2c 20 31 29 3b 0a 20 20 68 69 73 74  name, 1);.  hist
1090: 6f 72 69 63 61 6c 5f 76 65 72 73 69 6f 6e 5f 6f  orical_version_o
10a0: 66 5f 66 69 6c 65 28 7a 46 72 6f 6d 2c 20 62 6c  f_file(zFrom, bl
10b0: 6f 62 5f 73 74 72 28 26 66 6e 61 6d 65 29 2c 20  ob_str(&fname), 
10c0: 26 63 6f 6e 74 65 6e 74 29 3b 0a 20 20 64 69 66  &content);.  dif
10d0: 66 5f 66 69 6c 65 28 26 63 6f 6e 74 65 6e 74 2c  f_file(&content,
10e0: 20 67 2e 61 72 67 76 5b 32 5d 2c 20 67 2e 61 72   g.argv[2], g.ar
10f0: 67 76 5b 32 5d 2c 20 7a 44 69 66 66 43 6d 64 29  gv[2], zDiffCmd)
1100: 3b 0a 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26  ;.  blob_reset(&
1110: 63 6f 6e 74 65 6e 74 29 3b 0a 20 20 62 6c 6f 62  content);.  blob
1120: 5f 72 65 73 65 74 28 26 66 6e 61 6d 65 29 3b 0a  _reset(&fname);.
1130: 7d 0a 0a 2f 2a 0a 2a 2a 20 52 75 6e 20 61 20 64  }../*.** Run a d
1140: 69 66 66 20 62 65 74 77 65 65 6e 20 74 68 65 20  iff between the 
1150: 76 65 72 73 69 6f 6e 20 7a 46 72 6f 6d 20 61 6e  version zFrom an
1160: 64 20 66 69 6c 65 73 20 6f 6e 20 64 69 73 6b 2e  d files on disk.
1170: 20 20 7a 46 72 6f 6d 20 6d 69 67 68 74 0a 2a 2a    zFrom might.**
1180: 20 62 65 20 4e 55 4c 4c 20 77 68 69 63 68 20 6d   be NULL which m
1190: 65 61 6e 73 20 74 6f 20 73 69 6d 70 6c 79 20 73  eans to simply s
11a0: 68 6f 77 20 74 68 65 20 64 69 66 66 65 72 65 6e  how the differen
11b0: 63 65 20 62 65 74 77 65 65 6e 20 74 68 65 20 65  ce between the e
11c0: 64 69 74 65 64 0a 2a 2a 20 66 69 6c 65 73 20 6f  dited.** files o
11d0: 6e 20 64 69 73 6b 20 61 6e 64 20 74 68 65 20 63  n disk and the c
11e0: 68 65 63 6b 2d 6f 75 74 20 6f 6e 20 77 68 69 63  heck-out on whic
11f0: 68 20 74 68 65 79 20 61 72 65 20 62 61 73 65 64  h they are based
1200: 2e 0a 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64  ..*/.static void
1210: 20 64 69 66 66 5f 61 6c 6c 5f 61 67 61 69 6e 73   diff_all_agains
1220: 74 5f 64 69 73 6b 28 63 6f 6e 73 74 20 63 68 61  t_disk(const cha
1230: 72 20 2a 7a 46 72 6f 6d 2c 20 63 6f 6e 73 74 20  r *zFrom, const 
1240: 63 68 61 72 20 2a 7a 44 69 66 66 43 6d 64 29 7b  char *zDiffCmd){
1250: 0a 20 20 69 6e 74 20 76 69 64 3b 0a 20 20 42 6c  .  int vid;.  Bl
1260: 6f 62 20 73 71 6c 3b 0a 20 20 53 74 6d 74 20 71  ob sql;.  Stmt q
1270: 3b 0a 0a 20 20 76 69 64 20 3d 20 64 62 5f 6c 67  ;..  vid = db_lg
1280: 65 74 5f 69 6e 74 28 22 63 68 65 63 6b 6f 75 74  et_int("checkout
1290: 22 2c 20 30 29 3b 0a 20 20 76 66 69 6c 65 5f 63  ", 0);.  vfile_c
12a0: 68 65 63 6b 5f 73 69 67 6e 61 74 75 72 65 28 76  heck_signature(v
12b0: 69 64 29 3b 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f  id);.  blob_zero
12c0: 28 26 73 71 6c 29 3b 0a 20 20 64 62 5f 62 65 67  (&sql);.  db_beg
12d0: 69 6e 5f 74 72 61 6e 73 61 63 74 69 6f 6e 28 29  in_transaction()
12e0: 3b 0a 20 20 69 66 28 20 7a 46 72 6f 6d 20 29 7b  ;.  if( zFrom ){
12f0: 0a 20 20 20 20 69 6e 74 20 72 69 64 20 3d 20 6e  .    int rid = n
1300: 61 6d 65 5f 74 6f 5f 72 69 64 28 7a 46 72 6f 6d  ame_to_rid(zFrom
1310: 29 3b 0a 20 20 20 20 69 66 28 20 21 69 73 5f 61  );.    if( !is_a
1320: 5f 76 65 72 73 69 6f 6e 28 72 69 64 29 20 29 7b  _version(rid) ){
1330: 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 61  .      fossil_fa
1340: 74 61 6c 28 22 6e 6f 20 73 75 63 68 20 63 68 65  tal("no such che
1350: 63 6b 2d 69 6e 3a 20 25 73 22 2c 20 7a 46 72 6f  ck-in: %s", zFro
1360: 6d 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 6c 6f  m);.    }.    lo
1370: 61 64 5f 76 66 69 6c 65 5f 66 72 6f 6d 5f 72 69  ad_vfile_from_ri
1380: 64 28 72 69 64 29 3b 0a 20 20 20 20 62 6c 6f 62  d(rid);.    blob
1390: 5f 61 70 70 65 6e 64 66 28 26 73 71 6c 2c 0a 20  _appendf(&sql,. 
13a0: 20 20 20 20 20 22 53 45 4c 45 43 54 20 76 32 2e       "SELECT v2.
13b0: 70 61 74 68 6e 61 6d 65 2c 20 76 32 2e 64 65 6c  pathname, v2.del
13c0: 65 74 65 64 2c 20 76 32 2e 63 68 6e 67 65 64 2c  eted, v2.chnged,
13d0: 20 76 32 2e 72 69 64 3d 3d 30 2c 20 76 31 2e 72   v2.rid==0, v1.r
13e0: 69 64 22 0a 20 20 20 20 20 20 22 20 20 46 52 4f  id".      "  FRO
13f0: 4d 20 76 66 69 6c 65 20 76 31 2c 20 76 66 69 6c  M vfile v1, vfil
1400: 65 20 76 32 20 22 0a 20 20 20 20 20 20 22 20 57  e v2 ".      " W
1410: 48 45 52 45 20 76 31 2e 70 61 74 68 6e 61 6d 65  HERE v1.pathname
1420: 3d 76 32 2e 70 61 74 68 6e 61 6d 65 20 41 4e 44  =v2.pathname AND
1430: 20 76 31 2e 76 69 64 3d 25 64 20 41 4e 44 20 76   v1.vid=%d AND v
1440: 32 2e 76 69 64 3d 25 64 22 0a 20 20 20 20 20 20  2.vid=%d".      
1450: 22 20 20 20 41 4e 44 20 28 76 32 2e 64 65 6c 65  "   AND (v2.dele
1460: 74 65 64 20 4f 52 20 76 32 2e 63 68 6e 67 65 64  ted OR v2.chnged
1470: 20 4f 52 20 76 31 2e 72 69 64 21 3d 76 32 2e 72   OR v1.rid!=v2.r
1480: 69 64 29 22 0a 20 20 20 20 20 20 22 55 4e 49 4f  id)".      "UNIO
1490: 4e 20 22 0a 20 20 20 20 20 20 22 53 45 4c 45 43  N ".      "SELEC
14a0: 54 20 70 61 74 68 6e 61 6d 65 2c 20 31 2c 20 30  T pathname, 1, 0
14b0: 2c 20 30 2c 20 30 22 0a 20 20 20 20 20 20 22 20  , 0, 0".      " 
14c0: 20 46 52 4f 4d 20 76 66 69 6c 65 20 76 31 22 0a   FROM vfile v1".
14d0: 20 20 20 20 20 20 22 20 57 48 45 52 45 20 76 31        " WHERE v1
14e0: 2e 76 69 64 3d 25 64 22 0a 20 20 20 20 20 20 22  .vid=%d".      "
14f0: 20 20 20 41 4e 44 20 4e 4f 54 20 45 58 49 53 54     AND NOT EXIST
1500: 53 28 53 45 4c 45 43 54 20 31 20 46 52 4f 4d 20  S(SELECT 1 FROM 
1510: 76 66 69 6c 65 20 76 32 22 0a 20 20 20 20 20 20  vfile v2".      
1520: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1530: 20 20 22 20 57 48 45 52 45 20 76 32 2e 76 69 64    " WHERE v2.vid
1540: 3d 25 64 20 41 4e 44 20 76 32 2e 70 61 74 68 6e  =%d AND v2.pathn
1550: 61 6d 65 3d 76 31 2e 70 61 74 68 6e 61 6d 65 29  ame=v1.pathname)
1560: 22 0a 20 20 20 20 20 20 22 55 4e 49 4f 4e 20 22  ".      "UNION "
1570: 0a 20 20 20 20 20 20 22 53 45 4c 45 43 54 20 70  .      "SELECT p
1580: 61 74 68 6e 61 6d 65 2c 20 30 2c 20 30 2c 20 31  athname, 0, 0, 1
1590: 2c 20 30 22 0a 20 20 20 20 20 20 22 20 20 46 52  , 0".      "  FR
15a0: 4f 4d 20 76 66 69 6c 65 20 76 32 22 0a 20 20 20  OM vfile v2".   
15b0: 20 20 20 22 20 57 48 45 52 45 20 76 32 2e 76 69     " WHERE v2.vi
15c0: 64 3d 25 64 22 0a 20 20 20 20 20 20 22 20 20 20  d=%d".      "   
15d0: 41 4e 44 20 4e 4f 54 20 45 58 49 53 54 53 28 53  AND NOT EXISTS(S
15e0: 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 76 66 69  ELECT 1 FROM vfi
15f0: 6c 65 20 76 31 22 0a 20 20 20 20 20 20 20 20 20  le v1".         
1600: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22                 "
1610: 20 57 48 45 52 45 20 76 31 2e 76 69 64 3d 25 64   WHERE v1.vid=%d
1620: 20 41 4e 44 20 76 31 2e 70 61 74 68 6e 61 6d 65   AND v1.pathname
1630: 3d 76 32 2e 70 61 74 68 6e 61 6d 65 29 22 0a 20  =v2.pathname)". 
1640: 20 20 20 20 20 22 20 4f 52 44 45 52 20 42 59 20       " ORDER BY 
1650: 31 22 2c 0a 20 20 20 20 20 20 72 69 64 2c 20 76  1",.      rid, v
1660: 69 64 2c 20 72 69 64 2c 20 76 69 64 2c 20 76 69  id, rid, vid, vi
1670: 64 2c 20 72 69 64 0a 20 20 20 20 29 3b 0a 20 20  d, rid.    );.  
1680: 7d 65 6c 73 65 7b 0a 20 20 20 20 62 6c 6f 62 5f  }else{.    blob_
1690: 61 70 70 65 6e 64 66 28 26 73 71 6c 2c 0a 20 20  appendf(&sql,.  
16a0: 20 20 20 20 22 53 45 4c 45 43 54 20 70 61 74 68      "SELECT path
16b0: 6e 61 6d 65 2c 20 64 65 6c 65 74 65 64 2c 20 63  name, deleted, c
16c0: 68 6e 67 65 64 20 2c 20 72 69 64 3d 3d 30 2c 20  hnged , rid==0, 
16d0: 72 69 64 22 0a 20 20 20 20 20 20 22 20 20 46 52  rid".      "  FR
16e0: 4f 4d 20 76 66 69 6c 65 22 0a 20 20 20 20 20 20  OM vfile".      
16f0: 22 20 57 48 45 52 45 20 76 69 64 3d 25 64 22 0a  " WHERE vid=%d".
1700: 20 20 20 20 20 20 22 20 20 20 41 4e 44 20 28 64        "   AND (d
1710: 65 6c 65 74 65 64 20 4f 52 20 63 68 6e 67 65 64  eleted OR chnged
1720: 20 4f 52 20 72 69 64 3d 3d 30 29 22 0a 20 20 20   OR rid==0)".   
1730: 20 20 20 22 20 4f 52 44 45 52 20 42 59 20 70 61     " ORDER BY pa
1740: 74 68 6e 61 6d 65 22 2c 0a 20 20 20 20 20 20 76  thname",.      v
1750: 69 64 0a 20 20 20 20 29 3b 0a 20 20 7d 0a 20 20  id.    );.  }.  
1760: 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c 20 62  db_prepare(&q, b
1770: 6c 6f 62 5f 73 74 72 28 26 73 71 6c 29 29 3b 0a  lob_str(&sql));.
1780: 20 20 77 68 69 6c 65 28 20 64 62 5f 73 74 65 70    while( db_step
1790: 28 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57  (&q)==SQLITE_ROW
17a0: 20 29 7b 0a 20 20 20 20 63 6f 6e 73 74 20 63 68   ){.    const ch
17b0: 61 72 20 2a 7a 50 61 74 68 6e 61 6d 65 20 3d 20  ar *zPathname = 
17c0: 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26  db_column_text(&
17d0: 71 2c 30 29 3b 0a 20 20 20 20 69 6e 74 20 69 73  q,0);.    int is
17e0: 44 65 6c 65 74 65 64 20 3d 20 64 62 5f 63 6f 6c  Deleted = db_col
17f0: 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 31 29 3b 0a  umn_int(&q, 1);.
1800: 20 20 20 20 69 6e 74 20 69 73 43 68 6e 67 65 64      int isChnged
1810: 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74   = db_column_int
1820: 28 26 71 2c 32 29 3b 0a 20 20 20 20 69 6e 74 20  (&q,2);.    int 
1830: 69 73 4e 65 77 20 3d 20 64 62 5f 63 6f 6c 75 6d  isNew = db_colum
1840: 6e 5f 69 6e 74 28 26 71 2c 33 29 3b 0a 20 20 20  n_int(&q,3);.   
1850: 20 63 68 61 72 20 2a 7a 46 75 6c 6c 4e 61 6d 65   char *zFullName
1860: 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73 25 73   = mprintf("%s%s
1870: 22 2c 20 67 2e 7a 4c 6f 63 61 6c 52 6f 6f 74 2c  ", g.zLocalRoot,
1880: 20 7a 50 61 74 68 6e 61 6d 65 29 3b 0a 20 20 20   zPathname);.   
1890: 20 69 66 28 20 69 73 44 65 6c 65 74 65 64 20 29   if( isDeleted )
18a0: 7b 0a 20 20 20 20 20 20 70 72 69 6e 74 66 28 22  {.      printf("
18b0: 44 45 4c 45 54 45 44 20 20 25 73 5c 6e 22 2c 20  DELETED  %s\n", 
18c0: 7a 50 61 74 68 6e 61 6d 65 29 3b 0a 20 20 20 20  zPathname);.    
18d0: 7d 65 6c 73 65 20 69 66 28 20 61 63 63 65 73 73  }else if( access
18e0: 28 7a 46 75 6c 6c 4e 61 6d 65 2c 20 30 29 20 29  (zFullName, 0) )
18f0: 7b 0a 20 20 20 20 20 20 70 72 69 6e 74 66 28 22  {.      printf("
1900: 4d 49 53 53 49 4e 47 20 20 25 73 5c 6e 22 2c 20  MISSING  %s\n", 
1910: 7a 50 61 74 68 6e 61 6d 65 29 3b 0a 20 20 20 20  zPathname);.    
1920: 7d 65 6c 73 65 20 69 66 28 20 69 73 4e 65 77 20  }else if( isNew 
1930: 29 7b 0a 20 20 20 20 20 20 70 72 69 6e 74 66 28  ){.      printf(
1940: 22 41 44 44 45 44 20 20 20 20 25 73 5c 6e 22 2c  "ADDED    %s\n",
1950: 20 7a 50 61 74 68 6e 61 6d 65 29 3b 0a 20 20 20   zPathname);.   
1960: 20 7d 65 6c 73 65 20 69 66 28 20 69 73 44 65 6c   }else if( isDel
1970: 65 74 65 64 20 29 7b 0a 20 20 20 20 20 20 70 72  eted ){.      pr
1980: 69 6e 74 66 28 22 44 45 4c 45 54 45 44 20 20 25  intf("DELETED  %
1990: 73 5c 6e 22 2c 20 7a 50 61 74 68 6e 61 6d 65 29  s\n", zPathname)
19a0: 3b 0a 20 20 20 20 7d 65 6c 73 65 20 69 66 28 20  ;.    }else if( 
19b0: 69 73 43 68 6e 67 65 64 3d 3d 33 20 29 7b 0a 20  isChnged==3 ){. 
19c0: 20 20 20 20 20 70 72 69 6e 74 66 28 22 41 44 44       printf("ADD
19d0: 45 44 5f 42 59 5f 4d 45 52 47 45 20 25 73 5c 6e  ED_BY_MERGE %s\n
19e0: 22 2c 20 7a 50 61 74 68 6e 61 6d 65 29 3b 0a 20  ", zPathname);. 
19f0: 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20     }else{.      
1a00: 69 6e 74 20 73 72 63 69 64 20 3d 20 64 62 5f 63  int srcid = db_c
1a10: 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 34 29  olumn_int(&q, 4)
1a20: 3b 0a 20 20 20 20 20 20 42 6c 6f 62 20 63 6f 6e  ;.      Blob con
1a30: 74 65 6e 74 3b 0a 20 20 20 20 20 20 63 6f 6e 74  tent;.      cont
1a40: 65 6e 74 5f 67 65 74 28 73 72 63 69 64 2c 20 26  ent_get(srcid, &
1a50: 63 6f 6e 74 65 6e 74 29 3b 0a 20 20 20 20 20 20  content);.      
1a60: 70 72 69 6e 74 66 28 22 49 6e 64 65 78 3a 20 25  printf("Index: %
1a70: 73 5c 6e 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  s\n=============
1a80: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
1a90: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 22 0a 20 20 20 20  ==========".    
1aa0: 20 20 20 20 20 20 20 20 20 22 3d 3d 3d 3d 3d 3d           "======
1ab0: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
1ac0: 3d 3d 3d 3d 3d 3d 5c 6e 22 2c 0a 20 20 20 20 20  ======\n",.     
1ad0: 20 20 20 20 20 20 20 20 7a 50 61 74 68 6e 61 6d          zPathnam
1ae0: 65 0a 20 20 20 20 20 20 29 3b 0a 20 20 20 20 20  e.      );.     
1af0: 20 64 69 66 66 5f 66 69 6c 65 28 26 63 6f 6e 74   diff_file(&cont
1b00: 65 6e 74 2c 20 7a 46 75 6c 6c 4e 61 6d 65 2c 20  ent, zFullName, 
1b10: 7a 50 61 74 68 6e 61 6d 65 2c 20 7a 44 69 66 66  zPathname, zDiff
1b20: 43 6d 64 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62  Cmd);.      blob
1b30: 5f 72 65 73 65 74 28 26 63 6f 6e 74 65 6e 74 29  _reset(&content)
1b40: 3b 0a 20 20 20 20 7d 0a 20 20 20 20 66 72 65 65  ;.    }.    free
1b50: 28 7a 46 75 6c 6c 4e 61 6d 65 29 3b 0a 20 20 7d  (zFullName);.  }
1b60: 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26  .  db_finalize(&
1b70: 71 29 3b 0a 20 20 64 62 5f 65 6e 64 5f 74 72 61  q);.  db_end_tra
1b80: 6e 73 61 63 74 69 6f 6e 28 31 29 3b 0a 7d 0a 0a  nsaction(1);.}..
1b90: 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a  ../*.** COMMAND:
1ba0: 20 64 69 66 66 0a 2a 2a 20 43 4f 4d 4d 41 4e 44   diff.** COMMAND
1bb0: 3a 20 67 64 69 66 66 0a 2a 2a 0a 2a 2a 20 55 73  : gdiff.**.** Us
1bc0: 61 67 65 3a 20 25 66 6f 73 73 69 6c 20 64 69 66  age: %fossil dif
1bd0: 66 7c 67 64 69 66 66 20 3f 6f 70 74 69 6f 6e 73  f|gdiff ?options
1be0: 3f 20 3f 46 49 4c 45 3f 0a 2a 2a 0a 2a 2a 20 53  ? ?FILE?.**.** S
1bf0: 68 6f 77 20 74 68 65 20 64 69 66 66 65 72 65 6e  how the differen
1c00: 63 65 20 62 65 74 77 65 65 6e 20 74 68 65 20 63  ce between the c
1c10: 75 72 72 65 6e 74 20 76 65 72 73 69 6f 6e 20 6f  urrent version o
1c20: 66 20 46 49 4c 45 20 28 61 73 20 69 74 0a 2a 2a  f FILE (as it.**
1c30: 20 65 78 69 73 74 73 20 6f 6e 20 64 69 73 6b 29   exists on disk)
1c40: 20 61 6e 64 20 74 68 61 74 20 73 61 6d 65 20 66   and that same f
1c50: 69 6c 65 20 61 73 20 69 74 20 77 61 73 20 63 68  ile as it was ch
1c60: 65 63 6b 65 64 20 6f 75 74 2e 20 20 4f 72 0a 2a  ecked out.  Or.*
1c70: 2a 20 69 66 20 74 68 65 20 46 49 4c 45 20 61 72  * if the FILE ar
1c80: 67 75 6d 65 6e 74 20 69 73 20 6f 6d 69 74 74 65  gument is omitte
1c90: 64 2c 20 73 68 6f 77 20 74 68 65 20 75 6e 73 61  d, show the unsa
1ca0: 76 65 64 20 63 68 61 6e 67 65 64 20 63 75 72 72  ved changed curr
1cb0: 65 6e 74 6c 79 0a 2a 2a 20 69 6e 20 74 68 65 20  ently.** in the 
1cc0: 77 6f 72 6b 69 6e 67 20 63 68 65 63 6b 2d 6f 75  working check-ou
1cd0: 74 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20  t..**.** If the 
1ce0: 22 2d 2d 66 72 6f 6d 20 56 45 52 53 49 4f 4e 22  "--from VERSION"
1cf0: 20 6f 72 20 22 2d 72 20 56 45 52 53 49 4f 4e 22   or "-r VERSION"
1d00: 20 6f 70 74 69 6f 6e 20 69 73 20 75 73 65 64 20   option is used 
1d10: 69 74 20 73 70 65 63 69 66 69 65 73 0a 2a 2a 20  it specifies.** 
1d20: 74 68 65 20 73 6f 75 72 63 65 20 63 68 65 63 6b  the source check
1d30: 2d 69 6e 20 66 6f 72 20 74 68 65 20 64 69 66 66  -in for the diff
1d40: 20 6f 70 65 72 61 74 69 6f 6e 2e 20 20 49 66 20   operation.  If 
1d50: 6e 6f 74 20 73 70 65 63 69 66 69 65 64 2c 20 74  not specified, t
1d60: 68 65 20 0a 2a 2a 20 73 6f 75 72 63 65 20 63 68  he .** source ch
1d70: 65 63 6b 2d 69 6e 20 69 73 20 74 68 65 20 62 61  eck-in is the ba
1d80: 73 65 20 63 68 65 63 6b 2d 69 6e 20 66 6f 72 20  se check-in for 
1d90: 74 68 65 20 63 75 72 72 65 6e 74 20 63 68 65 63  the current chec
1da0: 6b 2d 6f 75 74 2e 0a 2a 2a 0a 2a 2a 20 49 66 20  k-out..**.** If 
1db0: 74 68 65 20 22 2d 2d 74 6f 20 56 45 52 53 49 4f  the "--to VERSIO
1dc0: 4e 22 20 6f 70 74 69 6f 6e 20 61 70 70 65 61 72  N" option appear
1dd0: 73 2c 20 69 74 20 73 70 65 63 69 66 69 65 73 20  s, it specifies 
1de0: 74 68 65 20 63 68 65 63 6b 2d 69 6e 20 66 72 6f  the check-in fro
1df0: 6d 0a 2a 2a 20 77 68 69 63 68 20 74 68 65 20 73  m.** which the s
1e00: 65 63 6f 6e 64 20 76 65 72 73 69 6f 6e 20 6f 66  econd version of
1e10: 20 74 68 65 20 66 69 6c 65 20 6f 72 20 66 69 6c   the file or fil
1e20: 65 73 20 69 73 20 74 61 6b 65 6e 2e 20 20 49 66  es is taken.  If
1e30: 20 74 68 65 72 65 20 69 73 0a 2a 2a 20 6e 6f 20   there is.** no 
1e40: 22 2d 2d 74 6f 22 20 6f 70 74 69 6f 6e 20 74 68  "--to" option th
1e50: 65 6e 20 74 68 65 20 28 70 6f 73 73 69 62 6c 79  en the (possibly
1e60: 20 65 64 69 74 65 64 29 20 66 69 6c 65 73 20 69   edited) files i
1e70: 6e 20 74 68 65 20 63 75 72 72 65 6e 74 20 63 68  n the current ch
1e80: 65 63 6b 2d 6f 75 74 0a 2a 2a 20 61 72 65 20 75  eck-out.** are u
1e90: 73 65 64 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 22  sed..**.** The "
1ea0: 2d 69 22 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65  -i" command-line
1eb0: 20 6f 70 74 69 6f 6e 20 66 6f 72 63 65 73 20 74   option forces t
1ec0: 68 65 20 75 73 65 20 6f 66 20 74 68 65 20 69 6e  he use of the in
1ed0: 74 65 72 6e 61 6c 20 64 69 66 66 20 6c 6f 67 69  ternal diff logi
1ee0: 63 0a 2a 2a 20 72 61 74 68 65 72 20 74 68 61 6e  c.** rather than
1ef0: 20 61 6e 79 20 65 78 74 65 72 6e 61 6c 20 64 69   any external di
1f00: 66 66 20 70 72 6f 67 72 61 6d 20 74 68 61 74 20  ff program that 
1f10: 6d 69 67 68 74 20 62 65 20 63 6f 6e 66 69 67 75  might be configu
1f20: 72 65 64 20 75 73 69 6e 67 0a 2a 2a 20 74 68 65  red using.** the
1f30: 20 22 73 65 74 74 69 6e 67 22 20 63 6f 6d 6d 61   "setting" comma
1f40: 6e 64 2e 20 20 49 66 20 6e 6f 20 65 78 74 65 72  nd.  If no exter
1f50: 6e 61 6c 20 64 69 66 66 20 70 72 6f 67 72 61 6d  nal diff program
1f60: 20 69 73 20 63 6f 6e 66 69 67 75 72 65 64 2c 20   is configured, 
1f70: 74 68 65 6e 0a 2a 2a 20 74 68 65 20 22 2d 69 22  then.** the "-i"
1f80: 20 6f 70 74 69 6f 6e 20 69 73 20 61 20 6e 6f 2d   option is a no-
1f90: 6f 70 2e 20 20 54 68 65 20 22 2d 69 22 20 6f 70  op.  The "-i" op
1fa0: 74 69 6f 6e 20 63 6f 6e 76 65 72 74 73 20 22 67  tion converts "g
1fb0: 64 69 66 66 22 20 69 6e 74 6f 20 22 64 69 66 66  diff" into "diff
1fc0: 22 2e 0a 2a 2f 0a 76 6f 69 64 20 64 69 66 66 5f  "..*/.void diff_
1fd0: 63 6d 64 28 76 6f 69 64 29 7b 0a 20 20 69 6e 74  cmd(void){.  int
1fe0: 20 69 73 47 44 69 66 66 3b 20 20 20 20 20 20 20   isGDiff;       
1ff0: 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20          /* True 
2000: 66 6f 72 20 67 64 69 66 66 2e 20 20 46 61 6c 73  for gdiff.  Fals
2010: 65 20 66 6f 72 20 6e 6f 72 6d 61 6c 20 64 69 66  e for normal dif
2020: 66 20 2a 2f 0a 20 20 69 6e 74 20 69 73 49 6e 74  f */.  int isInt
2030: 65 72 6e 44 69 66 66 3b 20 20 20 20 20 20 20 20  ernDiff;        
2040: 20 20 2f 2a 20 54 72 75 65 20 66 6f 72 20 69 6e    /* True for in
2050: 74 65 72 6e 61 6c 20 64 69 66 66 20 2a 2f 0a 20  ternal diff */. 
2060: 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 46 72   const char *zFr
2070: 6f 6d 3b 20 20 20 20 20 20 20 20 20 2f 2a 20 53  om;         /* S
2080: 6f 75 72 63 65 20 76 65 72 73 69 6f 6e 20 6e 75  ource version nu
2090: 6d 62 65 72 20 2a 2f 0a 20 20 63 6f 6e 73 74 20  mber */.  const 
20a0: 63 68 61 72 20 2a 7a 54 6f 3b 20 20 20 20 20 20  char *zTo;      
20b0: 20 20 20 20 20 2f 2a 20 54 61 72 67 65 74 20 76       /* Target v
20c0: 65 72 73 69 6f 6e 20 6e 75 6d 62 65 72 20 2a 2f  ersion number */
20d0: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  .  const char *z
20e0: 44 69 66 66 43 6d 64 20 3d 20 30 3b 20 20 2f 2a  DiffCmd = 0;  /*
20f0: 20 45 78 74 65 72 6e 61 6c 20 64 69 66 66 20 63   External diff c
2100: 6f 6d 6d 61 6e 64 2e 20 4e 55 4c 4c 20 66 6f 72  ommand. NULL for
2110: 20 69 6e 74 65 72 6e 61 6c 20 64 69 66 66 20 2a   internal diff *
2120: 2f 0a 0a 20 20 69 73 47 44 69 66 66 20 3d 20 67  /..  isGDiff = g
2130: 2e 61 72 67 76 5b 31 5d 5b 30 5d 3d 3d 27 67 27  .argv[1][0]=='g'
2140: 3b 0a 20 20 69 73 49 6e 74 65 72 6e 44 69 66 66  ;.  isInternDiff
2150: 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22   = find_option("
2160: 69 6e 74 65 72 6e 61 6c 22 2c 22 69 22 2c 30 29  internal","i",0)
2170: 21 3d 30 3b 0a 20 20 7a 46 72 6f 6d 20 3d 20 66  !=0;.  zFrom = f
2180: 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 66 72 6f 6d  ind_option("from
2190: 22 2c 20 22 72 22 2c 20 31 29 3b 0a 20 20 7a 54  ", "r", 1);.  zT
21a0: 6f 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28  o = find_option(
21b0: 22 74 6f 22 2c 20 30 2c 20 31 29 3b 0a 0a 20 20  "to", 0, 1);..  
21c0: 69 66 28 20 7a 54 6f 3d 3d 30 20 29 7b 0a 20 20  if( zTo==0 ){.  
21d0: 20 20 64 62 5f 6d 75 73 74 5f 62 65 5f 77 69 74    db_must_be_wit
21e0: 68 69 6e 5f 74 72 65 65 28 29 3b 0a 20 20 20 20  hin_tree();.    
21f0: 76 65 72 69 66 79 5f 61 6c 6c 5f 6f 70 74 69 6f  verify_all_optio
2200: 6e 73 28 29 3b 0a 20 20 20 20 69 66 28 20 21 69  ns();.    if( !i
2210: 73 49 6e 74 65 72 6e 44 69 66 66 20 26 26 20 67  sInternDiff && g
2220: 2e 61 72 67 63 3d 3d 33 20 29 7b 0a 20 20 20 20  .argc==3 ){.    
2230: 20 20 7a 44 69 66 66 43 6d 64 20 3d 20 64 62 5f    zDiffCmd = db_
2240: 67 65 74 28 69 73 47 44 69 66 66 20 3f 20 22 67  get(isGDiff ? "g
2250: 64 69 66 66 2d 63 6f 6d 6d 61 6e 64 22 20 3a 20  diff-command" : 
2260: 22 64 69 66 66 2d 63 6f 6d 6d 61 6e 64 22 2c 20  "diff-command", 
2270: 30 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 69 66  0);.    }.    if
2280: 28 20 67 2e 61 72 67 63 3d 3d 33 20 29 7b 0a 20  ( g.argc==3 ){. 
2290: 20 20 20 20 20 64 69 66 66 5f 6f 6e 65 5f 61 67       diff_one_ag
22a0: 61 69 6e 73 74 5f 64 69 73 6b 28 7a 46 72 6f 6d  ainst_disk(zFrom
22b0: 2c 20 7a 44 69 66 66 43 6d 64 29 3b 0a 20 20 20  , zDiffCmd);.   
22c0: 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 64 69   }else{.      di
22d0: 66 66 5f 61 6c 6c 5f 61 67 61 69 6e 73 74 5f 64  ff_all_against_d
22e0: 69 73 6b 28 7a 46 72 6f 6d 2c 20 7a 44 69 66 66  isk(zFrom, zDiff
22f0: 43 6d 64 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 65  Cmd);.    }.  }e
2300: 6c 73 65 20 69 66 28 20 7a 46 72 6f 6d 3d 3d 30  lse if( zFrom==0
2310: 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66   ){.    fossil_f
2320: 61 74 61 6c 28 22 6d 75 73 74 20 75 73 65 20 2d  atal("must use -
2330: 2d 66 72 6f 6d 20 69 66 20 2d 2d 74 6f 20 69 73  -from if --to is
2340: 20 70 72 65 73 65 6e 74 22 29 3b 0a 20 20 7d 65   present");.  }e
2350: 6c 73 65 7b 0a 20 20 20 20 64 62 5f 66 69 6e 64  lse{.    db_find
2360: 5f 61 6e 64 5f 6f 70 65 6e 5f 72 65 70 6f 73 69  _and_open_reposi
2370: 74 6f 72 79 28 31 29 3b 0a 20 20 20 20 76 65 72  tory(1);.    ver
2380: 69 66 79 5f 61 6c 6c 5f 6f 70 74 69 6f 6e 73 28  ify_all_options(
2390: 29 3b 0a 20 20 20 20 69 66 28 20 21 69 73 49 6e  );.    if( !isIn
23a0: 74 65 72 6e 44 69 66 66 20 26 26 20 67 2e 61 72  ternDiff && g.ar
23b0: 67 63 3d 3d 33 20 29 7b 0a 20 20 20 20 20 20 7a  gc==3 ){.      z
23c0: 44 69 66 66 43 6d 64 20 3d 20 64 62 5f 67 65 74  DiffCmd = db_get
23d0: 28 69 73 47 44 69 66 66 20 3f 20 22 67 64 69 66  (isGDiff ? "gdif
23e0: 66 2d 63 6f 6d 6d 61 6e 64 22 20 3a 20 22 64 69  f-command" : "di
23f0: 66 66 2d 63 6f 6d 6d 61 6e 64 22 2c 20 30 29 3b  ff-command", 0);
2400: 0a 20 20 20 20 7d 0a 20 20 20 20 66 6f 73 73 69  .    }.    fossi
2410: 6c 5f 66 61 74 61 6c 28 22 2d 2d 74 6f 20 6e 6f  l_fatal("--to no
2420: 74 20 79 65 74 20 69 6d 70 6c 65 6d 65 6e 74 65  t yet implemente
2430: 64 22 29 3b 0a 23 69 66 20 30 0a 20 20 20 20 69  d");.#if 0.    i
2440: 66 28 20 67 2e 61 72 67 63 3d 3d 33 20 29 7b 0a  f( g.argc==3 ){.
2450: 20 20 20 20 20 20 64 69 66 66 5f 6f 6e 65 5f 74        diff_one_t
2460: 77 6f 5f 76 65 72 73 69 6f 6e 73 28 7a 46 72 6f  wo_versions(zFro
2470: 6d 2c 20 7a 54 6f 2c 20 7a 44 69 66 66 43 6d 64  m, zTo, zDiffCmd
2480: 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20  );.    }else{.  
2490: 20 20 20 20 64 69 66 66 5f 61 6c 6c 5f 74 77 6f      diff_all_two
24a0: 5f 76 65 72 73 69 6f 6e 73 28 7a 46 72 6f 6d 2c  _versions(zFrom,
24b0: 20 7a 54 6f 2c 20 7a 44 69 66 66 43 6d 64 29 3b   zTo, zDiffCmd);
24c0: 0a 20 20 20 20 7d 0a 23 65 6e 64 69 66 0a 20 20  .    }.#endif.  
24d0: 7d 0a 7d 0a                                      }.}.