/*
** Copyright (c) 2007 D. Richard Hipp
**
** This program is free software; you can redistribute it and/or
** modify it under the terms of the GNU General Public
** License version 2 as published by the Free Software Foundation.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** General Public License for more details.
**
** You should have received a copy of the GNU General Public
** License along with this library; if not, write to the
** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
** Boston, MA 02111-1307, USA.
**
** Author contact information:
** drh@hwaci.com
** http://www.hwaci.com/drh/
**
*******************************************************************************
**
** This file contains code to implement the "info" command. The
** "info" command gives command-line access to information about
** the current tree, or a particular artifact or baseline.
*/
#include "config.h"
#include "info.h"
#include
}
@
}
return cnt;
}
/*
** Show information about ancestors of a baseline. Do this recursively
** to a depth of N. Return true if ancestors are shown and false if not.
*/
static void showAncestors(int pid, int depth, const char *zTitle){
Stmt q;
int cnt = 0;
db_prepare(&q,
"SELECT plink.pid, blob.uuid, datetime(event.mtime, 'localtime'),"
" coalesce(event.euser,event.user),"
" coalesce(event.comment,event.ecomment)"
" FROM plink, blob, event"
" WHERE plink.cid=%d"
" AND blob.rid=plink.pid"
" AND event.objid=plink.pid"
" ORDER BY event.mtime DESC",
pid
);
while( db_step(&q)==SQLITE_ROW ){
int cid = db_column_int(&q, 0);
const char *zUuid = db_column_text(&q, 1);
const char *zDate = db_column_text(&q, 2);
const char *zUser = db_column_text(&q, 3);
const char *zCom = db_column_text(&q, 4);
cnt++;
if( cnt==1 ){
if( zTitle ){
@
}
@
}
}
/*
** Show information about baselines mentioned in the "leaves" table.
*/
static void showLeaves(void){
Stmt q;
int cnt = 0;
db_prepare(&q,
"SELECT blob.uuid, datetime(event.mtime, 'localtime'),"
" coalesce(event.euser, event.user),"
" coalesce(event.ecomment,event.comment)"
" FROM leaves, blob, event"
" WHERE blob.rid=leaves.rid"
" AND event.objid=leaves.rid"
" ORDER BY event.mtime DESC"
);
while( db_step(&q)==SQLITE_ROW ){
const char *zUuid = db_column_text(&q, 0);
const char *zDate = db_column_text(&q, 1);
const char *zUser = db_column_text(&q, 2);
const char *zCom = db_column_text(&q, 3);
cnt++;
if( cnt==1 ){
@
}
@
}
}
/*
** Show information about all tags on a given node.
*/
static void showTags(int rid, const char *zNotGlob){
Stmt q;
int cnt = 0;
db_prepare(&q,
"SELECT tag.tagid, tagname, srcid, blob.uuid, value,"
" datetime(tagxref.mtime,'localtime'), tagtype"
" FROM tagxref JOIN tag ON tagxref.tagid=tag.tagid"
" LEFT JOIN blob ON blob.rid=tagxref.srcid"
" WHERE tagxref.rid=%d AND tagname NOT GLOB '%s'"
" ORDER BY tagname", rid, zNotGlob
);
while( db_step(&q)==SQLITE_ROW ){
const char *zTagname = db_column_text(&q, 1);
int srcid = db_column_int(&q, 2);
const char *zUuid = db_column_text(&q, 3);
const char *zValue = db_column_text(&q, 4);
const char *zDate = db_column_text(&q, 5);
int tagtype = db_column_int(&q, 6);
cnt++;
if( cnt==1 ){
@
}
@
}
}
/*
** WEBPAGE: vinfo
** URL: /vinfo?name=RID|UUID
**
** Return information about a baseline
*/
void vinfo_page(void){
Stmt q;
int rid;
int isLeaf;
login_check_credentials();
if( !g.okRead ){ login_needed(); return; }
rid = name_to_rid(PD("name","0"));
if( rid==0 ){
style_header("Baseline Information Error");
@ No such object: %h(g.argv[2])
style_footer();
return;
}
isLeaf = !db_exists("SELECT 1 FROM plink WHERE pid=%d", rid);
db_prepare(&q,
"SELECT uuid, datetime(mtime, 'localtime'), user, comment"
" FROM blob, event"
" WHERE blob.rid=%d"
" AND event.objid=%d",
rid, rid
);
if( db_step(&q)==SQLITE_ROW ){
const char *zUuid = db_column_text(&q, 0);
char *zTitle = mprintf("Baseline [%.10s]", zUuid);
char *zEUser, *zEComment;
const char *zUser;
const char *zComment;
style_header(zTitle);
login_anonymous_available();
free(zTitle);
zEUser = db_text(0,
"SELECT value FROM tagxref WHERE tagid=%d AND rid=%d",
TAG_USER, rid);
zEComment = db_text(0,
"SELECT value FROM tagxref WHERE tagid=%d AND rid=%d",
TAG_COMMENT, rid);
zUser = db_column_text(&q, 2);
zComment = db_column_text(&q, 3);
@
@
@ SHA1 Hash: %s(zUuid)
if( g.okSetup ){
@ Date: %s(db_column_text(&q, 1))
}
if( zEUser ){
@ Record ID: %d(rid)
@ Edited User: %h(zEUser)
}else{
@ Original User: %h(zUser)
}
if( zEComment ){
@ User: %h(zUser)
@ Edited Comment: %w(zEComment)
}else{
@ Original Comment: %w(zComment)
}
@
if( g.okHistory ){
@ Comment: %w(zComment)
@ Timelines:
@ ancestors
@ | descendants
@ | both
@
}
@ Commands:
@
@ diff
@ | ZIP archive
@ | manifest
if( g.okWrite ){
@ | edit
}
@
@
Version: | %s(zUuid) |
---|---|
Date: | %s(db_column_text(&q, 2)) |
Record ID: | %d(rid) |
Original User: | %s(db_column_text(&q, 3)) |
Commands: | @/* @ diff | */ @ history @ | raw-text @ | @
@
| ||||
%s(&zDate[11]) | @@ | hyperlink_to_uuid(zVers); @ %h(zCom) (By: %h(zUser)) @ Id: %s(zUuid)/%d(frid) if( g.okHistory ){ @ [view] if( fpid ){ @ [diff] } @ @ [annotate] @ | } } db_finalize(&q); @
} db_finalize(&q); style_footer(); } /* ** Write a description of an object to the www reply. ** ** If the object is a file then mention: ** ** * It's uuid ** * All its filenames ** * The baselines it was checked-in on, with times and users ** ** If the object is a manifest, then mention: ** ** * It's uuid ** * date of check-in ** * Comment & user */ static void object_description(int rid, int linkToView){ Stmt q; int cnt = 0; int nWiki = 0; db_prepare(&q, "SELECT filename.name, datetime(event.mtime), substr(a.uuid,1,10)," " coalesce(event.comment,event.ecomment)," " coalesce(event.euser,event.user)," " b.uuid" " FROM mlink, filename, event, blob a, blob b" " WHERE filename.fnid=mlink.fnid" " AND event.objid=mlink.mid" " AND a.rid=mlink.fid" " AND b.rid=mlink.mid" " AND mlink.fid=%d", rid ); while( db_step(&q)==SQLITE_ROW ){ const char *zName = db_column_text(&q, 0); const char *zDate = db_column_text(&q, 1); const char *zFuuid = db_column_text(&q, 2); const char *zCom = db_column_text(&q, 3); const char *zUser = db_column_text(&q, 4); const char *zVers = db_column_text(&q, 5); @ File %h(zName) @ uuid %s(zFuuid) part of check-in hyperlink_to_uuid(zVers); @ %w(zCom) by %h(zUser) on %s(zDate) cnt++; } db_finalize(&q); db_prepare(&q, "SELECT substr(tagname, 6, 10000), datetime(event.mtime)," " coalesce(event.euser, event.user), uuid" " FROM tagxref, tag, event, blob" " WHERE tagxref.rid=%d" " AND tag.tagid=tagxref.tagid" " AND tag.tagname LIKE 'wiki-%%'" " AND event.objid=tagxref.rid" " AND blob.rid=tagxref.rid", rid ); while( db_step(&q)==SQLITE_ROW ){ const char *zPagename = db_column_text(&q, 0); const char *zDate = db_column_text(&q, 1); const char *zUser = db_column_text(&q, 2); const char *zUuid = db_column_text(&q, 3); @ Wiki page @ [%h(zPagename)] @ uuid %s(zUuid) by %h(zUser) on %s(zDate) nWiki++; cnt++; } db_finalize(&q); if( nWiki==0 ){ db_prepare(&q, "SELECT datetime(mtime), user, comment, uuid, type" " FROM event, blob" " WHERE event.objid=%d" " AND blob.rid=%d", rid, rid ); while( db_step(&q)==SQLITE_ROW ){ const char *zDate = db_column_text(&q, 0); const char *zUuid = db_column_text(&q, 3); const char *zUser = db_column_text(&q, 1); const char *zCom = db_column_text(&q, 2); const char *zType = db_column_text(&q, 4); if( zType[0]=='w' ){ @ Wiki edit }else if( zType[0]=='t' ){ @ Ticket change }else if( zType[0]=='c' ){ @ Manifest of baseline }else{ @ Control file referencing } hyperlink_to_uuid(zUuid); @ %w(zCom) by %h(zUser) on %s(zDate) cnt++; } db_finalize(&q); } if( cnt==0 ){ char *zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); @ Control file %s(zUuid). }else if( linkToView ){ @ [view] } } /* ** WEBPAGE: fdiff ** ** Two arguments, v1 and v2, are integers. Show the difference between ** the two records. */ void diff_page(void){ int v1 = name_to_rid(PD("v1","0")); int v2 = name_to_rid(PD("v2","0")); Blob c1, c2, diff; login_check_credentials(); if( !g.okRead ){ login_needed(); return; } style_header("Diff"); @append_diff(pid, fid); @
object_description(v1, 1); @@
object_description(v2, 1); @@
blob_reset(&diff); style_footer(); } /* ** WEBPAGE: artifact ** URL: /artifact?name=UUID ** ** Show the complete content of a file identified by UUID ** as preformatted text. */ void artifact_page(void){ int rid; Blob content; rid = name_to_rid(PD("name","0")); login_check_credentials(); if( !g.okRead ){ login_needed(); return; } if( rid==0 ){ cgi_redirect("/home"); } if( g.okAdmin ){ const char *zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid); if( db_exists("SELECT 1 FROM shun WHERE uuid='%s'", zUuid) ){ style_submenu_element("Unshun","Unshun", "%s/shun?uuid=%s&sub=1", g.zTop, zUuid); }else{ style_submenu_element("Shun","Shun", "%s/shun?shun=%s#addshun", g.zTop, zUuid); } } style_header("Artifact Content"); @content_get(v1, &c1); content_get(v2, &c2); blob_zero(&diff); text_diff(&c1, &c2, &diff, 4); blob_reset(&c1); blob_reset(&c2); @ %h(blob_str(&diff)) @
object_description(rid, 0); @@
blob_reset(&content); style_footer(); } /* ** Return TRUE if the given BLOB contains a newline character. */ static int contains_newline(Blob *p){ const char *z = blob_str(p); while( *z ){ if( *z=='\n' ) return 1; z++; } return 0; } /* ** WEBPAGE: tinfo ** URL: /tinfo?name=UUID ** ** Show the details of a ticket change control artifact. */ void tinfo_page(void){ int rid; Blob content; char *zDate; int i; const char *zUuid; char zTktName[20]; const char *z; Manifest m; login_check_credentials(); if( !g.okRdTkt ){ login_needed(); return; } rid = name_to_rid(PD("name","0")); if( rid==0 ){ fossil_redirect_home(); } zUuid = db_text("", "SELECT uuid FROM blob WHERE rid=%d", rid); if( g.okAdmin ){ if( db_exists("SELECT 1 FROM shun WHERE uuid='%s'", zUuid) ){ style_submenu_element("Unshun","Unshun", "%s/shun?uuid=%s&sub=1", g.zTop, zUuid); }else{ style_submenu_element("Shun","Shun", "%s/shun?shun=%s#addshun", g.zTop, zUuid); } } content_get(rid, &content); if( manifest_parse(&m, &content)==0 ){ fossil_redirect_home(); } if( m.type!=CFTYPE_TICKET ){ fossil_redirect_home(); } style_header("Ticket Change Details"); zDate = db_text(0, "SELECT datetime(%.12f)", m.rDate); memcpy(zTktName, m.zTicketUuid, 10); zTktName[10] = 0; @content_get(rid, &content); @ %h(blob_str(&content)) @
By %h(m.zUser) on %s(zDate). See also: @ artifact content, and @ ticket history @
@ @Appended to %h(&z[1]):
wiki_convert(&val, 0, 0); @}else if( blob_size(&val)<=50 && contains_newline(&val) ){ @
Change %h(z) to:
wiki_convert(&val, 0, 0); @
Change %h(z) to "%h(blob_str(&val))"
No such object: %h(zName)
style_footer(); return; } if( db_exists("SELECT 1 FROM mlink WHERE mid=%d", rid) ){ vinfo_page(); }else if( db_exists("SELECT 1 FROM mlink WHERE fid=%d", rid) ){ finfo_page(); }else if( db_exists("SELECT 1 FROM tagxref JOIN tag USING(tagid)" " WHERE rid=%d AND tagname LIKE 'wiki-%%'", rid) ){ winfo_page(); }else if( db_exists("SELECT 1 FROM tagxref JOIN tag USING(tagid)" " WHERE rid=%d AND tagname LIKE 'tkt-%%'", rid) ){ tinfo_page(); }else { artifact_page(); } } /* ** WEBPAGE: vedit ** URL: vedit?r=RID&c=NEWCOMMENT&u=NEWUSER ** ** Present a dialog for updating properties of a baseline: ** ** * The check-in user ** * The check-in comment ** * The background color. */ void vedit_page(void){ int rid; const char *zComment; const char *zNewComment; const char *zUser; const char *zNewUser; char *zUuid; Blob comment; login_check_credentials(); if( !g.okWrite ){ login_needed(); return; } rid = atoi(PD("r","0")); zComment = db_text(0, "SELECT coalesce(ecomment,comment)" " FROM event WHERE objid=%d", rid); if( zComment==0 ) fossil_redirect_home(); zNewComment = PD("c",zComment); zUser = db_text(0, "SELECT coalesce(euser,user)" " FROM event WHERE objid=%d", rid); if( zUser==0 ) fossil_redirect_home(); zNewUser = PD("u",zUser); zUuid = db_text(0, "SELECT uuid FROM blob WHERE rid=%d", rid); if( P("cancel") ){ cgi_redirectf("vinfo?name=%d", rid); } if( P("apply") ){ Blob ctrl; char *zDate; int nChng = 0; blob_zero(&ctrl); zDate = db_text(0, "SELECT datetime('now')"); zDate[10] = 'T'; blob_appendf(&ctrl, "D %s\n", zDate); if( strcmp(zComment,zNewComment)!=0 ){ nChng++; blob_appendf(&ctrl, "T +comment %s %F\n", zUuid, zNewComment); } if( strcmp(zUser,zNewUser)!=0 ){ nChng++; blob_appendf(&ctrl, "T +user %s %F\n", zUuid, zNewUser); } if( nChng>0 ){ int nrid; Blob cksum; blob_appendf(&ctrl, "U %F\n", g.zLogin); md5sum_blob(&ctrl, &cksum); blob_appendf(&ctrl, "Z %b\n", &cksum); db_begin_transaction(); nrid = content_put(&ctrl, 0, 0); manifest_crosslink(nrid, &ctrl); db_end_transaction(0); } cgi_redirectf("vinfo?name=%d", rid); } blob_zero(&comment); blob_append(&comment, zNewComment, -1); zUuid[10] = 0; style_header("Edit Baseline [%s]", zUuid); @Make changes to the User and Comment for baseline @ [%s(zUuid)] then press the @ "Apply Changes" button.
@ style_footer(); }