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