git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/5] More recursive merge updates
@ 2005-09-13 21:37 Fredrik Kuivinen
  2005-09-13 21:39 ` [PATCH 1/5] Be more like the 'resolve' strategy Fredrik Kuivinen
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Fredrik Kuivinen @ 2005-09-13 21:37 UTC (permalink / raw
  To: git; +Cc: junkio

Here is another patch series with updates to the recursive merge
algorithm.

- Fredrik

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/5] Be more like the 'resolve' strategy.
  2005-09-13 21:37 [PATCH 0/5] More recursive merge updates Fredrik Kuivinen
@ 2005-09-13 21:39 ` Fredrik Kuivinen
  2005-09-13 21:40 ` [PATCH 2/5] Don't output 'Automatic merge failed, ...' Fredrik Kuivinen
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Fredrik Kuivinen @ 2005-09-13 21:39 UTC (permalink / raw
  To: git; +Cc: junkio

If there are non-mergeable changes leave the head contents in the
cache and update the working directory with the output from merge(1).

In the add/add and delete/modify conflict cases leave unmerged cache
entries in the index.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>


---

 git-merge-recursive.py |   68 +++++++++++++++++++++++-------------------------
 1 files changed, 33 insertions(+), 35 deletions(-)

11a6300badeb3b2a46d088877f2f264d18b2160d
diff --git a/git-merge-recursive.py b/git-merge-recursive.py
--- a/git-merge-recursive.py
+++ b/git-merge-recursive.py
@@ -7,8 +7,6 @@ from sets import Set
 sys.path.append('@@GIT_PYTHON_PATH@@')
 from gitMergeCommon import *
 
-alwaysWriteTree = False
-
 # The actual merge code
 # ---------------------
 
@@ -46,19 +44,14 @@ def merge(h1, h2, branch1Name, branch2Na
             runProgram(['git-update-cache', '-q', '--refresh'])
         # Use the original index if we only have one common ancestor
         
-        updateWd = True
-        if alwaysWriteTree:
-            cleanCache = True
-        else:
-            cleanCache = False
+        cleanCache = False
     else:
         runProgram(['git-read-tree', h1.tree()])
-        updateWd = False
         cleanCache = True
 
     [shaRes, clean] = mergeTrees(h1.tree(), h2.tree(), Ms.tree(),
                                  branch1Name, branch2Name,
-                                 cleanCache, updateWd)
+                                 cleanCache)
 
     if clean or cleanCache:
         res = Commit(None, [h1, h2], tree=shaRes)
@@ -125,7 +118,7 @@ def unmergedCacheEntries():
     return res
 
 def mergeTrees(head, merge, common, branch1Name, branch2Name,
-               cleanCache, updateWd):
+               cleanCache):
     '''Merge the trees 'head' and 'merge' with the common ancestor
     'common'. The name of the head branch is 'branch1Name' and the name of
     the merge branch is 'branch2Name'. Return a tuple (tree, cleanMerge)
@@ -138,10 +131,11 @@ def mergeTrees(head, merge, common, bran
         print 'Already uptodate!'
         return [head, True]
 
-    if updateWd:
-        updateArg = '-u'
-    else:
+    if cleanCache:
         updateArg = '-i'
+    else:
+        updateArg = '-u'
+
     runProgram(['git-read-tree', updateArg, '-m', common, head, merge])
     cleanMerge = True
 
@@ -157,7 +151,7 @@ def mergeTrees(head, merge, common, bran
         entries = unmergedCacheEntries()
         for name in entries:
             if not processEntry(entries[name], branch1Name, branch2Name,
-                                files, dirs, cleanCache, updateWd):
+                                files, dirs, cleanCache):
                 cleanMerge = False
                 
         if cleanMerge or cleanCache:
@@ -169,29 +163,25 @@ def mergeTrees(head, merge, common, bran
 
     return [tree, cleanMerge]
 
-def processEntry(entry, branch1Name, branch2Name, files, dirs,
-                 cleanCache, updateWd):
+def processEntry(entry, branch1Name, branch2Name, files, dirs, cleanCache):
     '''Merge one cache entry. 'files' is a Set with the files in both of
     the heads that we are going to merge. 'dirs' contains the
     corresponding data for directories. If 'cleanCache' is True no
     non-zero stages will be left in the cache for the path
     corresponding to the entry 'entry'.'''
 
-# cleanCache == True  => Don't leave any non-stage 0 entries in the cache.
-#               False => Leave unmerged entries
-
-# updateWd  == True  => Update the working directory to correspond to the cache
-#              False => Leave the working directory unchanged
+# cleanCache == True  => Don't leave any non-stage 0 entries in the cache and
+#                        don't update the working directory
+#               False => Leave unmerged entries and update the working directory
 
 # clean     == True  => non-conflict case
 #              False => conflict case
 
 # If cleanCache == False then the cache shouldn't be updated if clean == False
 
-    def updateFile(clean, sha, mode, path):
-        if cleanCache or (not cleanCache and clean):
-            runProgram(['git-update-cache', '--add', '--cacheinfo',
-                        '0%o' % mode, sha, path])
+    def updateFile(clean, sha, mode, path, onlyWd=False):
+        updateCache = not onlyWd and (cleanCache or (not cleanCache and clean))
+        updateWd = onlyWd or (not cleanCache and clean)
 
         if updateWd:
             prog = ['git-cat-file', 'blob', sha]
@@ -213,13 +203,18 @@ def processEntry(entry, branch1Name, bra
                 os.symlink(linkTarget, path)
             else:
                 assert(False)
-            runProgram(['git-update-cache', '--', path])
+
+        if updateWd and updateCache:
+            runProgram(['git-update-cache', '--add', '--', path])
+        elif updateCache:
+            runProgram(['git-update-cache', '--add', '--cacheinfo',
+                        '0%o' % mode, sha, path])
 
     def removeFile(clean, path):
         if cleanCache or (not cleanCache and clean):
             runProgram(['git-update-cache', '--force-remove', '--', path])
 
-        if updateWd:
+        if not cleanCache and clean:
             try:
                 os.unlink(path)
             except OSError, e:
@@ -235,8 +230,7 @@ def processEntry(entry, branch1Name, bra
         files.add(newPath)
         return newPath
 
-    debug('processing', entry.path, 'clean cache:', cleanCache,
-          'wd:', updateWd)
+    debug('processing', entry.path, 'clean cache:', cleanCache)
 
     cleanMerge = True
 
@@ -327,9 +321,9 @@ def processEntry(entry, branch1Name, bra
             if aMode != bMode:
                 cleanMerge = False
                 print 'CONFLICT: File "' + path + \
-                      '" added identically in both branches,'
-                print 'CONFLICT: but permissions conflict', '0%o' % aMode, \
-                      '->', '0%o' % bMode
+                      '" added identically in both branches,', \
+                      'but permissions conflict', '0%o' % aMode, '->', \
+                      '0%o' % bMode
                 print 'CONFLICT: adding with permission:', '0%o' % aMode
 
                 updateFile(False, aSha, aMode, path)
@@ -341,8 +335,7 @@ def processEntry(entry, branch1Name, bra
             newPath1 = uniquePath(path, branch1Name)
             newPath2 = uniquePath(path, branch2Name)
             print 'CONFLICT (add/add): File "' + path + \
-                  '" added non-identically in both branches.', \
-                  'Adding "' + newPath1 + '" and "' + newPath2 + '" instead.'
+                  '" added non-identically in both branches.'
             removeFile(False, path)
             updateFile(False, aSha, aMode, newPath1)
             updateFile(False, bSha, bMode, newPath2)
@@ -372,7 +365,12 @@ def processEntry(entry, branch1Name, bra
         if ret != 0:
             cleanMerge = False
             print 'CONFLICT (content): Merge conflict in "' + path + '".'
-            updateFile(False, sha, mode, path)
+
+            if cleanCache:
+                updateFile(False, sha, mode, path)
+            else:
+                updateFile(True, aSha, aMode, path)
+                updateFile(False, sha, mode, path, True)
         else:
             updateFile(True, sha, mode, path)
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 2/5] Don't output 'Automatic merge failed, ...'
  2005-09-13 21:37 [PATCH 0/5] More recursive merge updates Fredrik Kuivinen
  2005-09-13 21:39 ` [PATCH 1/5] Be more like the 'resolve' strategy Fredrik Kuivinen
