Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell Subversion to treat a file as a binary file?

Tags:

svn

How do I tell Subversion (svn) to treat a file as a binary file?

like image 484
Nick Avatar asked Sep 16 '08 15:09

Nick


People also ask

How does Subversion handle binary files?

If Subversion determines that the file is binary, the file receives an svn:mime-type property set to application/octet-stream. You can always override this by using the auto-props feature or by setting the property manually with svn propset . Subversion treats the following files as text: Files with no svn:mime-type.

How can a file be read as binary data?

You can open the file using open() method by passing b parameter to open it in binary mode and read the file bytes. open('filename', "rb") opens the binary file in read mode. b – To specify it's a binary file. No decoding of bytes to string attempt will be made.

How is a file stored in binary?

Serialisation is the process of converting an object (such as a dictionary of data) into binary sequences that can be stored in a file. When the file is accessed, the binary data is retrieved from the file and deserialised into objects that are exact copies of the original information.

How do you open a file for binary?

To open the Binary Editor on an existing file, go to menu File > Open > File, select the file you want to edit, then select the drop arrow next to the Open button, and choose Open With > Binary Editor.


2 Answers

It is possible to manually identify a file located within a repository as binary by using:

svn propset svn:mime-type application/octet-stream <filename> 

This is generally not necessary, as Subversion will attempt to determine whether a file is binary when the file is first added. If Subversion is incorrectly tagging a certain type as "text" when it should be treated as binary, it is possible to configure Subversion's auto-props feature to automatically tag that file with a non-text MIME type. Regardless of the properties configured on the file, Subversion still stores the file in a binary format within the repository.

If Subversion identifies the MIME type as a "text" type, it enables certain features which are not available on binary files, such as svn diff and svn blame. It also allows for automatic line ending conversion, which is configurable on a client-by-client basis.

For more information, see How does Subversion handle binary files?

like image 167
stormlash Avatar answered Oct 02 '22 10:10

stormlash


From page 367 of the Subversion book

In the most general sense, Subversion handles binary files more gracefully than CVS does. Because CVS uses RCS, it can only store successive full copies of a changing binary file. Subversion, however, expresses differences between files using a binary differencing algorithm, regardless of whether they contain textual or binary data. That means all files are stored differentially (compressed) in the repository.

CVS users have to mark binary files with -kb flags to prevent data from being garbled (due to keyword expansion and line-ending translations). They sometimes forget to do this.

Subversion takes the more paranoid route. First, it never performs any kind of keyword or line-ending translation unless you explicitly ask it to do so (see the section called “Keyword Substitution” and the section called “End-of-Line Character Sequences” for more details). By default, Subversion treats all file data as literal byte strings, and files are always stored in the repository in an untranslated state.

Second, Subversion maintains an internal notion of whether a file is “text” or “binary” data, but this notion is only extant in the working copy. During an svn update, Subversion will perform contextual merges on locally modified text files, but will not attempt to do so for binary files.

To determine whether a contextual merge is possible, Subversion examines the svn:mime-type property. If the file has no svn:mime-type property, or has a MIME type that is textual (e.g., text/*), Subversion assumes it is text. Otherwise, Subversion assumes the file is binary. Subversion also helps users by running a binary-detection algorithm in the svn import and svn add commands. These commands will make a good guess and then (possibly) set a binary svn:mime-type property on the file being added. (If Subversion guesses wrong, the user can always remove or hand-edit the property.)

Hand editing would be done by

svn propset svn:mime-type some/type filename.extension 
like image 42
Evil Andy Avatar answered Oct 02 '22 10:10

Evil Andy