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 32 2e 72 69 64 3d 3d 30 29 ed OR v2.rid==0)
1460: 22 0a 20 20 20 20 20 20 22 55 4e 49 4f 4e 20 22 ". "UNION "
1470: 0a 20 20 20 20 20 20 22 53 45 4c 45 43 54 20 70 . "SELECT p
1480: 61 74 68 6e 61 6d 65 2c 20 31 2c 20 30 2c 20 30 athname, 1, 0, 0
1490: 2c 20 30 22 0a 20 20 20 20 20 20 22 20 20 46 52 , 0". " FR
14a0: 4f 4d 20 76 66 69 6c 65 20 76 31 22 0a 20 20 20 OM vfile v1".
14b0: 20 20 20 22 20 57 48 45 52 45 20 76 31 2e 76 69 " WHERE v1.vi
14c0: 64 3d 25 64 22 0a 20 20 20 20 20 20 22 20 20 20 d=%d". "
14d0: 41 4e 44 20 4e 4f 54 20 45 58 49 53 54 53 28 53 AND NOT EXISTS(S
14e0: 45 4c 45 43 54 20 31 20 46 52 4f 4d 20 76 66 69 ELECT 1 FROM vfi
14f0: 6c 65 20 76 32 22 0a 20 20 20 20 20 20 20 20 20 le v2".
1500: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 22 "
1510: 20 57 48 45 52 45 20 76 32 2e 76 69 64 3d 25 64 WHERE v2.vid=%d
1520: 20 41 4e 44 20 76 32 2e 70 61 74 68 6e 61 6d 65 AND v2.pathname
1530: 3d 76 31 2e 70 61 74 68 6e 61 6d 65 29 22 0a 20 =v1.pathname)".
1540: 20 20 20 20 20 22 55 4e 49 4f 4e 20 22 0a 20 20 "UNION ".
1550: 20 20 20 20 22 53 45 4c 45 43 54 20 70 61 74 68 "SELECT path
1560: 6e 61 6d 65 2c 20 30 2c 20 30 2c 20 31 2c 20 30 name, 0, 0, 1, 0
1570: 22 0a 20 20 20 20 20 20 22 20 20 46 52 4f 4d 20 ". " FROM
1580: 76 66 69 6c 65 20 76 32 22 0a 20 20 20 20 20 20 vfile v2".
1590: 22 20 57 48 45 52 45 20 76 32 2e 76 69 64 3d 25 " WHERE v2.vid=%
15a0: 64 22 0a 20 20 20 20 20 20 22 20 20 20 41 4e 44 d". " AND
15b0: 20 4e 4f 54 20 45 58 49 53 54 53 28 53 45 4c 45 NOT EXISTS(SELE
15c0: 43 54 20 31 20 46 52 4f 4d 20 76 66 69 6c 65 20 CT 1 FROM vfile
15d0: 76 31 22 0a 20 20 20 20 20 20 20 20 20 20 20 20 v1".
15e0: 20 20 20 20 20 20 20 20 20 20 20 20 22 20 57 48 " WH
15f0: 45 52 45 20 76 31 2e 76 69 64 3d 25 64 20 41 4e ERE v1.vid=%d AN
1600: 44 20 76 31 2e 70 61 74 68 6e 61 6d 65 3d 76 32 D v1.pathname=v2
1610: 2e 70 61 74 68 6e 61 6d 65 29 22 0a 20 20 20 20 .pathname)".
1620: 20 20 22 20 4f 52 44 45 52 20 42 59 20 31 22 2c " ORDER BY 1",
1630: 0a 20 20 20 20 20 20 72 69 64 2c 20 76 69 64 2c . rid, vid,
1640: 20 72 69 64 2c 20 76 69 64 2c 20 76 69 64 2c 20 rid, vid, vid,
1650: 72 69 64 0a 20 20 20 20 29 3b 0a 20 20 7d 65 6c rid. );. }el
1660: 73 65 7b 0a 20 20 20 20 62 6c 6f 62 5f 61 70 70 se{. blob_app
1670: 65 6e 64 66 28 26 73 71 6c 2c 0a 20 20 20 20 20 endf(&sql,.
1680: 20 22 53 45 4c 45 43 54 20 70 61 74 68 6e 61 6d "SELECT pathnam
1690: 65 2c 20 64 65 6c 65 74 65 64 2c 20 63 68 6e 67 e, deleted, chng
16a0: 65 64 20 2c 20 72 69 64 3d 3d 30 2c 20 72 69 64 ed , rid==0, rid
16b0: 22 0a 20 20 20 20 20 20 22 20 20 46 52 4f 4d 20 ". " FROM
16c0: 76 66 69 6c 65 22 0a 20 20 20 20 20 20 22 20 57 vfile". " W
16d0: 48 45 52 45 20 76 69 64 3d 25 64 22 0a 20 20 20 HERE vid=%d".
16e0: 20 20 20 22 20 20 20 41 4e 44 20 28 64 65 6c 65 " AND (dele
16f0: 74 65 64 20 4f 52 20 63 68 6e 67 65 64 20 4f 52 ted OR chnged OR
1700: 20 72 69 64 3d 3d 30 29 22 0a 20 20 20 20 20 20 rid==0)".
1710: 22 20 4f 52 44 45 52 20 42 59 20 70 61 74 68 6e " ORDER BY pathn
1720: 61 6d 65 22 2c 0a 20 20 20 20 20 20 76 69 64 0a ame",. vid.
1730: 20 20 20 20 29 3b 0a 20 20 7d 0a 20 20 64 62 5f );. }. db_
1740: 70 72 65 70 61 72 65 28 26 71 2c 20 62 6c 6f 62 prepare(&q, blob
1750: 5f 73 74 72 28 26 73 71 6c 29 29 3b 0a 20 20 77 _str(&sql));. w
1760: 68 69 6c 65 28 20 64 62 5f 73 74 65 70 28 26 71 hile( db_step(&q
1770: 29 3d 3d 53 51 4c 49 54 45 5f 52 4f 57 20 29 7b )==SQLITE_ROW ){
1780: 0a 20 20 20 20 63 6f 6e 73 74 20 63 68 61 72 20 . const char
1790: 2a 7a 50 61 74 68 6e 61 6d 65 20 3d 20 64 62 5f *zPathname = db_
17a0: 63 6f 6c 75 6d 6e 5f 74 65 78 74 28 26 71 2c 30 column_text(&q,0
17b0: 29 3b 0a 20 20 20 20 69 6e 74 20 69 73 44 65 6c );. int isDel
17c0: 65 74 65 64 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e eted = db_column
17d0: 5f 69 6e 74 28 26 71 2c 20 31 29 3b 0a 20 20 20 _int(&q, 1);.
17e0: 20 69 6e 74 20 69 73 43 68 6e 67 65 64 20 3d 20 int isChnged =
17f0: 64 62 5f 63 6f 6c 75 6d 6e 5f 69 6e 74 28 26 71 db_column_int(&q
1800: 2c 32 29 3b 0a 20 20 20 20 69 6e 74 20 69 73 4e ,2);. int isN
1810: 65 77 20 3d 20 64 62 5f 63 6f 6c 75 6d 6e 5f 69 ew = db_column_i
1820: 6e 74 28 26 71 2c 33 29 3b 0a 20 20 20 20 63 68 nt(&q,3);. ch
1830: 61 72 20 2a 7a 46 75 6c 6c 4e 61 6d 65 20 3d 20 ar *zFullName =
1840: 6d 70 72 69 6e 74 66 28 22 25 73 25 73 22 2c 20 mprintf("%s%s",
1850: 67 2e 7a 4c 6f 63 61 6c 52 6f 6f 74 2c 20 7a 50 g.zLocalRoot, zP
1860: 61 74 68 6e 61 6d 65 29 3b 0a 20 20 20 20 69 66 athname);. if
1870: 28 20 69 73 44 65 6c 65 74 65 64 20 29 7b 0a 20 ( isDeleted ){.
1880: 20 20 20 20 20 70 72 69 6e 74 66 28 22 44 45 4c printf("DEL
1890: 45 54 45 44 20 20 25 73 5c 6e 22 2c 20 7a 50 61 ETED %s\n", zPa
18a0: 74 68 6e 61 6d 65 29 3b 0a 20 20 20 20 7d 65 6c thname);. }el
18b0: 73 65 20 69 66 28 20 61 63 63 65 73 73 28 7a 46 se if( access(zF
18c0: 75 6c 6c 4e 61 6d 65 2c 20 30 29 20 29 7b 0a 20 ullName, 0) ){.
18d0: 20 20 20 20 20 70 72 69 6e 74 66 28 22 4d 49 53 printf("MIS
18e0: 53 49 4e 47 20 20 25 73 5c 6e 22 2c 20 7a 50 61 SING %s\n", zPa
18f0: 74 68 6e 61 6d 65 29 3b 0a 20 20 20 20 7d 65 6c thname);. }el
1900: 73 65 20 69 66 28 20 69 73 4e 65 77 20 29 7b 0a se if( isNew ){.
1910: 20 20 20 20 20 20 70 72 69 6e 74 66 28 22 41 44 printf("AD
1920: 44 45 44 20 20 20 20 25 73 5c 6e 22 2c 20 7a 50 DED %s\n", zP
1930: 61 74 68 6e 61 6d 65 29 3b 0a 20 20 20 20 7d 65 athname);. }e
1940: 6c 73 65 20 69 66 28 20 69 73 44 65 6c 65 74 65 lse if( isDelete
1950: 64 20 29 7b 0a 20 20 20 20 20 20 70 72 69 6e 74 d ){. print
1960: 66 28 22 44 45 4c 45 54 45 44 20 20 25 73 5c 6e f("DELETED %s\n
1970: 22 2c 20 7a 50 61 74 68 6e 61 6d 65 29 3b 0a 20 ", zPathname);.
1980: 20 20 20 7d 65 6c 73 65 20 69 66 28 20 69 73 43 }else if( isC
1990: 68 6e 67 65 64 3d 3d 33 20 29 7b 0a 20 20 20 20 hnged==3 ){.
19a0: 20 20 70 72 69 6e 74 66 28 22 41 44 44 45 44 5f printf("ADDED_
19b0: 42 59 5f 4d 45 52 47 45 20 25 73 5c 6e 22 2c 20 BY_MERGE %s\n",
19c0: 7a 50 61 74 68 6e 61 6d 65 29 3b 0a 20 20 20 20 zPathname);.
19d0: 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 69 6e 74 }else{. int
19e0: 20 73 72 63 69 64 20 3d 20 64 62 5f 63 6f 6c 75 srcid = db_colu
19f0: 6d 6e 5f 69 6e 74 28 26 71 2c 20 34 29 3b 0a 20 mn_int(&q, 4);.
1a00: 20 20 20 20 20 42 6c 6f 62 20 63 6f 6e 74 65 6e Blob conten
1a10: 74 3b 0a 20 20 20 20 20 20 63 6f 6e 74 65 6e 74 t;. content
1a20: 5f 67 65 74 28 73 72 63 69 64 2c 20 26 63 6f 6e _get(srcid, &con
1a30: 74 65 6e 74 29 3b 0a 20 20 20 20 20 20 70 72 69 tent);. pri
1a40: 6e 74 66 28 22 49 6e 64 65 78 3a 20 25 73 5c 6e ntf("Index: %s\n
1a50: 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d 3d ================
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 22 0a 20 20 20 20 20 20 20 =======".
1a80: 20 20 20 20 20 20 22 3d 3d 3d 3d 3d 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 5c 6e 22 2c 0a 20 20 20 20 20 20 20 20 ===\n",.
1ab0: 20 20 20 20 20 7a 50 61 74 68 6e 61 6d 65 0a 20 zPathname.
1ac0: 20 20 20 20 20 29 3b 0a 20 20 20 20 20 20 64 69 );. di
1ad0: 66 66 5f 66 69 6c 65 28 26 63 6f 6e 74 65 6e 74 ff_file(&content
1ae0: 2c 20 7a 46 75 6c 6c 4e 61 6d 65 2c 20 7a 50 61 , zFullName, zPa
1af0: 74 68 6e 61 6d 65 2c 20 7a 44 69 66 66 43 6d 64 thname, zDiffCmd
1b00: 29 3b 0a 20 20 20 20 20 20 62 6c 6f 62 5f 72 65 );. blob_re
1b10: 73 65 74 28 26 63 6f 6e 74 65 6e 74 29 3b 0a 20 set(&content);.
1b20: 20 20 20 7d 0a 20 20 20 20 66 72 65 65 28 7a 46 }. free(zF
1b30: 75 6c 6c 4e 61 6d 65 29 3b 0a 20 20 7d 0a 20 20 ullName);. }.
1b40: 64 62 5f 66 69 6e 61 6c 69 7a 65 28 26 71 29 3b db_finalize(&q);
1b50: 0a 20 20 64 62 5f 65 6e 64 5f 74 72 61 6e 73 61 . db_end_transa
1b60: 63 74 69 6f 6e 28 31 29 3b 0a 7d 0a 0a 0a 0a 2f ction(1);.}..../
1b70: 2a 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 64 69 *.** COMMAND: di
1b80: 66 66 0a 2a 2a 20 43 4f 4d 4d 41 4e 44 3a 20 67 ff.** COMMAND: g
1b90: 64 69 66 66 0a 2a 2a 0a 2a 2a 20 55 73 61 67 65 diff.**.** Usage
1ba0: 3a 20 25 66 6f 73 73 69 6c 20 64 69 66 66 7c 67 : %fossil diff|g
1bb0: 64 69 66 66 20 3f 6f 70 74 69 6f 6e 73 3f 20 3f diff ?options? ?
1bc0: 46 49 4c 45 3f 0a 2a 2a 0a 2a 2a 20 53 68 6f 77 FILE?.**.** Show
1bd0: 20 74 68 65 20 64 69 66 66 65 72 65 6e 63 65 20 the difference
1be0: 62 65 74 77 65 65 6e 20 74 68 65 20 63 75 72 72 between the curr
1bf0: 65 6e 74 20 76 65 72 73 69 6f 6e 20 6f 66 20 46 ent version of F
1c00: 49 4c 45 20 28 61 73 20 69 74 0a 2a 2a 20 65 78 ILE (as it.** ex
1c10: 69 73 74 73 20 6f 6e 20 64 69 73 6b 29 20 61 6e ists on disk) an
1c20: 64 20 74 68 61 74 20 73 61 6d 65 20 66 69 6c 65 d that same file
1c30: 20 61 73 20 69 74 20 77 61 73 20 63 68 65 63 6b as it was check
1c40: 65 64 20 6f 75 74 2e 20 20 4f 72 0a 2a 2a 20 69 ed out. Or.** i
1c50: 66 20 74 68 65 20 46 49 4c 45 20 61 72 67 75 6d f the FILE argum
1c60: 65 6e 74 20 69 73 20 6f 6d 69 74 74 65 64 2c 20 ent is omitted,
1c70: 73 68 6f 77 20 74 68 65 20 75 6e 73 61 76 65 64 show the unsaved
1c80: 20 63 68 61 6e 67 65 64 20 63 75 72 72 65 6e 74 changed current
1c90: 6c 79 0a 2a 2a 20 69 6e 20 74 68 65 20 77 6f 72 ly.** in the wor
1ca0: 6b 69 6e 67 20 63 68 65 63 6b 2d 6f 75 74 2e 0a king check-out..
1cb0: 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 20 22 2d 2d **.** If the "--
1cc0: 66 72 6f 6d 20 56 45 52 53 49 4f 4e 22 20 6f 72 from VERSION" or
1cd0: 20 22 2d 72 20 56 45 52 53 49 4f 4e 22 20 6f 70 "-r VERSION" op
1ce0: 74 69 6f 6e 20 69 73 20 75 73 65 64 20 69 74 20 tion is used it
1cf0: 73 70 65 63 69 66 69 65 73 0a 2a 2a 20 74 68 65 specifies.** the
1d00: 20 73 6f 75 72 63 65 20 63 68 65 63 6b 2d 69 6e source check-in
1d10: 20 66 6f 72 20 74 68 65 20 64 69 66 66 20 6f 70 for the diff op
1d20: 65 72 61 74 69 6f 6e 2e 20 20 49 66 20 6e 6f 74 eration. If not
1d30: 20 73 70 65 63 69 66 69 65 64 2c 20 74 68 65 20 specified, the
1d40: 0a 2a 2a 20 73 6f 75 72 63 65 20 63 68 65 63 6b .** source check
1d50: 2d 69 6e 20 69 73 20 74 68 65 20 62 61 73 65 20 -in is the base
1d60: 63 68 65 63 6b 2d 69 6e 20 66 6f 72 20 74 68 65 check-in for the
1d70: 20 63 75 72 72 65 6e 74 20 63 68 65 63 6b 2d 6f current check-o
1d80: 75 74 2e 0a 2a 2a 0a 2a 2a 20 49 66 20 74 68 65 ut..**.** If the
1d90: 20 22 2d 2d 74 6f 20 56 45 52 53 49 4f 4e 22 20 "--to VERSION"
1da0: 6f 70 74 69 6f 6e 20 61 70 70 65 61 72 73 2c 20 option appears,
1db0: 69 74 20 73 70 65 63 69 66 69 65 73 20 74 68 65 it specifies the
1dc0: 20 63 68 65 63 6b 2d 69 6e 20 66 72 6f 6d 0a 2a check-in from.*
1dd0: 2a 20 77 68 69 63 68 20 74 68 65 20 73 65 63 6f * which the seco
1de0: 6e 64 20 76 65 72 73 69 6f 6e 20 6f 66 20 74 68 nd version of th
1df0: 65 20 66 69 6c 65 20 6f 72 20 66 69 6c 65 73 20 e file or files
1e00: 69 73 20 74 61 6b 65 6e 2e 20 20 49 66 20 74 68 is taken. If th
1e10: 65 72 65 20 69 73 0a 2a 2a 20 6e 6f 20 22 2d 2d ere is.** no "--
1e20: 74 6f 22 20 6f 70 74 69 6f 6e 20 74 68 65 6e 20 to" option then
1e30: 74 68 65 20 28 70 6f 73 73 69 62 6c 79 20 65 64 the (possibly ed
1e40: 69 74 65 64 29 20 66 69 6c 65 73 20 69 6e 20 74 ited) files in t
1e50: 68 65 20 63 75 72 72 65 6e 74 20 63 68 65 63 6b he current check
1e60: 2d 6f 75 74 0a 2a 2a 20 61 72 65 20 75 73 65 64 -out.** are used
1e70: 2e 0a 2a 2a 0a 2a 2a 20 54 68 65 20 22 2d 69 22 ..**.** The "-i"
1e80: 20 63 6f 6d 6d 61 6e 64 2d 6c 69 6e 65 20 6f 70 command-line op
1e90: 74 69 6f 6e 20 66 6f 72 63 65 73 20 74 68 65 20 tion forces the
1ea0: 75 73 65 20 6f 66 20 74 68 65 20 69 6e 74 65 72 use of the inter
1eb0: 6e 61 6c 20 64 69 66 66 20 6c 6f 67 69 63 0a 2a nal diff logic.*
1ec0: 2a 20 72 61 74 68 65 72 20 74 68 61 6e 20 61 6e * rather than an
1ed0: 79 20 65 78 74 65 72 6e 61 6c 20 64 69 66 66 20 y external diff
1ee0: 70 72 6f 67 72 61 6d 20 74 68 61 74 20 6d 69 67 program that mig
1ef0: 68 74 20 62 65 20 63 6f 6e 66 69 67 75 72 65 64 ht be configured
1f00: 20 75 73 69 6e 67 0a 2a 2a 20 74 68 65 20 22 73 using.** the "s
1f10: 65 74 74 69 6e 67 22 20 63 6f 6d 6d 61 6e 64 2e etting" command.
1f20: 20 20 49 66 20 6e 6f 20 65 78 74 65 72 6e 61 6c If no external
1f30: 20 64 69 66 66 20 70 72 6f 67 72 61 6d 20 69 73 diff program is
1f40: 20 63 6f 6e 66 69 67 75 72 65 64 2c 20 74 68 65 configured, the
1f50: 6e 0a 2a 2a 20 74 68 65 20 22 2d 69 22 20 6f 70 n.** the "-i" op
1f60: 74 69 6f 6e 20 69 73 20 61 20 6e 6f 2d 6f 70 2e tion is a no-op.
1f70: 20 20 54 68 65 20 22 2d 69 22 20 6f 70 74 69 6f The "-i" optio
1f80: 6e 20 63 6f 6e 76 65 72 74 73 20 22 67 64 69 66 n converts "gdif
1f90: 66 22 20 69 6e 74 6f 20 22 64 69 66 66 22 2e 0a f" into "diff"..
1fa0: 2a 2f 0a 76 6f 69 64 20 64 69 66 66 5f 63 6d 64 */.void diff_cmd
1fb0: 28 76 6f 69 64 29 7b 0a 20 20 69 6e 74 20 69 73 (void){. int is
1fc0: 47 44 69 66 66 3b 20 20 20 20 20 20 20 20 20 20 GDiff;
1fd0: 20 20 20 20 20 2f 2a 20 54 72 75 65 20 66 6f 72 /* True for
1fe0: 20 67 64 69 66 66 2e 20 20 46 61 6c 73 65 20 66 gdiff. False f
1ff0: 6f 72 20 6e 6f 72 6d 61 6c 20 64 69 66 66 20 2a or normal diff *
2000: 2f 0a 20 20 69 6e 74 20 69 73 49 6e 74 65 72 6e /. int isIntern
2010: 44 69 66 66 3b 20 20 20 20 20 20 20 20 20 20 2f Diff; /
2020: 2a 20 54 72 75 65 20 66 6f 72 20 69 6e 74 65 72 * True for inter
2030: 6e 61 6c 20 64 69 66 66 20 2a 2f 0a 20 20 63 6f nal diff */. co
2040: 6e 73 74 20 63 68 61 72 20 2a 7a 46 72 6f 6d 3b nst char *zFrom;
2050: 20 20 20 20 20 20 20 20 20 2f 2a 20 53 6f 75 72 /* Sour
2060: 63 65 20 76 65 72 73 69 6f 6e 20 6e 75 6d 62 65 ce version numbe
2070: 72 20 2a 2f 0a 20 20 63 6f 6e 73 74 20 63 68 61 r */. const cha
2080: 72 20 2a 7a 54 6f 3b 20 20 20 20 20 20 20 20 20 r *zTo;
2090: 20 20 2f 2a 20 54 61 72 67 65 74 20 76 65 72 73 /* Target vers
20a0: 69 6f 6e 20 6e 75 6d 62 65 72 20 2a 2f 0a 20 20 ion number */.
20b0: 63 6f 6e 73 74 20 63 68 61 72 20 2a 7a 44 69 66 const char *zDif
20c0: 66 43 6d 64 20 3d 20 30 3b 20 20 2f 2a 20 45 78 fCmd = 0; /* Ex
20d0: 74 65 72 6e 61 6c 20 64 69 66 66 20 63 6f 6d 6d ternal diff comm
20e0: 61 6e 64 2e 20 4e 55 4c 4c 20 66 6f 72 20 69 6e and. NULL for in
20f0: 74 65 72 6e 61 6c 20 64 69 66 66 20 2a 2f 0a 0a ternal diff */..
2100: 20 20 69 73 47 44 69 66 66 20 3d 20 67 2e 61 72 isGDiff = g.ar
2110: 67 76 5b 31 5d 5b 30 5d 3d 3d 27 67 27 3b 0a 20 gv[1][0]=='g';.
2120: 20 69 73 49 6e 74 65 72 6e 44 69 66 66 20 3d 20 isInternDiff =
2130: 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 69 6e 74 find_option("int
2140: 65 72 6e 61 6c 22 2c 22 69 22 2c 30 29 21 3d 30 ernal","i",0)!=0
2150: 3b 0a 20 20 7a 46 72 6f 6d 20 3d 20 66 69 6e 64 ;. zFrom = find
2160: 5f 6f 70 74 69 6f 6e 28 22 66 72 6f 6d 22 2c 20 _option("from",
2170: 22 72 22 2c 20 31 29 3b 0a 20 20 7a 54 6f 20 3d "r", 1);. zTo =
2180: 20 66 69 6e 64 5f 6f 70 74 69 6f 6e 28 22 74 6f find_option("to
2190: 22 2c 20 30 2c 20 31 29 3b 0a 0a 20 20 69 66 28 ", 0, 1);.. if(
21a0: 20 7a 54 6f 3d 3d 30 20 29 7b 0a 20 20 20 20 64 zTo==0 ){. d
21b0: 62 5f 6d 75 73 74 5f 62 65 5f 77 69 74 68 69 6e b_must_be_within
21c0: 5f 74 72 65 65 28 29 3b 0a 20 20 20 20 69 66 28 _tree();. if(
21d0: 20 21 69 73 49 6e 74 65 72 6e 44 69 66 66 20 29 !isInternDiff )
21e0: 7b 0a 20 20 20 20 20 20 7a 44 69 66 66 43 6d 64 {. zDiffCmd
21f0: 20 3d 20 64 62 5f 67 65 74 28 69 73 47 44 69 66 = db_get(isGDif
2200: 66 20 3f 20 22 67 64 69 66 66 2d 63 6f 6d 6d 61 f ? "gdiff-comma
2210: 6e 64 22 20 3a 20 22 64 69 66 66 2d 63 6f 6d 6d nd" : "diff-comm
2220: 61 6e 64 22 2c 20 30 29 3b 0a 20 20 20 20 7d 0a and", 0);. }.
2230: 20 20 20 20 76 65 72 69 66 79 5f 61 6c 6c 5f 6f verify_all_o
2240: 70 74 69 6f 6e 73 28 29 3b 0a 20 20 20 20 69 66 ptions();. if
2250: 28 20 67 2e 61 72 67 63 3d 3d 33 20 29 7b 0a 20 ( g.argc==3 ){.
2260: 20 20 20 20 20 64 69 66 66 5f 6f 6e 65 5f 61 67 diff_one_ag
2270: 61 69 6e 73 74 5f 64 69 73 6b 28 7a 46 72 6f 6d ainst_disk(zFrom
2280: 2c 20 7a 44 69 66 66 43 6d 64 29 3b 0a 20 20 20 , zDiffCmd);.
2290: 20 7d 65 6c 73 65 7b 0a 20 20 20 20 20 20 64 69 }else{. di
22a0: 66 66 5f 61 6c 6c 5f 61 67 61 69 6e 73 74 5f 64 ff_all_against_d
22b0: 69 73 6b 28 7a 46 72 6f 6d 2c 20 7a 44 69 66 66 isk(zFrom, zDiff
22c0: 43 6d 64 29 3b 0a 20 20 20 20 7d 0a 20 20 7d 65 Cmd);. }. }e
22d0: 6c 73 65 20 69 66 28 20 7a 46 72 6f 6d 3d 3d 30 lse if( zFrom==0
22e0: 20 29 7b 0a 20 20 20 20 66 6f 73 73 69 6c 5f 66 ){. fossil_f
22f0: 61 74 61 6c 28 22 6d 75 73 74 20 75 73 65 20 2d atal("must use -
2300: 2d 66 72 6f 6d 20 69 66 20 2d 2d 74 6f 20 69 73 -from if --to is
2310: 20 70 72 65 73 65 6e 74 22 29 3b 0a 20 20 7d 65 present");. }e
2320: 6c 73 65 7b 0a 20 20 20 20 64 62 5f 66 69 6e 64 lse{. db_find
2330: 5f 61 6e 64 5f 6f 70 65 6e 5f 72 65 70 6f 73 69 _and_open_reposi
2340: 74 6f 72 79 28 31 29 3b 0a 20 20 20 20 69 66 28 tory(1);. if(
2350: 20 21 69 73 49 6e 74 65 72 6e 44 69 66 66 20 29 !isInternDiff )
2360: 7b 0a 20 20 20 20 20 20 7a 44 69 66 66 43 6d 64 {. zDiffCmd
2370: 20 3d 20 64 62 5f 67 65 74 28 69 73 47 44 69 66 = db_get(isGDif
2380: 66 20 3f 20 22 67 64 69 66 66 2d 63 6f 6d 6d 61 f ? "gdiff-comma
2390: 6e 64 22 20 3a 20 22 64 69 66 66 2d 63 6f 6d 6d nd" : "diff-comm
23a0: 61 6e 64 22 2c 20 30 29 3b 0a 20 20 20 20 7d 0a and", 0);. }.
23b0: 20 20 20 20 76 65 72 69 66 79 5f 61 6c 6c 5f 6f verify_all_o
23c0: 70 74 69 6f 6e 73 28 29 3b 0a 20 20 20 20 66 6f ptions();. fo
23d0: 73 73 69 6c 5f 66 61 74 61 6c 28 22 2d 2d 74 6f ssil_fatal("--to
23e0: 20 6e 6f 74 20 79 65 74 20 69 6d 70 6c 65 6d 65 not yet impleme
23f0: 6e 74 65 64 22 29 3b 0a 23 69 66 20 30 0a 20 20 nted");.#if 0.
2400: 20 20 69 66 28 20 67 2e 61 72 67 63 3d 3d 33 20 if( g.argc==3
2410: 29 7b 0a 20 20 20 20 20 20 64 69 66 66 5f 6f 6e ){. diff_on
2420: 65 5f 74 77 6f 5f 76 65 72 73 69 6f 6e 73 28 7a e_two_versions(z
2430: 46 72 6f 6d 2c 20 7a 54 6f 2c 20 7a 44 69 66 66 From, zTo, zDiff
2440: 43 6d 64 29 3b 0a 20 20 20 20 7d 65 6c 73 65 7b Cmd);. }else{
2450: 0a 20 20 20 20 20 20 64 69 66 66 5f 61 6c 6c 5f . diff_all_
2460: 74 77 6f 5f 76 65 72 73 69 6f 6e 73 28 7a 46 72 two_versions(zFr
2470: 6f 6d 2c 20 7a 54 6f 2c 20 7a 44 69 66 66 43 6d om, zTo, zDiffCm
2480: 64 29 3b 0a 20 20 20 20 7d 0a 23 65 6e 64 69 66 d);. }.#endif
2490: 0a 20 20 7d 0a 7d 0a . }.}.