Commit 93f8a3371abdcbfdc9e411ff44942acb0198ca47

Christian Weisgerber 2021-08-30T16:34:04

tweak implementation of separate send {} and fetch {} conf blocks Tweak man page. Factor out repeated code in if/else branches in send_gotconfig_remotes(). ok stsp@

diff --git a/got/got.conf.5 b/got/got.conf.5
index 7b400d1..fdf7526 100644
--- a/got/got.conf.5
+++ b/got/got.conf.5
@@ -112,7 +112,7 @@ Specify one or more branches which
 .Cm got fetch
 and
 .Cm got send
-should fetch and send from the remote repository by default.
+should fetch from and send to the remote repository by default.
 The list of branches specified here can be overridden at the
 .Cm got fetch
 and
diff --git a/libexec/got-read-gotconfig/got-read-gotconfig.c b/libexec/got-read-gotconfig/got-read-gotconfig.c
index 87b6e32..3eb4560 100644
--- a/libexec/got-read-gotconfig/got-read-gotconfig.c
+++ b/libexec/got-read-gotconfig/got-read-gotconfig.c
@@ -255,32 +255,22 @@ send_gotconfig_remotes(struct imsgbuf *ibuf,
 		struct node_ref *ref;
 		int nfetch_branches = 0, nsend_branches = 0, nfetch_refs = 0;
 
-		if (repo->fetch_config && repo->fetch_config->branch) {
+		if (repo->fetch_config && repo->fetch_config->branch)
 			branch = repo->fetch_config->branch;
-			while (branch) {
-				branch = branch->next;
-				nfetch_branches++;
-			}
-		} else {
+		else
 			branch = repo->branch;
-			while (branch) {
-				branch = branch->next;
-				nfetch_branches++;
-			}
+		while (branch) {
+			branch = branch->next;
+			nfetch_branches++;
 		}
 
-		if (repo->send_config && repo->send_config->branch) {
+		if (repo->send_config && repo->send_config->branch)
 			branch = repo->send_config->branch;
-			while (branch) {
-				branch = branch->next;
-				nsend_branches++;
-			}
-		} else {
+		else
 			branch = repo->branch;
-			while (branch) {
-				branch = branch->next;
-				nsend_branches++;
-			}
+		while (branch) {
+			branch = branch->next;
+			nsend_branches++;
 		}
 
 		ref = repo->fetch_ref;
@@ -354,44 +344,26 @@ send_gotconfig_remotes(struct imsgbuf *ibuf,
 		free(send_url);
 		send_url = NULL;
 
-		if (repo->fetch_config && repo->fetch_config->branch) {
+		if (repo->fetch_config && repo->fetch_config->branch)
 			branch = repo->fetch_config->branch;
-			while (branch) {
-				err = send_gotconfig_str(ibuf,
-				    branch->branch_name);
-				if (err)
-					break;
-				branch = branch->next;
-			}
-		} else {
+		else
 			branch = repo->branch;
-			while (branch) {
-				err = send_gotconfig_str(ibuf,
-				    branch->branch_name);
-				if (err)
-					break;
-				branch = branch->next;
-			}
+		while (branch) {
+			err = send_gotconfig_str(ibuf, branch->branch_name);
+			if (err)
+				break;
+			branch = branch->next;
 		}
 
-		if (repo->send_config && repo->send_config->branch) {
+		if (repo->send_config && repo->send_config->branch)
 			branch = repo->send_config->branch;
-			while (branch) {
-				err = send_gotconfig_str(ibuf,
-				    branch->branch_name);
-				if (err)
-					break;
-				branch = branch->next;
-			}
-		} else {
+		else
 			branch = repo->branch;
-			while (branch) {
-				err = send_gotconfig_str(ibuf,
-				    branch->branch_name);
-				if (err)
-					break;
-				branch = branch->next;
-			}
+		while (branch) {
+			err = send_gotconfig_str(ibuf, branch->branch_name);
+			if (err)
+				break;
+			branch = branch->next;
 		}
 
 		ref = repo->fetch_ref;