Skip to content

Commit

Permalink
warning fix
Browse files Browse the repository at this point in the history
  • Loading branch information
findstr committed Nov 7, 2018
1 parent c04a9f3 commit 7171c0d
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ SRC:=main.c release.c history.c diff.c patch.c list.c checkout.c\
all:vdb

vdb:$(SRC)
gcc -g3 -o $@ $^
gcc -g3 -Wall -Werror -o $@ $^

6 changes: 4 additions & 2 deletions checkout.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include <errno.h>
#include <stdio.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "dr.h"
#include "dir.h"
#include "db.h"
Expand All @@ -15,7 +17,7 @@ checkout(dr_t hash, dr_t outdir)
db_readtree(&t, r.tree);
printf("tree:%s\n", r.tree->buf);
release_destroy(&r);
ret = mkdir(outdir->buf, 0755);
ret = mkdir(str(outdir), 0755);
if (ret == -1) {
fprintf(stderr, "checkout folder '%s' is exist\n",
outdir->buf);
Expand All @@ -25,7 +27,7 @@ checkout(dr_t hash, dr_t outdir)
struct ref *f;
f = &t.refs[i];
f->data = db_read(f->hash);
dir_writefile(f->name->buf, f->data, outdir);
dir_writefile(str(f->name), f->data, outdir);
}
tree_destroy(&t);
return ;
Expand Down
12 changes: 6 additions & 6 deletions dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,23 +184,23 @@ dir_remove(const char *path, dr_t root)
}

void
dir_movdir(const char *from, const char *to)
dir_movdir(dr_t from, dr_t to)
{
int i, n, ret;
int flen, tlen;
dr_t *list;
char buf[PATH_MAX];
n = dir_scan(from, &list, 0);
flen = strlen(from);
tlen = strlen(to);
memcpy(buf, to, tlen);
n = dir_scan(str(from), &list, 0);
flen = from->size;
tlen = to->size;
memcpy(buf, to->buf, tlen);
for (i = 0; i < n; i++) {
dr_t d = list[i];
memcpy(&buf[tlen], &d->buf[flen], d->size - flen);
buf[d->size - flen + tlen] = 0;
checkdir(buf);
ret = remove(buf);
assert(ret == 0 || ret == -1 && errno == ENOENT);
assert(ret == 0 || (ret == -1 && errno == ENOENT));
ret = rename((char *)d->buf, buf);
assert(ret == 0);
dr_unref(d);
Expand Down
2 changes: 1 addition & 1 deletion dir.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dr_t dir_readfile(const char *path, dr_t root);
void dir_writefile(const char *path, dr_t d, dr_t root);
void dir_rename(const char *from, const char *to, dr_t root);
void dir_remove(const char *path, dr_t root);
void dir_movdir(const char *from, const char *to);
void dir_movdir(dr_t from, dr_t to);

#endif

2 changes: 2 additions & 0 deletions dr.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <stdint.h>
#include <string.h>

#define str(dr) ((char *)(dr)->buf)

typedef struct dr_{ //data reference
int ref;
int size;
Expand Down
20 changes: 10 additions & 10 deletions patch.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ patch(struct patch_args *args)
{
dr_t patch;
dr_t outdir, outtemp = NULL;
int ret, size, dfn = 0;
int size, dfn = 0;
const uint8_t *p, *e;
outdir = args->output;
checkout(args->hash, outdir);
patch = dir_readfile(args->patch->buf, NULL);
patch = dir_readfile(str(args->patch), NULL);
if (patch == NULL) {
fprintf(stderr, "patch file '%s' %s\n",
args->patch->buf, strerror(errno));
Expand Down Expand Up @@ -82,11 +82,11 @@ patch(struct patch_args *args)
patch = ctrl.u.dfx.patch;
diff:
++dfn;
oldfile = dir_readfile(namea->buf, outdir);
oldfile = dir_readfile(str(namea), outdir);
newfile = patch_content(oldfile, patch);
hash = db_hash(newfile);
assert(dr_cmp(hash, ctrl.u.dff.hash) == 0);
dir_writefile(ctrl.u.dff.name->buf, newfile, outtemp);
dir_writefile(str(ctrl.u.dff.name), newfile, outtemp);
break;
case CTRL_MOV:
case CTRL_NEW:
Expand All @@ -103,24 +103,24 @@ patch(struct patch_args *args)
e = p + patch->size;
while (p < e) {
struct CTRL ctrl;
dr_t namea, patch, oldfile = NULL;
dr_t namea = NULL, oldfile = NULL;
dr_t hash = NULL, newfile = NULL;
p = ctrl_read(p, &ctrl);
switch (ctrl.type) {
case CTRL_NEW:
hash = db_hash(ctrl.u.new.data);
assert(dr_cmp(hash, ctrl.u.new.hash) == 0);
dir_writefile(ctrl.u.new.name->buf,
dir_writefile(str(ctrl.u.new.name),
ctrl.u.new.data, outdir);
break;
case CTRL_MOV:
oldfile = dir_readfile(namea->buf, outdir);
oldfile = dir_readfile(str(namea), outdir);
hash = db_hash(oldfile);
assert(dr_cmp(hash, ctrl.u.mov.hash) == 0);
dir_rename(namea->buf, ctrl.u.mov.name->buf, outdir);
dir_rename(str(namea), str(ctrl.u.mov.name), outdir);
break;
case CTRL_DEL:
dir_remove(ctrl.u.del.name->buf, outdir);
dir_remove(str(ctrl.u.del.name), outdir);
break;
}
dr_unref(hash);
Expand All @@ -130,7 +130,7 @@ patch(struct patch_args *args)
}
printf("apply DFF/DFX result\n");
if (dfn > 0)
dir_movdir(outtemp->buf, outdir->buf);
dir_movdir(outtemp, outdir);
dr_unref(patch);
dr_unref(outtemp);
return ;
Expand Down
13 changes: 3 additions & 10 deletions release.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,37 +8,30 @@
#include "object.h"
#include "release.h"

static int
namecmp(dr_t a, dr_t b)
{

}

void
release(struct release_args *args)
{
dr_t *list, head;
int i, n, keep;
struct release prevrel;
struct tree prevtree, tree;
n = dir_scan(args->fromdir->buf, &list, 1);
n = dir_scan(str(args->fromdir), &list, 1);
head = db_readhead(&prevrel, &prevtree);
tree_sort(&prevtree, ref_hashcmp);
tree.refn = n;
tree.refs = malloc(sizeof(struct ref) * n);
memset(tree.refs, 0, sizeof(struct ref) * n);
keep = 0;
for (i = 0; i < n; i++) {
int exist;
dr_t d, name;
struct ref *r, *f;
r = &tree.refs[i];
r->name = name = list[i];
d = dir_readfile(name->buf, args->fromdir);
d = dir_readfile(str(name), args->fromdir);
r->hash = db_write(name, d);
dr_unref(d);
f = tree_search(&prevtree, r, ref_hashcmp);
if (f && (strcmp(f->name->buf, name->buf) == 0)) {
if (f && (strcmp(str(f->name), str(name)) == 0)) {
dr_unref(f->name);
f->name = NULL;
keep += 1;
Expand Down

0 comments on commit 7171c0d

Please sign in to comment.