view unixSoft/bin/svn-hgmerge.py @ 336:ea73ef5dc38c

emacs: avoid weird package.el breakage with newish packages I've been toting around this package.el from 2009 or so, and something in the package format seems to have changed that broke me. Thanks to some related diagnostics by Lucas, I've grabbed the last package.el that worked with emacs 23 and stashed it here. This seems to work, modulo some things (notably js2-mode and smex) now seem to require emacs 24 if you install them using package.el, so this will end up being brittle on my last couple of emacs23 machines.
author Augie Fackler <raf@durin42.com>
date Thu, 29 May 2014 14:30:42 -0400
parents c30d68fbd368
children
line wrap: on
line source

#!/usr/bin/env python
# ====================================================================
# Copyright (c) 2007 CollabNet.  All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution.  The terms
# are also available at http://subversion.tigris.org/license-1.html.
# If newer versions of this license are posted there, you may use a
# newer version instead, at your option.
#
# This software consists of voluntary contributions made by many
# individuals.  For exact contribution history, see the revision
# history and logs, available at http://subversion.tigris.org/.
# ====================================================================
HGMERGE_BINARY='hgmerge'

'''This script allows using Mercurial's hgmerge script with Subversion.
'''

import os
import sys
import shutil
import tempfile

def do_hgmerge(base, repo, local, merged):
  '''Runs an interactive three-way merge using Mercurial's hgmerge script.
  
  This function is designed to convert Subversion's four-file interactive merges
  into Mercurial's three-file interactive merges so that hgmerge can be used for
  interactive merging in subversion.
  '''
  # We have to use a temporary directory because FileMerge on OS X fails to save
  # the file if it has to write to a file in the CWD. As of now, there's no
  # obvious reason for why that is, but this fixes it.
  temp_dir = tempfile.mkdtemp(prefix='svn_hgmerge')
  local_name = local.split('/')[-1]
  temp_file = temp_dir+'/'+local_name
  shutil.copyfile(local, temp_file)
  args = [HGMERGE_BINARY, temp_file, base, repo]
  status = os.spawnvp(os.P_WAIT, HGMERGE_BINARY, args)
  print status
  if status == 0:
    os.unlink(merged)
    shutil.copyfile(temp_file, merged)
  os.unlink(temp_file)
  os.rmdir(temp_dir)
  return status

if __name__ == '__main__':
  status = do_hgmerge(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
  sys.exit(status)