Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Fix 3 way merge on large files
Baptiste Daroussin committed 10 years ago
commit 2c587f0dbcf2826e3d89fe69cd6a9fbe322e76e3
parent 45d76d4
2 files changed +19 -16
modified libpkg/merge3.c
@@ -104,6 +104,14 @@ static int sameEdit(
  return 0;
}

+
/*
+
** Copy N lines of text from from into to.
+
** The return value is the number of characters copied, normally including
+
** the \n and should be used to advance the 'from' pointer.
+
**
+
** If to==NULL then this routine simply counts characters for N lines.
+
*/
+

static int
sbuf_copy_lines(struct sbuf *to, const char *from, int N)
{
@@ -112,25 +120,19 @@ sbuf_copy_lines(struct sbuf *to, const char *from, int N)

	if (N == 0)
		return (0);
-

-
	for (i = 0; from[i] != '\0'; i++) {
+
	i = 0;
+
	while (from[i] != 0) {
		if (from[i] == '\n') {
			cnt++;
-
			continue;
+
			if (cnt == N) {
+
				i++;
+
				break;
+
			}
		}
-
		if (cnt == N)
-
			break;
+
		i++;
	}
-

-
	if (to == NULL)
-
		return (i);
-
		
-
	if (sbuf_len(to) > 0 &&
-
	    sbuf_data(to)[sbuf_len(to)-1] != '\n')
-
		sbuf_putc(to, '\n');
-
	sbuf_bcat(to, from, i);
-
	sbuf_finish(to);
-

+
	if (to)
+
		sbuf_bcat(to, from, i);
	return (i);
}

@@ -277,5 +279,6 @@ int merge_3way(
  int rc;             /* Return code of subroutines and this routine */

  rc = sbuf_merge(pPivot, pV1, pV2, pOut);
+
  sbuf_finish(pOut);
  return rc;
}
modified libpkg/pkg_add.c
@@ -227,7 +227,7 @@ do_extract(struct archive *a, struct archive_entry *ae, const char *location,
		/*
		 * check if the file is already provided by previous package
		 */
-
		if (!automerge)
+
		if (automerge)
			attempt_to_merge(renamed, rcf, local, pathname, path, newconf);

		if (sbuf_len(newconf) == 0 && (rcf == NULL || rcf->content == NULL)) {