- commit
- 4604b321b3099eae22c6c1823cd5c9c492c402a5
- parent
- 72595cb5c729aaf72f9136610cc8fdf108f1aa25
- Author
- Tobias Bengfort <tobias.bengfort@posteo.de>
- Date
- 2020-03-28 07:51
reorder functions
Diffstat
M | stagit.c | 160 | ++++++++++++++++++++++++++++++------------------------------ |
1 files changed, 80 insertions, 80 deletions
diff --git a/stagit.c b/stagit.c
@@ -83,6 +83,37 @@ joinpath(char *buf, size_t bufsiz, const char *path, const char *path2) 83 83 path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2); 84 84 } 85 85 -1 86 int -1 87 mkdirp(const char *path) -1 88 { -1 89 char tmp[PATH_MAX], *p; -1 90 -1 91 if (strlcpy(tmp, path, sizeof(tmp)) >= sizeof(tmp)) -1 92 errx(1, "path truncated: '%s'", path); -1 93 for (p = tmp + (tmp[0] == '/'); *p; p++) { -1 94 if (*p != '/') -1 95 continue; -1 96 *p = '\0'; -1 97 if (mkdir(tmp, S_IRWXU | S_IRWXG | S_IRWXO) < 0 && errno != EEXIST) -1 98 return -1; -1 99 *p = '/'; -1 100 } -1 101 if (mkdir(tmp, S_IRWXU | S_IRWXG | S_IRWXO) < 0 && errno != EEXIST) -1 102 return -1; -1 103 return 0; -1 104 } -1 105 -1 106 FILE * -1 107 efopen(const char *name, const char *flags) -1 108 { -1 109 FILE *fp; -1 110 -1 111 if (!(fp = fopen(name, flags))) -1 112 err(1, "fopen: '%s'", name); -1 113 -1 114 return fp; -1 115 } -1 116 86 117 void 87 118 deltainfo_free(struct deltainfo *di) 88 119 { @@ -93,6 +124,55 @@ deltainfo_free(struct deltainfo *di) 93 124 free(di); 94 125 } 95 126 -1 127 void -1 128 commitinfo_free(struct commitinfo *ci) -1 129 { -1 130 size_t i; -1 131 -1 132 if (!ci) -1 133 return; -1 134 if (ci->deltas) -1 135 for (i = 0; i < ci->ndeltas; i++) -1 136 deltainfo_free(ci->deltas[i]); -1 137 -1 138 free(ci->deltas); -1 139 git_diff_free(ci->diff); -1 140 git_tree_free(ci->commit_tree); -1 141 git_tree_free(ci->parent_tree); -1 142 git_commit_free(ci->commit); -1 143 git_commit_free(ci->parent); -1 144 memset(ci, 0, sizeof(*ci)); -1 145 free(ci); -1 146 } -1 147 -1 148 struct commitinfo * -1 149 commitinfo_getbyoid(const git_oid *id) -1 150 { -1 151 struct commitinfo *ci; -1 152 -1 153 if (!(ci = calloc(1, sizeof(struct commitinfo)))) -1 154 err(1, "calloc"); -1 155 -1 156 if (git_commit_lookup(&(ci->commit), repo, id)) -1 157 goto err; -1 158 ci->id = id; -1 159 -1 160 git_oid_tostr(ci->oid, sizeof(ci->oid), git_commit_id(ci->commit)); -1 161 git_oid_tostr(ci->parentoid, sizeof(ci->parentoid), git_commit_parent_id(ci->commit, 0)); -1 162 -1 163 ci->author = git_commit_author(ci->commit); -1 164 ci->committer = git_commit_committer(ci->commit); -1 165 ci->summary = git_commit_summary(ci->commit); -1 166 ci->msg = git_commit_message(ci->commit); -1 167 -1 168 return ci; -1 169 -1 170 err: -1 171 commitinfo_free(ci); -1 172 -1 173 return NULL; -1 174 } -1 175 96 176 int 97 177 commitinfo_getstats(struct commitinfo *ci) 98 178 { @@ -191,66 +271,6 @@ err: 191 271 return -1; 192 272 } 193 273194 -1 void195 -1 commitinfo_free(struct commitinfo *ci)196 -1 {197 -1 size_t i;198 -1199 -1 if (!ci)200 -1 return;201 -1 if (ci->deltas)202 -1 for (i = 0; i < ci->ndeltas; i++)203 -1 deltainfo_free(ci->deltas[i]);204 -1205 -1 free(ci->deltas);206 -1 git_diff_free(ci->diff);207 -1 git_tree_free(ci->commit_tree);208 -1 git_tree_free(ci->parent_tree);209 -1 git_commit_free(ci->commit);210 -1 git_commit_free(ci->parent);211 -1 memset(ci, 0, sizeof(*ci));212 -1 free(ci);213 -1 }214 -1215 -1 struct commitinfo *216 -1 commitinfo_getbyoid(const git_oid *id)217 -1 {218 -1 struct commitinfo *ci;219 -1220 -1 if (!(ci = calloc(1, sizeof(struct commitinfo))))221 -1 err(1, "calloc");222 -1223 -1 if (git_commit_lookup(&(ci->commit), repo, id))224 -1 goto err;225 -1 ci->id = id;226 -1227 -1 git_oid_tostr(ci->oid, sizeof(ci->oid), git_commit_id(ci->commit));228 -1 git_oid_tostr(ci->parentoid, sizeof(ci->parentoid), git_commit_parent_id(ci->commit, 0));229 -1230 -1 ci->author = git_commit_author(ci->commit);231 -1 ci->committer = git_commit_committer(ci->commit);232 -1 ci->summary = git_commit_summary(ci->commit);233 -1 ci->msg = git_commit_message(ci->commit);234 -1235 -1 return ci;236 -1237 -1 err:238 -1 commitinfo_free(ci);239 -1240 -1 return NULL;241 -1 }242 -1243 -1 FILE *244 -1 efopen(const char *name, const char *flags)245 -1 {246 -1 FILE *fp;247 -1248 -1 if (!(fp = fopen(name, flags)))249 -1 err(1, "fopen: '%s'", name);250 -1251 -1 return fp;252 -1 }253 -1254 274 /* Escape characters below as HTML 2.0 / XML 1.0. */ 255 275 void 256 276 xmlencode(FILE *fp, const char *s, size_t len) @@ -269,26 +289,6 @@ xmlencode(FILE *fp, const char *s, size_t len) 269 289 } 270 290 } 271 291272 -1 int273 -1 mkdirp(const char *path)274 -1 {275 -1 char tmp[PATH_MAX], *p;276 -1277 -1 if (strlcpy(tmp, path, sizeof(tmp)) >= sizeof(tmp))278 -1 errx(1, "path truncated: '%s'", path);279 -1 for (p = tmp + (tmp[0] == '/'); *p; p++) {280 -1 if (*p != '/')281 -1 continue;282 -1 *p = '\0';283 -1 if (mkdir(tmp, S_IRWXU | S_IRWXG | S_IRWXO) < 0 && errno != EEXIST)284 -1 return -1;285 -1 *p = '/';286 -1 }287 -1 if (mkdir(tmp, S_IRWXU | S_IRWXG | S_IRWXO) < 0 && errno != EEXIST)288 -1 return -1;289 -1 return 0;290 -1 }291 -1292 292 void 293 293 printtimez(FILE *fp, const git_time *intime) 294 294 {