Skip to contentSkip to conversation

merge-recursive in C

PATCH In review Alex Riesen 3 participants 3 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 merge-recursive in C

This is summary of all merge-recursive patches floating around rebased off current git (75dedd5a21246be03ae443e9fc6a9f75c6d2995b).

---
I think I have to start doing this properly sometime, so that incremental patches can be posted. So I just chose a compiling state (it still has that ctime/mtime bug), added some of recent work on top of it and branched it all off Junio's master.

The merge_bases patches from Dscho ("refactor merge_bases()" and "move get_merge_bases() to core lib") can be applied on top of last.

 Makefile          |    7 
 git-merge.sh      |    4 
 graph.c           |  256 ++++++++
 graph.h           |   80 +++
 merge-recursive.c | 1622 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 path-list.c       |  110 ++++
 path-list.h       |   32 +
 7 files changed, 2108 insertions(+), 3 deletions(-)
Makefile +6 -1
index cde619c..660f09b 100644
@@ -163,7 +163,8 @@ PROGRAMS = \
 	git-upload-pack$X git-verify-pack$X \
 	git-symbolic-ref$X \
 	git-name-rev$X git-pack-redundant$X git-repo-config$X git-var$X \
-	git-describe$X git-merge-tree$X git-blame$X git-imap-send$X
+	git-describe$X git-merge-tree$X git-blame$X git-imap-send$X \
+	git-merge-recur$X
 
 BUILT_INS = git-log$X git-whatchanged$X git-show$X git-update-ref$X \
 	git-count-objects$X git-diff$X git-push$X git-mailsplit$X \
@@ -595,6 +596,10 @@ git-http-push$X: revision.o http.o http-
 	$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
 		$(LIBS) $(CURL_LIBCURL) $(EXPAT_LIBEXPAT)
 
+git-merge-recur$X: merge-recursive.o graph.o path-list.o $(LIB_FILE)
+	$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
+		$(LIBS)
+
 $(LIB_OBJS) $(BUILTIN_OBJS): $(LIB_H)
 $(patsubst git-%$X,%.o,$(PROGRAMS)): $(LIB_H) $(wildcard */*.h)
 $(DIFF_OBJS): diffcore.h
git-merge.sh +2 -2
index 24e3b50..3c3fed6 100755
@@ -9,7 +9,7 @@ USAGE='[-n] [--no-commit] [--squash] [-s
 LF='
 '
 
-all_strategies='recursive octopus resolve stupid ours'
+all_strategies='recur recursive octopus resolve stupid ours'
 default_twohead_strategies='recursive'
 default_octopus_strategies='octopus'
 no_trivial_merge_strategies='ours'
@@ -17,7 +17,7 @@ use_strategies=
 
 index_merge=t
 if test "@@NO_PYTHON@@"; then
-	all_strategies='resolve octopus stupid ours'
+	all_strategies='recur resolve octopus stupid ours'
 	default_twohead_strategies='resolve'
 fi
 
graph.c new file +256 -0

256 lines not on this page · raw message

graph.h new file +80 -0

80 lines not on this page · raw message

merge-recursive.c new file +1622 -0

1,622 lines not on this page · raw message

path-list.c new file +110 -0

110 lines not on this page · raw message

path-list.h new file +32 -0
new file mode 100644
index 0000000..a12c7a4
@@ -0,0 +1,32 @@
+#ifndef _PATH_LIST_H_
+#define _PATH_LIST_H_
+
+struct path_list
+{
+    char **paths;
+    unsigned int nr, alloc;
+};
+
+#define for_each_path(p,list) for ( p = (list)->paths; p != (list)->paths + (list)->nr; p++ )
+
+void print_path_list(const char *text, const struct path_list *p);
+
+#define path_list_count(list) (list)->nr
+
+int path_list_has_path(const struct path_list *list, const char *path);
+void path_list_union_update(struct path_list *dst, const struct path_list *src);
+static inline void path_list_clear(struct path_list *list, int free_paths)
+{
+	if (list->paths) {
+		int i;
+		if (free_paths)
+			for (i = 0; i < list->nr; i++)
+				free(list->paths[i]);
+		free(list->paths);
+	}
+	list->paths = NULL;
+	list->nr = list->alloc = 0;
+}
+char *path_list_insert(char *path, struct path_list *list);
+
+#endif /* _PATH_LIST_H_ */
Signature · 1 line
1.4.1.rc1.g17dc
#1 lore raw

path-list.c line 74

Quoted 5 lines · [email protected] (Alex Riesen) wrote:
path-list.c new file +5 -0
+/* in place */
+void path_list_union_update(struct path_list *dst, const struct path_list *src)
+{
+	char **new_paths;
+	int i = 0, j = 0, nr = 0, alloc = dst->nr + dst->nr;

It should be alloc = dst->nr + src->nr.

Signature · 1 line
http://onion.dynserv.net/~timo/
#2 lore raw

Hi,

Quoted 9 lines · Timo Hirvonen

path-list.c line 74

Quoted 5 lines · [email protected] (Alex Riesen) wrote:
path-list.c new file +5 -0
+/* in place */
+void path_list_union_update(struct path_list *dst, const struct path_list *src)
+{
+	char **new_paths;
+	int i = 0, j = 0, nr = 0, alloc = dst->nr + dst->nr;

It should be alloc = dst->nr + src->nr.

Good catch. Merci.

Ciao,
Dscho