GitMonitor.vala
[gitlive] / GitMonitorQueue.vala
1
2
3 public class GitMonitorQueue : MonitorNamePathDir {
4                 // name = basename
5                 // path = full path..
6                 // dir = dir path
7         
8                 public string gitpath;
9                 public string vdir;  // relative path (within git)
10                 public string vname;  // relative filename (within git)
11                 public string message ; // for commit
12                 public bool commit_all;
13                 public GitRepo repo;
14                  
15                 public GitMonitorQueue(MonitorNamePathDir f) {
16
17                         base(f.name, f.path, f.dir);
18  
19                         this.message = "";
20                         this.commit_all = false;
21                         
22                         var vpath_ar = this.dir.substring(GitMonitor.gitlive.length +1).split("/", 0);
23                         
24                         if (vpath_ar.length < 1 || vpath_ar[0].length < 1) {
25
26                                 this.gitpath = "";
27                                 this.vdir = "";
28                                 this.vname = "";
29                                 return;
30                         }         
31
32
33                         this.gitpath = GitMonitor.gitlive + "/" + vpath_ar[0];
34                         
35                         string[]  vpath = {};
36                         for (var i = 1; i< vpath_ar.length; i++) {
37                                 vpath += vpath_ar[i];
38                         }
39
40                         this.vdir =  string.joinv("/", vpath);
41
42                         this.vname =  this.vdir + (this.vdir.length > 0 ? "/" : "") + this.name;
43                         
44                         this.repo = GitRepo.get(this.gitpath);
45                         
46                         // trigger the suggestion to start a new branch
47                         if (!this.shouldIgnore() && !this.repo.is_wip_branch()) {
48                                 NewBranch.singleton().show(this.repo);
49                         }
50                 }
51
52
53                 public bool shouldIgnore()
54                 {
55                         
56                         // vim.. what a seriously brain dead program..
57                         if (this.name == "4913") {
58                                 GLib.debug("ignore name = 4913");
59                                 return true;
60                         }
61                          
62                         
63                         if (this.name[0] == '.') {
64                                 // except!
65                                 if (this.name == ".htaccess") {
66                                         
67                                         return false;
68                                 }
69                                 if (this.name == ".gitignore") {
70                                         return false;
71                                 }
72                                 GLib.debug("ignore name starts with dot %s", this.name);
73                                 return true;
74                         }
75                         
76                         
77                         if (this.name[this.name.length -1] == '~') {
78                                 GLib.debug("ignore name ends with ~");
79                                 return true;
80                         }
81                         // netbeans / android studio.. silly temp files..
82                         
83                         if (Regex.match_simple("___jb_old___$", this.name)) {
84                                 GLib.debug("ignore name includes jb_old");
85                             return true;
86                         }
87                         if (Regex.match_simple("___jb_bak___$", this.name)) {
88                                 GLib.debug("ignore name includes jb_bkc");
89                             return true;
90                         }
91                         //if (f.name.match(/^nbproject/)) {
92                         //    return true;
93                         //}
94                         // ignore anything in top level!!!!
95                         if (this.gitpath.length < 1) {
96                                 GLib.debug("ignore gitpath length is empty");
97                                 return true;
98                         }
99                         
100                         return false;
101                 }
102                 
103                 /** -- statics --*/
104                 
105                 public static int indexOfAdd( Array<GitMonitorQueue> add_files, string add)
106                 {
107                         for(var i =0; i < add_files.length; i++) {
108                                 if (add_files.index(i).vname == add) {
109                                         return i;
110                                 }
111                         }
112                         return -1;
113                 }
114                 public static  int indexOfMessage(Array<GitMonitorQueue> messages, string message)  {
115                         for(var i =0; i < messages.length; i++) {
116                                 if (messages.index(i).message == message) {
117                                         return i;
118                                 }
119                         }
120                         return -1;
121                 }
122                 public static string messageToString(Array<GitMonitorQueue> messages ) {
123                         string[] ret = {};
124                         for(var i =0; i < messages.length; i++) {
125                                 ret+= messages.index(i).message;
126                         }
127                         return string.joinv("\n",ret);
128                 }
129                 public static string queueArrayToString(Array<GitMonitorQueue> list) {
130                         var ret = "";
131                         for(var i =0; i < list.length; i++) {
132                                 
133                                 ret += (ret.length > 0 ? ", " : "") + list.index(i).vname;
134                         }
135                         return ret;
136                         
137                 }
138                 
139                 public static bool  queueHas(Array<GitMonitorQueue> list , GitMonitorQueue cmd_s, string action) {
140                         for(var i =0; i < list.length; i++) {
141                                 var test = list.index(i);
142                                 if (list.index(i).gitpath != cmd_s.gitpath) {
143                                         continue;
144                                 }
145                                 if (list.index(i).vname != cmd_s.vname) {
146                                         continue;
147                                 }
148                                 if (list.index(i).action != action) {
149                                         continue;
150                                 }
151                                 return true;
152                         }
153                         return false;
154                 }
155                 public string fullpath()
156                 {
157                         return this.gitpath + "/" + this.vname;
158                 }
159                 
160                         
161                         
162 }
163