1. Pierre-Yves David
  2. mergeseries

Commits

Pierre-Yves David  committed b2b8459

Add base and deletion support.

  • Participants
  • Parent commits 60fdcb3
  • Branches default

Comments (0)

Files changed (2)

File mergeseries.py

View file
 #!/usr/bin/python
 import sys
+import tempfile
 
+
+result = []
+
+base = sys.argv[1]
 local = sys.argv[2]
 other = sys.argv[3]
 
-target = open(local, 'a+')
+base_content  = set(open(base))
+other_content = set(open(other))
+
+other_rm = base_content - other_content
+
+for line in open(local):
+    if line not in other_rm:
+        result.append(line)
+
 for line in open(other):
-    target.write(line)
-target.close()
+    if line not in base_content:
+        result.append(line)
+
+final_target = open(local, 'w')
+final_target.writelines(result)
+final_target.close()

File test-mq-merge-series.t

View file
-#!/bin/sh
   $ mergeseries=mergeseries.py
+
 Simple append test
 
   $ cat > base << EOF
   > EOF
-  $ cat > f_local << EOF
+  $ cat > local << EOF
   > A
   > Babar
   > EOF
   > Denfert
   > F
   > EOF
-  $ $mergeseries base f_local other
-  $ cat f_local
+  $ $mergeseries base local other
+  $ cat local
+
+Simple append test with base
+
+  $ cat > base << EOF
+  > Auguste
+  > Blanqui
+  > EOF
+  $ cat > local << EOF
+  > Auguste
+  > Blanqui
+  > Celine
+  > Damien
+  > EOF
+  $ cat > other << EOF
+  > Auguste
+  > Blanqui
+  > Eugene
+  > Farid
+  > EOF
+  $ $mergeseries base local other
+  $ cat local
+  Auguste
+  Blanqui
+  Celine
+  Damien
+  Eugene
+  Farid
+
+Local delete, other append
+
+  $ cat > base << EOF
+  > Auguste
+  > Blanqui
+  > EOF
+  $ cat > local << EOF
+  > Auguste
+  > EOF
+  $ cat > other << EOF
+  > Auguste
+  > Blanqui
+  > Cat
+  > Dude
+  > EOF
+  $ $mergeseries base local other
+  $ cat local
+  Auguste
+  Cat
+  Dude
+
+  $ $mergeseries base other local
+  $ cat local
+  Auguste
+  Cat
+  Dude
+
+Local append, other delete
+
+  $ cat > base << EOF
+  > Auguste
+  > Blanqui
+  > EOF
+  $ cat > other << EOF
+  > Auguste
+  > EOF
+  $ cat > local << EOF
+  > Auguste
+  > Blanqui
+  > Cat
+  > Dude
+  > EOF
+  $ $mergeseries base local other
+  $ cat local
+  Auguste
+  Cat
+  Dude
+
   A
   Babar
   Denfert