PERFORCE change 180511 for review
Ivan Voras
ivoras at FreeBSD.org
Mon Jul 5 23:27:00 UTC 2010
http://p4web.freebsd.org/@@180511?ac=10
Change 180511 by ivoras at betelgeuse on 2010/07/05 23:26:12
Mass patch creation feature (Milestone 3) done.
Affected files ...
.. //depot/projects/soc2010/pkg_patch/src/patch/Makefile#19 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/applypatch.c#9 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/applypatch.h#9 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/hashjob.c#18 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/hashjob.h#18 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/main.c#19 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.c#17 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.h#17 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/mkpatchdir.c#1 add
.. //depot/projects/soc2010/pkg_patch/src/patch/mkpatchdir.h#1 add
.. //depot/projects/soc2010/pkg_patch/src/patch/pkg_patch.h#17 edit
.. //depot/projects/soc2010/pkg_patch/src/patch/support.c#16 edit
Differences ...
==== //depot/projects/soc2010/pkg_patch/src/patch/Makefile#19 (text+ko) ====
@@ -3,7 +3,7 @@
.include <bsd.own.mk>
PROG= pkg_patch
-SRCS= main.c applypatch.c mkpatch.c support.c hashjob.c
+SRCS= main.c applypatch.c mkpatch.c mkpatchdir.c support.c hashjob.c
WARNS?= 4
WFORMAT?= 1
==== //depot/projects/soc2010/pkg_patch/src/patch/applypatch.c#9 (text+ko) ====
@@ -264,7 +264,7 @@
* Apply patch command
*/
void
-perform_applypatch()
+perform_applypatch(char *file_patch)
{
char fpatch[PATH_MAX], dpatch[PATH_MAX], tmp[PATH_MAX], pext[10];
char backup_pkg[PATH_MAX];
@@ -275,10 +275,8 @@
FILE **fpvect;
unsigned int err_count, n_patched_files, i;
- if (argc < 1)
- errx(1, "Expecting argument: patch filename");
- if (realpath(argv[0], fpatch) == NULL)
- err(1, "Error resolving path: %s", argv[0]);
+ if (realpath(file_patch, fpatch) == NULL)
+ err(1, "Error resolving path: %s", file_patch);
if (access(fpatch, F_OK) != 0)
err(1, "File not found: %s", fpatch);
if (access(fpatch, R_OK) != 0)
==== //depot/projects/soc2010/pkg_patch/src/patch/applypatch.h#9 (text+ko) ====
@@ -20,6 +20,6 @@
#ifndef _APPLYPATCH_H_
#define _APPLYPATCH_H_
-void perform_applypatch(void);
+void perform_applypatch(char *file_patch);
#endif
==== //depot/projects/soc2010/pkg_patch/src/patch/hashjob.c#18 (text+ko) ====
==== //depot/projects/soc2010/pkg_patch/src/patch/hashjob.h#18 (text+ko) ====
==== //depot/projects/soc2010/pkg_patch/src/patch/main.c#19 (text+ko) ====
@@ -32,6 +32,7 @@
#define PKG_PATCH_MAIN
#include "pkg_patch.h"
#include "mkpatch.h"
+#include "mkpatchdir.h"
#include "applypatch.h"
@@ -53,6 +54,7 @@
printf("usage:\n");
printf("\t%s -c [-b] package_file_1 package_file_2 patch_file\n", argv[0]);
printf("\t%s -a patch_file\n", argv[0]);
+ printf("\t%s -m package_dir_1 package_dir_2 patch_dir\n", argv[0]);
}
@@ -60,7 +62,7 @@
proc_args() {
int ch;
- while ((ch = getopt(argc, argv, "abcfhv")) != -1) {
+ while ((ch = getopt(argc, argv, "abcfhmv")) != -1) {
switch (ch) {
case 'a':
patch_op = PP_APPLY;
@@ -78,6 +80,9 @@
usage_short();
exit(0);
break;
+ case 'm':
+ patch_op = PP_MKPATCHDIR;
+ break;
case 'v':
Verbose++;
break;
@@ -139,10 +144,21 @@
switch (patch_op) {
case PP_MKPATCH:
- perform_mkpatch();
+ if (argc < 3)
+ errx(1, "Expecting 3 arguments: old_package_file "
+ "new_package_file patch_file");
+ perform_mkpatch(argv[0], argv[1], argv[2]);
break;
case PP_APPLY:
- perform_applypatch();
+ if (argc < 1)
+ errx(1, "Expecting argument: patch filename");
+ perform_applypatch(argv[0]);
+ break;
+ case PP_MKPATCHDIR:
+ if (argc < 3)
+ errx(1, "Expecting 3 arguments: old_pkg_dir new_pkg_dir "
+ "patch_pkg_dir");
+ perform_mkpatchdir(argv[0], argv[1], argv[2]);
break;
default:
errx(1, "This should not happen - unknown patch_op");
==== //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.c#17 (text+ko) ====
@@ -35,7 +35,7 @@
void
-perform_mkpatch()
+perform_mkpatch(char *file_old, char *file_new, char *file_patch)
{
char fold[PATH_MAX], fnew[PATH_MAX], fpatch[PATH_MAX];
char dold[PATH_MAX], dnew[PATH_MAX], dpatch[PATH_MAX];
@@ -50,15 +50,12 @@
FILE *fp;
time_t tm;
- if (argc < 3)
- errx(1, "Expecting 3 arguments: old_package_file "
- "new_package_file patch_file");
- if (realpath(argv[0], fold) == NULL)
- err(1, "Error resolving path: %s", argv[0]);
- if (realpath(argv[1], fnew) == NULL)
- err(1, "Error resolving path: %s", argv[1]);
- if (realpath(argv[2], fpatch) == NULL)
- err(1, "Error resolving path: %s", argv[2]);
+ if (realpath(file_old, fold) == NULL)
+ err(1, "Error resolving path: %s", file_old);
+ if (realpath(file_new, fnew) == NULL)
+ err(1, "Error resolving path: %s", file_new);
+ if (realpath(file_patch, fpatch) == NULL)
+ err(1, "Error resolving path: %s", file_patch);
if (access(fold, F_OK) != 0)
err(1, "File not found: %s", fold);
@@ -297,4 +294,11 @@
err(1, "pclose() failed on final tar");
if (Verbose)
printf("Created %s.\n", fpatch);
+
+ filelist_free(&flold);
+ filelist_free(&flnew);
+ filelist_free(&fldiff_old_new);
+ filelist_free(&fldiff_new_old);
+ filelist_free(&flintersect);
+ filelist_free(&flchanged);
}
==== //depot/projects/soc2010/pkg_patch/src/patch/mkpatch.h#17 (text+ko) ====
@@ -20,6 +20,6 @@
#ifndef _MKPATCH_H_
#define _MKPATCH_H_
-void perform_mkpatch(void);
+void perform_mkpatch(char *file_old, char *file_new, char *file_patch);
#endif
==== //depot/projects/soc2010/pkg_patch/src/patch/pkg_patch.h#17 (text+ko) ====
@@ -56,7 +56,7 @@
#define PREFIX_DEFAULT "/usr/local"
#define PREFIX (getenv(PREFIX_ENV) ? getenv(PREFIX_ENV) : PREFIX_DEFAULT)
-enum PP_OP { PP_NONE, PP_MKPATCH, PP_APPLY };
+enum PP_OP { PP_NONE, PP_MKPATCH, PP_APPLY, PP_MKPATCHDIR };
struct pkgxjob {
char *filename;
@@ -76,6 +76,13 @@
SLIST_ENTRY(pathlist) linkage;
};
+SLIST_HEAD(pkgjoinlist_head, pkgjoinlist);
+struct pkgjoinlist {
+ char name1[PATH_MAX];
+ char name2[PATH_MAX];
+ SLIST_ENTRY(pkgjoinlist) linkage;
+};
+
enum PPMETHOD { PPMETHOD_UNKNOWN, PPMETHOD_CP, PPMETHOD_BSDIFF };
STAILQ_HEAD(pplist_head, pplist);
@@ -117,7 +124,10 @@
struct filelist_head *diff);
int filelist_intersect(struct filelist_head *fl1, struct filelist_head *fl2,
struct filelist_head *flisect);
+int filelist_intersect_pkg(struct filelist_head *fl1, struct filelist_head *f2,
+ struct pkgjoinlist_head *jlist);
unsigned int filelist_count(struct filelist_head *flist);
+void filelist_free(struct filelist_head *flist);
void parse_package_name(char *pkgfile, char *basename, char *version,
char *suffix);
int copy_file_absolute(char *from, char *to);
==== //depot/projects/soc2010/pkg_patch/src/patch/support.c#16 (text+ko) ====
@@ -224,6 +224,56 @@
/*
+ * Free the filelist's entries.
+ */
+void
+filelist_free(struct filelist_head *flist)
+{
+ struct filelist *fl1, *fl2;
+
+ SLIST_FOREACH_SAFE(fl1, flist, linkage, fl2) {
+ SLIST_REMOVE(flist, fl1, filelist, linkage);
+ free(fl1);
+ }
+}
+
+
+/*
+ * Returns a file list consisting of the intersection of packages from the first
+ * list
+ */
+int
+filelist_intersect_pkg(struct filelist_head *flist1, struct filelist_head *flist2,
+ struct pkgjoinlist_head *pkgisect)
+{
+ char basename1[PATH_MAX], version1[PATH_MAX], suffix1[20];
+ char basename2[PATH_MAX], version2[PATH_MAX], suffix2[20];
+ struct filelist *fl1, *fl2;
+ struct pkgjoinlist *pi;
+ int found;
+
+ SLIST_FOREACH(fl1, flist1, linkage) {
+ found = 0;
+ parse_package_name(fl1->filename, basename1, version1, suffix1);
+ SLIST_FOREACH(fl2, flist2, linkage) {
+ parse_package_name(fl2->filename, basename2, version2, suffix2);
+ if (strncmp(basename1, basename2, PATH_MAX) == 0) {
+ found = 1;
+ break;
+ }
+ }
+ if (found) {
+ pi = calloc(1, sizeof(*pi));
+ strncpy(pi->name1, fl1->filename, PATH_MAX);
+ strncpy(pi->name2, fl2->filename, PATH_MAX);
+ SLIST_INSERT_HEAD(pkgisect, pi, linkage);
+ }
+ }
+ return (0);
+}
+
+
+/*
* Returns the number of elements in the given filelist.
*/
unsigned int
More information about the p4-projects
mailing list