Commit e31a9b48 authored by Bernhard Link's avatar Bernhard Link

some more code to test rred patch merging

parent 7a702b07
......@@ -2,7 +2,7 @@ SUBDIRS = docs tests
EXTRA_DIST = autogen.sh
bin_PROGRAMS = reprepro changestool
bin_PROGRAMS = reprepro changestool rredtool
if HAVE_LIBARCHIVE
ARCHIVE_USED = ar.c debfile.c
......@@ -23,7 +23,9 @@ EXTRA_reprepro_SOURCE = $(ARCHIVE_UNUSED)
changestool_SOURCES = uncompression.c sourceextraction.c readtextfile.c filecntl.c tool.c chunkedit.c strlist.c checksums.c sha1.c sha256.c md5.c mprintf.c chunks.c signature.c dirs.c names.c $(ARCHIVE_USED)
noinst_HEADERS = pool.h atoms.h uncompression.h remoterepository.h copypackages.h sourceextraction.h checksums.h readtextfile.h filecntl.h sha1.h sha256.h configparser.h database_p.h database.h freespace.h log.h changes.h incoming.h guesscomponent.h md5.h dirs.h files.h chunks.h reference.h binaries.h sources.h checks.h names.h release.h error.h mprintf.h updates.h strlist.h signature.h distribution.h debfile.h checkindeb.h checkindsc.h upgradelist.h target.h aptmethod.h downloadcache.h override.h terms.h ignore.h filterlist.h dpkgversions.h checkin.h exports.h globals.h tracking.h trackingt.h optionsfile.h readrelease.h donefile.h pull.h ar.h filelist.h contents.h chunkedit.h uploaderslist.h indexfile.h
rredtool_SOURCES = rredtool.c rredpatch.c
noinst_HEADERS = pool.h atoms.h uncompression.h remoterepository.h copypackages.h sourceextraction.h checksums.h readtextfile.h filecntl.h sha1.h sha256.h configparser.h database_p.h database.h freespace.h log.h changes.h incoming.h guesscomponent.h md5.h dirs.h files.h chunks.h reference.h binaries.h sources.h checks.h names.h release.h error.h mprintf.h updates.h strlist.h signature.h distribution.h debfile.h checkindeb.h checkindsc.h upgradelist.h target.h aptmethod.h downloadcache.h override.h terms.h ignore.h filterlist.h dpkgversions.h checkin.h exports.h globals.h tracking.h trackingt.h optionsfile.h readrelease.h donefile.h pull.h ar.h filelist.h contents.h chunkedit.h uploaderslist.h indexfile.h rredpatch.h
MAINTAINERCLEANFILES = $(srcdir)/Makefile.in $(srcdir)/configure $(srcdir)/stamp-h.in $(srcdir)/aclocal.m4 $(srcdir)/config.h.in
......
This diff is collapsed.
struct rred_patch;
struct modification;
retvalue patch_load(const char *, off_t, /*@out@*/struct rred_patch **);
void patch_free(/*@only@*/struct rred_patch *);
/*@only@*//*@null@*/struct modification *patch_getmodifications(struct rred_patch *);
void modification_freelist(/*@only@*/struct modification *);
retvalue combine_patches(/*@out@*/struct modification **, /*@only@*/struct modification *, /*@only@*/struct modification *);
void modification_printaspatch(const struct modification *);
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include "globals.h"
#include "error.h"
#include "rredpatch.h"
static const struct option options[] = {
{"version", no_argument, NULL, 'V'},
{"help", no_argument, NULL, 'h'},
{"debug", no_argument, NULL, 'D'},
{"merge", no_argument, NULL, 'm'},
{NULL, 0, NULL, 0}
};
int main(int argc, const char *argv[]) {
struct rred_patch *patches[argc];
struct modification *m;
retvalue r;
bool mergemode = false;
int i, count;
const char *sourcename;
int debug = 0;
while( (i = getopt_long(argc, (char**)argv, "+hVDm", options, NULL)) != -1 ) {
switch (i) {
case 'h':
puts(
"rred-tool: handle some subset of ed-patches\n"
"Syntax: rred-tool --merge patches...\n"
"or: rred-tool file-to-patch patches...");
return EXIT_SUCCESS;
case 'V':
printf("rred-tool from " PACKAGE_NAME " version " PACKAGE_VERSION);
return EXIT_SUCCESS;
case 'D':
debug++;
break;
case 'm':
mergemode = 1;
break;
case '?':
default:
return EXIT_FAILURE;
}
}
i = optind;
if( !mergemode ) {
if( i >= argc ) {
fprintf(stderr, "Not enough arguments!\n");
return EXIT_FAILURE;
}
sourcename = argv[i++];
}
count = 0;
while( i < argc ) {
r = patch_load(argv[i], -1, &patches[count]);
if( RET_IS_OK(r) )
count++;
if( RET_WAS_ERROR(r) ) {
fprintf(stderr, "Aborting...\n");
return RET_ERRNO(r);
}
i++;
}
if( count <= 0 ) {
fprintf(stderr, "Not enough patches for operation...\n");
return EXIT_FAILURE;
}
m = patch_getmodifications(patches[0]);
for( i = 1; i < count ; i++ ) {
struct modification *a = patch_getmodifications(patches[i]);
if( debug ) {
puts("--------RESULT SO FAR----------------");
modification_printaspatch(m);
puts("--------TO BE MERGED WITH------------");
modification_printaspatch(a);
puts("-------------END---------------------");
}
r = combine_patches(&m, m, a);
if( RET_WAS_ERROR(r) ) {
for( i = 0 ; i < count ; i++ ) {
patch_free(patches[i]);
}
fprintf(stderr, "Aborting...\n");
return RET_ERRNO(r);
}
}
if( mergemode )
modification_printaspatch(m);
modification_freelist(m);
for( i = 0 ; i < count ; i++ )
patch_free(patches[i]);
return EXIT_SUCCESS;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment