baseline

yet another open-source distributed versioning control system
Log | Files | Refs

objects.h (1832B)


      1 /*
      2  * Copyright (c) 2014 Mohamed Aslan <maslan@sce.carleton.ca>
      3  *
      4  * Permission to use, copy, modify, and distribute this software for any
      5  * purpose with or without fee is hereby granted, provided that the above
      6  * copyright notice and this permission notice appear in all copies.
      7  *
      8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
      9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
     10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
     11  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
     12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
     13  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
     14  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
     15  */
     16 
     17 #ifndef _OBJECTS_H_
     18 #define _OBJECTS_H_
     19 
     20 #include <fcntl.h>
     21 #include <time.h>
     22 
     23 #define MAX_PARENTS	1
     24 
     25 enum objtype {
     26 	O_FILE,
     27 	O_DIR,
     28 	O_COMMIT,
     29 	O_TAG
     30 };
     31 
     32 struct user {
     33 	char *name;
     34 	char *email;
     35 	time_t timestamp;
     36 };
     37 
     38 struct commit {
     39 	char *id;
     40 	char *dir;
     41 	struct user author;
     42 	struct user committer;
     43 	u_int8_t n_parents;
     44 	char *parents[MAX_PARENTS];
     45 	char *message;
     46 };
     47 
     48 struct dirent {
     49 	char *id;
     50 	char *name;
     51 	/* TODO: get rid of type */
     52 	enum {
     53 		T_FILE,
     54 		T_DIR
     55 	} type;
     56 	mode_t mode;
     57 	struct dirent *next;
     58 };
     59 
     60 struct dir {
     61 	char *id;
     62 	struct dir *parent;
     63 	struct dirent *children;
     64 };
     65 
     66 struct file {
     67 	char *id;
     68 	enum {
     69 		LOC_FS,
     70 		LOC_MEM
     71 	} loc;
     72 	union {
     73 		int fd;
     74 		char *buffer;
     75 	};
     76 };
     77 
     78 /* file ops */
     79 struct file* baseline_file_new();
     80 void baseline_file_free(struct file *);
     81 /* commit ops */
     82 struct commit* baseline_commit_new();
     83 void baseline_commit_free(struct commit *);
     84 /* dir ops */
     85 struct dir* baseline_dir_new();
     86 void baseline_dir_free(struct dir *);
     87 void baseline_dir_append(struct dir *, struct dirent *);
     88 
     89 #endif