[gitg/unstage-selection-new-files: 5/5] Deal correctly with stage/unstage of selection on new files
- From: Alberto Fanjul <albfan src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gitg/unstage-selection-new-files: 5/5] Deal correctly with stage/unstage of selection on new files
- Date: Thu, 1 Sep 2022 19:58:41 +0000 (UTC)
commit efe545bc750fb748090ed27b680b50ccfcdc4bff
Author: Alberto Fanjul <albertofanjul gmail com>
Date: Thu Sep 1 21:56:29 2022 +0200
Deal correctly with stage/unstage of selection on new files
gitg/commit/gitg-commit.vala | 3 ++
libgitg/gitg-diff-selectable.vala | 1 +
.../gitg-diff-view-file-renderer-text-split.vala | 4 ++
libgitg/gitg-diff-view-file-renderer-text.vala | 7 +++-
libgitg/gitg-diff-view-file.vala | 9 +++++
libgitg/gitg-diff-view.vala | 9 +++++
libgitg/gitg-stage.vala | 46 ++++++++++++++++------
7 files changed, 67 insertions(+), 12 deletions(-)
---
diff --git a/gitg/commit/gitg-commit.vala b/gitg/commit/gitg-commit.vala
index 2b00cc39..cb561a09 100644
--- a/gitg/commit/gitg-commit.vala
+++ b/gitg/commit/gitg-commit.vala
@@ -1275,6 +1275,8 @@ namespace GitgCommit
foreach (var pset in selection)
{
+ if (pset.patches.length == 0)
+ continue;
if (staging)
{
yield stage.stage_patch(pset);
@@ -1284,6 +1286,7 @@ namespace GitgCommit
yield stage.unstage_patch(pset);
}
}
+ d_main.diff_view.clear_selection();
}
private async void discard_selection() throws Error
diff --git a/libgitg/gitg-diff-selectable.vala b/libgitg/gitg-diff-selectable.vala
index e0938c32..6e78362c 100644
--- a/libgitg/gitg-diff-selectable.vala
+++ b/libgitg/gitg-diff-selectable.vala
@@ -23,6 +23,7 @@ interface Gitg.DiffSelectable : Object
public abstract bool can_select { get; construct set; }
public abstract PatchSet selection { owned get; }
+ public abstract void clear_selection ();
}
// ex:ts=4 noet
diff --git a/libgitg/gitg-diff-view-file-renderer-text-split.vala
b/libgitg/gitg-diff-view-file-renderer-text-split.vala
index 696693a0..4d1bafcc 100644
--- a/libgitg/gitg-diff-view-file-renderer-text-split.vala
+++ b/libgitg/gitg-diff-view-file-renderer-text-split.vala
@@ -128,6 +128,10 @@ class Gitg.DiffViewFileRendererTextSplit : Gtk.Box, DiffSelectable, DiffViewFile
}
}
+ public void clear_selection()
+ {
+ }
+
public bool can_select { get; construct set; }
public PatchSet selection
diff --git a/libgitg/gitg-diff-view-file-renderer-text.vala b/libgitg/gitg-diff-view-file-renderer-text.vala
index ae3352d9..fe6c15d7 100644
--- a/libgitg/gitg-diff-view-file-renderer-text.vala
+++ b/libgitg/gitg-diff-view-file-renderer-text.vala
@@ -68,6 +68,8 @@ class Gitg.DiffViewFileRendererText : Gtk.SourceView, DiffSelectable, DiffViewFi
private Settings? d_stylesettings;
private FontManager d_font_manager;
+ private bool d_has_selection;
+
public Style d_style { get; construct set; }
public bool new_is_workdir { get; construct set; }
@@ -122,7 +124,10 @@ class Gitg.DiffViewFileRendererText : Gtk.SourceView, DiffSelectable, DiffViewFi
}
}
- private bool d_has_selection;
+ public void clear_selection()
+ {
+ d_has_selection = false;
+ }
public bool has_selection
{
diff --git a/libgitg/gitg-diff-view-file.vala b/libgitg/gitg-diff-view-file.vala
index cb86e17f..df1514e8 100644
--- a/libgitg/gitg-diff-view-file.vala
+++ b/libgitg/gitg-diff-view-file.vala
@@ -96,6 +96,15 @@ class Gitg.DiffViewFile : Gtk.Grid
return has_selection;
}
+ public void clear_selection()
+ {
+ foreach (var renderer in renderer_list)
+ {
+ var sel = renderer as DiffSelectable;
+ sel.clear_selection();
+ }
+ }
+
public PatchSet get_selection()
{
var ret = new PatchSet();
diff --git a/libgitg/gitg-diff-view.vala b/libgitg/gitg-diff-view.vala
index f40bcfcb..0894bd26 100644
--- a/libgitg/gitg-diff-view.vala
+++ b/libgitg/gitg-diff-view.vala
@@ -853,6 +853,7 @@ public class Gitg.DiffView : Gtk.Grid
renderer_text.notify["has-selection"].connect(on_selection_changed);
}
}
+ on_selection_changed();
}
if (current_is_binary)
{
@@ -1061,6 +1062,14 @@ public class Gitg.DiffView : Gtk.Grid
return ret;
}
+ public void clear_selection()
+ {
+ foreach (var file in d_grid_files.get_children())
+ {
+ ((Gitg.DiffViewFile)file).clear_selection();
+ }
+ }
+
private void update_hide_show_options(Gdk.Window window, int ex, int ey)
{
void *data;
diff --git a/libgitg/gitg-stage.vala b/libgitg/gitg-stage.vala
index 0eb2f071..367fca2c 100644
--- a/libgitg/gitg-stage.vala
+++ b/libgitg/gitg-stage.vala
@@ -874,15 +874,17 @@ public class Stage : Object
yield thread_index((index) => {
var entries = index.get_entries();
var entry = entries.get_by_path(newf, 0);
-
+ uchar[] old_content = new uchar[0];
if (entry == null)
{
- throw new StageError.INDEX_ENTRY_NOT_FOUND(patch.filename);
+ print("\npath not in index %s\n", newf.get_path());
+ index.add_file(newf);
+ index.write();
+ } else {
+ var old_blob = d_repository.lookup<Ggit.Blob>(entry.get_id());
+ old_content = old_blob.get_raw_content();
}
- var old_blob = d_repository.lookup<Ggit.Blob>(entry.get_id());
- unowned uchar[] old_content = old_blob.get_raw_content();
-
var old_stream = new MemoryInputStream.from_bytes(new Bytes(old_content));
apply_patch(index, old_stream, new_stream, patch);
@@ -957,14 +959,22 @@ public class Stage : Object
if (entry == null)
{
- throw new StageError.INDEX_ENTRY_NOT_FOUND(patch.filename);
+ index.add_file(file);
+ index.write();
+ entries = index.get_entries();
+ entry = entries.get_by_path(file, 0);
}
- var head_entry = tree.get_by_path(patch.filename);
- var head_blob = d_repository.lookup<Ggit.Blob>(head_entry.get_id());
- var index_blob = d_repository.lookup<Ggit.Blob>(entry.get_id());
- unowned uchar[] head_content = head_blob.get_raw_content();
+ uchar[] head_content = new uchar[0];
+ try {
+ var head_entry = tree.get_by_path(patch.filename);
+ var head_blob = d_repository.lookup<Ggit.Blob>(head_entry.get_id());
+
+ head_content = head_blob.get_raw_content();
+ } catch (Error e) {}
+
+ var index_blob = d_repository.lookup<Ggit.Blob>(entry.get_id());
unowned uchar[] index_content = index_blob.get_raw_content();
var head_stream = new MemoryInputStream.from_bytes(new Bytes(head_content));
@@ -972,7 +982,21 @@ public class Stage : Object
var reversed = patch.reversed();
- apply_patch(index, index_stream, head_stream, reversed);
+ try {
+ apply_patch(index, index_stream, head_stream, reversed);
+ } catch(Error e) {
+ var stage = d_repository.stage;
+ stage.delete_path.begin(file.get_path(), (obj, res) => {
+ try
+ {
+ stage.delete_path.end(res);
+ }
+ catch (Error e)
+ {
+ warning("%s\n", e.message);
+ }
+ });
+ }
head_stream.close();
index_stream.close();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]