Check-in [bfb4d414dd]
Not logged in
Overview

SHA1 Hash:bfb4d414dda55cc41956eefd176eada6bbc3ac75
Date: 2008-05-15 20:26:25
User: stephan
Comment:minor refactorings to the wiki commands
Timelines: ancestors | descendants | both | trunk
Other Links: files | ZIP archive | manifest

Tags And Properties
Changes
[hide diffs]

Modified src/wiki.c from [52056439c2] to [02c5204f87].

@@ -1,7 +1,8 @@
 /*
 ** Copyright (c) 2007 D. Richard Hipp
+** Copyright (c) 2008 Stephan Beal
 **
 ** 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.
 **
@@ -599,20 +600,15 @@
   @ </ol>
   style_footer();
 }
 
 /*
-**  wiki_cmd_commit() is the implementation of "wiki commit ...".
+** wiki_cmd_commit() is the implementation of "wiki commit ...".
 **
 ** As arguments it expects:
 **
 ** zPageName = the wiki entry's name.
-**
-** rid = record ID for the zPageName entry. This func SHOULD deduce
-** this from zPageName, but the code which calls this func already has
-** the rid, so we pass it along here. If it does not match the entry
-** for zPageName then Undefined Behaviour.
 **
 ** in = input file. The file is read until EOF but is not closed
 ** by this function (it might be stdin!).
 **
 ** Returns 0 on error, non-zero on success.
@@ -620,19 +616,33 @@
 ** TODOs:
 ** - take EITHER zPageName OR rid. We don't need both.
 ** - make use of the return value. Add more error checking.
 ** - give the uuid back to the caller so it can be shown
 **   in the status output. ("committed version XXXXX of page ...")
+** - return some status telling the user if there were no diffs
+** (i.e. no commit). How can we find this out?
 */
-int wiki_cmd_commit( char const * zPageName, int rid, FILE * in )
+int wiki_cmd_commit( char const * zPageName, FILE * in )
 {
   Blob wiki;              /* Wiki page content */
   Blob content;           /* read-in content */
   Blob cksum;             /* wiki checksum */
+  int rid;                /* rid of existing entry. */
   int nrid;               /* not really sure */
   char * zDate;           /* timestamp */
   char * zUuid;           /* uuid for rid */
+
+  rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
+	       " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
+	       " ORDER BY x.mtime DESC LIMIT 1",
+	       zPageName
+	       );
+  if( ! rid ){
+    fossil_fatal("wiki commit NewEntry not yet implemented.");
+  }
+
+
   blob_read_from_channel( &content, in, -1 );
   // ^^^ Reminder: we should allow empty (zero-byte) entries, so don't exit
   // if read returns 0.
   blob_zero(&wiki);
   zDate = db_text(0, "SELECT datetime('now')");
@@ -753,25 +763,16 @@
     for(i=strlen(zBody); i>0 && isspace(zBody[i-1]); i--){}
     printf("%.*s\n", i, zBody);
     return;
   }else
   if( strncmp(g.argv[2],"commit",n)==0 ){
-    int rid;
     char *zPageName;
     if( g.argc!=4 ){
       usage("commit PAGENAME");
     }
     zPageName = g.argv[3];
-    rid = db_int(0, "SELECT x.rid FROM tag t, tagxref x"
-                 " WHERE x.tagid=t.tagid AND t.tagname='wiki-%q'"
-		 " ORDER BY x.mtime DESC LIMIT 1",
-		 zPageName
-		 );
-    if( ! rid ){
-        fossil_fatal("wiki commit NewEntry not yet implemented.");
-    }
-    wiki_cmd_commit( zPageName, rid, stdin );
+    wiki_cmd_commit( zPageName, stdin );
     printf("Committed wiki page %s.\n", zPageName);
   }else
   if( strncmp(g.argv[2],"delete",n)==0 ){
     if( g.argc!=5 ){
       usage("delete PAGENAME");
@@ -794,7 +795,7 @@
     goto wiki_cmd_usage;
   }
   return;
 
 wiki_cmd_usage:
-  usage("delete|export|commit|list ...");
+  usage("export|commit|list ...");
 }