Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
merge3: get rid of utstring
Baptiste Daroussin committed 5 years ago
commit d88f0c4f533d3bb46ab19b6d325c77933b2d7df0
parent cd7a63a
6 files changed +28 -23
modified libpkg/merge3.c
@@ -50,7 +50,7 @@
*/

#include <sys/types.h>
-
#include <utstring.h>
+
#include <xstring.h>

#include <string.h>
#include <stdlib.h>
@@ -113,7 +113,7 @@ static int sameEdit(
*/

static int
-
buf_copy_lines(UT_string *to, const char *from, int N)
+
buf_copy_lines(xstring *to, const char *from, int N)
{
	int cnt = 0;
	int i;
@@ -132,7 +132,7 @@ buf_copy_lines(UT_string *to, const char *from, int N)
		i++;
	}
	if (to)
-
		utstring_bincpy(to, from, i);
+
		fwrite(from, i, 1, to->fp);
	return (i);
}

@@ -149,14 +149,14 @@ buf_copy_lines(UT_string *to, const char *from, int N)
** of conflicts is returns
*/
static int
-
buf_merge(char *pPivot, char *pV1, char *pV2, UT_string *pOut){
+
buf_merge(char *pPivot, char *pV1, char *pV2, xstring *pOut){
  int *aC1;              /* Changes from pPivot to pV1 */
  int *aC2;              /* Changes from pPivot to pV2 */
  int i1, i2;            /* Index into aC1[] and aC2[] */
  int nCpy, nDel, nIns;  /* Number of lines to copy, delete, or insert */
  int limit1, limit2;    /* Sizes of aC1[] and aC2[] */

-
  utstring_clear(pOut);         /* Merge results stored in pOut */
+
  xstring_reset(pOut);         /* Merge results stored in pOut */

  /* Compute the edits that occur from pPivot => pV1 (into aC1)
  ** and pPivot => pV2 (into aC2).  Each of the aC1 and aC2 arrays is
@@ -274,7 +274,7 @@ int merge_3way(
  char *pPivot,       /* Common ancestor (older) */
  char *pV1,    /* Name of file for version merging into (mine) */
  char *pV2,          /* Version merging from (yours) */
-
  UT_string *pOut         /* Output written here */
+
  xstring *pOut         /* Output written here */
){
  int rc;             /* Return code of subroutines and this routine */

modified libpkg/pkg_add.c
@@ -111,7 +111,7 @@ attempt_to_merge(int rootfd, struct pkg_config_file *rcf, struct pkg *local,
{
	const struct pkg_file *lf = NULL;
	struct stat st;
-
	UT_string *newconf;
+
	xstring *newconf;
	struct pkg_config_file *lcf = NULL;

	char *localconf = NULL;
@@ -168,14 +168,15 @@ attempt_to_merge(int rootfd, struct pkg_config_file *rcf, struct pkg *local,
	}

	pkg_debug(1, "Attempting to merge %s", rcf->path);
-
	utstring_new(newconf);
+
	newconf = xstring_new();
	if (merge_3way(lcf->content, localconf, rcf->content, newconf) != 0) {
+
		xstring_free(newconf);
		pkg_emit_error("Impossible to merge configuration file");
	} else {
-
		rcf->newcontent = xstrdup(utstring_body(newconf));
+
		char *conf = xstring_get(newconf);
+
		rcf->newcontent = conf;
		rcf->status = MERGE_SUCCESS;
	}
-
	utstring_free(newconf);
	free(localconf);
}

modified libpkg/pkg_repo_create.c
@@ -53,6 +53,7 @@
#include <poll.h>
#include <sys/uio.h>
#include <msgpuck.h>
+
#include <utstring.h>

#include "pkg.h"
#include "private/event.h"
modified libpkg/private/pkg.h
@@ -40,7 +40,6 @@
#include <stdbool.h>
#include <uthash.h>
#include <utlist.h>
-
#include <utstring.h>
#include <ucl.h>

#include "xmalloc.h"
modified libpkg/private/utils.h
@@ -34,7 +34,7 @@
#include <ucl.h>
#include <khash.h>
#include <pkg.h>
-
#include <utstring.h>
+
#include <xstring.h>

#define STARTS_WITH(string, needle) (strncasecmp(string, needle, strlen(needle)) == 0)
#define RELATIVE_PATH(p) (p + (*p == '/' ? 1 : 0))
@@ -97,7 +97,7 @@ pid_t process_spawn_pipe(FILE *inout[2], const char *command);

void *parse_mode(const char *str);
int *text_diff(char *a, char *b);
-
int merge_3way(char *pivot, char *v1, char *v2, UT_string *out);
+
int merge_3way(char *pivot, char *v1, char *v2, xstring *out);
bool string_end_with(const char *path, const char *str);
bool mkdirat_p(int fd, const char *path);
int get_socketpair(int *);
modified tests/lib/merge.c
@@ -39,40 +39,44 @@ ATF_TC_HEAD(merge, tc)

ATF_TC_BODY(merge, tc)
{
-
	UT_string *b;
-
	utstring_new(b);
+
	xstring *b;
+
	b = xstring_new();
	char *pivot = "test1\ntest2\n";
	char *modified = "test1\n#test2\n";
	char *new = "test1\ntest2\ntest3\n";

	ATF_REQUIRE_EQ(merge_3way(pivot, modified, new, b), 0);
-
	ATF_REQUIRE_STREQ(utstring_body(b), "test1\n#test2\ntest3\n");
+
	fflush(b->fp);
+
	ATF_REQUIRE_STREQ(b->buf, "test1\n#test2\ntest3\n");

-
	utstring_clear(b);
+
	xstring_reset(b);
	pivot = "test1\ntest2";
	modified = "test1\n#test2";
	new = "test1\ntest2\ntest3";

	ATF_REQUIRE_EQ(merge_3way(pivot, modified, new, b), 0);
-
	ATF_REQUIRE_STREQ(utstring_body(b), "test1\n#test2test3");
+
	fflush(b->fp);
+
	ATF_REQUIRE_STREQ(b->buf, "test1\n#test2test3");

-
	utstring_clear(b);
+
	xstring_reset(b);
	pivot = "test1\ntest2";
	modified = "test1\n";
	new = "test1\ntest2\ntest3";

	ATF_REQUIRE_EQ(merge_3way(pivot, modified, new, b), 0);
-
	ATF_REQUIRE_STREQ(utstring_body(b), "test1\ntest3");
+
	fflush(b->fp);
+
	ATF_REQUIRE_STREQ(b->buf, "test1\ntest3");

-
	utstring_clear(b);
+
	xstring_reset(b);
	pivot = "test1\ntest2\ntest3";
	modified = "test1\na\ntest2\ntest3";
	new = "test1\ntest2\ntest3";

	ATF_REQUIRE_EQ(merge_3way(pivot, modified, new, b), 0);
-
	ATF_REQUIRE_STREQ(utstring_body(b), "test1\na\ntest2\ntest3");
+
	fflush(b->fp);
+
	ATF_REQUIRE_STREQ(b->buf, "test1\na\ntest2\ntest3");

-
	utstring_free(b);
+
	xstring_free(b);
}

ATF_TP_ADD_TCS(tp)