[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Modifying a file in the repository without prior checkout

From: Markus Kuhn <Markus.Kuhn_at_cl.cam.ac.uk>
Date: 2007-06-27 13:10:32 CEST

I want to write a CGI script that allows users to edit text files in a
Subversion repository. The CGI script is to be written in Perl and can
call either the Perl Subversion API binding or the svn command line
tools. The Repository can only be reached via the svn+ssh protocol.

At the moment, the only solution that I have identified rather ugly,
namely

  - do a full -N checkout to a local disk directory
  - modify the single file in question on disk
  - commit
  - erase the working directory

This is far less than ideal, because

  - in a CGI script, I would rather not have to modify anything
    on the local file system (which only needs cleaning up afterwards,
    creates quota and security problems, etc.)

  - even a "svn checkout -N" will transfer all the other files
    in the (potentially huge) directory that do not actually want to
    modify in this transaction

Ideal would be a new svn command such as

  svn modify -r REV -m "..." URL

that reads from stdin (or from a file provided with -F) the new content
of the file at URL, and modifies (or adds) the file at that URL
accordingly.

Important detail: If option -r is present, the operation will fail
unless the existing file to be modified has the given HEAD revision REV
at the time of the commit. I can then use that mechanism to build my own
collision handling procedures that are suitable for an interactive CGI
editor. It is sufficient if "svn modify" just helps me to detect a collission.

For that purpose, it would also be useful to have an "svn youngest"
command, similar to "svnlook youngest", or to allow "svnlook youngest
URL". (In general, it would be great if all "svnlook" facilities were
available on URLs, and not only on repository paths. CGI scripts need
very similar information as hook scripts, but do not have direct access
to the repository.)

So what I would like to be able to do is essentially something like

  $URL='svn+ssh://.....';
  $REV = `svn youngest $URL`; # give me the HEAD revision number of the file
  $text = `svn cat -r $REV $URL`; # get that revision
  edit($text); # change it
  `svn merge -r $REV -m "CGI edit" $URL <<'$test' `; # commit the changes back
                                                      # via stdin, with collision
                                                      # detection

I've tried various things but they did not work. In particular, both
"svn import" and "svn copy" seem only to be able to *add* new files to a
repository, but not to modify existing ones. Deleting the old and adding
the new file seems less inefficient than a proper "M"odify transaction.

I was told that the WebDAV interface does support modifying files
without prior checkout, but I am restricted to the svn+ssh protocol in
this application.

Any suggestions, or anyone interested in seconding these suggestions as
a desired feature? I believe the functionality proposed above would make
it possible to write a lot of exciting new browser-based editing tools
for Subversion, and to use Subversion as the database engine in things
like browser-based content-management systems.

Thanks!

Markus

-- 
Markus Kuhn, Computer Laboratory, University of Cambridge
http://www.cl.cam.ac.uk/~mgk25/ || CB3 0FD, Great Britain
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Wed Jun 27 13:10:49 2007

This is an archived mail posted to the Subversion Users mailing list.