Hex Artifact Content
Not logged in

Artifact 88a94ee318aee01e614bf2cd874942e6ae4af127:

File src/diffcmd.c part of check-in [7b82a73bd3] - Remove the --yes option from the "revert" command. In its place, make the "revert" opration undoable. by drh on 2009-12-17 21:22:52.

0000: 2f 2a 0a 2a 2a 20 43 6f 70 79 72 69 67 68 74 20  /*.** Copyright 
0010: 28 63 29 20 32 30 30 37 20 44 2e 20 52 69 63 68  (c) 2007 D. Rich
0020: 61 72 64 20 48 69 70 70 0a 2a 2a 0a 2a 2a 20 54  ard Hipp.**.** T
0030: 68 69 73 20 70 72 6f 67 72 61 6d 20 69 73 20 66  his program is f
0040: 72 65 65 20 73 6f 66 74 77 61 72 65 3b 20 79 6f  ree software; yo
0050: 75 20 63 61 6e 20 72 65 64 69 73 74 72 69 62 75  u can redistribu
0060: 74 65 20 69 74 20 61 6e 64 2f 6f 72 0a 2a 2a 20  te it and/or.** 
0070: 6d 6f 64 69 66 79 20 69 74 20 75 6e 64 65 72 20  modify it under 
0080: 74 68 65 20 74 65 72 6d 73 20 6f 66 20 74 68 65  the terms of the
0090: 20 47 4e 55 20 47 65 6e 65 72 61 6c 20 50 75 62   GNU General Pub
00a0: 6c 69 63 0a 2a 2a 20 4c 69 63 65 6e 73 65 20 76  lic.** License v
00b0: 65 72 73 69 6f 6e 20 32 20 61 73 20 70 75 62 6c  ersion 2 as publ
00c0: 69 73 68 65 64 20 62 79 20 74 68 65 20 46 72 65  ished by the Fre
00d0: 65 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64  e Software Found
00e0: 61 74 69 6f 6e 2e 0a 2a 2a 0a 2a 2a 20 54 68 69  ation..**.** Thi
00f0: 73 20 70 72 6f 67 72 61 6d 20 69 73 20 64 69 73  s program is dis
0100: 74 72 69 62 75 74 65 64 20 69 6e 20 74 68 65 20  tributed in the 
0110: 68 6f 70 65 20 74 68 61 74 20 69 74 20 77 69 6c  hope that it wil
0120: 6c 20 62 65 20 75 73 65 66 75 6c 2c 0a 2a 2a 20  l be useful,.** 
0130: 62 75 74 20 57 49 54 48 4f 55 54 20 41 4e 59 20  but WITHOUT ANY 
0140: 57 41 52 52 41 4e 54 59 3b 20 77 69 74 68 6f 75  WARRANTY; withou
0150: 74 20 65 76 65 6e 20 74 68 65 20 69 6d 70 6c 69  t even the impli
0160: 65 64 20 77 61 72 72 61 6e 74 79 20 6f 66 0a 2a  ed warranty of.*
0170: 2a 20 4d 45 52 43 48 41 4e 54 41 42 49 4c 49 54  * MERCHANTABILIT
0180: 59 20 6f 72 20 46 49 54 4e 45 53 53 20 46 4f 52  Y or FITNESS FOR
0190: 20 41 20 50 41 52 54 49 43 55 4c 41 52 20 50 55   A PARTICULAR PU
01a0: 52 50 4f 53 45 2e 20 20 53 65 65 20 74 68 65 20  RPOSE.  See the 
01b0: 47 4e 55 0a 2a 2a 20 47 65 6e 65 72 61 6c 20 50  GNU.** General P
01c0: 75 62 6c 69 63 20 4c 69 63 65 6e 73 65 20 66 6f  ublic License fo
01d0: 72 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 2e 0a  r more details..
01e0: 2a 2a 0a 2a 2a 20 59 6f 75 20 73 68 6f 75 6c 64  **.** You should
01f0: 20 68 61 76 65 20 72 65 63 65 69 76 65 64 20 61   have received a
0200: 20 63 6f 70 79 20 6f 66 20 74 68 65 20 47 4e 55   copy of the GNU
0210: 20 47 65 6e 65 72 61 6c 20 50 75 62 6c 69 63 0a   General Public.
0220: 2a 2a 20 4c 69 63 65 6e 73 65 20 61 6c 6f 6e 67  ** License along
0230: 20 77 69 74 68 20 74 68 69 73 20 6c 69 62 72 61   with this libra
0240: 72 79 3b 20 69 66 20 6e 6f 74 2c 20 77 72 69 74  ry; if not, writ
0250: 65 20 74 6f 20 74 68 65 0a 2a 2a 20 46 72 65 65  e to the.** Free
0260: 20 53 6f 66 74 77 61 72 65 20 46 6f 75 6e 64 61   Software Founda
0270: 74 69 6f 6e 2c 20 49 6e 63 2e 2c 20 35 39 20 54  tion, Inc., 59 T
0280: 65 6d 70 6c 65 20 50 6c 61 63 65 20 2d 20 53 75  emple Place - Su
0290: 69 74 65 20 33 33 30 2c 0a 2a 2a 20 42 6f 73 74  ite 330,.** Bost
02a0: 6f 6e 2c 20 4d 41 20 20 30 32 31 31 31 2d 31 33  on, MA  02111-13
02b0: 30 37 2c 20 55 53 41 2e 0a 2a 2a 0a 2a 2a 20 41  07, USA..**.** A
02c0: 75 74 68 6f 72 20 63 6f 6e 74 61 63 74 20 69 6e  uthor contact in
02d0: 66 6f 72 6d 61 74 69 6f 6e 3a 0a 2a 2a 20 20 20  formation:.**   
02e0: 64 72 68 40 68 77 61 63 69 2e 63 6f 6d 0a 2a 2a  drh@hwaci.com.**
02f0: 20 20 20 68 74 74 70 3a 2f 2f 77 77 77 2e 68 77     http://www.hw
0300: 61 63 69 2e 63 6f 6d 2f 64 72 68 2f 0a 2a 2a 0a  aci.com/drh/.**.
0310: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0320: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0330: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0340: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a  ****************
0350: 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 2a 0a  ***************.
0360: 2a 2a 0a 2a 2a 20 54 68 69 73 20 66 69 6c 65 20  **.** This file 
0370: 63 6f 6e 74 61 69 6e 73 20 63 6f 64 65 20 75 73  contains code us
0380: 65 64 20 74 6f 20 69 6d 70 6c 65 6d 65 6e 74 20  ed to implement 
0390: 74 68 65 20 22 64 69 66 66 22 20 63 6f 6d 6d 61  the "diff" comma
03a0: 6e 64 0a 2a 2f 0a 23 69 6e 63 6c 75 64 65 20 22  nd.*/.#include "
03b0: 63 6f 6e 66 69 67 2e 68 22 0a 23 69 6e 63 6c 75  config.h".#inclu
03c0: 64 65 20 22 64 69 66 66 63 6d 64 2e 68 22 0a 23  de "diffcmd.h".#
03d0: 69 6e 63 6c 75 64 65 20 3c 61 73 73 65 72 74 2e  include <assert.
03e0: 68 3e 0a 0a 2f 2a 0a 2a 2a 20 53 68 65 6c 6c 2d  h>../*.** Shell-
03f0: 65 73 63 61 70 65 20 74 68 65 20 67 69 76 65 6e  escape the given
0400: 20 73 74 72 69 6e 67 2e 20 20 41 70 70 65 6e 64   string.  Append
0410: 20 74 68 65 20 72 65 73 75 6c 74 20 74 6f 20 61   the result to a
0420: 20 62 6c 6f 62 2e 0a 2a 2f 0a 73 74 61 74 69 63   blob..*/.static
0430: 20 76 6f 69 64 20 73 68 65 6c 6c 5f 65 73 63 61   void shell_esca
0440: 70 65 28 42 6c 6f 62 20 2a 70 42 6c 6f 62 2c 20  pe(Blob *pBlob, 
0450: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 49 6e 29  const char *zIn)
0460: 7b 0a 20 20 69 6e 74 20 6e 20 3d 20 62 6c 6f 62  {.  int n = blob
0470: 5f 73 69 7a 65 28 70 42 6c 6f 62 29 3b 0a 20 20  _size(pBlob);.  
0480: 69 6e 74 20 6b 20 3d 20 73 74 72 6c 65 6e 28 7a  int k = strlen(z
0490: 49 6e 29 3b 0a 20 20 69 6e 74 20 69 2c 20 63 3b  In);.  int i, c;
04a0: 0a 20 20 63 68 61 72 20 2a 7a 3b 0a 20 20 66 6f  .  char *z;.  fo
04b0: 72 28 69 3d 30 3b 20 28 63 20 3d 20 7a 49 6e 5b  r(i=0; (c = zIn[
04c0: 69 5d 29 21 3d 30 3b 20 69 2b 2b 29 7b 0a 20 20  i])!=0; i++){.  
04d0: 20 20 69 66 28 20 69 73 73 70 61 63 65 28 63 29    if( isspace(c)
04e0: 20 7c 7c 20 63 3d 3d 27 22 27 20 7c 7c 20 28 63   || c=='"' || (c
04f0: 3d 3d 27 5c 5c 27 20 26 26 20 7a 49 6e 5b 69 2b  =='\\' && zIn[i+
0500: 31 5d 21 3d 30 29 20 29 7b 0a 20 20 20 20 20 20  1]!=0) ){.      
0510: 62 6c 6f 62 5f 61 70 70 65 6e 64 66 28 70 42 6c  blob_appendf(pBl
0520: 6f 62 2c 20 22 5c 22 25 73 5c 22 22 2c 20 7a 49  ob, "\"%s\"", zI
0530: 6e 29 3b 0a 20 20 20 20 20 20 7a 20 3d 20 62 6c  n);.      z = bl
0540: 6f 62 5f 62 75 66 66 65 72 28 70 42 6c 6f 62 29  ob_buffer(pBlob)
0550: 3b 0a 20 20 20 20 20 20 66 6f 72 28 69 3d 6e 2b  ;.      for(i=n+
0560: 31 3b 20 69 3c 3d 6e 2b 6b 3b 20 69 2b 2b 29 7b  1; i<=n+k; i++){
0570: 0a 20 20 20 20 20 20 20 20 69 66 28 20 7a 5b 69  .        if( z[i
0580: 5d 3d 3d 27 22 27 20 29 20 7a 5b 69 5d 20 3d 20  ]=='"' ) z[i] = 
0590: 27 5f 27 3b 0a 20 20 20 20 20 20 7d 0a 20 20 20  '_';.      }.   
05a0: 20 20 20 72 65 74 75 72 6e 3b 0a 20 20 20 20 7d     return;.    }
05b0: 0a 20 20 7d 0a 20 20 62 6c 6f 62 5f 61 70 70 65  .  }.  blob_appe
05c0: 6e 64 28 70 42 6c 6f 62 2c 20 7a 49 6e 2c 20 2d  nd(pBlob, zIn, -
05d0: 31 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 54 68 69  1);.}../*.** Thi
05e0: 73 20 66 75 6e 63 74 69 6f 6e 20 69 6d 70 6c 65  s function imple
05f0: 6d 65 6e 74 73 20 61 20 63 72 6f 73 73 2d 70 6c  ments a cross-pl
0600: 61 74 66 6f 72 6d 20 22 73 79 73 74 65 6d 28 29  atform "system()
0610: 22 20 69 6e 74 65 72 66 61 63 65 2e 0a 2a 2f 0a  " interface..*/.
0620: 69 6e 74 20 70 6f 72 74 61 62 6c 65 5f 73 79 73  int portable_sys
0630: 74 65 6d 28 63 68 61 72 20 2a 7a 4f 72 69 67 43  tem(char *zOrigC
0640: 6d 64 29 7b 0a 20 20 69 6e 74 20 72 63 3b 0a 23  md){.  int rc;.#
0650: 69 66 64 65 66 20 5f 5f 4d 49 4e 47 57 33 32 5f  ifdef __MINGW32_
0660: 5f 0a 20 20 2f 2a 20 4f 6e 20 77 69 6e 64 6f 77  _.  /* On window
0670: 73 2c 20 77 65 20 68 61 76 65 20 74 6f 20 70 75  s, we have to pu
0680: 74 20 64 6f 75 62 6c 65 2d 71 75 6f 74 65 73 20  t double-quotes 
0690: 61 72 6f 75 6e 64 20 74 68 65 20 65 6e 74 69 72  around the entir
06a0: 65 20 63 6f 6d 6d 61 6e 64 2e 0a 20 20 2a 2a 20  e command..  ** 
06b0: 57 68 6f 20 6b 6e 6f 77 73 20 77 68 79 20 2d 20  Who knows why - 
06c0: 74 68 69 73 20 69 73 20 6a 75 73 74 20 74 68 65  this is just the
06d0: 20 77 61 79 20 77 69 6e 64 6f 77 73 20 77 6f 72   way windows wor
06e0: 6b 73 2e 0a 20 20 2a 2f 0a 20 20 63 68 61 72 20  ks..  */.  char 
06f0: 2a 7a 4e 65 77 43 6d 64 20 3d 20 6d 70 72 69 6e  *zNewCmd = mprin
0700: 74 66 28 22 5c 22 25 73 5c 22 22 2c 20 7a 4f 72  tf("\"%s\"", zOr
0710: 69 67 43 6d 64 29 3b 0a 20 20 72 63 20 3d 20 73  igCmd);.  rc = s
0720: 79 73 74 65 6d 28 7a 4e 65 77 43 6d 64 29 3b 0a  ystem(zNewCmd);.
0730: 20 20 66 72 65 65 28 7a 4e 65 77 43 6d 64 29 3b    free(zNewCmd);
0740: 0a 23 65 6c 73 65 0a 20 20 2f 2a 20 4f 6e 20 75  .#else.  /* On u
0750: 6e 69 78 2c 20 65 76 61 6c 75 61 74 65 20 74 68  nix, evaluate th
0760: 65 20 63 6f 6d 6d 61 6e 64 20 64 69 72 65 63 74  e command direct
0770: 6c 79 2e 0a 20 20 2a 2f 0a 20 20 72 63 20 3d 20  ly..  */.  rc = 
0780: 73 79 73 74 65 6d 28 7a 4f 72 69 67 43 6d 64 29  system(zOrigCmd)
0790: 3b 0a 23 65 6e 64 69 66 20 0a 20 20 72 65 74 75  ;.#endif .  retu
07a0: 72 6e 20 72 63 3b 20 0a 7d 0a 0a 2f 2a 0a 2a 2a  rn rc; .}../*.**
07b0: 20 53 68 6f 77 20 74 68 65 20 64 69 66 66 65 72   Show the differ
07c0: 65 6e 63 65 20 62 65 74 77 65 65 6e 20 74 77 6f  ence between two
07d0: 20 66 69 6c 65 73 2c 20 6f 6e 65 20 69 6e 20 6d   files, one in m
07e0: 65 6d 6f 72 79 20 61 6e 64 20 6f 6e 65 20 6f 6e  emory and one on
07f0: 20 64 69 73 6b 2e 0a 2a 2a 0a 2a 2a 20 54 68 65   disk..**.** The
0800: 20 64 69 66 66 65 72 65 6e 63 65 20 69 73 20 74   difference is t
0810: 68 65 20 73 65 74 20 6f 66 20 65 64 69 74 73 20  he set of edits 
0820: 6e 65 65 64 65 64 20 74 6f 20 74 72 61 6e 73 66  needed to transf
0830: 6f 72 6d 20 70 46 69 6c 65 31 20 69 6e 74 6f 0a  orm pFile1 into.
0840: 2a 2a 20 7a 46 69 6c 65 32 2e 20 20 54 68 65 20  ** zFile2.  The 
0850: 63 6f 6e 74 65 6e 74 20 6f 66 20 70 46 69 6c 65  content of pFile
0860: 31 20 69 73 20 69 6e 20 6d 65 6d 6f 72 79 2e 20  1 is in memory. 
0870: 20 7a 46 69 6c 65 32 20 65 78 69 73 74 73 20 6f   zFile2 exists o
0880: 6e 20 64 69 73 6b 2e 0a 2a 2a 0a 2a 2a 20 55 73  n disk..**.** Us
0890: 65 20 74 68 65 20 69 6e 74 65 72 6e 61 6c 20 64  e the internal d
08a0: 69 66 66 20 6c 6f 67 69 63 20 69 66 20 7a 44 69  iff logic if zDi
08b0: 66 66 43 6d 64 20 69 73 20 4e 55 4c 4c 2e 20 20  ffCmd is NULL.  
08c0: 4f 74 68 65 72 77 69 73 65 20 63 61 6c 6c 20 74  Otherwise call t
08d0: 68 65 0a 2a 2a 20 63 6f 6d 6d 61 6e 64 20 7a 44  he.** command zD
08e0: 69 66 66 43 6d 64 20 74 6f 20 64 6f 20 74 68 65  iffCmd to do the
08f0: 20 64 69 66 66 69 6e 67 2e 0a 2a 2f 0a 73 74 61   diffing..*/.sta
0900: 74 69 63 20 76 6f 69 64 20 64 69 66 66 5f 66 69  tic void diff_fi
0910: 6c 65 28 0a 20 20 42 6c 6f 62 20 2a 70 46 69 6c  le(.  Blob *pFil
0920: 65 31 2c 20 20 20 20 20 20 20 20 20 20 20 20 20  e1,             
0930: 2f 2a 20 49 6e 20 6d 65 6d 6f 72 79 20 63 6f 6e  /* In memory con
0940: 74 65 6e 74 20 74 6f 20 63 6f 6d 70 61 72 65 20  tent to compare 
0950: 66 72 6f 6d 20 2a 2f 0a 20 20 63 6f 6e 73 74 20  from */.  const 
0960: 63 68 61 72 20 2a 7a 46 69 6c 65 32 2c 20 20 20  char *zFile2,   
0970: 20 20 20 20 2f 2a 20 4f 6e 20 64 69 73 6b 20 63      /* On disk c
0980: 6f 6e 74 65 6e 74 20 74 6f 20 63 6f 6d 70 61 72  ontent to compar
0990: 65 20 74 6f 20 2a 2f 0a 20 20 63 6f 6e 73 74 20  e to */.  const 
09a0: 63 68 61 72 20 2a 7a 4e 61 6d 65 2c 20 20 20 20  char *zName,    
09b0: 20 20 20 20 2f 2a 20 44 69 73 70 6c 61 79 20 6e      /* Display n
09c0: 61 6d 65 20 6f 66 20 74 68 65 20 66 69 6c 65 20  ame of the file 
09d0: 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20  */.  const char 
09e0: 2a 7a 44 69 66 66 43 6d 64 20 20 20 20 20 20 2f  *zDiffCmd      /
09f0: 2a 20 43 6f 6d 6d 61 6e 64 20 66 6f 72 20 63 6f  * Command for co
0a00: 6d 70 61 72 69 73 6f 6e 20 2a 2f 0a 29 7b 0a 20  mparison */.){. 
0a10: 20 69 66 28 20 7a 44 69 66 66 43 6d 64 3d 3d 30   if( zDiffCmd==0
0a20: 20 29 7b 0a 20 20 20 20 42 6c 6f 62 20 6f 75 74   ){.    Blob out
0a30: 3b 20 20 20 20 20 20 2f 2a 20 44 69 66 66 20 6f  ;      /* Diff o
0a40: 75 74 70 75 74 20 74 65 78 74 20 2a 2f 0a 20 20  utput text */.  
0a50: 20 20 42 6c 6f 62 20 66 69 6c 65 32 3b 20 20 20    Blob file2;   
0a60: 20 2f 2a 20 43 6f 6e 74 65 6e 74 20 6f 66 20 7a   /* Content of z
0a70: 46 69 6c 65 32 20 2a 2f 0a 0a 20 20 20 20 2f 2a  File2 */..    /*
0a80: 20 52 65 61 64 20 63 6f 6e 74 65 6e 74 20 6f 66   Read content of
0a90: 20 7a 46 69 6c 65 32 20 69 6e 74 6f 20 6d 65 6d   zFile2 into mem
0aa0: 6f 72 79 20 2a 2f 0a 20 20 20 20 62 6c 6f 62 5f  ory */.    blob_
0ab0: 7a 65 72 6f 28 26 66 69 6c 65 32 29 3b 0a 20 20  zero(&file2);.  
0ac0: 20 20 62 6c 6f 62 5f 72 65 61 64 5f 66 72 6f 6d    blob_read_from
0ad0: 5f 66 69 6c 65 28 26 66 69 6c 65 32 2c 20 7a 46  _file(&file2, zF
0ae0: 69 6c 65 32 29 3b 0a 0a 20 20 20 20 2f 2a 20 43  ile2);..    /* C
0af0: 6f 6d 70 75 74 65 20 61 6e 64 20 6f 75 74 70 75  ompute and outpu
0b00: 74 20 74 68 65 20 64 69 66 66 65 72 65 6e 63 65  t the difference
0b10: 73 20 2a 2f 0a 20 20 20 20 62 6c 6f 62 5f 7a 65  s */.    blob_ze
0b20: 72 6f 28 26 6f 75 74 29 3b 0a 20 20 20 20 74 65  ro(&out);.    te
0b30: 78 74 5f 64 69 66 66 28 70 46 69 6c 65 31 2c 20  xt_diff(pFile1, 
0b40: 26 66 69 6c 65 32 2c 20 26 6f 75 74 2c 20 35 29  &file2, &out, 5)
0b50: 3b 0a 20 20 20 20 70 72 69 6e 74 66 28 22 2d 2d  ;.    printf("--
0b60: 2d 20 25 73 5c 6e 2b 2b 2b 20 25 73 5c 6e 22 2c  - %s\n+++ %s\n",
0b70: 20 7a 4e 61 6d 65 2c 20 7a 4e 61 6d 65 29 3b 0a   zName, zName);.
0b80: 20 20 20 20 70 72 69 6e 74 66 28 22 25 73 5c 6e      printf("%s\n
0b90: 22 2c 20 62 6c 6f 62 5f 73 74 72 28 26 6f 75 74  ", blob_str(&out
0ba0: 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 52 65 6c 65  ));..    /* Rele
0bb0: 61 73 65 20 6d 65 6d 6f 72 79 20 72 65 73 6f 75  ase memory resou
0bc0: 72 63 65 73 20 2a 2f 0a 20 20 20 20 62 6c 6f 62  rces */.    blob
0bd0: 5f 72 65 73 65 74 28 26 66 69 6c 65 32 29 3b 0a  _reset(&file2);.
0be0: 20 20 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26      blob_reset(&
0bf0: 6f 75 74 29 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20  out);.  }else{. 
0c00: 20 20 20 69 6e 74 20 63 6e 74 20 3d 20 30 3b 0a     int cnt = 0;.
0c10: 20 20 20 20 42 6c 6f 62 20 6e 61 6d 65 46 69 6c      Blob nameFil
0c20: 65 31 3b 20 20 20 20 2f 2a 20 4e 61 6d 65 20 6f  e1;    /* Name o
0c30: 66 20 74 65 6d 70 6f 72 61 72 79 20 66 69 6c 65  f temporary file
0c40: 20 74 6f 20 6f 6c 64 20 70 46 69 6c 65 31 20 63   to old pFile1 c
0c50: 6f 6e 74 65 6e 74 20 2a 2f 0a 20 20 20 20 42 6c  ontent */.    Bl
0c60: 6f 62 20 63 6d 64 3b 20 20 20 20 20 20 20 20 20  ob cmd;         
0c70: 20 2f 2a 20 54 65 78 74 20 6f 66 20 63 6f 6d 6d   /* Text of comm
0c80: 61 6e 64 20 74 6f 20 72 75 6e 20 2a 2f 0a 0a 20  and to run */.. 
0c90: 20 20 20 2f 2a 20 43 6f 6e 73 74 72 75 63 74 20     /* Construct 
0ca0: 61 20 74 65 6d 70 6f 72 61 72 79 20 66 69 6c 65  a temporary file
0cb0: 20 74 6f 20 68 6f 6c 64 20 70 46 69 6c 65 31 20   to hold pFile1 
0cc0: 62 61 73 65 64 20 6f 6e 20 74 68 65 20 6e 61 6d  based on the nam
0cd0: 65 20 6f 66 0a 20 20 20 20 2a 2a 20 7a 46 69 6c  e of.    ** zFil
0ce0: 65 32 20 2a 2f 0a 20 20 20 20 62 6c 6f 62 5f 7a  e2 */.    blob_z
0cf0: 65 72 6f 28 26 6e 61 6d 65 46 69 6c 65 31 29 3b  ero(&nameFile1);
0d00: 0a 20 20 20 20 64 6f 7b 0a 20 20 20 20 20 20 62  .    do{.      b
0d10: 6c 6f 62 5f 72 65 73 65 74 28 26 6e 61 6d 65 46  lob_reset(&nameF
0d20: 69 6c 65 31 29 3b 0a 20 20 20 20 20 20 62 6c 6f  ile1);.      blo
0d30: 62 5f 61 70 70 65 6e 64 66 28 26 6e 61 6d 65 46  b_appendf(&nameF
0d40: 69 6c 65 31 2c 20 22 25 73 7e 25 64 22 2c 20 7a  ile1, "%s~%d", z
0d50: 46 69 6c 65 32 2c 20 63 6e 74 2b 2b 29 3b 0a 20  File2, cnt++);. 
0d60: 20 20 20 7d 77 68 69 6c 65 28 20 61 63 63 65 73     }while( acces
0d70: 73 28 62 6c 6f 62 5f 73 74 72 28 26 6e 61 6d 65  s(blob_str(&name
0d80: 46 69 6c 65 31 29 2c 30 29 3d 3d 30 20 29 3b 0a  File1),0)==0 );.
0d90: 20 20 20 20 62 6c 6f 62 5f 77 72 69 74 65 5f 74      blob_write_t
0da0: 6f 5f 66 69 6c 65 28 70 46 69 6c 65 31 2c 20 62  o_file(pFile1, b
0db0: 6c 6f 62 5f 73 74 72 28 26 6e 61 6d 65 46 69 6c  lob_str(&nameFil
0dc0: 65 31 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 43 6f  e1));..    /* Co
0dd0: 6e 73 74 72 75 63 74 20 74 68 65 20 65 78 74 65  nstruct the exte
0de0: 72 6e 61 6c 20 64 69 66 66 20 63 6f 6d 6d 61 6e  rnal diff comman
0df0: 64 20 2a 2f 0a 20 20 20 20 62 6c 6f 62 5f 7a 65  d */.    blob_ze
0e00: 72 6f 28 26 63 6d 64 29 3b 0a 20 20 20 20 62 6c  ro(&cmd);.    bl
0e10: 6f 62 5f 61 70 70 65 6e 64 66 28 26 63 6d 64 2c  ob_appendf(&cmd,
0e20: 20 22 25 73 20 22 2c 20 7a 44 69 66 66 43 6d 64   "%s ", zDiffCmd
0e30: 29 3b 0a 20 20 20 20 73 68 65 6c 6c 5f 65 73 63  );.    shell_esc
0e40: 61 70 65 28 26 63 6d 64 2c 20 62 6c 6f 62 5f 73  ape(&cmd, blob_s
0e50: 74 72 28 26 6e 61 6d 65 46 69 6c 65 31 29 29 3b  tr(&nameFile1));
0e60: 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64  .    blob_append
0e70: 28 26 63 6d 64 2c 20 22 20 22 2c 20 31 29 3b 0a  (&cmd, " ", 1);.
0e80: 20 20 20 20 73 68 65 6c 6c 5f 65 73 63 61 70 65      shell_escape
0e90: 28 26 63 6d 64 2c 20 7a 46 69 6c 65 32 29 3b 0a  (&cmd, zFile2);.
0ea0: 0a 20 20 20 20 2f 2a 20 52 75 6e 20 74 68 65 20  .    /* Run the 
0eb0: 65 78 74 65 72 6e 61 6c 20 64 69 66 66 20 63 6f  external diff co
0ec0: 6d 6d 61 6e 64 20 2a 2f 0a 20 20 20 20 70 6f 72  mmand */.    por
0ed0: 74 61 62 6c 65 5f 73 79 73 74 65 6d 28 62 6c 6f  table_system(blo
0ee0: 62 5f 73 74 72 28 26 63 6d 64 29 29 3b 0a 0a 20  b_str(&cmd));.. 
0ef0: 20 20 20 2f 2a 20 44 65 6c 65 74 65 20 74 68 65     /* Delete the
0f00: 20 74 65 6d 70 6f 72 61 72 79 20 66 69 6c 65 20   temporary file 
0f10: 61 6e 64 20 63 6c 65 61 6e 20 75 70 20 6d 65 6d  and clean up mem
0f20: 6f 72 79 20 75 73 65 64 20 2a 2f 0a 20 20 20 20  ory used */.    
0f30: 75 6e 6c 69 6e 6b 28 62 6c 6f 62 5f 73 74 72 28  unlink(blob_str(
0f40: 26 6e 61 6d 65 46 69 6c 65 31 29 29 3b 0a 20 20  &nameFile1));.  
0f50: 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 6e 61    blob_reset(&na
0f60: 6d 65 46 69 6c 65 31 29 3b 0a 20 20 20 20 62 6c  meFile1);.    bl
0f70: 6f 62 5f 72 65 73 65 74 28 26 63 6d 64 29 3b 0a  ob_reset(&cmd);.
0f80: 20 20 7d 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 53 68 6f    }.}../*.** Sho
0f90: 77 20 74 68 65 20 64 69 66 66 65 72 65 6e 63 65  w the difference
0fa0: 20 62 65 74 77 65 65 6e 20 74 77 6f 20 66 69 6c   between two fil
0fb0: 65 73 2c 20 62 6f 74 68 20 69 6e 20 6d 65 6d 6f  es, both in memo
0fc0: 72 79 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 64 69  ry..**.** The di
0fd0: 66 66 65 72 65 6e 63 65 20 69 73 20 74 68 65 20  fference is the 
0fe0: 73 65 74 20 6f 66 20 65 64 69 74 73 20 6e 65 65  set of edits nee
0ff0: 64 65 64 20 74 6f 20 74 72 61 6e 73 66 6f 72 6d  ded to transform
1000: 20 70 46 69 6c 65 31 20 69 6e 74 6f 0a 2a 2a 20   pFile1 into.** 
1010: 70 46 69 6c 65 32 2e 0a 2a 2a 0a 2a 2a 20 55 73  pFile2..**.** Us
1020: 65 20 74 68 65 20 69 6e 74 65 72 6e 61 6c 20 64  e the internal d
1030: 69 66 66 20 6c 6f 67 69 63 20 69 66 20 7a 44 69  iff logic if zDi
1040: 66 66 43 6d 64 20 69 73 20 4e 55 4c 4c 2e 20 20  ffCmd is NULL.  
1050: 4f 74 68 65 72 77 69 73 65 20 63 61 6c 6c 20 74  Otherwise call t
1060: 68 65 0a 2a 2a 20 63 6f 6d 6d 61 6e 64 20 7a 44  he.** command zD
1070: 69 66 66 43 6d 64 20 74 6f 20 64 6f 20 74 68 65  iffCmd to do the
1080: 20 64 69 66 66 69 6e 67 2e 0a 2a 2f 0a 73 74 61   diffing..*/.sta
1090: 74 69 63 20 76 6f 69 64 20 64 69 66 66 5f 66 69  tic void diff_fi
10a0: 6c 65 5f 6d 65 6d 28 0a 20 20 42 6c 6f 62 20 2a  le_mem(.  Blob *
10b0: 70 46 69 6c 65 31 2c 20 20 20 20 20 20 20 20 20  pFile1,         
10c0: 20 20 20 20 2f 2a 20 49 6e 20 6d 65 6d 6f 72 79      /* In memory
10d0: 20 63 6f 6e 74 65 6e 74 20 74 6f 20 63 6f 6d 70   content to comp
10e0: 61 72 65 20 66 72 6f 6d 20 2a 2f 0a 20 20 42 6c  are from */.  Bl
10f0: 6f 62 20 2a 70 46 69 6c 65 32 2c 20 20 20 20 20  ob *pFile2,     
1100: 20 20 20 20 20 20 20 20 2f 2a 20 49 6e 20 6d 65          /* In me
1110: 6d 6f 72 79 20 63 6f 6e 74 65 6e 74 20 74 6f 20  mory content to 
1120: 63 6f 6d 70 61 72 65 20 74 6f 20 2a 2f 0a 20 20  compare to */.  
1130: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 4e 61 6d  const char *zNam
1140: 65 2c 20 20 20 20 20 20 20 20 2f 2a 20 44 69 73  e,        /* Dis
1150: 70 6c 61 79 20 6e 61 6d 65 20 6f 66 20 74 68 65  play name of the
1160: 20 66 69 6c 65 20 2a 2f 0a 20 20 63 6f 6e 73 74   file */.  const
1170: 20 63 68 61 72 20 2a 7a 44 69 66 66 43 6d 64 20   char *zDiffCmd 
1180: 20 20 20 20 20 2f 2a 20 43 6f 6d 6d 61 6e 64 20       /* Command 
1190: 66 6f 72 20 63 6f 6d 70 61 72 69 73 6f 6e 20 2a  for comparison *
11a0: 2f 0a 29 7b 0a 20 20 69 66 28 20 7a 44 69 66 66  /.){.  if( zDiff
11b0: 43 6d 64 3d 3d 30 20 29 7b 0a 20 20 20 20 42 6c  Cmd==0 ){.    Bl
11c0: 6f 62 20 6f 75 74 3b 20 20 20 20 20 20 2f 2a 20  ob out;      /* 
11d0: 44 69 66 66 20 6f 75 74 70 75 74 20 74 65 78 74  Diff output text
11e0: 20 2a 2f 0a 0a 20 20 20 20 62 6c 6f 62 5f 7a 65   */..    blob_ze
11f0: 72 6f 28 26 6f 75 74 29 3b 0a 20 20 20 20 74 65  ro(&out);.    te
1200: 78 74 5f 64 69 66 66 28 70 46 69 6c 65 31 2c 20  xt_diff(pFile1, 
1210: 70 46 69 6c 65 32 2c 20 26 6f 75 74 2c 20 35 29  pFile2, &out, 5)
1220: 3b 0a 20 20 20 20 70 72 69 6e 74 66 28 22 2d 2d  ;.    printf("--
1230: 2d 20 25 73 5c 6e 2b 2b 2b 20 25 73 5c 6e 22 2c  - %s\n+++ %s\n",
1240: 20 7a 4e 61 6d 65 2c 20 7a 4e 61 6d 65 29 3b 0a   zName, zName);.
1250: 20 20 20 20 70 72 69 6e 74 66 28 22 25 73 5c 6e      printf("%s\n
1260: 22 2c 20 62 6c 6f 62 5f 73 74 72 28 26 6f 75 74  ", blob_str(&out
1270: 29 29 3b 0a 0a 20 20 20 20 2f 2a 20 52 65 6c 65  ));..    /* Rele
1280: 61 73 65 20 6d 65 6d 6f 72 79 20 72 65 73 6f 75  ase memory resou
1290: 72 63 65 73 20 2a 2f 0a 20 20 20 20 62 6c 6f 62  rces */.    blob
12a0: 5f 72 65 73 65 74 28 26 6f 75 74 29 3b 0a 20 20  _reset(&out);.  
12b0: 7d 65 6c 73 65 7b 0a 20 20 20 20 42 6c 6f 62 20  }else{.    Blob 
12c0: 63 6d 64 3b 0a 20 20 20 20 63 68 61 72 20 7a 54  cmd;.    char zT
12d0: 65 6d 70 31 5b 33 30 30 5d 3b 0a 20 20 20 20 63  emp1[300];.    c
12e0: 68 61 72 20 7a 54 65 6d 70 32 5b 33 30 30 5d 3b  har zTemp2[300];
12f0: 0a 0a 20 20 20 20 2f 2a 20 43 6f 6e 73 74 72 75  ..    /* Constru
1300: 63 74 20 61 20 74 65 6d 70 6f 72 61 72 79 20 66  ct a temporary f
1310: 69 6c 65 20 6e 61 6d 65 73 20 2a 2f 0a 20 20 20  ile names */.   
1320: 20 66 69 6c 65 5f 74 65 6d 70 6e 61 6d 65 28 73   file_tempname(s
1330: 69 7a 65 6f 66 28 7a 54 65 6d 70 31 29 2c 20 7a  izeof(zTemp1), z
1340: 54 65 6d 70 31 29 3b 0a 20 20 20 20 66 69 6c 65  Temp1);.    file
1350: 5f 74 65 6d 70 6e 61 6d 65 28 73 69 7a 65 6f 66  _tempname(sizeof
1360: 28 7a 54 65 6d 70 32 29 2c 20 7a 54 65 6d 70 32  (zTemp2), zTemp2
1370: 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 77 72 69 74  );.    blob_writ
1380: 65 5f 74 6f 5f 66 69 6c 65 28 70 46 69 6c 65 31  e_to_file(pFile1
1390: 2c 20 7a 54 65 6d 70 31 29 3b 0a 20 20 20 20 62  , zTemp1);.    b
13a0: 6c 6f 62 5f 77 72 69 74 65 5f 74 6f 5f 66 69 6c  lob_write_to_fil
13b0: 65 28 70 46 69 6c 65 32 2c 20 7a 54 65 6d 70 32  e(pFile2, zTemp2
13c0: 29 3b 0a 0a 20 20 20 20 2f 2a 20 43 6f 6e 73 74  );..    /* Const
13d0: 72 75 63 74 20 74 68 65 20 65 78 74 65 72 6e 61  ruct the externa
13e0: 6c 20 64 69 66 66 20 63 6f 6d 6d 61 6e 64 20 2a  l diff command *
13f0: 2f 0a 20 20 20 20 62 6c 6f 62 5f 7a 65 72 6f 28  /.    blob_zero(
1400: 26 63 6d 64 29 3b 0a 20 20 20 20 62 6c 6f 62 5f  &cmd);.    blob_
1410: 61 70 70 65 6e 64 66 28 26 63 6d 64 2c 20 22 25  appendf(&cmd, "%
1420: 73 20 22 2c 20 7a 44 69 66 66 43 6d 64 29 3b 0a  s ", zDiffCmd);.
1430: 20 20 20 20 73 68 65 6c 6c 5f 65 73 63 61 70 65      shell_escape
1440: 28 26 63 6d 64 2c 20 7a 54 65 6d 70 31 29 3b 0a  (&cmd, zTemp1);.
1450: 20 20 20 20 62 6c 6f 62 5f 61 70 70 65 6e 64 28      blob_append(
1460: 26 63 6d 64 2c 20 22 20 22 2c 20 31 29 3b 0a 20  &cmd, " ", 1);. 
1470: 20 20 20 73 68 65 6c 6c 5f 65 73 63 61 70 65 28     shell_escape(
1480: 26 63 6d 64 2c 20 7a 54 65 6d 70 32 29 3b 0a 0a  &cmd, zTemp2);..
1490: 20 20 20 20 2f 2a 20 52 75 6e 20 74 68 65 20 65      /* Run the e
14a0: 78 74 65 72 6e 61 6c 20 64 69 66 66 20 63 6f 6d  xternal diff com
14b0: 6d 61 6e 64 20 2a 2f 0a 20 20 20 20 70 6f 72 74  mand */.    port
14c0: 61 62 6c 65 5f 73 79 73 74 65 6d 28 62 6c 6f 62  able_system(blob
14d0: 5f 73 74 72 28 26 63 6d 64 29 29 3b 0a 0a 20 20  _str(&cmd));..  
14e0: 20 20 2f 2a 20 44 65 6c 65 74 65 20 74 68 65 20    /* Delete the 
14f0: 74 65 6d 70 6f 72 61 72 79 20 66 69 6c 65 20 61  temporary file a
1500: 6e 64 20 63 6c 65 61 6e 20 75 70 20 6d 65 6d 6f  nd clean up memo
1510: 72 79 20 75 73 65 64 20 2a 2f 0a 20 20 20 20 75  ry used */.    u
1520: 6e 6c 69 6e 6b 28 7a 54 65 6d 70 31 29 3b 0a 20  nlink(zTemp1);. 
1530: 20 20 20 75 6e 6c 69 6e 6b 28 7a 54 65 6d 70 32     unlink(zTemp2
1540: 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 72 65 73 65  );.    blob_rese
1550: 74 28 26 63 6d 64 29 3b 0a 20 20 7d 0a 7d 0a 0a  t(&cmd);.  }.}..
1560: 2f 2a 0a 2a 2a 20 44 6f 20 61 20 64 69 66 66 20  /*.** Do a diff 
1570: 61 67 61 69 6e 73 74 20 61 20 73 69 6e 67 6c 65  against a single
1580: 20 66 69 6c 65 20 6e 61 6d 65 64 20 69 6e 20 67   file named in g
1590: 2e 61 72 67 76 5b 32 5d 20 66 72 6f 6d 20 76 65  .argv[2] from ve
15a0: 72 73 69 6f 6e 20 7a 46 72 6f 6d 0a 2a 2a 20 61  rsion zFrom.** a
15b0: 67 61 69 6e 73 74 20 74 68 65 20 73 61 6d 65 20  gainst the same 
15c0: 66 69 6c 65 20 6f 6e 20 64 69 73 6b 2e 0a 2a 2f  file on disk..*/
15d0: 0a 73 74 61 74 69 63 20 76 6f 69 64 20 64 69 66  .static void dif
15e0: 66 5f 6f 6e 65 5f 61 67 61 69 6e 73 74 5f 64 69  f_one_against_di
15f0: 73 6b 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  sk(const char *z
1600: 46 72 6f 6d 2c 20 63 6f 6e 73 74 20 63 68 61 72  From, const char
1610: 20 2a 7a 44 69 66 66 43 6d 64 29 7b 0a 20 20 42   *zDiffCmd){.  B
1620: 6c 6f 62 20 66 6e 61 6d 65 3b 0a 20 20 42 6c 6f  lob fname;.  Blo
1630: 62 20 63 6f 6e 74 65 6e 74 3b 0a 20 20 66 69 6c  b content;.  fil
1640: 65 5f 74 72 65 65 5f 6e 61 6d 65 28 67 2e 61 72  e_tree_name(g.ar
1650: 67 76 5b 32 5d 2c 20 26 66 6e 61 6d 65 2c 20 31  gv[2], &fname, 1
1660: 29 3b 0a 20 20 68 69 73 74 6f 72 69 63 61 6c 5f  );.  historical_
1670: 76 65 72 73 69 6f 6e 5f 6f 66 5f 66 69 6c 65 28  version_of_file(
1680: 7a 46 72 6f 6d 2c 20 62 6c 6f 62 5f 73 74 72 28  zFrom, blob_str(
1690: 26 66 6e 61 6d 65 29 2c 20 26 63 6f 6e 74 65 6e  &fname), &conten
16a0: 74 2c 20 30 29 3b 0a 20 20 64 69 66 66 5f 66 69  t, 0);.  diff_fi
16b0: 6c 65 28 26 63 6f 6e 74 65 6e 74 2c 20 67 2e 61  le(&content, g.a
16c0: 72 67 76 5b 32 5d 2c 20 67 2e 61 72 67 76 5b 32  rgv[2], g.argv[2
16d0: 5d 2c 20 7a 44 69 66 66 43 6d 64 29 3b 0a 20 20  ], zDiffCmd);.  
16e0: 62 6c 6f 62 5f 72 65 73 65 74 28 26 63 6f 6e 74  blob_reset(&cont
16f0: 65 6e 74 29 3b 0a 20 20 62 6c 6f 62 5f 72 65 73  ent);.  blob_res
1700: 65 74 28 26 66 6e 61 6d 65 29 3b 0a 7d 0a 0a 2f  et(&fname);.}../
1710: 2a 0a 2a 2a 20 52 75 6e 20 61 20 64 69 66 66 20  *.** Run a diff 
1720: 62 65 74 77 65 65 6e 20 74 68 65 20 76 65 72 73  between the vers
1730: 69 6f 6e 20 7a 46 72 6f 6d 20 61 6e 64 20 66 69  ion zFrom and fi
1740: 6c 65 73 20 6f 6e 20 64 69 73 6b 2e 20 20 7a 46  les on disk.  zF
1750: 72 6f 6d 20 6d 69 67 68 74 0a 2a 2a 20 62 65 20  rom might.** be 
1760: 4e 55 4c 4c 20 77 68 69 63 68 20 6d 65 61 6e 73  NULL which means
1770: 20 74 6f 20 73 69 6d 70 6c 79 20 73 68 6f 77 20   to simply show 
1780: 74 68 65 20 64 69 66 66 65 72 65 6e 63 65 20 62  the difference b
1790: 65 74 77 65 65 6e 20 74 68 65 20 65 64 69 74 65  etween the edite
17a0: 64 0a 2a 2a 20 66 69 6c 65 73 20 6f 6e 20 64 69  d.** files on di
17b0: 73 6b 20 61 6e 64 20 74 68 65 20 63 68 65 63 6b  sk and the check
17c0: 2d 6f 75 74 20 6f 6e 20 77 68 69 63 68 20 74 68  -out on which th
17d0: 65 79 20 61 72 65 20 62 61 73 65 64 2e 0a 2a 2f  ey are based..*/
17e0: 0a 73 74 61 74 69 63 20 76 6f 69 64 20 64 69 66  .static void dif
17f0: 66 5f 61 6c 6c 5f 61 67 61 69 6e 73 74 5f 64 69  f_all_against_di
1800: 73 6b 28 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a  sk(const char *z
1810: 46 72 6f 6d 2c 20 63 6f 6e 73 74 20 63 68 61 72  From, const char
1820: 20 2a 7a 44 69 66 66 43 6d 64 29 7b 0a 20 20 69   *zDiffCmd){.  i
1830: 6e 74 20 76 69 64 3b 0a 20 20 42 6c 6f 62 20 73  nt vid;.  Blob s
1840: 71 6c 3b 0a 20 20 53 74 6d 74 20 71 3b 0a 0a 20  ql;.  Stmt q;.. 
1850: 20 76 69 64 20 3d 20 64 62 5f 6c 67 65 74 5f 69   vid = db_lget_i
1860: 6e 74 28 22 63 68 65 63 6b 6f 75 74 22 2c 20 30  nt("checkout", 0
1870: 29 3b 0a 20 20 76 66 69 6c 65 5f 63 68 65 63 6b  );.  vfile_check
1880: 5f 73 69 67 6e 61 74 75 72 65 28 76 69 64 29 3b  _signature(vid);
1890: 0a 20 20 62 6c 6f 62 5f 7a 65 72 6f 28 26 73 71  .  blob_zero(&sq
18a0: 6c 29 3b 0a 20 20 64 62 5f 62 65 67 69 6e 5f 74  l);.  db_begin_t
18b0: 72 61 6e 73 61 63 74 69 6f 6e 28 29 3b 0a 20 20  ransaction();.  
18c0: 69 66 28 20 7a 46 72 6f 6d 20 29 7b 0a 20 20 20  if( zFrom ){.   
18d0: 20 69 6e 74 20 72 69 64 20 3d 20 6e 61 6d 65 5f   int rid = name_
18e0: 74 6f 5f 72 69 64 28 7a 46 72 6f 6d 29 3b 0a 20  to_rid(zFrom);. 
18f0: 20 20 20 69 66 28 20 21 69 73 5f 61 5f 76 65 72     if( !is_a_ver
1900: 73 69 6f 6e 28 72 69 64 29 20 29 7b 0a 20 20 20  sion(rid) ){.   
1910: 20 20 20 66 6f 73 73 69 6c 5f 66 61 74 61 6c 28     fossil_fatal(
1920: 22 6e 6f 20 73 75 63 68 20 63 68 65 63 6b 2d 69  "no such check-i
1930: 6e 3a 20 25 73 22 2c 20 7a 46 72 6f 6d 29 3b 0a  n: %s", zFrom);.
1940: 20 20 20 20 7d 0a 20 20 20 20 6c 6f 61 64 5f 76      }.    load_v
1950: 66 69 6c 65 5f 66 72 6f 6d 5f 72 69 64 28 72 69  file_from_rid(ri
1960: 64 29 3b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70  d);.    blob_app
1970: 65 6e 64 66 28 26 73 71 6c 2c 0a 20 20 20 20 20  endf(&sql,.     
1980: 20 22 53 45 4c 45 43 54 20 76 32 2e 70 61 74 68   "SELECT v2.path
1990: 6e 61 6d 65 2c 20 76 32 2e 64 65 6c 65 74 65 64  name, v2.deleted
19a0: 2c 20 76 32 2e 63 68 6e 67 65 64 2c 20 76 32 2e  , v2.chnged, v2.
19b0: 72 69 64 3d 3d 30 2c 20 76 31 2e 72 69 64 22 0a  rid==0, v1.rid".
19c0: 20 20 20 20 20 20 22 20 20 46 52 4f 4d 20 76 66        "  FROM vf
19d0: 69 6c 65 20 76 31 2c 20 76 66 69 6c 65 20 76 32  ile v1, vfile v2
19e0: 20 22 0a 20 20 20 20 20 20 22 20 57 48 45 52 45   ".      " WHERE
19f0: 20 76 31 2e 70 61 74 68 6e 61 6d 65 3d 76 32 2e   v1.pathname=v2.
1a00: 70 61 74 68 6e 61 6d 65 20 41 4e 44 20 76 31 2e  pathname AND v1.
1a10: 76 69 64 3d 25 64 20 41 4e 44 20 76 32 2e 76 69  vid=%d AND v2.vi
1a20: 64 3d 25 64 22 0a 20 20 20 20 20 20 22 20 20 20  d=%d".      "   
1a30: 41 4e 44 20 28 76 32 2e 64 65 6c 65 74 65 64 20  AND (v2.deleted 
1a40: 4f 52 20 76 32 2e 63 68 6e 67 65 64 20 4f 52 20  OR v2.chnged OR 
1a50: 76 31 2e 72 69 64 21 3d 76 32 2e 72 69 64 29 22  v1.rid!=v2.rid)"
1a60: 0a 20 20 20 20 20 20 22 55 4e 49 4f 4e 20 22 0a  .      "UNION ".
1a70: 20 20 20 20 20 20 22 53 45 4c 45 43 54 20 70 61        "SELECT pa
1a80: 74 68 6e 61 6d 65 2c 20 31 2c 20 30 2c 20 30 2c  thname, 1, 0, 0,
1a90: 20 30 22 0a 20 20 20 20 20 20 22 20 20 46 52 4f   0".      "  FRO
1aa0: 4d 20 76 66 69 6c 65 20 76 31 22 0a 20 20 20 20  M vfile v1".    
1ab0: 20 20 22 20 57 48 45 52 45 20 76 31 2e 76 69 64    " WHERE v1.vid
1ac0: 3d 25 64 22 0a 20 20 20 20 20 20 22 20 20 20 41  =%d".      "   A
1ad0: 4e 44 20 4e 4f 54 20 45 58 49 53 54 53 28 53 45  ND NOT EXISTS(SE
1ae0: 4c 45 43 54 20 31 20 46 52 4f 4d 20 76 66 69 6c  LECT 1 FROM vfil
1af0: 65 20 76 32 22 0a 20 20 20 20 20 20 20 20 20 20  e v2".          
1b00: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 20                " 
1b10: 57 48 45 52 45 20 76 32 2e 76 69 64 3d 25 64 20  WHERE v2.vid=%d 
1b20: 41 4e 44 20 76 32 2e 70 61 74 68 6e 61 6d 65 3d  AND v2.pathname=
1b30: 76 31 2e 70 61 74 68 6e 61 6d 65 29 22 0a 20 20  v1.pathname)".  
1b40: 20 20 20 20 22 55 4e 49 4f 4e 20 22 0a 20 20 20      "UNION ".   
1b50: 20 20 20 22 53 45 4c 45 43 54 20 70 61 74 68 6e     "SELECT pathn
1b60: 61 6d 65 2c 20 30 2c 20 30 2c 20 31 2c 20 30 22  ame, 0, 0, 1, 0"
1b70: 0a 20 20 20 20 20 20 22 20 20 46 52 4f 4d 20 76  .      "  FROM v
1b80: 66 69 6c 65 20 76 32 22 0a 20 20 20 20 20 20 22  file v2".      "
1b90: 20 57 48 45 52 45 20 76 32 2e 76 69 64 3d 25 64   WHERE v2.vid=%d
1ba0: 22 0a 20 20 20 20 20 20 22 20 20 20 41 4e 44 20  ".      "   AND 
1bb0: 4e 4f 54 20 45 58 49 53 54 53 28 53 45 4c 45 43  NOT EXISTS(SELEC
1bc0: 54 20 31 20 46 52 4f 4d 20 76 66 69 6c 65 20 76  T 1 FROM vfile v
1bd0: 31 22 0a 20 20 20 20 20 20 20 20 20 20 20 20 20  1".             
1be0: 20 20 20 20 20 20 20 20 20 20 20 22 20 57 48 45             " WHE
1bf0: 52 45 20 76 31 2e 76 69 64 3d 25 64 20 41 4e 44  RE v1.vid=%d AND
1c00: 20 76 31 2e 70 61 74 68 6e 61 6d 65 3d 76 32 2e   v1.pathname=v2.
1c10: 70 61 74 68 6e 61 6d 65 29 22 0a 20 20 20 20 20  pathname)".     
1c20: 20 22 20 4f 52 44 45 52 20 42 59 20 31 22 2c 0a   " ORDER BY 1",.
1c30: 20 20 20 20 20 20 72 69 64 2c 20 76 69 64 2c 20        rid, vid, 
1c40: 72 69 64 2c 20 76 69 64 2c 20 76 69 64 2c 20 72  rid, vid, vid, r
1c50: 69 64 0a 20 20 20 20 29 3b 0a 20 20 7d 65 6c 73  id.    );.  }els
1c60: 65 7b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 65  e{.    blob_appe
1c70: 6e 64 66 28 26 73 71 6c 2c 0a 20 20 20 20 20 20  ndf(&sql,.      
1c80: 22 53 45 4c 45 43 54 20 70 61 74 68 6e 61 6d 65  "SELECT pathname
1c90: 2c 20 64 65 6c 65 74 65 64 2c 20 63 68 6e 67 65  , deleted, chnge
1ca0: 64 20 2c 20 72 69 64 3d 3d 30 2c 20 72 69 64 22  d , rid==0, rid"
1cb0: 0a 20 20 20 20 20 20 22 20 20 46 52 4f 4d 20 76  .      "  FROM v
1cc0: 66 69 6c 65 22 0a 20 20 20 20 20 20 22 20 57 48  file".      " WH
1cd0: 45 52 45 20 76 69 64 3d 25 64 22 0a 20 20 20 20  ERE vid=%d".    
1ce0: 20 20 22 20 20 20 41 4e 44 20 28 64 65 6c 65 74    "   AND (delet
1cf0: 65 64 20 4f 52 20 63 68 6e 67 65 64 20 4f 52 20  ed OR chnged OR 
1d00: 72 69 64 3d 3d 30 29 22 0a 20 20 20 20 20 20 22  rid==0)".      "
1d10: 20 4f 52 44 45 52 20 42 59 20 70 61 74 68 6e 61   ORDER BY pathna
1d20: 6d 65 22 2c 0a 20 20 20 20 20 20 76 69 64 0a 20  me",.      vid. 
1d30: 20 20 20 29 3b 0a 20 20 7d 0a 20 20 64 62 5f 70     );.  }.  db_p
1d40: 72 65 70 61 72 65 28 26 71 2c 20 62 6c 6f 62 5f  repare(&q, blob_
1d50: 73 74 72 28 26 73 71 6c 29 29 3b 0a 20 20 77 68  str(&sql));.  wh
1d60: 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26 71 29  ile( db_step(&q)
1d70: 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b 0a  ==SQLITE_ROW ){.
1d80: 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 2a      const char *
1d90: 7a 50 61 74 68 6e 61 6d 65 20 3d 20 64 62 5f 63  zPathname = db_c
1da0: 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 30 29  olumn_text(&q,0)
1db0: 3b 0a 20 20 20 20 69 6e 74 20 69 73 44 65 6c 65  ;.    int isDele
1dc0: 74 65 64 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f  ted = db_column_
1dd0: 69 6e 74 28 26 71 2c 20 31 29 3b 0a 20 20 20 20  int(&q, 1);.    
1de0: 69 6e 74 20 69 73 43 68 6e 67 65 64 20 3d 20 64  int isChnged = d
1df0: 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 2c  b_column_int(&q,
1e00: 32 29 3b 0a 20 20 20 20 69 6e 74 20 69 73 4e 65  2);.    int isNe
1e10: 77 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e  w = db_column_in
1e20: 74 28 26 71 2c 33 29 3b 0a 20 20 20 20 63 68 61  t(&q,3);.    cha
1e30: 72 20 2a 7a 46 75 6c 6c 4e 61 6d 65 20 3d 20 6d  r *zFullName = m
1e40: 70 72 69 6e 74 66 28 22 25 73 25 73 22 2c 20 67  printf("%s%s", g
1e50: 2e 7a 4c 6f 63 61 6c 52 6f 6f 74 2c 20 7a 50 61  .zLocalRoot, zPa
1e60: 74 68 6e 61 6d 65 29 3b 0a 20 20 20 20 69 66 28  thname);.    if(
1e70: 20 69 73 44 65 6c 65 74 65 64 20 29 7b 0a 20 20   isDeleted ){.  
1e80: 20 20 20 20 70 72 69 6e 74 66 28 22 44 45 4c 45      printf("DELE
1e90: 54 45 44 20 20 25 73 5c 6e 22 2c 20 7a 50 61 74  TED  %s\n", zPat
1ea0: 68 6e 61 6d 65 29 3b 0a 20 20 20 20 7d 65 6c 73  hname);.    }els
1eb0: 65 20 69 66 28 20 61 63 63 65 73 73 28 7a 46 75  e if( access(zFu
1ec0: 6c 6c 4e 61 6d 65 2c 20 30 29 20 29 7b 0a 20 20  llName, 0) ){.  
1ed0: 20 20 20 20 70 72 69 6e 74 66 28 22 4d 49 53 53      printf("MISS
1ee0: 49 4e 47 20 20 25 73 5c 6e 22 2c 20 7a 50 61 74  ING  %s\n", zPat
1ef0: 68 6e 61 6d 65 29 3b 0a 20 20 20 20 7d 65 6c 73  hname);.    }els
1f00: 65 20 69 66 28 20 69 73 4e 65 77 20 29 7b 0a 20  e if( isNew ){. 
1f10: 20 20 20 20 20 70 72 69 6e 74 66 28 22 41 44 44       printf("ADD
1f20: 45 44 20 20 20 20 25 73 5c 6e 22 2c 20 7a 50 61  ED    %s\n", zPa
1f30: 74 68 6e 61 6d 65 29 3b 0a 20 20 20 20 7d 65 6c  thname);.    }el
1f40: 73 65 20 69 66 28 20 69 73 44 65 6c 65 74 65 64  se if( isDeleted
1f50: 20 29 7b 0a 20 20 20 20 20 20 70 72 69 6e 74 66   ){.      printf
1f60: 28 22 44 45 4c 45 54 45 44 20 20 25 73 5c 6e 22  ("DELETED  %s\n"
1f70: 2c 20 7a 50 61 74 68 6e 61 6d 65 29 3b 0a 20 20  , zPathname);.  
1f80: 20 20 7d 65 6c 73 65 20 69 66 28 20 69 73 43 68    }else if( isCh
1f90: 6e 67 65 64 3d 3d 33 20 29 7b 0a 20 20 20 20 20  nged==3 ){.     
1fa0: 20 70 72 69 6e 74 66 28 22 41 44 44 45 44 5f 42   printf("ADDED_B
1fb0: 59 5f 4d 45 52 47 45 20 25 73 5c 6e 22 2c 20 7a  Y_MERGE %s\n", z
1fc0: 50 61 74 68 6e 61 6d 65 29 3b 0a 20 20 20 20 7d  Pathname);.    }
1fd0: 65 6c 73 65 7b 0a 20 20 20 20 20 20 69 6e 74 20  else{.      int 
1fe0: 73 72 63 69 64 20 3d 20 64 62 5f 63 6f 6c 75 6d  srcid = db_colum
1ff0: 6e 5f 69 6e 74 28 26 71 2c 20 34 29 3b 0a 20 20  n_int(&q, 4);.  
2000: 20 20 20 20 42 6c 6f 62 20 63 6f 6e 74 65 6e 74      Blob content
2010: 3b 0a 20 20 20 20 20 20 63 6f 6e 74 65 6e 74 5f  ;.      content_
2020: 67 65 74 28 73 72 63 69 64 2c 20 26 63 6f 6e 74  get(srcid, &cont
2030: 65 6e 74 29 3b 0a 20 20 20 20 20 20 70 72 69 6e  ent);.      prin
2040: 74 66 28 22 49 6e 64 65 78 3a 20 25 73 5c 6e 3d  tf("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 3d 3d 3d 22 0a 20 20 20 20 20 20 20 20  ======".        
2080: 20 20 20 20 20 22 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 3d  ================
20a0: 3d 3d 5c 6e 22 2c 0a 20 20 20 20 20 20 20 20 20  ==\n",.         
20b0: 20 20 20 20 7a 50 61 74 68 6e 61 6d 65 0a 20 20      zPathname.  
20c0: 20 20 20 20 29 3b 0a 20 20 20 20 20 20 64 69 66      );.      dif
20d0: 66 5f 66 69 6c 65 28 26 63 6f 6e 74 65 6e 74 2c  f_file(&content,
20e0: 20 7a 46 75 6c 6c 4e 61 6d 65 2c 20 7a 50 61 74   zFullName, zPat
20f0: 68 6e 61 6d 65 2c 20 7a 44 69 66 66 43 6d 64 29  hname, zDiffCmd)
2100: 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 73  ;.      blob_res
2110: 65 74 28 26 63 6f 6e 74 65 6e 74 29 3b 0a 20 20  et(&content);.  
2120: 20 20 7d 0a 20 20 20 20 66 72 65 65 28 7a 46 75    }.    free(zFu
2130: 6c 6c 4e 61 6d 65 29 3b 0a 20 20 7d 0a 20 20 64  llName);.  }.  d
2140: 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b 0a  b_finalize(&q);.
2150: 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 63    db_end_transac
2160: 74 69 6f 6e 28 31 29 3b 0a 7d 0a 0a 2f 2a 0a 2a  tion(1);.}../*.*
2170: 2a 20 4f 75 74 70 75 74 20 74 68 65 20 64 69 66  * Output the dif
2180: 66 65 72 65 6e 63 65 73 20 62 65 74 77 65 65 6e  ferences between
2190: 20 74 77 6f 20 76 65 72 73 69 6f 6e 73 20 6f 66   two versions of
21a0: 20 61 20 73 69 6e 67 6c 65 20 66 69 6c 65 2e 0a   a single file..
21b0: 2a 2a 20 7a 46 72 6f 6d 20 61 6e 64 20 7a 54 6f  ** zFrom and zTo
21c0: 20 61 72 65 20 74 68 65 20 63 68 65 63 6b 2d 69   are the check-i
21d0: 6e 73 20 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68  ns containing th
21e0: 65 20 74 77 6f 20 66 69 6c 65 20 76 65 72 73 69  e two file versi
21f0: 6f 6e 73 2e 0a 2a 2a 20 54 68 65 20 66 69 6c 65  ons..** The file
2200: 6e 61 6d 65 20 69 73 20 63 6f 6e 74 61 69 6e 65  name is containe
2210: 64 20 69 6e 20 67 2e 61 72 67 76 5b 32 5d 2e 0a  d in g.argv[2]..
2220: 2a 2f 0a 73 74 61 74 69 63 20 76 6f 69 64 20 64  */.static void d
2230: 69 66 66 5f 6f 6e 65 5f 74 77 6f 5f 76 65 72 73  iff_one_two_vers
2240: 69 6f 6e 73 28 0a 20 20 63 6f 6e 73 74 20 63 68  ions(.  const ch
2250: 61 72 20 2a 7a 46 72 6f 6d 2c 0a 20 20 63 6f 6e  ar *zFrom,.  con
2260: 73 74 20 63 68 61 72 20 2a 7a 54 6f 2c 0a 20 20  st char *zTo,.  
2270: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 44 69 66  const char *zDif
2280: 66 43 6d 64 0a 29 7b 0a 20 20 63 68 61 72 20 2a  fCmd.){.  char *
2290: 7a 4e 61 6d 65 3b 0a 20 20 42 6c 6f 62 20 66 6e  zName;.  Blob fn
22a0: 61 6d 65 3b 0a 20 20 42 6c 6f 62 20 76 31 2c 20  ame;.  Blob v1, 
22b0: 76 32 3b 0a 20 20 66 69 6c 65 5f 74 72 65 65 5f  v2;.  file_tree_
22c0: 6e 61 6d 65 28 67 2e 61 72 67 76 5b 32 5d 2c 20  name(g.argv[2], 
22d0: 26 66 6e 61 6d 65 2c 20 31 29 3b 0a 20 20 7a 4e  &fname, 1);.  zN
22e0: 61 6d 65 20 3d 20 62 6c 6f 62 5f 73 74 72 28 26  ame = blob_str(&
22f0: 66 6e 61 6d 65 29 3b 0a 20 20 68 69 73 74 6f 72  fname);.  histor
2300: 69 63 61 6c 5f 76 65 72 73 69 6f 6e 5f 6f 66 5f  ical_version_of_
2310: 66 69 6c 65 28 7a 46 72 6f 6d 2c 20 7a 4e 61 6d  file(zFrom, zNam
2320: 65 2c 20 26 76 31 2c 20 30 29 3b 0a 20 20 68 69  e, &v1, 0);.  hi
2330: 73 74 6f 72 69 63 61 6c 5f 76 65 72 73 69 6f 6e  storical_version
2340: 5f 6f 66 5f 66 69 6c 65 28 7a 54 6f 2c 20 7a 4e  _of_file(zTo, zN
2350: 61 6d 65 2c 20 26 76 32 2c 20 30 29 3b 0a 20 20  ame, &v2, 0);.  
2360: 64 69 66 66 5f 66 69 6c 65 5f 6d 65 6d 28 26 76  diff_file_mem(&v
2370: 31 2c 20 26 76 32 2c 20 7a 4e 61 6d 65 2c 20 7a  1, &v2, zName, z
2380: 44 69 66 66 43 6d 64 29 3b 0a 20 20 62 6c 6f 62  DiffCmd);.  blob
2390: 5f 72 65 73 65 74 28 26 76 31 29 3b 0a 20 20 62  _reset(&v1);.  b
23a0: 6c 6f 62 5f 72 65 73 65 74 28 26 76 32 29 3b 0a  lob_reset(&v2);.
23b0: 20 20 62 6c 6f 62 5f 72 65 73 65 74 28 26 66 6e    blob_reset(&fn
23c0: 61 6d 65 29 3b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 4f  ame);.}../*.** O
23d0: 75 74 70 75 74 20 74 68 65 20 64 69 66 66 65 72  utput the differ
23e0: 65 6e 63 65 73 20 62 65 74 77 65 65 6e 20 74 77  ences between tw
23f0: 6f 20 63 68 65 63 6b 2d 69 6e 73 2e 0a 2a 2f 0a  o check-ins..*/.
2400: 73 74 61 74 69 63 20 76 6f 69 64 20 64 69 66 66  static void diff
2410: 5f 61 6c 6c 5f 74 77 6f 5f 76 65 72 73 69 6f 6e  _all_two_version
2420: 73 28 0a 20 20 63 6f 6e 73 74 20 63 68 61 72 20  s(.  const char 
2430: 2a 7a 46 72 6f 6d 2c 0a 20 20 63 6f 6e 73 74 20  *zFrom,.  const 
2440: 63 68 61 72 20 2a 7a 54 6f 2c 0a 20 20 63 6f 6e  char *zTo,.  con
2450: 73 74 20 63 68 61 72 20 2a 7a 44 69 66 66 43 6d  st char *zDiffCm
2460: 64 0a 29 7b 0a 7d 0a 0a 2f 2a 0a 2a 2a 20 43 4f  d.){.}../*.** CO
2470: 4d 4d 41 4e 44 3a 20 64 69 66 66 0a 2a 2a 20 43  MMAND: diff.** C
2480: 4f 4d 4d 41 4e 44 3a 20 67 64 69 66 66 0a 2a 2a  OMMAND: gdiff.**
2490: 0a 2a 2a 20 55 73 61 67 65 3a 20 25 66 6f 73 73  .** Usage: %foss
24a0: 69 6c 20 64 69 66 66 7c 67 64 69 66 66 20 3f 6f  il diff|gdiff ?o
24b0: 70 74 69 6f 6e 73 3f 20 3f 46 49 4c 45 3f 0a 2a  ptions? ?FILE?.*
24c0: 2a 0a 2a 2a 20 53 68 6f 77 20 74 68 65 20 64 69  *.** Show the di
24d0: 66 66 65 72 65 6e 63 65 20 62 65 74 77 65 65 6e  fference between
24e0: 20 74 68 65 20 63 75 72 72 65 6e 74 20 76 65 72   the current ver
24f0: 73 69 6f 6e 20 6f 66 20 46 49 4c 45 20 28 61 73  sion of FILE (as
2500: 20 69 74 0a 2a 2a 20 65 78 69 73 74 73 20 6f 6e   it.** exists on
2510: 20 64 69 73 6b 29 20 61 6e 64 20 74 68 61 74 20   disk) and that 
2520: 73 61 6d 65 20 66 69 6c 65 20 61 73 20 69 74 20  same file as it 
2530: 77 61 73 20 63 68 65 63 6b 65 64 20 6f 75 74 2e  was checked out.
2540: 20 20 4f 72 0a 2a 2a 20 69 66 20 74 68 65 20 46    Or.** if the F
2550: 49 4c 45 20 61 72 67 75 6d 65 6e 74 20 69 73 20  ILE argument is 
2560: 6f 6d 69 74 74 65 64 2c 20 73 68 6f 77 20 74 68  omitted, show th
2570: 65 20 75 6e 73 61 76 65 64 20 63 68 61 6e 67 65  e unsaved change
2580: 64 20 63 75 72 72 65 6e 74 6c 79 0a 2a 2a 20 69  d currently.** i
2590: 6e 20 74 68 65 20 77 6f 72 6b 69 6e 67 20 63 68  n the working ch
25a0: 65 63 6b 2d 6f 75 74 2e 0a 2a 2a 0a 2a 2a 20 49  eck-out..**.** I
25b0: 66 20 74 68 65 20 22 2d 2d 66 72 6f 6d 20 56 45  f the "--from VE
25c0: 52 53 49 4f 4e 22 20 6f 72 20 22 2d 72 20 56 45  RSION" or "-r VE
25d0: 52 53 49 4f 4e 22 20 6f 70 74 69 6f 6e 20 69 73  RSION" option is
25e0: 20 75 73 65 64 20 69 74 20 73 70 65 63 69 66 69   used it specifi
25f0: 65 73 0a 2a 2a 20 74 68 65 20 73 6f 75 72 63 65  es.** the source
2600: 20 63 68 65 63 6b 2d 69 6e 20 66 6f 72 20 74 68   check-in for th
2610: 65 20 64 69 66 66 20 6f 70 65 72 61 74 69 6f 6e  e diff operation
2620: 2e 20 20 49 66 20 6e 6f 74 20 73 70 65 63 69 66  .  If not specif
2630: 69 65 64 2c 20 74 68 65 20 0a 2a 2a 20 73 6f 75  ied, the .** sou
2640: 72 63 65 20 63 68 65 63 6b 2d 69 6e 20 69 73 20  rce check-in is 
2650: 74 68 65 20 62 61 73 65 20 63 68 65 63 6b 2d 69  the base check-i
2660: 6e 20 66 6f 72 20 74 68 65 20 63 75 72 72 65 6e  n for the curren
2670: 74 20 63 68 65 63 6b 2d 6f 75 74 2e 0a 2a 2a 0a  t check-out..**.
2680: 2a 2a 20 49 66 20 74 68 65 20 22 2d 2d 74 6f 20  ** If the "--to 
2690: 56 45 52 53 49 4f 4e 22 20 6f 70 74 69 6f 6e 20  VERSION" option 
26a0: 61 70 70 65 61 72 73 2c 20 69 74 20 73 70 65 63  appears, it spec
26b0: 69 66 69 65 73 20 74 68 65 20 63 68 65 63 6b 2d  ifies the check-
26c0: 69 6e 20 66 72 6f 6d 0a 2a 2a 20 77 68 69 63 68  in from.** which
26d0: 20 74 68 65 20 73 65 63 6f 6e 64 20 76 65 72 73   the second vers
26e0: 69 6f 6e 20 6f 66 20 74 68 65 20 66 69 6c 65 20  ion of the file 
26f0: 6f 72 20 66 69 6c 65 73 20 69 73 20 74 61 6b 65  or files is take
2700: 6e 2e 20 20 49 66 20 74 68 65 72 65 20 69 73 0a  n.  If there is.
2710: 2a 2a 20 6e 6f 20 22 2d 2d 74 6f 22 20 6f 70 74  ** no "--to" opt
2720: 69 6f 6e 20 74 68 65 6e 20 74 68 65 20 28 70 6f  ion then the (po
2730: 73 73 69 62 6c 79 20 65 64 69 74 65 64 29 20 66  ssibly edited) f
2740: 69 6c 65 73 20 69 6e 20 74 68 65 20 63 75 72 72  iles in the curr
2750: 65 6e 74 20 63 68 65 63 6b 2d 6f 75 74 0a 2a 2a  ent check-out.**
2760: 20 61 72 65 20 75 73 65 64 2e 0a 2a 2a 0a 2a 2a   are used..**.**
2770: 20 54 68 65 20 22 2d 69 22 20 63 6f 6d 6d 61 6e   The "-i" comman
2780: 64 2d 6c 69 6e 65 20 6f 70 74 69 6f 6e 20 66 6f  d-line option fo
2790: 72 63 65 73 20 74 68 65 20 75 73 65 20 6f 66 20  rces the use of 
27a0: 74 68 65 20 69 6e 74 65 72 6e 61 6c 20 64 69 66  the internal dif
27b0: 66 20 6c 6f 67 69 63 0a 2a 2a 20 72 61 74 68 65  f logic.** rathe
27c0: 72 20 74 68 61 6e 20 61 6e 79 20 65 78 74 65 72  r than any exter
27d0: 6e 61 6c 20 64 69 66 66 20 70 72 6f 67 72 61 6d  nal diff program
27e0: 20 74 68 61 74 20 6d 69 67 68 74 20 62 65 20 63   that might be c
27f0: 6f 6e 66 69 67 75 72 65 64 20 75 73 69 6e 67 0a  onfigured using.
2800: 2a 2a 20 74 68 65 20 22 73 65 74 74 69 6e 67 22  ** the "setting"
2810: 20 63 6f 6d 6d 61 6e 64 2e 20 20 49 66 20 6e 6f   command.  If no
2820: 20 65 78 74 65 72 6e 61 6c 20 64 69 66 66 20 70   external diff p
2830: 72 6f 67 72 61 6d 20 69 73 20 63 6f 6e 66 69 67  rogram is config
2840: 75 72 65 64 2c 20 74 68 65 6e 0a 2a 2a 20 74 68  ured, then.** th
2850: 65 20 22 2d 69 22 20 6f 70 74 69 6f 6e 20 69 73  e "-i" option is
2860: 20 61 20 6e 6f 2d 6f 70 2e 20 20 54 68 65 20 22   a no-op.  The "
2870: 2d 69 22 20 6f 70 74 69 6f 6e 20 63 6f 6e 76 65  -i" option conve
2880: 72 74 73 20 22 67 64 69 66 66 22 20 69 6e 74 6f  rts "gdiff" into
2890: 20 22 64 69 66 66 22 2e 0a 2a 2f 0a 76 6f 69 64   "diff"..*/.void
28a0: 20 64 69 66 66 5f 63 6d 64 28 76 6f 69 64 29 7b   diff_cmd(void){
28b0: 0a 20 20 69 6e 74 20 69 73 47 44 69 66 66 3b 20  .  int isGDiff; 
28c0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a                /*
28d0: 20 54 72 75 65 20 66 6f 72 20 67 64 69 66 66 2e   True for gdiff.
28e0: 20 20 46 61 6c 73 65 20 66 6f 72 20 6e 6f 72 6d    False for norm
28f0: 61 6c 20 64 69 66 66 20 2a 2f 0a 20 20 69 6e 74  al diff */.  int
2900: 20 69 73 49 6e 74 65 72 6e 44 69 66 66 3b 20 20   isInternDiff;  
2910: 20 20 20 20 20 20 20 20 2f 2a 20 54 72 75 65 20          /* True 
2920: 66 6f 72 20 69 6e 74 65 72 6e 61 6c 20 64 69 66  for internal dif
2930: 66 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61  f */.  const cha
2940: 72 20 2a 7a 46 72 6f 6d 3b 20 20 20 20 20 20 20  r *zFrom;       
2950: 20 20 2f 2a 20 53 6f 75 72 63 65 20 76 65 72 73    /* Source vers
2960: 69 6f 6e 20 6e 75 6d 62 65 72 20 2a 2f 0a 20 20  ion number */.  
2970: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 54 6f 3b  const char *zTo;
2980: 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20 54 61             /* Ta
2990: 72 67 65 74 20 76 65 72 73 69 6f 6e 20 6e 75 6d  rget version num
29a0: 62 65 72 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63  ber */.  const c
29b0: 68 61 72 20 2a 7a 44 69 66 66 43 6d 64 20 3d 20  har *zDiffCmd = 
29c0: 30 3b 20 20 2f 2a 20 45 78 74 65 72 6e 61 6c 20  0;  /* External 
29d0: 64 69 66 66 20 63 6f 6d 6d 61 6e 64 2e 20 4e 55  diff command. NU
29e0: 4c 4c 20 66 6f 72 20 69 6e 74 65 72 6e 61 6c 20  LL for internal 
29f0: 64 69 66 66 20 2a 2f 0a 0a 20 20 69 73 47 44 69  diff */..  isGDi
2a00: 66 66 20 3d 20 67 2e 61 72 67 76 5b 31 5d 5b 30  ff = g.argv[1][0
2a10: 5d 3d 3d 27 67 27 3b 0a 20 20 69 73 49 6e 74 65  ]=='g';.  isInte
2a20: 72 6e 44 69 66 66 20 3d 20 66 69 6e 64 5f 6f 70  rnDiff = find_op
2a30: 74 69 6f 6e 28 22 69 6e 74 65 72 6e 61 6c 22 2c  tion("internal",
2a40: 22 69 22 2c 30 29 21 3d 30 3b 0a 20 20 7a 46 72  "i",0)!=0;.  zFr
2a50: 6f 6d 20 3d 20 66 69 6e 64 5f 6f 70 74 69 6f 6e  om = find_option
2a60: 28 22 66 72 6f 6d 22 2c 20 22 72 22 2c 20 31 29  ("from", "r", 1)
2a70: 3b 0a 20 20 7a 54 6f 20 3d 20 66 69 6e 64 5f 6f  ;.  zTo = find_o
2a80: 70 74 69 6f 6e 28 22 74 6f 22 2c 20 30 2c 20 31  ption("to", 0, 1
2a90: 29 3b 0a 0a 20 20 69 66 28 20 7a 54 6f 3d 3d 30  );..  if( zTo==0
2aa0: 20 29 7b 0a 20 20 20 20 64 62 5f 6d 75 73 74 5f   ){.    db_must_
2ab0: 62 65 5f 77 69 74 68 69 6e 5f 74 72 65 65 28 29  be_within_tree()
2ac0: 3b 0a 20 20 20 20 76 65 72 69 66 79 5f 61 6c 6c  ;.    verify_all
2ad0: 5f 6f 70 74 69 6f 6e 73 28 29 3b 0a 20 20 20 20  _options();.    
2ae0: 69 66 28 20 21 69 73 49 6e 74 65 72 6e 44 69 66  if( !isInternDif
2af0: 66 20 26 26 20 67 2e 61 72 67 63 3d 3d 33 20 29  f && g.argc==3 )
2b00: 7b 0a 20 20 20 20 20 20 7a 44 69 66 66 43 6d 64  {.      zDiffCmd
2b10: 20 3d 20 64 62 5f 67 65 74 28 69 73 47 44 69 66   = db_get(isGDif
2b20: 66 20 3f 20 22 67 64 69 66 66 2d 63 6f 6d 6d 61  f ? "gdiff-comma
2b30: 6e 64 22 20 3a 20 22 64 69 66 66 2d 63 6f 6d 6d  nd" : "diff-comm
2b40: 61 6e 64 22 2c 20 30 29 3b 0a 20 20 20 20 7d 0a  and", 0);.    }.
2b50: 20 20 20 20 69 66 28 20 67 2e 61 72 67 63 3d 3d      if( g.argc==
2b60: 33 20 29 7b 0a 20 20 20 20 20 20 64 69 66 66 5f  3 ){.      diff_
2b70: 6f 6e 65 5f 61 67 61 69 6e 73 74 5f 64 69 73 6b  one_against_disk
2b80: 28 7a 46 72 6f 6d 2c 20 7a 44 69 66 66 43 6d 64  (zFrom, zDiffCmd
2b90: 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a 20 20  );.    }else{.  
2ba0: 20 20 20 20 64 69 66 66 5f 61 6c 6c 5f 61 67 61      diff_all_aga
2bb0: 69 6e 73 74 5f 64 69 73 6b 28 7a 46 72 6f 6d 2c  inst_disk(zFrom,
2bc0: 20 7a 44 69 66 66 43 6d 64 29 3b 0a 20 20 20 20   zDiffCmd);.    
2bd0: 7d 0a 20 20 7d 65 6c 73 65 20 69 66 28 20 7a 46  }.  }else if( zF
2be0: 72 6f 6d 3d 3d 30 20 29 7b 0a 20 20 20 20 66 6f  rom==0 ){.    fo
2bf0: 73 73 69 6c 5f 66 61 74 61 6c 28 22 6d 75 73 74  ssil_fatal("must
2c00: 20 75 73 65 20 2d 2d 66 72 6f 6d 20 69 66 20 2d   use --from if -
2c10: 2d 74 6f 20 69 73 20 70 72 65 73 65 6e 74 22 29  -to is present")
2c20: 3b 0a 20 20 7d 65 6c 73 65 7b 0a 20 20 20 20 64  ;.  }else{.    d
2c30: 62 5f 66 69 6e 64 5f 61 6e 64 5f 6f 70 65 6e 5f  b_find_and_open_
2c40: 72 65 70 6f 73 69 74 6f 72 79 28 31 29 3b 0a 20  repository(1);. 
2c50: 20 20 20 76 65 72 69 66 79 5f 61 6c 6c 5f 6f 70     verify_all_op
2c60: 74 69 6f 6e 73 28 29 3b 0a 20 20 20 20 69 66 28  tions();.    if(
2c70: 20 21 69 73 49 6e 74 65 72 6e 44 69 66 66 20 26   !isInternDiff &
2c80: 26 20 67 2e 61 72 67 63 3d 3d 33 20 29 7b 0a 20  & g.argc==3 ){. 
2c90: 20 20 20 20 20 7a 44 69 66 66 43 6d 64 20 3d 20       zDiffCmd = 
2ca0: 64 62 5f 67 65 74 28 69 73 47 44 69 66 66 20 3f  db_get(isGDiff ?
2cb0: 20 22 67 64 69 66 66 2d 63 6f 6d 6d 61 6e 64 22   "gdiff-command"
2cc0: 20 3a 20 22 64 69 66 66 2d 63 6f 6d 6d 61 6e 64   : "diff-command
2cd0: 22 2c 20 30 29 3b 0a 20 20 20 20 7d 0a 20 20 20  ", 0);.    }.   
2ce0: 20 69 66 28 20 67 2e 61 72 67 63 3d 3d 33 20 29   if( g.argc==3 )
2cf0: 7b 0a 20 20 20 20 20 20 64 69 66 66 5f 6f 6e 65  {.      diff_one
2d00: 5f 74 77 6f 5f 76 65 72 73 69 6f 6e 73 28 7a 46  _two_versions(zF
2d10: 72 6f 6d 2c 20 7a 54 6f 2c 20 7a 44 69 66 66 43  rom, zTo, zDiffC
2d20: 6d 64 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b 0a  md);.    }else{.
2d30: 20 20 20 20 20 20 66 6f 73 73 69 6c 5f 66 61 74        fossil_fat
2d40: 61 6c 28 22 2d 2d 74 6f 20 6f 6e 20 63 6f 6d 70  al("--to on comp
2d50: 6c 65 74 65 20 63 68 65 63 6b 2d 69 6e 73 20 6e  lete check-ins n
2d60: 6f 74 20 79 65 74 20 69 6d 70 6c 65 6d 65 6e 74  ot yet implement
2d70: 65 64 22 29 3b 0a 20 20 20 20 20 20 64 69 66 66  ed");.      diff
2d80: 5f 61 6c 6c 5f 74 77 6f 5f 76 65 72 73 69 6f 6e  _all_two_version
2d90: 73 28 7a 46 72 6f 6d 2c 20 7a 54 6f 2c 20 7a 44  s(zFrom, zTo, zD
2da0: 69 66 66 43 6d 64 29 3b 0a 20 20 20 20 7d 0a 20  iffCmd);.    }. 
2db0: 20 7d 0a 7d 0a                                    }.}.