Edgewall Software
Modify

Opened 15 years ago

Closed 15 years ago

Last modified 14 years ago

#303 closed enhancement (fixed)

Get zip file with files changed in a changeset

Reported by: arnarb@… Owned by: Christopher Lenz
Priority: low Milestone: 0.9
Component: version control/changeset view Version: 0.8
Severity: normal Keywords: archive
Cc: Branch:
Release Notes:
API Changes:

Description (last modified by daniel)

I develop software (in PHP) that needs to be deployed frequently to a Windows machine. Normally, I would use patches, but since that's nonstandard for Windows I have created by hand zip files containing changed files for each version. I then unzip the file on the target machine so that changed files are overwritten.

It would be nice to be able to click a link on the changeset file and get in return a zip file containing the updated versions of changed/added files.

Following is a small patch for a preliminary implementation of this

Index: trac/Changeset.py
===================================================================
--- trac/Changeset.py   (revision 462)
+++ trac/Changeset.py   (working copy)
@@ -151,6 +151,45 @@
     def apply_textdelta(self, file_baton, base_checksum):
         self.print_diff (*file_baton)
 
+    def close(self): pass
+
+import zipfile
+class ZipDiffEditor (delta.Editor):
+    def __init__(self,old_root,new_root,rev,output):
+        self.old_root = old_root
+        self.new_root = new_root
+        self.rev = rev
+        self.output = output
+        self.zip = zipfile.ZipFile(output, 'w', zipfile.ZIP_DEFLATED)
+
+    def addFileToZip(self, path, file_pool):
+        fd = fs.file_contents(self.new_root, path, file_pool)
+        info = zipfile.ZipInfo()
+        info.filename = path
+        date = fs.revision_prop(fs.root_fs(self.new_root), self.rev, util.SVN_PROP_REVISION_DATE, file_pool)
+        date = util.svn_time_from_cstring(date, file_pool) / 1000000
+        date = time.localtime(date)
+        info.date_time = date[0:6]
+        info.compress_type = zipfile.ZIP_DEFLATED
+        data = ""
+        while 1:
+            chunk = util.svn_stream_read(fd, 512)
+            if not chunk:
+                break
+            data = data + chunk
+        self.zip.writestr(info, data)
+
+    def add_file(self, path, parent_baton, copyfrom_path,
+                 copyfrom_revision, file_pool):
+        self.addFileToZip(path, file_pool)
+    
+    def open_file(self, path, parent_baton, base_revision, file_pool):
+        self.addFileToZip(path, file_pool)
+
+    def close(self):
+        self.zip.close()
+
+
 class UnifiedDiffEditor(HtmlDiffEditor):
     """
     generates a unified diff of the changes for a given changeset.
@@ -199,6 +238,7 @@
         repos.svn_repos_dir_delta(old_root, '', '',
                                   new_root, '', e_ptr, e_baton, authz_cb,
                                   0, 1, 0, 1, pool)
+    editor.close()
     return output.getvalue()
 
 class Changeset (Module):
@@ -266,5 +306,13 @@
         self.req.end_headers()
         difftext = render_diffs(self.fs_ptr, int(self.rev), self.pool, UnifiedDiffEditor)
         self.req.write(difftext)
+
+    def display_zipdiff (self):
+        self.req.send_response(200)
+        self.req.send_header('Content-Type', 'application/zip')
+        #self.req.send_header('Content-Type', 'text/plain')
+        self.req.end_headers()
+        difftext = render_diffs(self.fs_ptr, int(self.rev), self.pool, ZipDiffEditor)
+        self.req.write(difftext)
         
         
Index: templates/changeset.cs
===================================================================
--- templates/changeset.cs      (revision 462)
+++ templates/changeset.cs      (working copy)
@@ -2,6 +2,7 @@
 <div id="page-content">
  <ul class="subheader-links">
    <li><a href="?format=diff">Download Diff</a></li>
+   <li><a href="?format=zipdiff">Download zip patch</a></li>
  </ul>
  <div id="main">
   <div id="main-content">

Attachments (0)

Change History (5)

comment:1 by daniel, 15 years ago

Milestone: 0.8
Priority: normallow

This seems like a pretty cool idea.

comment:2 by daniel, 15 years ago

If applied, there should of course be a tar.(gz|bz2) option as well.

comment:3 by daniel, 15 years ago

Description: modified (diff)
Milestone: 0.80.9

comment:4 by Christopher Lenz, 15 years ago

Owner: changed from Jonas Borgström to Christopher Lenz
Status: newassigned
Version: devel0.8

I'm working on this.

Personally, I'm not sure whether tar support should be added, especially considering the use case reported here:

Normally, I would use patches, but since that's nonstandard for Windows I have created by hand zip files containing changed files for each version.

Since tar is mostly a unix thing, folks could also just use the diff. And it's not like zip wasn't available on every system these days ;-)

Tar support would also depend on the tarfile API that was apparently only added in python 2.3 (while zipfile has been available since 1.6).

comment:5 by Christopher Lenz, 15 years ago

Keywords: archive added
Resolution: fixed
Status: assignedclosed

ZIP support is implemented in [1101]. Let's open a new ticket for Tar support if the need surfaces.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christopher Lenz.
The resolution will be deleted. Next status will be 'reopened'.
to as closed The owner will be changed from Christopher Lenz to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.