[gitg/wip/commit] Add convenience stage functions for relative paths



commit 312f5e12e196481259ae045e7f068bbcdb631778
Author: Jesse van den Kieboom <jessevdk gmail com>
Date:   Wed Jul 3 18:50:43 2013 +0200

    Add convenience stage functions for relative paths

 libgitg/gitg-stage.vala |  117 ++++++++++++++++++++++++++++++++++-------------
 1 files changed, 85 insertions(+), 32 deletions(-)
---
diff --git a/libgitg/gitg-stage.vala b/libgitg/gitg-stage.vala
index 863b375..479ac9f 100644
--- a/libgitg/gitg-stage.vala
+++ b/libgitg/gitg-stage.vala
@@ -130,6 +130,21 @@ public class Stage : Object
        }
 
        /**
+        * Revert working directory changes.
+        *
+        * @param path path relative to the working directory.
+        *
+        * Revert a path to the version currently recorded in HEAD. This will delete
+        * any modifications done in the current working directory to this file,
+        * so use with care! Note that this only affects the working directory,
+        * not the index.
+        */
+       public async void revert_path(string path) throws Error
+       {
+               yield revert(d_repository.get_workdir().resolve_relative_path(path));
+       }
+
+       /**
         * Delete a file from the index.
         *
         * @param file the file to delete.
@@ -145,6 +160,18 @@ public class Stage : Object
        }
 
        /**
+        * Delete a relative path from the index.
+        *
+        * @param path path relative to the working directory.
+        *
+        * Delete the relative path from the index.
+        */
+       public async void delete_path(string path) throws Error
+       {
+               yield this.delete(d_repository.get_workdir().resolve_relative_path(path));
+       }
+
+       /**
         * Stage a file to the index.
         *
         * @param file the file to stage.
@@ -160,39 +187,17 @@ public class Stage : Object
                });
        }
 
-       public async Ggit.DiffList? diff_index(StageStatusFile f) throws Error
-       {
-               var opts = new Ggit.DiffOptions(Ggit.DiffOption.INCLUDE_UNTRACKED_CONTENT |
-                                               Ggit.DiffOption.DISABLE_PATHSPEC_MATCH |
-                                               Ggit.DiffOption.RECURSE_UNTRACKED_DIRS,
-                                               3,
-                                               3,
-                                               null,
-                                               null,
-                                               new string[] {f.path});
-
-               var tree = yield get_head_tree();
-
-               return new Ggit.DiffList.tree_to_index(d_repository,
-                                                      tree,
-                                                      d_repository.get_index(),
-                                                      opts);
-       }
-
-       public async Ggit.DiffList? diff_workdir(StageStatusFile f) throws Error
+       /**
+        * Stage a path to the index.
+        *
+        * @param path path relative to the working directory.
+        *
+        * Stage a relative path to the index. This will record the state of the file in
+        * the working directory to the index.
+        */
+       public async void stage_path(string path) throws Error
        {
-               var opts = new Ggit.DiffOptions(Ggit.DiffOption.INCLUDE_UNTRACKED_CONTENT |
-                                               Ggit.DiffOption.DISABLE_PATHSPEC_MATCH |
-                                               Ggit.DiffOption.RECURSE_UNTRACKED_DIRS,
-                                               3,
-                                               3,
-                                               null,
-                                               null,
-                                               new string[] {f.path});
-
-               return new Ggit.DiffList.index_to_workdir(d_repository,
-                                                         d_repository.get_index(),
-                                                         opts);
+               yield stage(d_repository.get_workdir().resolve_relative_path(path));
        }
 
        /**
@@ -230,6 +235,54 @@ public class Stage : Object
                        index.write();
                });
        }
+
+       /**
+        * Unstage a path from the index.
+        *
+        * @param path path relative to the working directory.
+        *
+        * Unstage changes in the specified relative path from the index. This will record
+        * the state of the file in HEAD to the index.
+        */
+       public async void unstage_path(string path) throws Error
+       {
+               yield unstage(d_repository.get_workdir().resolve_relative_path(path));
+       }
+
+       public async Ggit.DiffList? diff_index(StageStatusFile f) throws Error
+       {
+               var opts = new Ggit.DiffOptions(Ggit.DiffOption.INCLUDE_UNTRACKED_CONTENT |
+                                               Ggit.DiffOption.DISABLE_PATHSPEC_MATCH |
+                                               Ggit.DiffOption.RECURSE_UNTRACKED_DIRS,
+                                               3,
+                                               3,
+                                               null,
+                                               null,
+                                               new string[] {f.path});
+
+               var tree = yield get_head_tree();
+
+               return new Ggit.DiffList.tree_to_index(d_repository,
+                                                      tree,
+                                                      d_repository.get_index(),
+                                                      opts);
+       }
+
+       public async Ggit.DiffList? diff_workdir(StageStatusFile f) throws Error
+       {
+               var opts = new Ggit.DiffOptions(Ggit.DiffOption.INCLUDE_UNTRACKED_CONTENT |
+                                               Ggit.DiffOption.DISABLE_PATHSPEC_MATCH |
+                                               Ggit.DiffOption.RECURSE_UNTRACKED_DIRS,
+                                               3,
+                                               3,
+                                               null,
+                                               null,
+                                               new string[] {f.path});
+
+               return new Ggit.DiffList.index_to_workdir(d_repository,
+                                                         d_repository.get_index(),
+                                                         opts);
+       }
 }
 
 }


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