@ 2005-09-13 21:40 ` Fredrik Kuivinen
  2005-09-13 21:40 ` [PATCH 3/5] Adjust git-merge-recursive.py for the new tool names Fredrik Kuivinen
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Fredrik Kuivinen @ 2005-09-13 21:40 UTC (permalink / raw
  To: git; +Cc: junkio

git-merge.sh does this for us.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>


---

 git-merge-recursive.py |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)

e0e1a108a224b6bf202beb59c1514325205d3638
diff --git a/git-merge-recursive.py b/git-merge-recursive.py
--- a/git-merge-recursive.py
+++ b/git-merge-recursive.py
@@ -423,5 +423,4 @@ except:
 if clean:
     sys.exit(0)
 else:
-    print 'Automatic merge failed, fix up by hand'
     sys.exit(1)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 3/5] Adjust git-merge-recursive.py for the new tool names.
  2005-09-13 21:37 [PATCH 0/5] More recursive merge updates Fredrik Kuivinen
  2005-09-13 21:39 ` [PATCH 1/5] Be more like the 'resolve' strategy Fredrik Kuivinen
  2005-09-13 21:40 ` [PATCH 2/5] Don't output 'Automatic merge failed, ...' Fredrik Kuivinen
@ 2005-09-13 21:40 ` Fredrik Kuivinen
  2005-09-13 21:41 ` [PATCH 4/5] Use a temporary index file when we merge the common ancestors Fredrik Kuivinen
  2005-09-13 21:41 ` [PATCH 5/5] Use the 'die' function where it is appropriate Fredrik Kuivinen
  4 siblings, 0 replies; 6+ messages in thread
From: Fredrik Kuivinen @ 2005-09-13 21:40 UTC (permalink / raw
  To: git; +Cc: junkio

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>


---

 git-merge-recursive.py |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

c8d10db0a5380fc52681255b78433390b357c4d0
diff --git a/git-merge-recursive.py b/git-merge-recursive.py
--- a/git-merge-recursive.py
+++ b/git-merge-recursive.py
@@ -41,7 +41,7 @@ def merge(h1, h2, branch1Name, branch2Na
     if callDepth == 0:
         if len(ca) > 1:
             runProgram(['git-read-tree', h1.tree()])
-            runProgram(['git-update-cache', '-q', '--refresh'])
+            runProgram(['git-update-index', '-q', '--refresh'])
         # Use the original index if we only have one common ancestor
         
         cleanCache = False
@@ -205,14 +205,14 @@ def processEntry(entry, branch1Name, bra
                 assert(False)
 
         if updateWd and updateCache:
-            runProgram(['git-update-cache', '--add', '--', path])
+            runProgram(['git-update-index', '--add', '--', path])
         elif updateCache:
-            runProgram(['git-update-cache', '--add', '--cacheinfo',
+            runProgram(['git-update-index', '--add', '--cacheinfo',
                         '0%o' % mode, sha, path])
 
     def removeFile(clean, path):
         if cleanCache or (not cleanCache and clean):
-            runProgram(['git-update-cache', '--force-remove', '--', path])
+            runProgram(['git-update-index', '--force-remove', '--', path])
 
         if not cleanCache and clean:
             try:

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 4/5] Use a temporary index file when we merge the common ancestors.
  2005-09-13 21:37 [PATCH 0/5] More recursive merge updates Fredrik Kuivinen
                   ` (2 preceding siblings ...)
  2005-09-13 21:40 ` [PATCH 3/5] Adjust git-merge-recursive.py for the new tool names Fredrik Kuivinen
@ 2005-09-13 21:41 ` Fredrik Kuivinen
  2005-09-13 21:41 ` [PATCH 5/5] Use the 'die' function where it is appropriate Fredrik Kuivinen
  4 siblings, 0 replies; 6+ messages in thread
From: Fredrik Kuivinen @ 2005-09-13 21:41 UTC (permalink / raw
  To: git; +Cc: junkio

With this change we can get rid of a call to 'git-update-index
--refresh'.

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>


---

 git-merge-recursive.py |   23 ++++++++++++++++++-----
 1 files changed, 18 insertions(+), 5 deletions(-)

68a73c83a0ba2175cb366bddf3b851f824c6d598
diff --git a/git-merge-recursive.py b/git-merge-recursive.py
--- a/git-merge-recursive.py
+++ b/git-merge-recursive.py
@@ -10,6 +10,22 @@ from gitMergeCommon import *
 # The actual merge code
 # ---------------------
 
+originalIndexFile = os.environ.get('GIT_INDEX_FILE',
+                                   os.environ.get('GIT_DIR', '.git') + '/index')
+temporaryIndexFile = os.environ.get('GIT_DIR', '.git') + \
+                     '/merge-recursive-tmp-index'
+def setupIndex(temporary):
+    try:
+        os.unlink(temporaryIndexFile)
+    except OSError:
+        pass
+    if temporary:
+        newIndex = temporaryIndexFile
+        os.environ
+    else:
+        newIndex = originalIndexFile
+    os.environ['GIT_INDEX_FILE'] = newIndex
+
 def merge(h1, h2, branch1Name, branch2Name, graph, callDepth=0):
     '''Merge the commits h1 and h2, return the resulting virtual
     commit object and a flag indicating the cleaness of the merge.'''
@@ -39,13 +55,10 @@ def merge(h1, h2, branch1Name, branch2Na
         assert(isinstance(Ms, Commit))
 
     if callDepth == 0:
-        if len(ca) > 1:
-            runProgram(['git-read-tree', h1.tree()])
-            runProgram(['git-update-index', '-q', '--refresh'])
-        # Use the original index if we only have one common ancestor
-        
+        setupIndex(False)
         cleanCache = False
     else:
+        setupIndex(True)
         runProgram(['git-read-tree', h1.tree()])
         cleanCache = True
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 5/5] Use the 'die' function where it is appropriate.
  2005-09-13 21:37 [PATCH 0/5] More recursive merge updates Fredrik Kuivinen
                   ` (3 preceding siblings ...)
  2005-09-13 21:41 ` [PATCH 4/5] Use a temporary index file when we merge the common ancestors Fredrik Kuivinen
@ 2005-09-13 21:41 ` Fredrik Kuivinen
  4 siblings, 0 replies; 6+ messages in thread
