Skip to content

Instantly share code, notes, and snippets.

@joaotavora
Forked from bhankas/README.md
Last active October 20, 2022 11:15
Show Gist options
  • Save joaotavora/2ed97f2ec85958986983d5cb78202770 to your computer and use it in GitHub Desktop.
Save joaotavora/2ed97f2ec85958986983d5cb78202770 to your computer and use it in GitHub Desktop.
eglot2emacs
emacs/
eglot/

Collecting authors with non-trivial changes

cd eglot
git filter-repo --quiet --commit-callback ../collect-emails-from-non-trivial.py \
    2> /dev/null | head -n -2 | sort -u -t$'\t' -k2,2
    > ../mailmap.txt

Now mailmap.txt can be edited, as it has in the checked-in version. The emails were adjusted to match the emails in the copyright assignment file. The following command adjusts the emails and is included in the ./eglot2emacs.sh script.

git filter-repo --mailmap ../mailmap.txt

Rewriting the repository in batch.

Read commentary in ./eglot2emacs.sh.

def doit(m):
m = re.sub(b"\r",b"",m)
refs = []
refverb = None
url = "https://github.com/joaotavora/eglot/issues/"
header = "GitHub-reference:"
[firstline, _ , rest] = m.partition(b'\n')
def collect_firstline_ref(match):
nonlocal refverb
refverb = match.group(1) or refverb
refs.append([match.group(2), refverb])
return b""
def adjust_firstline(fl):
return re.sub(b" *(Per|Fix(?:es)?|Close(?:s)?)? *#([0-9]+)(?:[,:] *)?",
collect_firstline_ref,
fl)
rest = re.sub(b"#([0-9]+)",
f"{url}\\1".encode(),
rest)
rest = rest.strip()
def bottom_reference(p):
verb = f"{p[1].decode().lower()} " if p[1] else ""
return f"{header} {verb}{url}{p[0].decode()}".encode()
last_line_is_header = bool(re.search(b"\n[A-Z][^\s:\n]*: [^:\n]*$", rest))
return (adjust_firstline(firstline).capitalize().strip()
+ b"\n\n"
+ rest
+ b"\n"
+ (b"" if last_line_is_header else b"\n")
+ b"\n".join(map(bottom_reference, refs)))
return doit(message)
if (commit.original_id in [b"fcb8ab638bf20cd51f13445bbbc3213b774333d0",
b"aa50b4bb9e52d15472c7a4f9c6101506dfa4f8b4",
b"133bee1a93d14d33e87e1646abd55a367bd52245",
b"badcaeca88bc0f3908b94be99d82949309c4ebb5",
b"a0eca3f8a7db7694006b4446390235b03ad80842"]):
print("This commit is considered copyright exempt:: " + commit.original_id.decode())
commit.message += b"\nCopyright-paperwork-exempt: yes\n"
if (not re.search(b"Copyright-[Pp]aperwork-[Ee]xempt:.*[Yy]es", commit.message)):
print((commit.author_name + b"\t<" + commit.author_email + b">").decode())
# This code merges `eglot.el` from joaotavora/eglot to upstream
# `emacs.git` master branch.
#
# It does the following things:
#
# - Move eglot.el to lisp/progmodes/eglot.el
#
# - Preserve complete history from original repo for the file
#
# - Edit commit messages to append URLs for all mentioned issues and
# PRs to individual commit message
# Dependencies required
#
# - https://github.com/newren/git-filter-repo
# nix shell nixpkgs#git-filter-repo
# arch: pacman -S git-filter-repo
# - git
# While made by order, it is perfect example and suitable to rearrange
# code while preserving as well as modifying git history
# programmatically.
# Hope it helps!
#
#
# Repo will be cloned in this directory if they don't exist directory.
# No repo update will be performed automatically.
#
# It is recommended that the Emacs repo be cloned here under the
# scratch/eglot2emacs branch. This can be done by moving on to the
# principal emacs worktree and typing:
#
# git worktree add /path-to-this-files-directory/emacs scratch/eglot2emacs
#
# If (when) things go sour, this normally helps:
#
# rm -rf eglot # will be recloned
# cd emacs
# git merge --abort
# cd ../
#
# clone repos
test -d eglot/.git || git clone https://github.com/joaotavora/eglot.git
test -d emacs/.git || git clone -b master git://git.sv.gnu.org/emacs.git
# filter eglot to keep only eglot.el. This destroys the current
# worktree of the repo.
#
# move eglot.el to lisp/progmodes/eglot.el -> This makes history file
# specific and everything makes find+replace in commit messages
(
cd eglot
git filter-repo -f --message-callback ../adjust-issue-references.py
git filter-repo -f --commit-callback ../adjust-some-commits.py
git filter-repo -f --mailmap ../mailmap.txt
git filter-repo -f --to-subdirectory-filter lisp/progmodes/ --path eglot.el
)
(
cd emacs
git reset --hard origin/master
# add filtered eglot as upstream
git remote add eglot2emacs-filtered-eglot ../eglot/
git fetch eglot2emacs-filtered-eglot master
git merge remotes/eglot2emacs-filtered-eglot/master --allow-unrelated-histories --no-commit
# make a commit
git commit -m "; Merge from https://github.com/joaotavora/eglot"
)
Alan Zimmerman <alan.zimm@gmail.com>
Alex Branham <alex.branham@gmail.com> Alex Branham <jabranham@users.noreply.github.com>
Andrii Kolomoiets <andreyk.mad@gmail.com>
Augusto Stoffel <arstoffel@gmail.com> <astoff@users.noreply.github.com>
Basil L. Contovounesios <contovob@tcd.ie>
Brian Cully <bjc@kublai.com>
Brian Leung <bkleung89@gmail.com> <29217594+leungbk@users.noreply.github.com>
<bkleung89@gmail.com> <leungbk@mailfence.com>
<bkleung89@gmail.com> <leungbk@posteo.net>
Christian Garbs <mitch@cgarbs.de>
Damien Merenne <dam@cosinux.org>
Dan Davison <dandavison7@gmail.com>
Dmitry Gutov <dgutov@yandex.ru>
Evgeni Kolev <evgenysw@gmail.com>
Felicián Németh <felician.nemeth@gmail.com>
Fredrik Bergroth <fbergroth@gmail.com>
Ingo Lohmar <ingo.lohmar@posteo.net> <ingo.lohmar@github.com>
James Nguyen <james@jojojames.com>
Jim Porter <itsjimporter@gmail.com> <826865+jimporter@users.noreply.github.com>
Josh Elsasser <jelsasser@appneta.com>
João Távora <joaotavora@gmail.com>
Jürgen Hötzel <juergen@archlinux.org>
Manuel Uberti <manuel.uberti@inventati.org> <manuel-uberti@users.noreply.github.com>
Michael Livshin <mlivshin@gmail.com> <repo@cmm.kakpryg.net>
Michal Krzywkowski <k.michal@zoho.com>
Mohsin Kaleem <mohkale@kisara.moe>
Omar Polo <op@omarpolo.com>
Philip Kaludercic <philipk@posteo.net> Philip K <philip@warpmail.net>
Philipp Stephani <p.stephani2@gmail.com>
Rudolf Schlatte <rudi@constantly.at>
Stefan Kangas <stefankangas@gmail.com> <stefan@marxist.se>
Stefan Monnier <monnier@iro.umontreal.ca>
Stephen Leake <stephen_leake@stephe-leake.org> <stephen.leake84@gmail.com>
Steve Purcell <steve@sanityinc.com>
Theodor Thornhill <theo@thornhill.no> <theodorthornhill@icloud.com>
<theo@thornhill.no> <theothornhill@pm.me>
Tom Tromey <tom@tromey.com>
Trevor Murphy <trevormurphy@google.com>
Yuan Fu <casouri@gmail.com>
# These authors have only trivial commits, but are not marked
# jgart <47760695+jgarte@users.noreply.github.com>
# Sergey Kostyaev <s-kostyaev@users.noreply.github.com>
# brotzeit <brotzeitmacher@gmail.com>
# Fangrui Song <i@maskray.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment