{"action":"created","comment":{"url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/pulls/comments/48695602","id":48695602,"diff_hunk":"@@ -85,21 +85,38 @@ pub fn write_file(text: &StringBuffer,\n         }\n     }\n \n+    fn diff(text: &StringBuffer,\n+            filename: &str,\n+            config: &Config)\n+            -> Result<Vec<Mismatch>, io::Error> {\n+        let mut f = try!(File::open(filename));\n+        let mut ori_text = String::new();\n+        try!(f.read_to_string(&mut ori_text));\n+        let mut v = Vec::new();\n+        try!(write_system_newlines(&mut v, text, config));\n+        let fmt_text = String::from_utf8(v).unwrap();\n+        Ok(make_diff(&ori_text, &fmt_text, 3))\n+    }\n+\n     match mode {\n         WriteMode::Replace => {\n-            // Do a little dance to make writing safer - write to a temp file\n-            // rename the original to a .bk, then rename the temp file to the\n-            // original.\n-            let tmp_name = filename.to_owned() + \".tmp\";\n-            let bk_name = filename.to_owned() + \".bk\";\n-            {\n-                // Write text to temp file\n-                let tmp_file = try!(File::create(&tmp_name));\n-                try!(write_system_newlines(tmp_file, text, config));\n-            }\n+            if let Ok(diff) = diff(text, filename, config) {\n+                if diff.len() > 0 {","path":"src/filemap.rs","position":39,"original_position":39,"commit_id":"08f91bdcebfe996e2cabd123a8a9e637f1fd497b","original_commit_id":"08f91bdcebfe996e2cabd123a8a9e637f1fd497b","user":{"login":"svmnotn","id":12618337,"avatar_url":"https://avatars.githubusercontent.com/u/12618337?v=3","gravatar_id":"","url":"https://api.github.com/users/svmnotn","html_url":"https://github.com/svmnotn","followers_url":"https://api.github.com/users/svmnotn/followers","following_url":"https://api.github.com/users/svmnotn/following{/other_user}","gists_url":"https://api.github.com/users/svmnotn/gists{/gist_id}","starred_url":"https://api.github.com/users/svmnotn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svmnotn/subscriptions","organizations_url":"https://api.github.com/users/svmnotn/orgs","repos_url":"https://api.github.com/users/svmnotn/repos","events_url":"https://api.github.com/users/svmnotn/events{/privacy}","received_events_url":"https://api.github.com/users/svmnotn/received_events","type":"User","site_admin":false},"body":"forgot that existed...","created_at":"2016-01-03T18:34:54Z","updated_at":"2016-01-03T18:34:54Z","html_url":"https://github.com/rust-lang-nursery/rustfmt/pull/740#discussion_r48695602","pull_request_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/pulls/740","_links":{"self":{"href":"https://api.github.com/repos/rust-lang-nursery/rustfmt/pulls/comments/48695602"},"html":{"href":"https://github.com/rust-lang-nursery/rustfmt/pull/740#discussion_r48695602"},"pull_request":{"href":"https://api.github.com/repos/rust-lang-nursery/rustfmt/pulls/740"}}},"pull_request":{"url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/pulls/740","id":54918639,"html_url":"https://github.com/rust-lang-nursery/rustfmt/pull/740","diff_url":"https://github.com/rust-lang-nursery/rustfmt/pull/740.diff","patch_url":"https://github.com/rust-lang-nursery/rustfmt/pull/740.patch","issue_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/issues/740","number":740,"state":"open","locked":false,"title":"stop creating bk files if there are no changes. Fixes #733","user":{"login":"svmnotn","id":12618337,"avatar_url":"https://avatars.githubusercontent.com/u/12618337?v=3","gravatar_id":"","url":"https://api.github.com/users/svmnotn","html_url":"https://github.com/svmnotn","followers_url":"https://api.github.com/users/svmnotn/followers","following_url":"https://api.github.com/users/svmnotn/following{/other_user}","gists_url":"https://api.github.com/users/svmnotn/gists{/gist_id}","starred_url":"https://api.github.com/users/svmnotn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svmnotn/subscriptions","organizations_url":"https://api.github.com/users/svmnotn/orgs","repos_url":"https://api.github.com/users/svmnotn/repos","events_url":"https://api.github.com/users/svmnotn/events{/privacy}","received_events_url":"https://api.github.com/users/svmnotn/received_events","type":"User","site_admin":false},"body":"I'm open to any comments on how to do this in a better way","created_at":"2016-01-03T04:22:52Z","updated_at":"2016-01-03T18:34:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0859e3df4aa5051154857161713d6de1f164d4eb","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/pulls/740/commits","review_comments_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/pulls/740/comments","review_comment_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/pulls/comments{/number}","comments_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/issues/740/comments","statuses_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/statuses/08f91bdcebfe996e2cabd123a8a9e637f1fd497b","head":{"label":"svmnotn:less_tmp_files","ref":"less_tmp_files","sha":"08f91bdcebfe996e2cabd123a8a9e637f1fd497b","user":{"login":"svmnotn","id":12618337,"avatar_url":"https://avatars.githubusercontent.com/u/12618337?v=3","gravatar_id":"","url":"https://api.github.com/users/svmnotn","html_url":"https://github.com/svmnotn","followers_url":"https://api.github.com/users/svmnotn/followers","following_url":"https://api.github.com/users/svmnotn/following{/other_user}","gists_url":"https://api.github.com/users/svmnotn/gists{/gist_id}","starred_url":"https://api.github.com/users/svmnotn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svmnotn/subscriptions","organizations_url":"https://api.github.com/users/svmnotn/orgs","repos_url":"https://api.github.com/users/svmnotn/repos","events_url":"https://api.github.com/users/svmnotn/events{/privacy}","received_events_url":"https://api.github.com/users/svmnotn/received_events","type":"User","site_admin":false},"repo":{"id":48872559,"name":"rustfmt","full_name":"svmnotn/rustfmt","owner":{"login":"svmnotn","id":12618337,"avatar_url":"https://avatars.githubusercontent.com/u/12618337?v=3","gravatar_id":"","url":"https://api.github.com/users/svmnotn","html_url":"https://github.com/svmnotn","followers_url":"https://api.github.com/users/svmnotn/followers","following_url":"https://api.github.com/users/svmnotn/following{/other_user}","gists_url":"https://api.github.com/users/svmnotn/gists{/gist_id}","starred_url":"https://api.github.com/users/svmnotn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/svmnotn/subscriptions","organizations_url":"https://api.github.com/users/svmnotn/orgs","repos_url":"https://api.github.com/users/svmnotn/repos","events_url":"https://api.github.com/users/svmnotn/events{/privacy}","received_events_url":"https://api.github.com/users/svmnotn/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/svmnotn/rustfmt","description":"Format Rust code","fork":true,"url":"https://api.github.com/repos/svmnotn/rustfmt","forks_url":"https://api.github.com/repos/svmnotn/rustfmt/forks","keys_url":"https://api.github.com/repos/svmnotn/rustfmt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/svmnotn/rustfmt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/svmnotn/rustfmt/teams","hooks_url":"https://api.github.com/repos/svmnotn/rustfmt/hooks","issue_events_url":"https://api.github.com/repos/svmnotn/rustfmt/issues/events{/number}","events_url":"https://api.github.com/repos/svmnotn/rustfmt/events","assignees_url":"https://api.github.com/repos/svmnotn/rustfmt/assignees{/user}","branches_url":"https://api.github.com/repos/svmnotn/rustfmt/branches{/branch}","tags_url":"https://api.github.com/repos/svmnotn/rustfmt/tags","blobs_url":"https://api.github.com/repos/svmnotn/rustfmt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/svmnotn/rustfmt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/svmnotn/rustfmt/git/refs{/sha}","trees_url":"https://api.github.com/repos/svmnotn/rustfmt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/svmnotn/rustfmt/statuses/{sha}","languages_url":"https://api.github.com/repos/svmnotn/rustfmt/languages","stargazers_url":"https://api.github.com/repos/svmnotn/rustfmt/stargazers","contributors_url":"https://api.github.com/repos/svmnotn/rustfmt/contributors","subscribers_url":"https://api.github.com/repos/svmnotn/rustfmt/subscribers","subscription_url":"https://api.github.com/repos/svmnotn/rustfmt/subscription","commits_url":"https://api.github.com/repos/svmnotn/rustfmt/commits{/sha}","git_commits_url":"https://api.github.com/repos/svmnotn/rustfmt/git/commits{/sha}","comments_url":"https://api.github.com/repos/svmnotn/rustfmt/comments{/number}","issue_comment_url":"https://api.github.com/repos/svmnotn/rustfmt/issues/comments{/number}","contents_url":"https://api.github.com/repos/svmnotn/rustfmt/contents/{+path}","compare_url":"https://api.github.com/repos/svmnotn/rustfmt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/svmnotn/rustfmt/merges","archive_url":"https://api.github.com/repos/svmnotn/rustfmt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/svmnotn/rustfmt/downloads","issues_url":"https://api.github.com/repos/svmnotn/rustfmt/issues{/number}","pulls_url":"https://api.github.com/repos/svmnotn/rustfmt/pulls{/number}","milestones_url":"https://api.github.com/repos/svmnotn/rustfmt/milestones{/number}","notifications_url":"https://api.github.com/repos/svmnotn/rustfmt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/svmnotn/rustfmt/labels{/name}","releases_url":"https://api.github.com/repos/svmnotn/rustfmt/releases{/id}","created_at":"2016-01-01T07:46:42Z","updated_at":"2016-01-01T07:46:43Z","pushed_at":"2016-01-03T04:22:09Z","git_url":"git://github.com/svmnotn/rustfmt.git","ssh_url":"git@github.com:svmnotn/rustfmt.git","clone_url":"https://github.com/svmnotn/rustfmt.git","svn_url":"https://github.com/svmnotn/rustfmt","homepage":null,"size":1349,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"rust-lang-nursery:master","ref":"master","sha":"fe58ff1a155667ea3a3fe50123a1dc85ae00a766","user":{"login":"rust-lang-nursery","id":14631425,"avatar_url":"https://avatars.githubusercontent.com/u/14631425?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang-nursery","html_url":"https://github.com/rust-lang-nursery","followers_url":"https://api.github.com/users/rust-lang-nursery/followers","following_url":"https://api.github.com/users/rust-lang-nursery/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang-nursery/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang-nursery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang-nursery/subscriptions","organizations_url":"https://api.github.com/users/rust-lang-nursery/orgs","repos_url":"https://api.github.com/users/rust-lang-nursery/repos","events_url":"https://api.github.com/users/rust-lang-nursery/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang-nursery/received_events","type":"Organization","site_admin":false},"repo":{"id":31830551,"name":"rustfmt","full_name":"rust-lang-nursery/rustfmt","owner":{"login":"rust-lang-nursery","id":14631425,"avatar_url":"https://avatars.githubusercontent.com/u/14631425?v=3","gravatar_id":"","url":"https://api.github.com/users/rust-lang-nursery","html_url":"https://github.com/rust-lang-nursery","followers_url":"https://api.github.com/users/rust-lang-nursery/followers","following_url":"https://api.github.com/users/rust-lang-nursery/following{/other_user}","gists_url":"https://api.github.com/users/rust-lang-nursery/gists{/gist_id}","starred_url":"https://api.github.com/users/rust-lang-nursery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rust-lang-nursery/subscriptions","organizations_url":"https://api.github.com/users/rust-lang-nursery/orgs","repos_url":"https://api.github.com/users/rust-lang-nursery/repos","events_url":"https://api.github.com/users/rust-lang-nursery/events{/privacy}","received_events_url":"https://api.github.com/users/rust-lang-nursery/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/rust-lang-nursery/rustfmt","description":"Format Rust code","fork":false,"url":"https://api.github.com/repos/rust-lang-nursery/rustfmt","forks_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/forks","keys_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/keys{/key_id}","collaborators_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/teams","hooks_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/hooks","issue_events_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/issues/events{/number}","events_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/events","assignees_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/assignees{/user}","branches_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/branches{/branch}","tags_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/tags","blobs_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/git/refs{/sha}","trees_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/git/trees{/sha}","statuses_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/statuses/{sha}","languages_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/languages","stargazers_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/stargazers","contributors_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/contributors","subscribers_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/subscribers","subscription_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/subscription","commits_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/commits{/sha}","git_commits_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/git/commits{/sha}","comments_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/comments{/number}","issue_comment_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/issues/comments{/number}","contents_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/contents/{+path}","compare_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/compare/{base}...{head}","merges_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/merges","archive_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/downloads","issues_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/issues{/number}","pulls_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/pulls{/number}","milestones_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/milestones{/number}","notifications_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/labels{/name}","releases_url":"https://api.github.com/repos/rust-lang-nursery/rustfmt/releases{/id}","created_at":"2015-03-07T22:51:56Z","updated_at":"2016-01-02T16:39:47Z","pushed_at":"2016-01-03T04:22:52Z","git_url":"git://github.com/rust-lang-nursery/rustfmt.git","ssh_url":"git@github.com:rust-lang-nursery/rustfmt.git","clone_url":"https://github.com/rust-lang-nursery/rustfmt.git","svn_url":"https://github.com/rust-lang-nursery/rustfmt","homepage":null,"size":1444,"stargazers_count":574,"watchers_count":574,"language":"Rust","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":99,"mirror_url":null,"open_issues_count":156,"forks":99,"open_issues":156,"watchers":574,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/rust-lang-nursery/rustfmt/pulls/740"},"html":{"href":"https://github.com/rust-lang-nursery/rustfmt/pull/740"},"issue":{"href":"https://api.github.com/repos/rust-lang-nursery/rustfmt/issues/740"},"comments":{"href":"https://api.github.com/repos/rust-lang-nursery/rustfmt/issues/740/comments"},"review_comments":{"href":"https://api.github.com/repos/rust-lang-nursery/rustfmt/pulls/740/comments"},"review_comment":{"href":"https://api.github.com/repos/rust-lang-nursery/rustfmt/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/rust-lang-nursery/rustfmt/pulls/740/commits"},"statuses":{"href":"https://api.github.com/repos/rust-lang-nursery/rustfmt/statuses/08f91bdcebfe996e2cabd123a8a9e637f1fd497b"}}}}