From: Fredrik Kuivinen @ 2005-09-13 21:41 UTC (permalink / raw
  To: git; +Cc: junkio

Signed-off-by: Fredrik Kuivinen <freku045@student.liu.se>


---

 gitMergeCommon.py |   27 +++++++++++++--------------
 1 files changed, 13 insertions(+), 14 deletions(-)

bd535d629be12d94648a40c2feb89cf14482f772
diff --git a/gitMergeCommon.py b/gitMergeCommon.py
--- a/gitMergeCommon.py
+++ b/gitMergeCommon.py
@@ -1,19 +1,24 @@
 import sys, re, os, traceback
 from sets import Set
 
+def die(*args):
+    printList(args, sys.stderr)
+    sys.exit(2)
+
+def printList(list, file=sys.stdout):
+    for x in list:
+        file.write(str(x))
+        file.write(' ')
+    file.write('\n')
+
 if sys.version_info[0] < 2 or \
        (sys.version_info[0] == 2 and sys.version_info[1] < 4):
-    print 'Python version 2.4 required, found', \
-          str(sys.version_info[0])+'.'+str(sys.version_info[1])+'.'+ \
-          str(sys.version_info[2])
-    sys.exit(1)
+    die('Python version 2.4 required, found', \
+        str(sys.version_info[0])+'.'+str(sys.version_info[1])+'.'+ \
+        str(sys.version_info[2]))
 
 import subprocess
 
-def die(*args):
-    printList(args, sys.stderr)
-    sys.exit(2)
-
 # Debugging machinery
 # -------------------
 
@@ -32,12 +37,6 @@ def debug(*args):
         if funcName in functionsToDebug:
             printList(args)
 
-def printList(list, file=sys.stdout):
-    for x in list:
-        file.write(str(x))
-        file.write(' ')
-    file.write('\n')
-
 # Program execution
 # -----------------
 

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-09-13 21:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-13 21:37 [PATCH 0/5] More recursive merge updates Fredrik Kuivinen
2005-09-13 21:39 ` [PATCH 1/5] Be more like the 'resolve' strategy Fredrik Kuivinen
2005-09-13 21:40 ` [PATCH 2/5] Don't output 'Automatic merge failed, ...' Fredrik Kuivinen
2005-09-13 21:40 ` [PATCH 3/5] Adjust git-merge-recursive.py for the new tool names Fredrik Kuivinen
2005-09-13 21:41 ` [PATCH 4/5] Use a temporary index file when we merge the common ancestors Fredrik Kuivinen
2005-09-13 21:41 ` [PATCH 5/5] Use the 'die' function where it is appropriate Fredrik Kuivinen

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).