monotone-commits-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Monotone-commits-diffs] net.venge.monotone: d2c56ab00604e0e40d76125b8b3


From: code
Subject: [Monotone-commits-diffs] net.venge.monotone: d2c56ab00604e0e40d76125b8b320211e62c1822
Date: Sun, 9 Dec 2012 20:02:40 +0100 (CET)

revision:            d2c56ab00604e0e40d76125b8b320211e62c1822
date:                2012-12-09T19:00:37
author:              Richard Hopkins <address@hidden>
branch:              net.venge.monotone
changelog:
Add 'filemodehint' parameter to 'temp_file' and 'write_to_temporary_file'

When writing files for external tools, such as loading the user's 3-way merge
tool to resolve a merge conflict, we want the contents to be exact; both for
presentation and the resulting file which will be used for the commit.

In other cases, like adding a 'comment' cert, we still work as before and
allow possible line-ending sanitisation.

manifest:
format_version "1"

new_manifest [95fca80c96fc819b40dbecde893ac2b289a54529]

old_revision [a7c3a1d9de1ba7a62c9dd9efee17252234bb502c]

patch "src/std_hooks.lua"
 from [ada658bd275399032411e0f520d9900bad966dc4]
   to [a594ce3c5f5377c8d44c6781d41444a14a64cbb6]
============================================================
--- src/std_hooks.lua	ada658bd275399032411e0f520d9900bad966dc4
+++ src/std_hooks.lua	a594ce3c5f5377c8d44c6781d41444a14a64cbb6
@@ -10,7 +10,7 @@
 -- this is the standard set of lua hooks for monotone;
 -- user-provided files can override it or add to it.
 
-function temp_file(namehint)
+function temp_file(namehint, filemodehint)
    local tdir
    tdir = os.getenv("TMPDIR")
    if tdir == nil then tdir = os.getenv("TMP") end
@@ -22,8 +22,14 @@ function temp_file(namehint)
    else
       filename = string.format("%s/mtn.%s.XXXXXX", tdir, namehint)
    end
+   local filemode
+   if filemodehint == nil then
+      filemode = "r+"
+   else
+      filemode = filemodehint
+   end
    local name = mkstemp(filename)
-   local file = io.open(name, "r+")
+   local file = io.open(name, filemode)
    return file, name
 end
 
@@ -826,8 +832,8 @@ mergers.opendiff = {
    wanted = function () return true end
 }
 
-function write_to_temporary_file(data, namehint)
-   tmp, filename = temp_file(namehint)
+function write_to_temporary_file(data, namehint, filemodehint)
+   tmp, filename = temp_file(namehint, filemodehint)
    if (tmp == nil) then
       return nil
    end;
@@ -914,10 +920,10 @@ function merge3 (anc_path, left_path, ri
    tbl.rfile = nil
    tbl.outfile = nil
    tbl.meld_exists = false
-   tbl.lfile = write_to_temporary_file (left, "left")
-   tbl.afile = write_to_temporary_file (ancestor, "ancestor")
-   tbl.rfile = write_to_temporary_file (right, "right")
-   tbl.outfile = write_to_temporary_file ("", "merged")
+   tbl.lfile = write_to_temporary_file (left, "left", "rb+")
+   tbl.afile = write_to_temporary_file (ancestor, "ancestor", "rb+")
+   tbl.rfile = write_to_temporary_file (right, "right", "rb+")
+   tbl.outfile = write_to_temporary_file ("", "merged", "rb+")
 
    if tbl.lfile ~= nil and tbl.rfile ~= nil and tbl.afile ~= nil and tbl.outfile ~= nil
    then
@@ -1055,8 +1061,8 @@ function external_diff(file_path, data_o
 
 -- default external diff, works for gnu diff
 function external_diff(file_path, data_old, data_new, is_binary, diff_args, rev_old, rev_new)
-   local old_file = write_to_temporary_file(data_old);
-   local new_file = write_to_temporary_file(data_new);
+   local old_file = write_to_temporary_file(data_old, nil, "rb+");
+   local new_file = write_to_temporary_file(data_new, nil, "rb+");
 
    if diff_args == nil then diff_args = external_diff_default_args end
    execute("diff", diff_args, "--label", file_path .. "\told", old_file, "--label", file_path .. "\tnew", new_file);

reply via email to

[Prev in Thread] Current Thread [Next in Thread]