[gitg/wip/format-patch] Add "Get Patch" button to Diff View
- From: Sindhu S <sindhus src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/wip/format-patch] Add "Get Patch" button to Diff View
- Date: Sat, 27 Jul 2013 15:09:32 +0000 (UTC)
commit b61403907a24a2b40133c6a04cb8e71f80815c2d
Author: Sindhu S <sindhus gnome org>
Date: Thu Jul 25 15:25:24 2013 +0530
Add "Get Patch" button to Diff View
gitg/history/gitg-history.vala | 36 +++++++++++++++++
libgitg/gitg-diff-view-request-resource.vala | 53 ++++++++++++++++++++++++++
libgitg/gitg-diff-view.vala | 3 +
libgitg/resources/diff-view.css | 8 ++++
libgitg/resources/diff-view.html | 2 +
libgitg/resources/diff-view.js | 8 ++++
6 files changed, 110 insertions(+), 0 deletions(-)
---
diff --git a/gitg/history/gitg-history.vala b/gitg/history/gitg-history.vala
index 57bf6b8..058cb92 100644
--- a/gitg/history/gitg-history.vala
+++ b/gitg/history/gitg-history.vala
@@ -152,6 +152,42 @@ namespace GitgHistory
d_commit_list_model.disconnect(d_insertsig);
d_insertsig = 0;
}
+ d_main.commit_list_view.row_activated.connect(double_click_to_create_patch);
+ }
+
+ private void double_click_to_create_patch(Gtk.TreePath path, Gtk.TreeViewColumn column)
+ {
+ Gitg.Commit selected_commit = d_commit_list_model.commit_from_path(path);
+ string commit_subject = selected_commit.get_subject().replace(" ","-");
+ string commit_message = selected_commit.get_message();
+ var file = File.new_for_path(commit_subject + ".patch");
+ string sha1 = selected_commit.get_id().to_string();
+ string legacydate = "Mon Sep 17 00:00:00 2001";
+ string author = selected_commit.get_author().get_name();
+ string author_email = selected_commit.get_author().get_email();
+ string datetime = selected_commit.get_author().get_time().format("%a, %e %b %Y %T
%z");
+ try
+ {
+ Ggit.DiffList diff = selected_commit.get_diff(null);
+ Ggit.DiffPatch patch;
+ Ggit.DiffDelta delta;
+ diff.get_patch(0, out patch, out delta);
+
+ //write the patch to file
+ FileOutputStream os = file.create (FileCreateFlags.PRIVATE);
+ os.write("From %s %s".printf(sha1, legacydate).data);
+ os.write("\nFrom: %s <%s>".printf(author, author_email).data);
+ os.write("\nDate: %s".printf(datetime).data);
+ os.write("\nSubject: [PATCH] %s\n\n".printf(commit_message).data);
+ os.write(patch.to_string().data);
+ os.write("--\n".data);
+ os.write("Gitg\n\n".data);
+ }
+ catch (Error e)
+ {
+ //TODO: Route error message to Infobar?
+ stdout.printf("Failed: %s".printf(e.message));
+ }
}
public bool available
diff --git a/libgitg/gitg-diff-view-request-resource.vala b/libgitg/gitg-diff-view-request-resource.vala
index 164b04c..faed345 100644
--- a/libgitg/gitg-diff-view-request-resource.vala
+++ b/libgitg/gitg-diff-view-request-resource.vala
@@ -102,6 +102,59 @@ namespace Gitg
return stream;
}
}
+
+ class DiffViewRequestPatch : DiffViewRequest
+ {
+ public DiffViewRequestPatch (DiffView? view, WebKit.URISchemeRequest request, Soup.URI uri)
+ {
+ base(view, request, uri);
+ d_view = view;
+ d_hasView = false;
+ }
+
+ public override InputStream? run_async(Cancellable? cancellable) throws GLib.Error
+ {
+ //Gtk.FileChooserDialog chooser = new Gtk.FileChooserDialog ("Save Patch File", null,
Gtk.FileChooserAction.SAVE);
+ //chooser.show();
+ //stdout.printf("Formatting a patch");
+ if(d_view == null) {
+ stdout.printf ("The view is null");
+ }
+ Gitg.Commit selected_commit = d_view.commit;
+ string commit_subject = selected_commit.get_subject().replace(" ","-");
+ string commit_message = selected_commit.get_message();
+ stdout.printf("Pushing commit with message %s\n", commit_message);
+ /*var file = File.new_for_path(commit_subject + ".patch");
+ string sha1 = selected_commit.get_id().to_string();
+ string legacydate = "Mon Sep 17 00:00:00 2001";
+ string author = selected_commit.get_author().get_name();
+ string author_email = selected_commit.get_author().get_email();
+ string datetime = selected_commit.get_author().get_time().format("%a, %e %b %Y %T
%z");
+ try
+ {
+ Ggit.DiffList diff = selected_commit.get_diff(null);
+ Ggit.DiffPatch patch;
+ Ggit.DiffDelta delta;
+ diff.get_patch(0, out patch, out delta);
+
+ //write the patch to file
+ FileOutputStream os = file.create (FileCreateFlags.PRIVATE);
+ os.write("From %s %s".printf(sha1, legacydate).data);
+ os.write("\nFrom: %s <%s>".printf(author, author_email).data);
+ os.write("\nDate: %s".printf(datetime).data);
+ os.write("\nSubject: [PATCH] %s\n\n".printf(commit_message).data);
+ os.write(patch.to_string().data);
+ os.write("--\n".data);
+ os.write("Gitg\n\n".data);
+ }
+ catch (Error e)
+ {
+ //TODO: Route error message to Infobar?
+ stdout.printf("Failed: %s".printf(e.message));
+ }*/
+ return null;
+ }
+ }
}
// ex:ts=4 noet
diff --git a/libgitg/gitg-diff-view.vala b/libgitg/gitg-diff-view.vala
index bd076e9..4309789 100644
--- a/libgitg/gitg-diff-view.vala
+++ b/libgitg/gitg-diff-view.vala
@@ -107,6 +107,7 @@ namespace Gitg
{
var uri = new Soup.URI(request.get_uri());
var path = uri.get_path();
+ stdout.printf("The path is %s\n", path);
var parts = path.split("/", 3);
if (parts.length != 3)
@@ -138,6 +139,8 @@ namespace Gitg
return new DiffViewRequestResource(view, request, uri);
case "diff":
return new DiffViewRequestDiff(view, request, uri);
+ case "patch":
+ return new DiffViewRequestPatch(view, request, uri);
}
return null;
diff --git a/libgitg/resources/diff-view.css b/libgitg/resources/diff-view.css
index c4f755f..233ff0c 100644
--- a/libgitg/resources/diff-view.css
+++ b/libgitg/resources/diff-view.css
@@ -244,4 +244,12 @@ span.hunk_header, span.file_path {
vertical-align: middle;
}
+.format_patch_button {
+ float:right;
+ margin-top:13px;
+ padding: 7px;
+ margin-right: 3px;
+}
+
+
/* vi:ts=2:et */
diff --git a/libgitg/resources/diff-view.html b/libgitg/resources/diff-view.html
index 82f92e7..0c678ae 100644
--- a/libgitg/resources/diff-view.html
+++ b/libgitg/resources/diff-view.html
@@ -6,9 +6,11 @@
<script type="text/javascript" src="diff-view.js"></script>
</head>
<body>
+
<div id="templates">
<!-- Commit template -->
<div class="commit">
+ <button class="format_patch_button">Get Patch</button>
<img class="avatar"/>
<p>
<span class="author"></span><br/>
diff --git a/libgitg/resources/diff-view.js b/libgitg/resources/diff-view.js
index ec989e3..fdc844d 100644
--- a/libgitg/resources/diff-view.js
+++ b/libgitg/resources/diff-view.js
@@ -231,6 +231,12 @@ function update_diff(id, lsettings)
if ('commit' in j)
{
$('#diff_header').html(write_commit(j.commit));
+
+ $(".format_patch_button").click(function(){
+ var r = new XMLHttpRequest();
+ r.open("GET", "gitg-diff:/patch/?id=" + j.commit.id);
+ r.send();
+ });
}
}
@@ -279,6 +285,8 @@ addEventListener('DOMContentLoaded', function () {
loader.attr('src', gravatar);
},
});
+
+
}, false);
// vi:ts=4
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]