Hex Artifact Content
Not logged in

Artifact 4a3e578a599a8b5819bd7c90cec5c01633e7f6b0:

File src/diffcmd.c part of check-in [db608ee72f] - Continuing work on the "diff" command. by drh on 2009-11-06 02:47:30.

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 62 6c 6f 62 5f 7a 65  ", 0);.  blob_ze
12a0: 72 6f 28 26 73 71 6c 29 3b 0a 20 20 64 62 5f 62  ro(&sql);.  db_b
12b0: 65 67 69 6e 5f 74 72 61 6e 73 61 63 74 69 6f 6e  egin_transaction
12c0: 28 29 3b 0a 20 20 69 66 28 20 7a 46 72 6f 6d 20  ();.  if( zFrom 
12d0: 29 7b 0a 20 20 20 20 69 6e 74 20 72 69 64 20 3d  ){.    int rid =
12e0: 20 6e 61 6d 65 5f 74 6f 5f 72 69 64 28 7a 46 72   name_to_rid(zFr
12f0: 6f 6d 29 3b 0a 20 20 20 20 69 66 28 20 21 69 73  om);.    if( !is
1300: 5f 61 5f 76 65 72 73 69 6f 6e 28 72 69 64 29 20  _a_version(rid) 
1310: 29 7b 0a 20 20 20 20 20 20 66 6f 73 73 69 6c 5f  ){.      fossil_
1320: 66 61 74 61 6c 28 22 6e 6f 20 73 75 63 68 20 63  fatal("no such c
1330: 68 65 63 6b 2d 69 6e 3a 20 25 73 22 2c 20 7a 46  heck-in: %s", zF
1340: 72 6f 6d 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20  rom);.    }.    
1350: 6c 6f 61 64 5f 76 66 69 6c 65 5f 66 72 6f 6d 5f  load_vfile_from_
1360: 72 69 64 28 72 69 64 29 3b 0a 20 20 20 20 62 6c  rid(rid);.    bl
1370: 6f 62 5f 61 70 70 65 6e 64 66 28 26 73 71 6c 2c  ob_appendf(&sql,
1380: 0a 20 20 20 20 20 20 22 53 45 4c 45 43 54 20 76  .      "SELECT v
1390: 32 2e 70 61 74 68 6e 61 6d 65 2c 20 76 32 2e 64  2.pathname, v2.d
13a0: 65 6c 65 74 65 64 2c 20 76 32 2e 63 68 6e 67 65  eleted, v2.chnge
13b0: 64 2c 20 76 32 2e 72 69 64 3d 3d 30 2c 20 76 31  d, v2.rid==0, v1
13c0: 2e 72 69 64 22 0a 20 20 20 20 20 20 22 20 20 46  .rid".      "  F
13d0: 52 4f 4d 20 76 66 69 6c 65 20 76 31 2c 20 76 66  ROM vfile v1, vf
13e0: 69 6c 65 20 76 32 20 22 0a 20 20 20 20 20 20 22  ile v2 ".      "
13f0: 20 57 48 45 52 45 20 76 31 2e 70 61 74 68 6e 61   WHERE v1.pathna
1400: 6d 65 3d 76 32 2e 70 61 74 68 6e 61 6d 65 20 41  me=v2.pathname A
1410: 4e 44 20 76 31 2e 76 69 64 3d 25 64 20 41 4e 44  ND v1.vid=%d AND
1420: 20 76 32 2e 76 69 64 3d 25 64 22 0a 20 20 20 20   v2.vid=%d".    
1430: 20 20 22 20 20 20 41 4e 44 20 28 76 32 2e 64 65    "   AND (v2.de
1440: 6c 65 74 65 64 20 4f 52 20 76 32 2e 63 68 6e 67  leted OR v2.chng
1450: 65 64 20 4f 52 20 76 31 2e 72 69 64 21 3d 76 32  ed OR v1.rid!=v2
1460: 2e 72 69 64 29 22 0a 20 20 20 20 20 20 22 55 4e  .rid)".      "UN
1470: 49 4f 4e 20 22 0a 20 20 20 20 20 20 22 53 45 4c  ION ".      "SEL
1480: 45 43 54 20 70 61 74 68 6e 61 6d 65 2c 20 31 2c  ECT pathname, 1,
1490: 20 30 2c 20 30 2c 20 30 22 0a 20 20 20 20 20 20   0, 0, 0".      
14a0: 22 20 20 46 52 4f 4d 20 76 66 69 6c 65 20 76 31  "  FROM vfile v1
14b0: 22 0a 20 20 20 20 20 20 22 20 57 48 45 52 45 20  ".      " WHERE 
14c0: 76 31 2e 76 69 64 3d 25 64 22 0a 20 20 20 20 20  v1.vid=%d".     
14d0: 20 22 20 20 20 41 4e 44 20 4e 4f 54 20 45 58 49   "   AND NOT EXI
14e0: 53 54 53 28 53 45 4c 45 43 54 20 31 20 46 52 4f  STS(SELECT 1 FRO
14f0: 4d 20 76 66 69 6c 65 20 76 32 22 0a 20 20 20 20  M vfile v2".    
1500: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
1510: 20 20 20 20 22 20 57 48 45 52 45 20 76 32 2e 76      " WHERE v2.v
1520: 69 64 3d 25 64 20 41 4e 44 20 76 32 2e 70 61 74  id=%d AND v2.pat
1530: 68 6e 61 6d 65 3d 76 31 2e 70 61 74 68 6e 61 6d  hname=v1.pathnam
1540: 65 29 22 0a 20 20 20 20 20 20 22 55 4e 49 4f 4e  e)".      "UNION
1550: 20 22 0a 20 20 20 20 20 20 22 53 45 4c 45 43 54   ".      "SELECT
1560: 20 70 61 74 68 6e 61 6d 65 2c 20 30 2c 20 30 2c   pathname, 0, 0,
1570: 20 31 2c 20 30 22 0a 20 20 20 20 20 20 22 20 20   1, 0".      "  
1580: 46 52 4f 4d 20 76 66 69 6c 65 20 76 32 22 0a 20  FROM vfile v2". 
1590: 20 20 20 20 20 22 20 57 48 45 52 45 20 76 32 2e       " WHERE v2.
15a0: 76 69 64 3d 25 64 22 0a 20 20 20 20 20 20 22 20  vid=%d".      " 
15b0: 20 20 41 4e 44 20 4e 4f 54 20 45 58 49 53 54 53    AND NOT EXISTS
15c0: 28 53 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 76  (SELECT 1 FROM v
15d0: 66 69 6c 65 20 76 31 22 0a 20 20 20 20 20 20 20  file v1".       
15e0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20                  
15f0: 20 22 20 57 48 45 52 45 20 76 31 2e 76 69 64 3d   " WHERE v1.vid=
1600: 25 64 20 41 4e 44 20 76 31 2e 70 61 74 68 6e 61  %d AND v1.pathna
1610: 6d 65 3d 76 32 2e 70 61 74 68 6e 61 6d 65 29 22  me=v2.pathname)"
1620: 0a 20 20 20 20 20 20 22 20 4f 52 44 45 52 20 42  .      " ORDER B
1630: 59 20 31 22 2c 0a 20 20 20 20 20 20 72 69 64 2c  Y 1",.      rid,
1640: 20 76 69 64 2c 20 72 69 64 2c 20 76 69 64 2c 20   vid, rid, vid, 
1650: 76 69 64 2c 20 72 69 64 0a 20 20 20 20 29 3b 0a  vid, rid.    );.
1660: 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 62 6c 6f    }else{.    blo
1670: 62 5f 61 70 70 65 6e 64 66 28 26 73 71 6c 2c 0a  b_appendf(&sql,.
1680: 20 20 20 20 20 20 22 53 45 4c 45 43 54 20 70 61        "SELECT pa
1690: 74 68 6e 61 6d 65 2c 20 64 65 6c 65 74 65 64 2c  thname, deleted,
16a0: 20 63 68 6e 67 65 64 20 2c 20 72 69 64 3d 3d 30   chnged , rid==0
16b0: 2c 20 72 69 64 22 0a 20 20 20 20 20 20 22 20 20  , rid".      "  
16c0: 46 52 4f 4d 20 76 66 69 6c 65 22 0a 20 20 20 20  FROM vfile".    
16d0: 20 20 22 20 57 48 45 52 45 20 76 69 64 3d 25 64    " WHERE vid=%d
16e0: 22 0a 20 20 20 20 20 20 22 20 20 20 41 4e 44 20  ".      "   AND 
16f0: 28 64 65 6c 65 74 65 64 20 4f 52 20 63 68 6e 67  (deleted OR chng
1700: 65 64 20 4f 52 20 72 69 64 3d 3d 30 29 22 0a 20  ed OR rid==0)". 
1710: 20 20 20 20 20 22 20 4f 52 44 45 52 20 42 59 20       " ORDER BY 
1720: 70 61 74 68 6e 61 6d 65 22 2c 0a 20 20 20 20 20  pathname",.     
1730: 20 76 69 64 0a 20 20 20 20 29 3b 0a 20 20 7d 0a   vid.    );.  }.
1740: 20 20 64 62 5f 70 72 65 70 61 72 65 28 26 71 2c    db_prepare(&q,
1750: 20 62 6c 6f 62 5f 73 74 72 28 26 73 71 6c 29 29   blob_str(&sql))
1760: 3b 0a 20 20 77 68 69 6c 65 28 20 64 62 5f 73 74  ;.  while( db_st
1770: 65 70 28 26 71 29 3d 3d 53 51 4c 49 54 45 5f 52  ep(&q)==SQLITE_R
1780: 4f 57 20 29 7b 0a 20 20 20 20 63 6f 6e 73 74 20  OW ){.    const 
1790: 63 68 61 72 20 2a 7a 50 61 74 68 6e 61 6d 65 20  char *zPathname 
17a0: 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 74 65 78 74  = db_column_text
17b0: 28 26 71 2c 30 29 3b 0a 20 20 20 20 69 6e 74 20  (&q,0);.    int 
17c0: 69 73 44 65 6c 65 74 65 64 20 3d 20 64 62 5f 63  isDeleted = db_c
17d0: 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20 31 29  olumn_int(&q, 1)
17e0: 3b 0a 20 20 20 20 69 6e 74 20 69 73 43 68 6e 67  ;.    int isChng
17f0: 65 64 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69  ed = db_column_i
1800: 6e 74 28 26 71 2c 32 29 3b 0a 20 20 20 20 69 6e  nt(&q,2);.    in
1810: 74 20 69 73 4e 65 77 20 3d 20 64 62 5f 63 6f 6c  t isNew = db_col
1820: 75 6d 6e 5f 69 6e 74 28 26 71 2c 33 29 3b 0a 20  umn_int(&q,3);. 
1830: 20 20 20 63 68 61 72 20 2a 7a 46 75 6c 6c 4e 61     char *zFullNa
1840: 6d 65 20 3d 20 6d 70 72 69 6e 74 66 28 22 25 73  me = mprintf("%s
1850: 25 73 22 2c 20 67 2e 7a 4c 6f 63 61 6c 52 6f 6f  %s", g.zLocalRoo
1860: 74 2c 20 7a 50 61 74 68 6e 61 6d 65 29 3b 0a 20  t, zPathname);. 
1870: 20 20 20 69 66 28 20 69 73 44 65 6c 65 74 65 64     if( isDeleted
1880: 20 29 7b 0a 20 20 20 20 20 20 70 72 69 6e 74 66   ){.      printf
1890: 28 22 44 45 4c 45 54 45 44 20 20 25 73 5c 6e 22  ("DELETED  %s\n"
18a0: 2c 20 7a 50 61 74 68 6e 61 6d 65 29 3b 0a 20 20  , zPathname);.  
18b0: 20 20 7d 65 6c 73 65 20 69 66 28 20 61 63 63 65    }else if( acce
18c0: 73 73 28 7a 46 75 6c 6c 4e 61 6d 65 2c 20 30 29  ss(zFullName, 0)
18d0: 20 29 7b 0a 20 20 20 20 20 20 70 72 69 6e 74 66   ){.      printf
18e0: 28 22 4d 49 53 53 49 4e 47 20 20 25 73 5c 6e 22  ("MISSING  %s\n"
18f0: 2c 20 7a 50 61 74 68 6e 61 6d 65 29 3b 0a 20 20  , zPathname);.  
1900: 20 20 7d 65 6c 73 65 20 69 66 28 20 69 73 4e 65    }else if( isNe
1910: 77 20 29 7b 0a 20 20 20 20 20 20 70 72 69 6e 74  w ){.      print
1920: 66 28 22 41 44 44 45 44 20 20 20 20 25 73 5c 6e  f("ADDED    %s\n
1930: 22 2c 20 7a 50 61 74 68 6e 61 6d 65 29 3b 0a 20  ", zPathname);. 
1940: 20 20 20 7d 65 6c 73 65 20 69 66 28 20 69 73 44     }else if( isD
1950: 65 6c 65 74 65 64 20 29 7b 0a 20 20 20 20 20 20  eleted ){.      
1960: 70 72 69 6e 74 66 28 22 44 45 4c 45 54 45 44 20  printf("DELETED 
1970: 20 25 73 5c 6e 22 2c 20 7a 50 61 74 68 6e 61 6d   %s\n", zPathnam
1980: 65 29 3b 0a 20 20 20 20 7d 65 6c 73 65 20 69 66  e);.    }else if
1990: 28 20 69 73 43 68 6e 67 65 64 3d 3d 33 20 29 7b  ( isChnged==3 ){
19a0: 0a 20 20 20 20 20 20 70 72 69 6e 74 66 28 22 41  .      printf("A
19b0: 44 44 45 44 5f 42 59 5f 4d 45 52 47 45 20 25 73  DDED_BY_MERGE %s
19c0: 5c 6e 22 2c 20 7a 50 61 74 68 6e 61 6d 65 29 3b  \n", zPathname);
19d0: 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20  .    }else{.    
19e0: 20 20 69 6e 74 20 73 72 63 69 64 20 3d 20 64 62    int srcid = db
19f0: 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c 20  _column_int(&q, 
1a00: 34 29 3b 0a 20 20 20 20 20 20 42 6c 6f 62 20 63  4);.      Blob c
1a10: 6f 6e 74 65 6e 74 3b 0a 20 20 20 20 20 20 63 6f  ontent;.      co
1a20: 6e 74 65 6e 74 5f 67 65 74 28 73 72 63 69 64 2c  ntent_get(srcid,
1a30: 20 26 63 6f 6e 74 65 6e 74 29 3b 0a 20 20 20 20   &content);.    
1a40: 20 20 70 72 69 6e 74 66 28 22 49 6e 64 65 78 3a    printf("Index:
1a50: 20 25 73 5c 6e 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d   %s\n===========
1a60: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
1a70: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 22 0a 20 20  ============".  
1a80: 20 20 20 20 20 20 20 20 20 20 20 22 3d 3d 3d 3d             "====
1a90: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d  ================
1aa0: 3d 3d 3d 3d 3d 3d 3d 3d 5c 6e 22 2c 0a 20 20 20  ========\n",.   
1ab0: 20 20 20 20 20 20 20 20 20 20 7a 50 61 74 68 6e            zPathn
1ac0: 61 6d 65 0a 20 20 20 20 20 20 29 3b 0a 20 20 20  ame.      );.   
1ad0: 20 20 20 64 69 66 66 5f 66 69 6c 65 28 26 63 6f     diff_file(&co
1ae0: 6e 74 65 6e 74 2c 20 7a 46 75 6c 6c 4e 61 6d 65  ntent, zFullName
1af0: 2c 20 7a 50 61 74 68 6e 61 6d 65 2c 20 7a 44 69  , zPathname, zDi
1b00: 66 66 43 6d 64 29 3b 0a 20 20 20 20 20 20 62 6c  ffCmd);.      bl
1b10: 6f 62 5f 72 65 73 65 74 28 26 63 6f 6e 74 65 6e  ob_reset(&conten
1b20: 74 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 66 72  t);.    }.    fr
1b30: 65 65 28 7a 46 75 6c 6c 4e 61 6d 65 29 3b 0a 20  ee(zFullName);. 
1b40: 20 7d 0a 20 20 64 62 5f 66 69 6e 61 6c 69 7a 65   }.  db_finalize
1b50: 28 26 71 29 3b 0a 20 20 64 62 5f 65 6e 64 5f 74  (&q);.  db_end_t
1b60: 72 61 6e 73 61 63 74 69 6f 6e 28 31 29 3b 0a 7d  ransaction(1);.}
1b70: 0a 0a 0a 0a 2f 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e  ..../*.** COMMAN
1b80: 44 3a 20 64 69 66 66 0a 2a 2a 20 43 4f 4d 4d 41  D: diff.** COMMA
1b90: 4e 44 3a 20 67 64 69 66 66 0a 2a 2a 0a 2a 2a 20  ND: gdiff.**.** 
1ba0: 55 73 61 67 65 3a 20 25 66 6f 73 73 69 6c 20 64  Usage: %fossil d
1bb0: 69 66 66 7c 67 64 69 66 66 20 3f 6f 70 74 69 6f  iff|gdiff ?optio
1bc0: 6e 73 3f 20 3f 46 49 4c 45 3f 0a 2a 2a 0a 2a 2a  ns? ?FILE?.**.**
1bd0: 20 53 68 6f 77 20 74 68 65 20 64 69 66 66 65 72   Show the differ
1be0: 65 6e 63 65 20 62 65 74 77 65 65 6e 20 74 68 65  ence between the
1bf0: 20 63 75 72 72 65 6e 74 20 76 65 72 73 69 6f 6e   current version
1c00: 20 6f 66 20 46 49 4c 45 20 28 61 73 20 69 74 0a   of FILE (as it.
1c10: 2a 2a 20 65 78 69 73 74 73 20 6f 6e 20 64 69 73  ** exists on dis
1c20: 6b 29 20 61 6e 64 20 74 68 61 74 20 73 61 6d 65  k) and that same
1c30: 20 66 69 6c 65 20 61 73 20 69 74 20 77 61 73 20   file as it was 
1c40: 63 68 65 63 6b 65 64 20 6f 75 74 2e 20 20 4f 72  checked out.  Or
1c50: 0a 2a 2a 20 69 66 20 74 68 65 20 46 49 4c 45 20  .** if the FILE 
1c60: 61 72 67 75 6d 65 6e 74 20 69 73 20 6f 6d 69 74  argument is omit
1c70: 74 65 64 2c 20 73 68 6f 77 20 74 68 65 20 75 6e  ted, show the un
1c80: 73 61 76 65 64 20 63 68 61 6e 67 65 64 20 63 75  saved changed cu
1c90: 72 72 65 6e 74 6c 79 0a 2a 2a 20 69 6e 20 74 68  rrently.** in th
1ca0: 65 20 77 6f 72 6b 69 6e 67 20 63 68 65 63 6b 2d  e working check-
1cb0: 6f 75 74 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68  out..**.** If th
1cc0: 65 20 22 2d 2d 66 72 6f 6d 20 56 45 52 53 49 4f  e "--from VERSIO
1cd0: 4e 22 20 6f 72 20 22 2d 72 20 56 45 52 53 49 4f  N" or "-r VERSIO
1ce0: 4e 22 20 6f 70 74 69 6f 6e 20 69 73 20 75 73 65  N" option is use
1cf0: 64 20 69 74 20 73 70 65 63 69 66 69 65 73 0a 2a  d it specifies.*
1d00: 2a 20 74 68 65 20 73 6f 75 72 63 65 20 63 68 65  * the source che
1d10: 63 6b 2d 69 6e 20 66 6f 72 20 74 68 65 20 64 69  ck-in for the di
1d20: 66 66 20 6f 70 65 72 61 74 69 6f 6e 2e 20 20 49  ff operation.  I
1d30: 66 20 6e 6f 74 20 73 70 65 63 69 66 69 65 64 2c  f not specified,
1d40: 20 74 68 65 20 0a 2a 2a 20 73 6f 75 72 63 65 20   the .** source 
1d50: 63 68 65 63 6b 2d 69 6e 20 69 73 20 74 68 65 20  check-in is the 
1d60: 62 61 73 65 20 63 68 65 63 6b 2d 69 6e 20 66 6f  base check-in fo
1d70: 72 20 74 68 65 20 63 75 72 72 65 6e 74 20 63 68  r the current ch
1d80: 65 63 6b 2d 6f 75 74 2e 0a 2a 2a 0a 2a 2a 20 49  eck-out..**.** I
1d90: 66 20 74 68 65 20 22 2d 2d 74 6f 20 56 45 52 53  f the "--to VERS
1da0: 49 4f 4e 22 20 6f 70 74 69 6f 6e 20 61 70 70 65  ION" option appe
1db0: 61 72 73 2c 20 69 74 20 73 70 65 63 69 66 69 65  ars, it specifie
1dc0: 73 20 74 68 65 20 63 68 65 63 6b 2d 69 6e 20 66  s the check-in f
1dd0: 72 6f 6d 0a 2a 2a 20 77 68 69 63 68 20 74 68 65  rom.** which the
1de0: 20 73 65 63 6f 6e 64 20 76 65 72 73 69 6f 6e 20   second version 
1df0: 6f 66 20 74 68 65 20 66 69 6c 65 20 6f 72 20 66  of the file or f
1e00: 69 6c 65 73 20 69 73 20 74 61 6b 65 6e 2e 20 20  iles is taken.  
1e10: 49 66 20 74 68 65 72 65 20 69 73 0a 2a 2a 20 6e  If there is.** n
1e20: 6f 20 22 2d 2d 74 6f 22 20 6f 70 74 69 6f 6e 20  o "--to" option 
1e30: 74 68 65 6e 20 74 68 65 20 28 70 6f 73 73 69 62  then the (possib
1e40: 6c 79 20 65 64 69 74 65 64 29 20 66 69 6c 65 73  ly edited) files
1e50: 20 69 6e 20 74 68 65 20 63 75 72 72 65 6e 74 20   in the current 
1e60: 63 68 65 63 6b 2d 6f 75 74 0a 2a 2a 20 61 72 65  check-out.** are
1e70: 20 75 73 65 64 2e 0a 2a 2a 0a 2a 2a 20 54 68 65   used..**.** The
1e80: 20 22 2d 69 22 20 63 6f 6d 6d 61 6e 64 2d 6c 69   "-i" command-li
1e90: 6e 65 20 6f 70 74 69 6f 6e 20 66 6f 72 63 65 73  ne option forces
1ea0: 20 74 68 65 20 75 73 65 20 6f 66 20 74 68 65 20   the use of the 
1eb0: 69 6e 74 65 72 6e 61 6c 20 64 69 66 66 20 6c 6f  internal diff lo
1ec0: 67 69 63 0a 2a 2a 20 72 61 74 68 65 72 20 74 68  gic.** rather th
1ed0: 61 6e 20 61 6e 79 20 65 78 74 65 72 6e 61 6c 20  an any external 
1ee0: 64 69 66 66 20 70 72 6f 67 72 61 6d 20 74 68 61  diff program tha
1ef0: 74 20 6d 69 67 68 74 20 62 65 20 63 6f 6e 66 69  t might be confi
1f00: 67 75 72 65 64 20 75 73 69 6e 67 0a 2a 2a 20 74  gured using.** t
1f10: 68 65 20 22 73 65 74 74 69 6e 67 22 20 63 6f 6d  he "setting" com
1f20: 6d 61 6e 64 2e 20 20 49 66 20 6e 6f 20 65 78 74  mand.  If no ext
1f30: 65 72 6e 61 6c 20 64 69 66 66 20 70 72 6f 67 72  ernal diff progr
1f40: 61 6d 20 69 73 20 63 6f 6e 66 69 67 75 72 65 64  am is configured
1f50: 2c 20 74 68 65 6e 0a 2a 2a 20 74 68 65 20 22 2d  , then.** the "-
1f60: 69 22 20 6f 70 74 69 6f 6e 20 69 73 20 61 20 6e  i" option is a n
1f70: 6f 2d 6f 70 2e 20 20 54 68 65 20 22 2d 69 22 20  o-op.  The "-i" 
1f80: 6f 70 74 69 6f 6e 20 63 6f 6e 76 65 72 74 73 20  option converts 
1f90: 22 67 64 69 66 66 22 20 69 6e 74 6f 20 22 64 69  "gdiff" into "di
1fa0: 66 66 22 2e 0a 2a 2f 0a 76 6f 69 64 20 64 69 66  ff"..*/.void dif
1fb0: 66 5f 63 6d 64 28 76 6f 69 64 29 7b 0a 20 20 69  f_cmd(void){.  i
1fc0: 6e 74 20 69 73 47 44 69 66 66 3b 20 20 20 20 20  nt isGDiff;     
1fd0: 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75            /* Tru
1fe0: 65 20 66 6f 72 20 67 64 69 66 66 2e 20 20 46 61  e for gdiff.  Fa
1ff0: 6c 73 65 20 66 6f 72 20 6e 6f 72 6d 61 6c 20 64  lse for normal d
2000: 69 66 66 20 2a 2f 0a 20 20 69 6e 74 20 69 73 49  iff */.  int isI
2010: 6e 74 65 72 6e 44 69 66 66 3b 20 20 20 20 20 20  nternDiff;      
2020: 20 20 20 20 2f 2a 20 54 72 75 65 20 66 6f 72 20      /* True for 
2030: 69 6e 74 65 72 6e 61 6c 20 64 69 66 66 20 2a 2f  internal diff */
2040: 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  .  const char *z
2050: 46 72 6f 6d 3b 20 20 20 20 20 20 20 20 20 2f 2a  From;         /*
2060: 20 53 6f 75 72 63 65 20 76 65 72 73 69 6f 6e 20   Source version 
2070: 6e 75 6d 62 65 72 20 2a 2f 0a 20 20 63 6f 6e 73  number */.  cons
2080: 74 20 63 68 61 72 20 2a 7a 54 6f 3b 20 20 20 20  t char *zTo;    
2090: 20 20 20 20 20 20 20 2f 2a 20 54 61 72 67 65 74         /* Target
20a0: 20 76 65 72 73 69 6f 6e 20 6e 75 6d 62 65 72 20   version number 
20b0: 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20  */.  const char 
20c0: 2a 7a 44 69 66 66 43 6d 64 20 3d 20 30 3b 20 20  *zDiffCmd = 0;  
20d0: 2f 2a 20 45 78 74 65 72 6e 61 6c 20 64 69 66 66  /* External diff
20e0: 20 63 6f 6d 6d 61 6e 64 2e 20 4e 55 4c 4c 20 66   command. NULL f
20f0: 6f 72 20 69 6e 74 65 72 6e 61 6c 20 64 69 66 66  or internal diff
2100: 20 2a 2f 0a 0a 20 20 69 73 47 44 69 66 66 20 3d   */..  isGDiff =
2110: 20 67 2e 61 72 67 76 5b 31 5d 5b 30 5d 3d 3d 27   g.argv[1][0]=='
2120: 67 27 3b 0a 20 20 69 73 49 6e 74 65 72 6e 44 69  g';.  isInternDi
2130: 66 66 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e  ff = find_option
2140: 28 22 69 6e 74 65 72 6e 61 6c 22 2c 22 69 22 2c  ("internal","i",
2150: 30 29 21 3d 30 3b 0a 20 20 7a 46 72 6f 6d 20 3d  0)!=0;.  zFrom =
2160: 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 66 72   find_option("fr
2170: 6f 6d 22 2c 20 22 72 22 2c 20 31 29 3b 0a 20 20  om", "r", 1);.  
2180: 7a 54 6f 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f  zTo = find_optio
2190: 6e 28 22 74 6f 22 2c 20 30 2c 20 31 29 3b 0a 0a  n("to", 0, 1);..
21a0: 20 20 69 66 28 20 7a 54 6f 3d 3d 30 20 29 7b 0a    if( zTo==0 ){.
21b0: 20 20 20 20 64 62 5f 6d 75 73 74 5f 62 65 5f 77      db_must_be_w
21c0: 69 74 68 69 6e 5f 74 72 65 65 28 29 3b 0a 20 20  ithin_tree();.  
21d0: 20 20 76 65 72 69 66 79 5f 61 6c 6c 5f 6f 70 74    verify_all_opt
21e0: 69 6f 6e 73 28 29 3b 0a 20 20 20 20 69 66 28 20  ions();.    if( 
21f0: 21 69 73 49 6e 74 65 72 6e 44 69 66 66 20 26 26  !isInternDiff &&
2200: 20 67 2e 61 72 67 63 3d 3d 33 20 29 7b 0a 20 20   g.argc==3 ){.  
2210: 20 20 20 20 7a 44 69 66 66 43 6d 64 20 3d 20 64      zDiffCmd = d
2220: 62 5f 67 65 74 28 69 73 47 44 69 66 66 20 3f 20  b_get(isGDiff ? 
2230: 22 67 64 69 66 66 2d 63 6f 6d 6d 61 6e 64 22 20  "gdiff-command" 
2240: 3a 20 22 64 69 66 66 2d 63 6f 6d 6d 61 6e 64 22  : "diff-command"
2250: 2c 20 30 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20  , 0);.    }.    
2260: 69 66 28 20 67 2e 61 72 67 63 3d 3d 33 20 29 7b  if( g.argc==3 ){
2270: 0a 20 20 20 20 20 20 64 69 66 66 5f 6f 6e 65 5f  .      diff_one_
2280: 61 67 61 69 6e 73 74 5f 64 69 73 6b 28 7a 46 72  against_disk(zFr
2290: 6f 6d 2c 20 7a 44 69 66 66 43 6d 64 29 3b 0a 20  om, zDiffCmd);. 
22a0: 20 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20     }else{.      
22b0: 64 69 66 66 5f 61 6c 6c 5f 61 67 61 69 6e 73 74  diff_all_against
22c0: 5f 64 69 73 6b 28 7a 46 72 6f 6d 2c 20 7a 44 69  _disk(zFrom, zDi
22d0: 66 66 43 6d 64 29 3b 0a 20 20 20 20 7d 0a 20 20  ffCmd);.    }.  
22e0: 7d 65 6c 73 65 20 69 66 28 20 7a 46 72 6f 6d 3d  }else if( zFrom=
22f0: 3d 30 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c  =0 ){.    fossil
2300: 5f 66 61 74 61 6c 28 22 6d 75 73 74 20 75 73 65  _fatal("must use
2310: 20 2d 2d 66 72 6f 6d 20 69 66 20 2d 2d 74 6f 20   --from if --to 
2320: 69 73 20 70 72 65 73 65 6e 74 22 29 3b 0a 20 20  is present");.  
2330: 7d 65 6c 73 65 7b 0a 20 20 20 20 64 62 5f 66 69  }else{.    db_fi
2340: 6e 64 5f 61 6e 64 5f 6f 70 65 6e 5f 72 65 70 6f  nd_and_open_repo
2350: 73 69 74 6f 72 79 28 31 29 3b 0a 20 20 20 20 76  sitory(1);.    v
2360: 65 72 69 66 79 5f 61 6c 6c 5f 6f 70 74 69 6f 6e  erify_all_option
2370: 73 28 29 3b 0a 20 20 20 20 69 66 28 20 21 69 73  s();.    if( !is
2380: 49 6e 74 65 72 6e 44 69 66 66 20 26 26 20 67 2e  InternDiff && g.
2390: 61 72 67 63 3d 3d 33 20 29 7b 0a 20 20 20 20 20  argc==3 ){.     
23a0: 20 7a 44 69 66 66 43 6d 64 20 3d 20 64 62 5f 67   zDiffCmd = db_g
23b0: 65 74 28 69 73 47 44 69 66 66 20 3f 20 22 67 64  et(isGDiff ? "gd
23c0: 69 66 66 2d 63 6f 6d 6d 61 6e 64 22 20 3a 20 22  iff-command" : "
23d0: 64 69 66 66 2d 63 6f 6d 6d 61 6e 64 22 2c 20 30  diff-command", 0
23e0: 29 3b 0a 20 20 20 20 7d 0a 20 20 20 20 66 6f 73  );.    }.    fos
23f0: 73 69 6c 5f 66 61 74 61 6c 28 22 2d 2d 74 6f 20  sil_fatal("--to 
2400: 6e 6f 74 20 79 65 74 20 69 6d 70 6c 65 6d 65 6e  not yet implemen
2410: 74 65 64 22 29 3b 0a 23 69 66 20 30 0a 20 20 20  ted");.#if 0.   
2420: 20 69 66 28 20 67 2e 61 72 67 63 3d 3d 33 20 29   if( g.argc==3 )
2430: 7b 0a 20 20 20 20 20 20 64 69 66 66 5f 6f 6e 65  {.      diff_one
2440: 5f 74 77 6f 5f 76 65 72 73 69 6f 6e 73 28 7a 46  _two_versions(zF
2450: 72 6f 6d 2c 20 7a 54 6f 2c 20 7a 44 69 66 66 43  rom, zTo, zDiffC
2460: 6d 64 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a  md);.    }else{.
2470: 20 20 20 20 20 20 64 69 66 66 5f 61 6c 6c 5f 74        diff_all_t
2480: 77 6f 5f 76 65 72 73 69 6f 6e 73 28 7a 46 72 6f  wo_versions(zFro
2490: 6d 2c 20 7a 54 6f 2c 20 7a 44 69 66 66 43 6d 64  m, zTo, zDiffCmd
24a0: 29 3b 0a 20 20 20 20 7d 0a 23 65 6e 64 69 66 0a  );.    }.#endif.
24b0: 20 20 7d 0a 7d 0a                                  }.}.