-
Notifications
You must be signed in to change notification settings - Fork 259
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #144
- Loading branch information
Showing
12 changed files
with
237 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Set the default behavior, in case people don't have core.autocrlf set. | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
*.orig | ||
*.pyc | ||
.dotest | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import os | ||
import imp | ||
PluginFolder = os.path.join(os.path.dirname(os.path.realpath(__file__)),"..","plugins") | ||
MainModule = "__init__" | ||
|
||
def get_plugin(name, plugin_path): | ||
search_dirs = [PluginFolder] | ||
if plugin_path: | ||
search_dirs = [plugin_path] + search_dirs | ||
for dir in search_dirs: | ||
location = os.path.join(dir, name) | ||
if not os.path.isdir(location) or not MainModule + ".py" in os.listdir(location): | ||
continue | ||
info = imp.find_module(MainModule, [location]) | ||
return {"name": name, "info": info, "path": location} | ||
raise Exception("Could not find plugin with name " + name) | ||
|
||
def load_plugin(plugin): | ||
return imp.load_module(MainModule, *plugin["info"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
## Branch Name in Commit Message | ||
|
||
Mercurial has a much stronger notion of branches than Git, | ||
and some parties may not wish to lose the branch information | ||
during the migration to Git. You can use this plugin to either | ||
prepend or append the branch name from the mercurial | ||
commit into the commit message in Git. | ||
|
||
To use the plugin, add | ||
`--plugin branch_name_in_commit=(start|end)`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
def build_filter(args): | ||
return Filter(args) | ||
|
||
class Filter: | ||
def __init__(self, args): | ||
if not args in ['start','end']: | ||
raise Exception('Cannot have branch name anywhere but start and end') | ||
self.pos = args | ||
|
||
def commit_message_filter(self,commit_data): | ||
if self.pos == 'start': | ||
commit_data['desc'] = commit_data['branch'] + '\n' + commit_data['desc'] | ||
if self.pos == 'end': | ||
commit_data['desc'] = commit_data['desc'] + '\n' + commit_data['branch'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Dos2unix filter | ||
|
||
This plugin converts CRLF line ending to LF in text files in the repo. | ||
It is recommended that you have a .gitattributes file that maintains | ||
the usage of LF endings going forward, for after you have converted your | ||
repository. | ||
|
||
To use the plugin, add | ||
`--plugin dos2unix`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
def build_filter(args): | ||
return Filter(args) | ||
|
||
class Filter(): | ||
def __init__(self, args): | ||
pass | ||
|
||
def file_data_filter(self,file_data): | ||
file_ctx = file_data['file_ctx'] | ||
if not file_ctx.isbinary(): | ||
file_data['data'] = file_data['data'].replace('\r\n', '\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
## Shell Script File Filter | ||
|
||
This plugin uses shell scripts in order to perform filtering of files. | ||
If your preferred scripting is done via shell, this tool is for you. | ||
Be noted, though, that this method can cause an order of magnitude slow | ||
down. For small repositories, this wont be an issue. | ||
|
||
To use the plugin, add | ||
`--plugin shell_filter_file_contents=path/to/shell/script.sh`. | ||
The filter script is supplied to the plugin option after the plugin name, | ||
which is in turned passed to the plugin initialization. hg-fast-export | ||
runs the filter for each exported file, pipes its content to the filter's | ||
standard input, and uses the filter's standard output in place | ||
of the file's original content. An example use of this feature | ||
is to convert line endings in text files from CRLF to git's preferred LF, | ||
although this task is faster performed using the native plugin. | ||
|
||
The script is called with the following syntax: | ||
`FILTER_CONTENTS <file-path> <hg-hash> <is-binary>` | ||
|
||
``` | ||
-- Start of crlf-filter.sh -- | ||
#!/bin/sh | ||
# $1 = pathname of exported file relative to the root of the repo | ||
# $2 = Mercurial's hash of the file | ||
# $3 = "1" if Mercurial reports the file as binary, otherwise "0" | ||
if [ "$3" == "1" ]; then cat; else dos2unix; fi | ||
-- End of crlf-filter.sh -- | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#Pipe contents of each exported file through FILTER_CONTENTS <file-path> <hg-hash> <is-binary>" | ||
import subprocess | ||
import shlex | ||
import sys | ||
from mercurial import node | ||
|
||
def build_filter(args): | ||
return Filter(args) | ||
|
||
class Filter: | ||
def __init__(self, args): | ||
self.filter_contents = shlex.split(args) | ||
|
||
def file_data_filter(self,file_data): | ||
d = file_data['data'] | ||
file_ctx = file_data['file_ctx'] | ||
filename = file_data['filename'] | ||
filter_cmd = self.filter_contents + [filename, node.hex(file_ctx.filenode()), '1' if file_ctx.isbinary() else '0'] | ||
try: | ||
filter_proc = subprocess.Popen(filter_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE) | ||
d, _ = filter_proc.communicate(d) | ||
except: | ||
sys.stderr.write('Running filter-contents %s:\n' % filter_cmd) | ||
raise | ||
filter_ret = filter_proc.poll() | ||
if filter_ret: | ||
raise subprocess.CalledProcessError(filter_ret, filter_cmd) | ||
file_data['data'] = d |