Fossil
Check-in [2582ecf2ed]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview

SHA1 Hash:2582ecf2edc2d0d9c5818dc481bc7b330381716d
Date: 2010-03-11 03:29:57
User: drh
Comment:Add a "zip" command for generating a ZIP archive of a check-in from the command-line.

Tags And Properties
Changes
[hide diffs]

Changes to src/zip.c

@@ -378,23 +378,42 @@
   blob_reset(&filename);
   zip_close(pZip);
 }
 
 /*
-** COMMAND: test-baseline-zip
+** COMMAND: zip
+**
+** Usage: %fossil zip VERSION OUTPUTFILE [--name DIRECTORYNAME]
 **
-** Generate a ZIP archive for a specified baseline.
+** Generate a ZIP archive for a specified version.  If the --name option is
+** used, it argument becomes the name of the top-level directory in the
+** resulting ZIP archive.  If --name is omitted, the top-level directory
+** named is derived from the project name, the check-in date and time, and
+** the artifact ID of the check-in.
 */
 void baseline_zip_cmd(void){
   int rid;
   Blob zip;
+  const char *zName;
+  zName = find_option("name", 0, 1);
+  db_find_and_open_repository(1);
   if( g.argc!=4 ){
-    usage("UUID ZIPFILE");
+    usage("VERSION OUTPUTFILE");
   }
-  db_must_be_within_tree();
   rid = name_to_rid(g.argv[2]);
-  zip_of_baseline(rid, &zip, g.argv[2]);
+  if( zName==0 ){
+    zName = db_text("default-name",
+       "SELECT replace(%Q,' ','_') "
+          " || strftime('_%%Y-%%m-%%d_%%H%%M%%S_', event.mtime) "
+          " || substr(blob.uuid, 1, 10)"
+       "  FROM event, blob"
+       " WHERE event.objid=%d"
+       "   AND blob.rid=%d",
+       db_get("project-name", "unnamed"), rid, rid
+    );
+  }
+  zip_of_baseline(rid, &zip, zName);
   blob_write_to_file(&zip, g.argv[3]);
 }
 
 /*
 ** WEBPAGE: zip