commit 252b803afe458ec9452b7c14d7d1ccbc8f5c059c
parent ea286a8ea769650e74ee2cd2a8ae56ac17a217f7
Author: Remy Noulin <loader2x@gmail.com>
Date: Fri, 23 Dec 2016 11:00:50 +0100
fix crash because of missing config
README.md | 2 +-
c/git-off.c | 195 +++++++++++++++++++++++++++++++++++++++++-------------------
c/gitoff.c | 195 +++++++++++++++++++++++++++++++++++++++++-------------------
3 files changed, 269 insertions(+), 123 deletions(-)
Diffstat:
| M | README.md | | | 2 | +- |
| M | c/git-off.c | | | 195 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------- |
| M | c/gitoff.c | | | 195 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------- |
3 files changed, 269 insertions(+), 123 deletions(-)
diff --git a/README.md b/README.md
@@ -35,7 +35,7 @@ In Debian:
```
apt-get install tcc
cd /usr/local/bin
-ln -s $PATH_TO_GITOFF_GIT/c/gitoff git-off.c
+ln -s $PATH_TO_GITOFF_GIT/c/git-off.c git-off
```
In MacOS:
diff --git a/c/git-off.c b/c/git-off.c
@@ -72,8 +72,13 @@
// modules
//////
// includes and function prototypes
+ #ifdef unitTest
// gitoff.h is used in unit tests
#include "gitoff.h"
+ #else
+typedef void (*gConfig_set_t)(char*, char*);
+typedef void (*cmdSetF_t)(gConfig_set_t);
+ #endif
#define internal static
@@ -93,6 +98,7 @@ char *expandHome(char *p);
void offLog(char* s);
void offLogRepo(char* s);
char *exec(int cmdName, char* paramsArray);
+bool strEq(char *string1, char *string2);
void gitConfig_set(char* key, char* value);
void gitConfig_setLocal(char* key, char* value);
void gitConfig_setThisRepo(char* key, char* value);
@@ -240,6 +246,9 @@ char *expandHome(char *p) {
wordexp_t exp_result;
size_t len;
+ if (p == NULL) {
+ return(NULL);
+ }
wordexp(p, &exp_result, 0);
p = realloc(p, strlen(exp_result.we_wordv[0])+1);
strcpy(p, exp_result.we_wordv[0]);
@@ -333,6 +342,18 @@ char *exec(int cmdName, char* paramsArray) {
return(line);
}
+// compare strings
+bool strEq(char *string1, char *string2) {
+
+ if (string1 == NULL) {
+ return(false);
+ }
+ if (string2 == NULL) {
+ return(false);
+ }
+ return(strcmp(string1,string2) == 0);;
+}
+
// handles global git config
void gitConfig_set(char* key, char* value) {
@@ -384,7 +405,7 @@ char *gitConfig_get(char *key) {
char* gitOffConfigEnv = NULL;
// configAlways
- if (strcmp(offHelpers_offConfigAlways(), "GIT_OFF_CONFIG") == 0) {
+ if (strEq(offHelpers_offConfigAlways(), "GIT_OFF_CONFIG")) {
gitOffConfigEnv = getenv("GIT_OFF_CONFIG");
if ((gitOffConfigEnv != NULL) && (access(gitOffConfigEnv, F_OK) != -1)) {
p = malloc(strlen(gitOffConfigEnv) + strlen(key) + 1 + 8);
@@ -394,7 +415,7 @@ char *gitConfig_get(char *key) {
}
return(r);
}
- if (strcmp(offHelpers_offConfigAlways(), "repo") == 0) {
+ if (strEq(offHelpers_offConfigAlways(), "repo")) {
p = malloc(strlen(offHelpers_gitRepoRoot()) + 1 + 9);
sprintf(p, "%s/.git-off", offHelpers_gitRepoRoot());
if (access(p, F_OK) != -1) {
@@ -406,7 +427,7 @@ char *gitConfig_get(char *key) {
free(p);
return(r);
}
- if (strcmp(offHelpers_offConfigAlways(), "global") == 0) {
+ if (strEq(offHelpers_offConfigAlways(), "global")) {
r = gitConfig_getDefault(key);
return(r);
}
@@ -793,7 +814,7 @@ char *offHelpers_transformFrom() {
char *offHelpers_userAt() {
- if ((offHelpers_offScpUser() != NULL) && (strcmp(offHelpers_offScpUser(), "") != 0)) {
+ if ((offHelpers_offScpUser() != NULL) && (!strEq(offHelpers_offScpUser(), ""))) {
char *u;
u = malloc(strlen(offHelpers_offScpUser()) + 1 + 1);
sprintf(u, "%s@", offHelpers_offScpUser());
@@ -879,7 +900,7 @@ void offHelpers_mkdirStore(char *p) {
sprintf(sshCmd, "mkdir -p %s/%s", h_l[1], p);
// setup ssh/scp private key
- if ((offHelpers_offPem() == NULL) || (strcmp(offHelpers_offPem(), "offNoValue") == 0)) {
+ if ((offHelpers_offPem() == NULL) || (strEq(offHelpers_offPem(), "offNoValue")) || (offHelpers_offPem() == NULL)) {
pem = strdup("");
}
else {
@@ -913,7 +934,7 @@ void offHelpers_rmAllStore(char *p) {
char **h_l = NULL;
// setup ssh/scp private key
- if ((offHelpers_offPem() == NULL) || (strcmp(offHelpers_offPem(), "offNoValue") == 0)) {
+ if ((offHelpers_offPem() == NULL) || (strEq(offHelpers_offPem(), "offNoValue")) || (offHelpers_offPem() == NULL)) {
pem = strdup("");
}
else {
@@ -982,14 +1003,14 @@ bool offHelpers_checkIntegrity(char *p) {
char *receivedSha = NULL;
char *base = NULL;
- if (strcmp(offHelpers_offIntegrity(), "disable") == 0) {
+ if (strEq(offHelpers_offIntegrity(), "disable")) {
return(true);
}
receivedSha = exec(sha, p);
base = strdup(basename(p));
- if (strcmp(base, receivedSha) != 0) {
+ if (!strEq(base, receivedSha)) {
// the file received is different from the one that was sent.
printf("git-off: The file %s differs from the one that was pushed.", p); {
printf("\n");
@@ -1034,7 +1055,7 @@ void transportCopyReceive(char *file) {
char b[1024];
FILE *f = NULL;
- if ((strcmp(offHelpers_transform(), "enable") == 0) && (offHelpers_transformFrom() != NULL)) {
+ if ((strEq(offHelpers_transform(), "enable")) && (offHelpers_transformFrom() != NULL)) {
// create file directories in objectPath
char **f_l;
DIR *d;
@@ -1107,7 +1128,7 @@ void transportScpSend(char *file) {
h_l = offHelpers_getSSHConfig();
// setup ssh/scp private key
- if ((offHelpers_offPem() == NULL) || (strcmp(offHelpers_offPem(), "offNoValue") == 0)) {
+ if ((offHelpers_offPem() == NULL) || (strEq(offHelpers_offPem(), "offNoValue")) || (offHelpers_offPem() == NULL)) {
pem = strdup("");
}
else {
@@ -1162,7 +1183,7 @@ void transportScpReceive(char *file) {
h_l = offHelpers_getSSHConfig();
// setup ssh/scp private key
- if ((offHelpers_offPem() == NULL) || (strcmp(offHelpers_offPem(), "offNoValue") == 0)) {
+ if ((offHelpers_offPem() == NULL) || (strEq(offHelpers_offPem(), "offNoValue")) || (offHelpers_offPem() == NULL)) {
pem = strdup("");
}
else {
@@ -1199,7 +1220,7 @@ void transportScpReceive(char *file) {
char b[1024];
FILE *f;
- if ((strcmp(offHelpers_transform(), "enable") == 0) && (offHelpers_transformFrom() != NULL)) {
+ if ((strEq(offHelpers_transform(), "enable")) && (offHelpers_transformFrom() != NULL)) {
transport_transformFrom(file);
p = malloc(strlen(offHelpers_objectPath()) + strlen(file) + 1 + 8);
sprintf(p, "%s/../tmp/%s", offHelpers_objectPath(), file);
@@ -1266,7 +1287,7 @@ void transportHttpReceive(char *file) {
char b[1024];
FILE *f;
- if ((strcmp(offHelpers_transform(), "enable") == 0) && (offHelpers_transformFrom() != NULL)) {
+ if ((strEq(offHelpers_transform(), "enable")) && (offHelpers_transformFrom() != NULL)) {
transport_transformFrom(file);
p = malloc(strlen(offHelpers_objectPath()) + strlen(file) + 1 + 8);
sprintf(p, "%s/../tmp/%s", offHelpers_objectPath(), file);
@@ -1304,7 +1325,7 @@ void offHelpers_setTransport(char *mode ) {
// copy, scp
// use mode from config or from parameter
- if (strcmp(mode, "config") == 0) {
+ if (strEq(mode, "config")) {
m = strdup(offHelpers_offMode());
}
else {
@@ -1312,19 +1333,19 @@ void offHelpers_setTransport(char *mode ) {
}
// copy mode
- if (strcmp(m, "copy") == 0) {
+ if (strEq(m, "copy")) {
transport.send = transportCopySend;
transport.receive = transportCopyReceive;
}
// scp mode
- else if (strcmp(m, "scp") == 0) {
+ else if (strEq(m, "scp")) {
transport.send = transportScpSend;
transport.receive = transportScpReceive;
}
// http mode
- else if (strcmp(m, "http") == 0) {
+ else if (strEq(m, "http")) {
transport.send = transportHttpSend;
transport.receive = transportHttpReceive;
}
@@ -1498,7 +1519,7 @@ void transport_transformFrom(char *file) {
void thisrepo(cmdSetF_t cmd) {
- if ((argc > 2) && (strcmp(argv[2], "thisrepo") == 0)) {
+ if ((argc > 2) && (strEq(argv[2], "thisrepo"))) {
cmd(gitConfig_setThisRepo);
return;
}
@@ -1530,7 +1551,7 @@ int findCommand(char *p) {
int i;
for (i=0; i < lastC ;i++) {
- if (strcmp(p, COMMAND_MAP[i]) == 0) {
+ if (strEq(p, COMMAND_MAP[i])) {
break;
}
}
@@ -1671,11 +1692,11 @@ void offCommands_install(gConfig_set_t setF ) {
// create off.store
- if (strcmp(runtimeConfig[offMode], "copy") == 0) {
+ if (strEq(runtimeConfig[offMode], "copy")) {
mkdirParents(runtimeConfig[offStore]);
}
- if (strcmp(runtimeConfig[offMode], "scp") == 0) {
+ if (strEq(runtimeConfig[offMode], "scp")) {
offHelpers_mkdirStore("");
}
}
@@ -1727,7 +1748,7 @@ void offCommands_track() {
void offCommands_configAlways() {
- if (strcmp(argv[argc-1], "configAlways") != 0) {
+ if (!strEq(argv[argc-1], "configAlways")) {
gitConfig_set(COMMAND_GITCONFIG[configAlwaysC], argv[argc-1]);
}
else {
@@ -1740,7 +1761,7 @@ void offCommands_setGetGitConfig(gConfig_set_t setF) {
int i;
i = findCommand(argv[1]);
- if ((argc > 2) && (strcmp(argv[argc-1], "thisrepo") != 0)) {
+ if ((argc > 2) && (!strEq(argv[argc-1], "thisrepo"))) {
setF(COMMAND_GITCONFIG[i], argv[argc-1]);
}
else {
@@ -1809,7 +1830,7 @@ void offCommands_clean() {
chmod(filePath, S_IRUSR | S_IRGRP | S_IROTH);
// transform input file
- if ((strcmp(offHelpers_transform(), "enable") == 0) && (offHelpers_transformTo() != NULL)) {
+ if ((strEq(offHelpers_transform(), "enable")) && (offHelpers_transformTo() != NULL)) {
char *tmpDir;
tmpDir = malloc(strlen(offHelpers_objectPath()) + strlen(offFilePath[1]) + 1 + 8);
sprintf(tmpDir, "%s/../tmp/%s", offHelpers_objectPath(), offFilePath[1]);
@@ -2073,7 +2094,7 @@ void offCommands_smudge() {
if (access(filePath, F_OK) != -1) {
// copy from cache
FILE *fCache;
- if ((strcmp(offHelpers_transform(), "enable") == 0) && (offHelpers_transformFrom() != NULL)) {
+ if ((strEq(offHelpers_transform(), "enable")) && (offHelpers_transformFrom() != NULL)) {
// transform file
transport_transformFrom(offFilePath[0]);
@@ -2155,10 +2176,10 @@ void offCommands_clearCache() {
void offCommands_clearStore() {
// delete store
- if (strcmp(offHelpers_offMode(), "copy") == 0) {
+ if (strEq(offHelpers_offMode(), "copy")) {
rmAll(offHelpers_offStore());
}
- if (strcmp(offHelpers_offMode(), "scp") == 0) {
+ if (strEq(offHelpers_offMode(), "scp")) {
offHelpers_rmAllStore("");
}
}
@@ -2184,42 +2205,94 @@ void offCommands_defaults() {
}
void offCommands_env() {
+ char *s = NULL;
- printf("off.mode %s", offHelpers_offMode());
- printf("\n");
- printf("off.integrity %s", offHelpers_offIntegrity());
- printf("\n");
- printf("off.pem %s", offHelpers_offPem());
- printf("\n");
- printf("off.sshoptions %s", offHelpers_offSshOptions());
- printf("\n");
- printf("off.scpoptions %s", offHelpers_offScpOptions());
- printf("\n");
- printf("off.store %s", offHelpers_offStore());
- printf("\n");
- printf("off.http %s", offHelpers_offHttp());
- printf("\n");
- printf("off.curloptions %s", offHelpers_offCurlOptions());
- printf("\n");
- printf("off.scphost %s", offHelpers_offScp());
- printf("\n");
- printf("off.scpuser %s", offHelpers_offScpUser());
- printf("\n");
- printf("off.log %s", offHelpers_getLog());
- printf("\n");
- printf("off.configAlways %s", offHelpers_offConfigAlways());
- printf("\n");
- printf("off.s3region %s", offHelpers_s3Region());
- printf("\n");
- printf("off.s3bucket %s", offHelpers_s3Bucket());
- printf("\n");
- printf("off.transform %s", offHelpers_transform());
- printf("\n");
- printf("off.transformTo %s", offHelpers_transformTo());
- printf("\n");
- printf("off.transformFrom %s", offHelpers_transformFrom());
- printf("\n");
+ s = offHelpers_offMode();
+ if (s != NULL) {
+ printf("off.mode %s", offHelpers_offMode());
+ printf("\n");
+ }
+ s = offHelpers_offIntegrity();
+ if (s != NULL) {
+ printf("off.integrity %s", offHelpers_offIntegrity());
+ printf("\n");
+ }
+ s = offHelpers_offPem();
+ if (s != NULL) {
+ printf("off.pem %s", offHelpers_offPem());
+ printf("\n");
+ }
+ s = offHelpers_offSshOptions();
+ if (s != NULL) {
+ printf("off.sshoptions %s", offHelpers_offSshOptions());
+ printf("\n");
+ }
+ s = offHelpers_offScpOptions();
+ if (s != NULL) {
+ printf("off.scpoptions %s", offHelpers_offScpOptions());
+ printf("\n");
+ }
+ s = offHelpers_offStore();
+ if (s != NULL) {
+ printf("off.store %s", offHelpers_offStore());
+ printf("\n");
+ }
+ s = offHelpers_offHttp();
+ if (s != NULL) {
+ printf("off.http %s", offHelpers_offHttp());
+ printf("\n");
+ }
+ s = offHelpers_offCurlOptions();
+ if (s != NULL) {
+ printf("off.curloptions %s", offHelpers_offCurlOptions());
+ printf("\n");
+ }
+ s = offHelpers_offScp();
+ if (s != NULL) {
+ printf("off.scphost %s", offHelpers_offScp());
+ printf("\n");
+ }
+ s = offHelpers_offScpUser();
+ if (s != NULL) {
+ printf("off.scpuser %s", offHelpers_offScpUser());
+ printf("\n");
+ }
+ s = offHelpers_getLog();
+ if (s != NULL) {
+ printf("off.log %s", offHelpers_getLog());
+ printf("\n");
+ }
+ s = offHelpers_offConfigAlways();
+ if (s != NULL) {
+ printf("off.configAlways %s", offHelpers_offConfigAlways());
+ printf("\n");
+ }
+ s = offHelpers_s3Region();
+ if (s != NULL) {
+ printf("off.s3region %s", offHelpers_s3Region());
+ printf("\n");
+ }
+ s = offHelpers_s3Bucket();
+ if (s != NULL) {
+ printf("off.s3bucket %s", offHelpers_s3Bucket());
+ printf("\n");
+ }
+ s = offHelpers_transform();
+ if (s != NULL) {
+ printf("off.transform %s", offHelpers_transform());
+ printf("\n");
+ }
+ s = offHelpers_transformTo();
+ if (s != NULL) {
+ printf("off.transformTo %s", offHelpers_transformTo());
+ printf("\n");
+ }
+ s = offHelpers_transformFrom();
+ if (s != NULL) {
+ printf("off.transformFrom %s", offHelpers_transformFrom());
+ printf("\n");
}
+ }
void offCommands_help() {
diff --git a/c/gitoff.c b/c/gitoff.c
@@ -71,8 +71,13 @@
// modules
//////
// includes and function prototypes
+ #ifdef unitTest
// gitoff.h is used in unit tests
#include "gitoff.h"
+ #else
+typedef void (*gConfig_set_t)(char*, char*);
+typedef void (*cmdSetF_t)(gConfig_set_t);
+ #endif
#define internal static
@@ -92,6 +97,7 @@ char *expandHome(char *p);
void offLog(char* s);
void offLogRepo(char* s);
char *exec(int cmdName, char* paramsArray);
+bool strEq(char *string1, char *string2);
void gitConfig_set(char* key, char* value);
void gitConfig_setLocal(char* key, char* value);
void gitConfig_setThisRepo(char* key, char* value);
@@ -239,6 +245,9 @@ char *expandHome(char *p) {
wordexp_t exp_result;
size_t len;
+ if (p == NULL) {
+ return(NULL);
+ }
wordexp(p, &exp_result, 0);
p = realloc(p, strlen(exp_result.we_wordv[0])+1);
strcpy(p, exp_result.we_wordv[0]);
@@ -332,6 +341,18 @@ char *exec(int cmdName, char* paramsArray) {
return(line);
}
+// compare strings
+bool strEq(char *string1, char *string2) {
+
+ if (string1 == NULL) {
+ return(false);
+ }
+ if (string2 == NULL) {
+ return(false);
+ }
+ return(strcmp(string1,string2) == 0);;
+}
+
// handles global git config
void gitConfig_set(char* key, char* value) {
@@ -383,7 +404,7 @@ char *gitConfig_get(char *key) {
char* gitOffConfigEnv = NULL;
// configAlways
- if (strcmp(offHelpers_offConfigAlways(), "GIT_OFF_CONFIG") == 0) {
+ if (strEq(offHelpers_offConfigAlways(), "GIT_OFF_CONFIG")) {
gitOffConfigEnv = getenv("GIT_OFF_CONFIG");
if ((gitOffConfigEnv != NULL) && (access(gitOffConfigEnv, F_OK) != -1)) {
p = malloc(strlen(gitOffConfigEnv) + strlen(key) + 1 + 8);
@@ -393,7 +414,7 @@ char *gitConfig_get(char *key) {
}
return(r);
}
- if (strcmp(offHelpers_offConfigAlways(), "repo") == 0) {
+ if (strEq(offHelpers_offConfigAlways(), "repo")) {
p = malloc(strlen(offHelpers_gitRepoRoot()) + 1 + 9);
sprintf(p, "%s/.git-off", offHelpers_gitRepoRoot());
if (access(p, F_OK) != -1) {
@@ -405,7 +426,7 @@ char *gitConfig_get(char *key) {
free(p);
return(r);
}
- if (strcmp(offHelpers_offConfigAlways(), "global") == 0) {
+ if (strEq(offHelpers_offConfigAlways(), "global")) {
r = gitConfig_getDefault(key);
return(r);
}
@@ -792,7 +813,7 @@ char *offHelpers_transformFrom() {
char *offHelpers_userAt() {
- if ((offHelpers_offScpUser() != NULL) && (strcmp(offHelpers_offScpUser(), "") != 0)) {
+ if ((offHelpers_offScpUser() != NULL) && (!strEq(offHelpers_offScpUser(), ""))) {
char *u;
u = malloc(strlen(offHelpers_offScpUser()) + 1 + 1);
sprintf(u, "%s@", offHelpers_offScpUser());
@@ -878,7 +899,7 @@ void offHelpers_mkdirStore(char *p) {
sprintf(sshCmd, "mkdir -p %s/%s", h_l[1], p);
// setup ssh/scp private key
- if ((offHelpers_offPem() == NULL) || (strcmp(offHelpers_offPem(), "offNoValue") == 0)) {
+ if ((offHelpers_offPem() == NULL) || (strEq(offHelpers_offPem(), "offNoValue")) || (offHelpers_offPem() == NULL)) {
pem = strdup("");
}
else {
@@ -912,7 +933,7 @@ void offHelpers_rmAllStore(char *p) {
char **h_l = NULL;
// setup ssh/scp private key
- if ((offHelpers_offPem() == NULL) || (strcmp(offHelpers_offPem(), "offNoValue") == 0)) {
+ if ((offHelpers_offPem() == NULL) || (strEq(offHelpers_offPem(), "offNoValue")) || (offHelpers_offPem() == NULL)) {
pem = strdup("");
}
else {
@@ -981,14 +1002,14 @@ bool offHelpers_checkIntegrity(char *p) {
char *receivedSha = NULL;
char *base = NULL;
- if (strcmp(offHelpers_offIntegrity(), "disable") == 0) {
+ if (strEq(offHelpers_offIntegrity(), "disable")) {
return(true);
}
receivedSha = exec(sha, p);
base = strdup(basename(p));
- if (strcmp(base, receivedSha) != 0) {
+ if (!strEq(base, receivedSha)) {
// the file received is different from the one that was sent.
printf("git-off: The file %s differs from the one that was pushed.", p); {
printf("\n");
@@ -1033,7 +1054,7 @@ void transportCopyReceive(char *file) {
char b[1024];
FILE *f = NULL;
- if ((strcmp(offHelpers_transform(), "enable") == 0) && (offHelpers_transformFrom() != NULL)) {
+ if ((strEq(offHelpers_transform(), "enable")) && (offHelpers_transformFrom() != NULL)) {
// create file directories in objectPath
char **f_l;
DIR *d;
@@ -1106,7 +1127,7 @@ void transportScpSend(char *file) {
h_l = offHelpers_getSSHConfig();
// setup ssh/scp private key
- if ((offHelpers_offPem() == NULL) || (strcmp(offHelpers_offPem(), "offNoValue") == 0)) {
+ if ((offHelpers_offPem() == NULL) || (strEq(offHelpers_offPem(), "offNoValue")) || (offHelpers_offPem() == NULL)) {
pem = strdup("");
}
else {
@@ -1161,7 +1182,7 @@ void transportScpReceive(char *file) {
h_l = offHelpers_getSSHConfig();
// setup ssh/scp private key
- if ((offHelpers_offPem() == NULL) || (strcmp(offHelpers_offPem(), "offNoValue") == 0)) {
+ if ((offHelpers_offPem() == NULL) || (strEq(offHelpers_offPem(), "offNoValue")) || (offHelpers_offPem() == NULL)) {
pem = strdup("");
}
else {
@@ -1198,7 +1219,7 @@ void transportScpReceive(char *file) {
char b[1024];
FILE *f;
- if ((strcmp(offHelpers_transform(), "enable") == 0) && (offHelpers_transformFrom() != NULL)) {
+ if ((strEq(offHelpers_transform(), "enable")) && (offHelpers_transformFrom() != NULL)) {
transport_transformFrom(file);
p = malloc(strlen(offHelpers_objectPath()) + strlen(file) + 1 + 8);
sprintf(p, "%s/../tmp/%s", offHelpers_objectPath(), file);
@@ -1265,7 +1286,7 @@ void transportHttpReceive(char *file) {
char b[1024];
FILE *f;
- if ((strcmp(offHelpers_transform(), "enable") == 0) && (offHelpers_transformFrom() != NULL)) {
+ if ((strEq(offHelpers_transform(), "enable")) && (offHelpers_transformFrom() != NULL)) {
transport_transformFrom(file);
p = malloc(strlen(offHelpers_objectPath()) + strlen(file) + 1 + 8);
sprintf(p, "%s/../tmp/%s", offHelpers_objectPath(), file);
@@ -1303,7 +1324,7 @@ void offHelpers_setTransport(char *mode ) {
// copy, scp
// use mode from config or from parameter
- if (strcmp(mode, "config") == 0) {
+ if (strEq(mode, "config")) {
m = strdup(offHelpers_offMode());
}
else {
@@ -1311,19 +1332,19 @@ void offHelpers_setTransport(char *mode ) {
}
// copy mode
- if (strcmp(m, "copy") == 0) {
+ if (strEq(m, "copy")) {
transport.send = transportCopySend;
transport.receive = transportCopyReceive;
}
// scp mode
- else if (strcmp(m, "scp") == 0) {
+ else if (strEq(m, "scp")) {
transport.send = transportScpSend;
transport.receive = transportScpReceive;
}
// http mode
- else if (strcmp(m, "http") == 0) {
+ else if (strEq(m, "http")) {
transport.send = transportHttpSend;
transport.receive = transportHttpReceive;
}
@@ -1497,7 +1518,7 @@ void transport_transformFrom(char *file) {
void thisrepo(cmdSetF_t cmd) {
- if ((argc > 2) && (strcmp(argv[2], "thisrepo") == 0)) {
+ if ((argc > 2) && (strEq(argv[2], "thisrepo"))) {
cmd(gitConfig_setThisRepo);
return;
}
@@ -1529,7 +1550,7 @@ int findCommand(char *p) {
int i;
for (i=0; i < lastC ;i++) {
- if (strcmp(p, COMMAND_MAP[i]) == 0) {
+ if (strEq(p, COMMAND_MAP[i])) {
break;
}
}
@@ -1670,11 +1691,11 @@ void offCommands_install(gConfig_set_t setF ) {
// create off.store
- if (strcmp(runtimeConfig[offMode], "copy") == 0) {
+ if (strEq(runtimeConfig[offMode], "copy")) {
mkdirParents(runtimeConfig[offStore]);
}
- if (strcmp(runtimeConfig[offMode], "scp") == 0) {
+ if (strEq(runtimeConfig[offMode], "scp")) {
offHelpers_mkdirStore("");
}
}
@@ -1726,7 +1747,7 @@ void offCommands_track() {
void offCommands_configAlways() {
- if (strcmp(argv[argc-1], "configAlways") != 0) {
+ if (!strEq(argv[argc-1], "configAlways")) {
gitConfig_set(COMMAND_GITCONFIG[configAlwaysC], argv[argc-1]);
}
else {
@@ -1739,7 +1760,7 @@ void offCommands_setGetGitConfig(gConfig_set_t setF) {
int i;
i = findCommand(argv[1]);
- if ((argc > 2) && (strcmp(argv[argc-1], "thisrepo") != 0)) {
+ if ((argc > 2) && (!strEq(argv[argc-1], "thisrepo"))) {
setF(COMMAND_GITCONFIG[i], argv[argc-1]);
}
else {
@@ -1808,7 +1829,7 @@ void offCommands_clean() {
chmod(filePath, S_IRUSR | S_IRGRP | S_IROTH);
// transform input file
- if ((strcmp(offHelpers_transform(), "enable") == 0) && (offHelpers_transformTo() != NULL)) {
+ if ((strEq(offHelpers_transform(), "enable")) && (offHelpers_transformTo() != NULL)) {
char *tmpDir;
tmpDir = malloc(strlen(offHelpers_objectPath()) + strlen(offFilePath[1]) + 1 + 8);
sprintf(tmpDir, "%s/../tmp/%s", offHelpers_objectPath(), offFilePath[1]);
@@ -2072,7 +2093,7 @@ void offCommands_smudge() {
if (access(filePath, F_OK) != -1) {
// copy from cache
FILE *fCache;
- if ((strcmp(offHelpers_transform(), "enable") == 0) && (offHelpers_transformFrom() != NULL)) {
+ if ((strEq(offHelpers_transform(), "enable")) && (offHelpers_transformFrom() != NULL)) {
// transform file
transport_transformFrom(offFilePath[0]);
@@ -2154,10 +2175,10 @@ void offCommands_clearCache() {
void offCommands_clearStore() {
// delete store
- if (strcmp(offHelpers_offMode(), "copy") == 0) {
+ if (strEq(offHelpers_offMode(), "copy")) {
rmAll(offHelpers_offStore());
}
- if (strcmp(offHelpers_offMode(), "scp") == 0) {
+ if (strEq(offHelpers_offMode(), "scp")) {
offHelpers_rmAllStore("");
}
}
@@ -2183,42 +2204,94 @@ void offCommands_defaults() {
}
void offCommands_env() {
+ char *s = NULL;
- printf("off.mode %s", offHelpers_offMode());
- printf("\n");
- printf("off.integrity %s", offHelpers_offIntegrity());
- printf("\n");
- printf("off.pem %s", offHelpers_offPem());
- printf("\n");
- printf("off.sshoptions %s", offHelpers_offSshOptions());
- printf("\n");
- printf("off.scpoptions %s", offHelpers_offScpOptions());
- printf("\n");
- printf("off.store %s", offHelpers_offStore());
- printf("\n");
- printf("off.http %s", offHelpers_offHttp());
- printf("\n");
- printf("off.curloptions %s", offHelpers_offCurlOptions());
- printf("\n");
- printf("off.scphost %s", offHelpers_offScp());
- printf("\n");
- printf("off.scpuser %s", offHelpers_offScpUser());
- printf("\n");
- printf("off.log %s", offHelpers_getLog());
- printf("\n");
- printf("off.configAlways %s", offHelpers_offConfigAlways());
- printf("\n");
- printf("off.s3region %s", offHelpers_s3Region());
- printf("\n");
- printf("off.s3bucket %s", offHelpers_s3Bucket());
- printf("\n");
- printf("off.transform %s", offHelpers_transform());
- printf("\n");
- printf("off.transformTo %s", offHelpers_transformTo());
- printf("\n");
- printf("off.transformFrom %s", offHelpers_transformFrom());
- printf("\n");
+ s = offHelpers_offMode();
+ if (s != NULL) {
+ printf("off.mode %s", offHelpers_offMode());
+ printf("\n");
+ }
+ s = offHelpers_offIntegrity();
+ if (s != NULL) {
+ printf("off.integrity %s", offHelpers_offIntegrity());
+ printf("\n");
+ }
+ s = offHelpers_offPem();
+ if (s != NULL) {
+ printf("off.pem %s", offHelpers_offPem());
+ printf("\n");
+ }
+ s = offHelpers_offSshOptions();
+ if (s != NULL) {
+ printf("off.sshoptions %s", offHelpers_offSshOptions());
+ printf("\n");
+ }
+ s = offHelpers_offScpOptions();
+ if (s != NULL) {
+ printf("off.scpoptions %s", offHelpers_offScpOptions());
+ printf("\n");
+ }
+ s = offHelpers_offStore();
+ if (s != NULL) {
+ printf("off.store %s", offHelpers_offStore());
+ printf("\n");
+ }
+ s = offHelpers_offHttp();
+ if (s != NULL) {
+ printf("off.http %s", offHelpers_offHttp());
+ printf("\n");
+ }
+ s = offHelpers_offCurlOptions();
+ if (s != NULL) {
+ printf("off.curloptions %s", offHelpers_offCurlOptions());
+ printf("\n");
+ }
+ s = offHelpers_offScp();
+ if (s != NULL) {
+ printf("off.scphost %s", offHelpers_offScp());
+ printf("\n");
+ }
+ s = offHelpers_offScpUser();
+ if (s != NULL) {
+ printf("off.scpuser %s", offHelpers_offScpUser());
+ printf("\n");
+ }
+ s = offHelpers_getLog();
+ if (s != NULL) {
+ printf("off.log %s", offHelpers_getLog());
+ printf("\n");
+ }
+ s = offHelpers_offConfigAlways();
+ if (s != NULL) {
+ printf("off.configAlways %s", offHelpers_offConfigAlways());
+ printf("\n");
+ }
+ s = offHelpers_s3Region();
+ if (s != NULL) {
+ printf("off.s3region %s", offHelpers_s3Region());
+ printf("\n");
+ }
+ s = offHelpers_s3Bucket();
+ if (s != NULL) {
+ printf("off.s3bucket %s", offHelpers_s3Bucket());
+ printf("\n");
+ }
+ s = offHelpers_transform();
+ if (s != NULL) {
+ printf("off.transform %s", offHelpers_transform());
+ printf("\n");
+ }
+ s = offHelpers_transformTo();
+ if (s != NULL) {
+ printf("off.transformTo %s", offHelpers_transformTo());
+ printf("\n");
+ }
+ s = offHelpers_transformFrom();
+ if (s != NULL) {
+ printf("off.transformFrom %s", offHelpers_transformFrom());
+ printf("\n");
}
+ }
void offCommands_help() {