sync
[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                         
48                 }
49
50
51                 public bool shouldIgnore()
52                 {
53                         
54                         // vim.. what a seriously brain dead program..
55                         if (this.name == "4913") {
56                                 GLib.debug("ignore name = 4913");
57                                 return true;
58                         }
59                          
60                         
61                         if (this.name[0] == '.') {
62                                 // except!
63                                 if (this.name == ".htaccess") {
64                                         
65                                         return false;
66                                 }
67                                 if (this.name == ".gitignore") {
68                                         return false;
69                                 }
70                                 GLib.debug("ignore name starts with dot %s", this.name);
71                                 return true;
72                         }
73                         
74                         
75                         if (this.name[this.name.length -1] == '~') {
76                                 GLib.debug("ignore name ends with ~");
77                                 return true;
78                         }
79                         // netbeans / android studio.. silly temp files..
80                         
81                         if (Regex.match_simple("___jb_old___$", this.name)) {
82                                 GLib.debug("ignore name includes jb_old");
83                             return true;
84                         }
85                         if (Regex.match_simple("___jb_bak___$", this.name)) {
86                                 GLib.debug("ignore name includes jb_bkc");
87                             return true;
88                         }
89                         //if (f.name.match(/^nbproject/)) {
90                         //    return true;
91                         //}
92                         // ignore anything in top level!!!!
93                         if (this.gitpath.length < 1) {
94                                 GLib.debug("ignore gitpath length is empty");
95                                 return true;
96                         }
97                         
98                         return false;
99                 }
100                 
101                 /** -- statics --*/
102                 
103                 public static int indexOfAdd( Gee.ArrayList<GitMonitorQueue> add_files, string add)
104                 {
105                         for(var i =0; i < add_files.size; i++) {
106                                 if (add_files.get(i).vname == add) {
107                                         return i;
108                                 }
109                         }
110                         return -1;
111                 }
112                 public static  int indexOfMessage(Gee.ArrayList<GitMonitorQueue> messages, string message)  {
113                         for(var i =0; i < messages.size; i++) {
114                                 if (messages.get(i).message == message) {
115                                         return i;
116                                 }
117                         }
118                         return -1;
119                 }
120                 public static string messageToString(Gee.ArrayList<GitMonitorQueue> messages ) {
121                         string[] ret = {};
122                         for(var i =0; i < messages.size; i++) {
123                                 ret+= messages.get(i).message;
124                         }
125                         return string.joinv("\n",ret);
126                 }
127                 public static string queueArrayToString(Gee.ArrayList<GitMonitorQueue> list) {
128                         var ret = "";
129                         for(var i =0; i < list.size; i++) {
130                                 
131                                 ret += (ret.length > 0 ? ", " : "") + list.get(i).vname;
132                         }
133                         return ret;
134                         
135                 }
136                 
137                 public static bool  queueHas(Gee.ArrayList<GitMonitorQueue> list , GitMonitorQueue cmd_s, string action) {
138                         for(var i =0; i < list.size; i++) {
139                                 var test = list.get(i);
140                                 if (list.get(i).gitpath != cmd_s.gitpath) {
141                                         continue;
142                                 }
143                                 if (list.get(i).vname != cmd_s.vname) {
144                                         continue;
145                                 }
146                                 if (list.get(i).action != action) {
147                                         continue;
148                                 }
149                                 return true;
150                         }
151                         return false;
152                 }
153                 public string fullpath()
154                 {
155                         return this.gitpath + "/" + this.vname;
156                 }
157                 
158                         
159                         
160 }
161