[gitg] Update for new Ggit.Diff API
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg] Update for new Ggit.Diff API
- Date: Sat, 23 Nov 2013 14:11:37 +0000 (UTC)
commit 9f8b7780c1f8302a1b002ebb60c56dfc3785a810
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Sat Nov 23 14:54:29 2013 +0100
Update for new Ggit.Diff API
libgitg/gitg-commit.vala | 28 ++++++------
libgitg/gitg-diff-view-request-diff.vala | 62 ++++++++++++-----------------
libgitg/gitg-diff-view-request-patch.vala | 13 ++++--
libgitg/gitg-diff-view.vala | 4 +-
libgitg/gitg-stage.vala | 22 +++++-----
5 files changed, 61 insertions(+), 68 deletions(-)
---
diff --git a/libgitg/gitg-commit.vala b/libgitg/gitg-commit.vala
index fa0b51a..bcce2ba 100644
--- a/libgitg/gitg-commit.vala
+++ b/libgitg/gitg-commit.vala
@@ -111,9 +111,9 @@ public class Commit : Ggit.Commit
}
}
- public Ggit.DiffList get_diff(Ggit.DiffOptions? options)
+ public Ggit.Diff get_diff(Ggit.DiffOptions? options)
{
- Ggit.DiffList? diff = null;
+ Ggit.Diff? diff = null;
var repo = get_owner();
@@ -124,10 +124,10 @@ public class Commit : Ggit.Commit
// Create a new diff from the parents to the commit tree
if (parents.size() == 0)
{
- diff = new Ggit.DiffList.tree_to_tree(repo,
- null,
- get_tree(),
- options);
+ diff = new Ggit.Diff.tree_to_tree(repo,
+ null,
+ get_tree(),
+ options);
}
else
{
@@ -137,17 +137,17 @@ public class Commit : Ggit.Commit
if (i == 0)
{
- diff = new Ggit.DiffList.tree_to_tree(repo,
- parent.get_tree(),
- get_tree(),
- options);
+ diff = new Ggit.Diff.tree_to_tree(repo,
+ parent.get_tree(),
+ get_tree(),
+ options);
}
else
{
- var d = new Ggit.DiffList.tree_to_tree(repo,
- parent.get_tree(),
- get_tree(),
- options);
+ var d = new Ggit.Diff.tree_to_tree(repo,
+ parent.get_tree(),
+ get_tree(),
+ options);
diff.merge(d);
}
diff --git a/libgitg/gitg-diff-view-request-diff.vala b/libgitg/gitg-diff-view-request-diff.vala
index 8cb214e..9ff6800 100644
--- a/libgitg/gitg-diff-view-request-diff.vala
+++ b/libgitg/gitg-diff-view-request-diff.vala
@@ -28,7 +28,7 @@ namespace Gitg
}
private DiffType d_diff_type;
- private Ggit.DiffList? d_diff;
+ private Ggit.Diff? d_diff;
private Ggit.Commit? d_commit;
public DiffViewRequestDiff(DiffView? view, WebKit.URISchemeRequest request, Soup.URI uri)
@@ -126,11 +126,11 @@ namespace Gitg
state.in_file = true;
}
- private void hunk_cb(Json.Builder builder,
- DiffState state,
+ private void hunk_cb(Json.Builder builder,
+ DiffState state,
Ggit.DiffDelta delta,
- Ggit.DiffRange range,
- string header)
+ Ggit.DiffHunk hunk,
+ string header)
{
if (state.in_hunk)
{
@@ -147,12 +147,12 @@ namespace Gitg
builder.begin_object();
{
range_to_json(builder.set_member_name("old"),
- range.get_old_start(),
- range.get_old_lines());
+ hunk.get_old_start(),
+ hunk.get_old_lines());
range_to_json(builder.set_member_name("new"),
- range.get_new_start(),
- range.get_new_lines());
+ hunk.get_new_start(),
+ hunk.get_new_lines());
}
builder.end_object();
@@ -164,16 +164,17 @@ namespace Gitg
state.in_hunk = true;
}
- private void line_cb(Json.Builder builder,
+ private void line_cb(Json.Builder builder,
Ggit.DiffDelta delta,
- Ggit.DiffRange range,
- Ggit.DiffLineType line_type,
- string content)
+ Ggit.DiffHunk hunk,
+ Ggit.DiffLine line)
{
builder.begin_object();
{
- builder.set_member_name("type").add_int_value(line_type);
- builder.set_member_name("content").add_string_value(content);
+ var content = line.get_content();
+
+ builder.set_member_name("type").add_int_value((int)line.get_origin());
+ builder.set_member_name("content").add_string_value((string)content);
}
builder.end_object();
}
@@ -219,7 +220,7 @@ namespace Gitg
builder.end_object();
}
- private void build_diff(Ggit.DiffList? diff, Json.Builder builder, Cancellable? cancellable)
throws GLib.Error
+ private void build_diff(Ggit.Diff? diff, Json.Builder builder, Cancellable? cancellable)
throws GLib.Error
{
DiffState state = new DiffState();
@@ -239,14 +240,14 @@ namespace Gitg
return 0;
},
- (delta, range, header) => {
+ (delta, hunk) => {
if (cancellable != null && cancellable.is_cancelled())
{
return 1;
}
- var maxold = range.get_old_start() + range.get_old_lines();
- var maxnew = range.get_new_start() + range.get_new_lines();
+ var maxold = hunk.get_old_start() + hunk.get_old_lines();
+ var maxnew = hunk.get_new_start() + hunk.get_new_lines();
var ml = int64.max(maxold, maxnew);
@@ -255,24 +256,13 @@ namespace Gitg
maxlines = ml;
}
- // There seems to be a bug where sometimes the hunk header
- // contains null-bytes. As a temporary fix, we scan the
- // header for the first null byte and truncate it
- //
- // see: https://github.com/libgit2/libgit2/issues/1710
- for (int i = 0; i < header.length; ++i)
- {
- if (header[i] == 0)
- {
- header.length = i;
- }
- }
+ var header = hunk.get_header();
- hunk_cb(builder, state, delta, range,
((string)header)[0:header.length]);
+ hunk_cb(builder, state, delta, hunk, header);
return 0;
},
- (delta, range, line_type, content) => {
+ (delta, hunk, line) => {
if (cancellable != null && cancellable.is_cancelled())
{
return 1;
@@ -282,7 +272,7 @@ namespace Gitg
{
++numlines;
- line_cb(builder, delta, range, line_type,
((string)content)[0:content.length]);
+ line_cb(builder, delta, hunk, line);
}
return 0;
@@ -311,13 +301,13 @@ namespace Gitg
builder.set_member_name("maxlines").add_int_value(maxlines);
}
- private void build_commit(Ggit.DiffList? diff, Json.Builder builder, Cancellable? cancellable)
+ private void build_commit(Ggit.Diff? diff, Json.Builder builder, Cancellable? cancellable)
{
builder.set_member_name("commit");
commit_to_json(builder, d_commit);
}
- private InputStream? run_diff(Ggit.DiffList? diff, Cancellable? cancellable) throws GLib.Error
+ private InputStream? run_diff(Ggit.Diff? diff, Cancellable? cancellable) throws GLib.Error
{
if (diff == null)
{
diff --git a/libgitg/gitg-diff-view-request-patch.vala b/libgitg/gitg-diff-view-request-patch.vala
index f575107..c9afcc3 100644
--- a/libgitg/gitg-diff-view-request-patch.vala
+++ b/libgitg/gitg-diff-view-request-patch.vala
@@ -47,19 +47,21 @@ namespace Gitg
string patch_content = "";
try
{
- Ggit.DiffList diff = selected_commit.get_diff(null);
- Ggit.DiffPatch patch;
- Ggit.DiffDelta delta;
+ Ggit.Diff diff = selected_commit.get_diff(null);
+
var number_of_deltas = diff.get_num_deltas();
patch_content += "From %s %s".printf(sha1, legacydate);
patch_content += "\nFrom: %s <%s>".printf(author, author_email);
patch_content += "\nDate: %s".printf(datetime);
patch_content += "\nSubject: [PATCH] %s\n\n".printf(commit_message);
- for (var i = 0; i < number_of_deltas; i++) {
- diff.get_patch(i, out patch, out delta);
+
+ for (var i = 0; i < number_of_deltas; i++)
+ {
+ var patch = new Ggit.Patch.from_diff(diff, i);
patch_content += patch.to_string();
}
+
patch_content += "--\n";
patch_content += "Gitg\n\n";
@@ -101,6 +103,7 @@ namespace Gitg
Gtk.ResponseType.CANCEL,
Gtk.Stock.SAVE,
Gtk.ResponseType.OK);
+
chooser.do_overwrite_confirmation = true;
chooser.set_current_name(commit_subject + ".patch");
diff --git a/libgitg/gitg-diff-view.vala b/libgitg/gitg-diff-view.vala
index cee5621..2c776e4 100644
--- a/libgitg/gitg-diff-view.vala
+++ b/libgitg/gitg-diff-view.vala
@@ -21,7 +21,7 @@ namespace Gitg
{
public class DiffView : WebKit.WebView
{
- private Ggit.DiffList? d_diff;
+ private Ggit.Diff? d_diff;
private Commit? d_commit;
private Settings d_fontsettings;
@@ -36,7 +36,7 @@ namespace Gitg
private bool d_loaded;
private ulong d_diffid;
- public Ggit.DiffList? diff
+ public Ggit.Diff? diff
{
get { return d_diff; }
set
diff --git a/libgitg/gitg-stage.vala b/libgitg/gitg-stage.vala
index 442fcd0..a480456 100644
--- a/libgitg/gitg-stage.vala
+++ b/libgitg/gitg-stage.vala
@@ -597,9 +597,9 @@ public class Stage : Object
yield unstage(d_repository.get_workdir().resolve_relative_path(path));
}
- public async Ggit.DiffList? diff_index(StageStatusFile f) throws Error
+ public async Ggit.Diff? diff_index(StageStatusFile f) throws Error
{
- var opts = new Ggit.DiffOptions(Ggit.DiffOption.INCLUDE_UNTRACKED_CONTENT |
+ var opts = new Ggit.DiffOptions(Ggit.DiffOption.INCLUDE_UNTRACKED |
Ggit.DiffOption.DISABLE_PATHSPEC_MATCH |
Ggit.DiffOption.RECURSE_UNTRACKED_DIRS,
3,
@@ -610,15 +610,15 @@ public class Stage : Object
var tree = yield get_head_tree();
- return new Ggit.DiffList.tree_to_index(d_repository,
- tree,
- d_repository.get_index(),
- opts);
+ return new Ggit.Diff.tree_to_index(d_repository,
+ tree,
+ d_repository.get_index(),
+ opts);
}
- public async Ggit.DiffList? diff_workdir(StageStatusFile f) throws Error
+ public async Ggit.Diff? diff_workdir(StageStatusFile f) throws Error
{
- var opts = new Ggit.DiffOptions(Ggit.DiffOption.INCLUDE_UNTRACKED_CONTENT |
+ var opts = new Ggit.DiffOptions(Ggit.DiffOption.INCLUDE_UNTRACKED |
Ggit.DiffOption.DISABLE_PATHSPEC_MATCH |
Ggit.DiffOption.RECURSE_UNTRACKED_DIRS,
3,
@@ -627,9 +627,9 @@ public class Stage : Object
null,
new string[] {f.path});
- return new Ggit.DiffList.index_to_workdir(d_repository,
- d_repository.get_index(),
- opts);
+ return new Ggit.Diff.index_to_workdir(d_repository,
+ d_repository.get_index(),
+ opts);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]