Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch export #318

Open
williewillus opened this issue Dec 11, 2022 · 12 comments · May be fixed by #981
Open

Patch export #318

williewillus opened this issue Dec 11, 2022 · 12 comments · May be fixed by #981

Comments

@williewillus
Copy link

It would be nice if we had the ability to export commits under the Git email .patch (example: https://patch-diff.githubusercontent.com/raw/facebook/sapling/pull/287.patch)

I use the mailing list patch workflow for some personal projects and would love to use sl to manage the repo, but exporting diffs to mail is a bit difficult right now.

sl export exists, but it's descended from hg export and does not have all the information the Git patch format does (From lines, date, Subject lines, diffstat, unified file diffs)

@sggutier
Copy link
Contributor

I think at the moment the outputs of sl export and sl export --git are pretty much the same, so it seems that we actually dropped support for the non-git export format some time ago, besides the headers you mention. Hopefully sending a fix for including those should not be too hard.

@nemith
Copy link

nemith commented Jan 9, 2023

Looks like in hg land this is usually done with the patchbomb extension which adds an email command and looks better than added to export itself? https://www.mercurial-scm.org/wiki/PatchbombExtension

Are extensions a thing with sl?

@sggutier
Copy link
Contributor

@nemith Extensions are also a thing in Sapling (see https://github.com/facebook/sapling/tree/main/eden/scm/edenscm/ext )

I'm not sure how compatible would that extension be with Sapling, however.

@williewillus
Copy link
Author

williewillus commented May 19, 2023

Is changing the output of export okay? If so, I'll take a stab at implementing this.

I'm assuming it's ok since sl export is not documented on the Sapling website, but the current format could be relied on internally. I guess I could add a --email flag though to get around that.

We'd also need some sort of apply command that takes an mbox file containing a commit and applies it to the repo, like git am. Maybe sl import (also inherited from hg and not documented) could be repurposed, or it works out of the box.

@VishalGawade1
Copy link

Hello @zzl0 ,
I wanted to check in and see if there’s any update on this issue or if anyone’s actively working on it. If not, I’d be interested in contributing. I was considering either adding an --email flag to sl export or possibly making it an extension, as discussed above.

@zzl0
Copy link
Contributor

zzl0 commented Oct 27, 2024

@VishalGawade1 I don’t believe anyone is actively working on it. Thank you for your interest—please feel free to take it on!

@VishalGawade1
Copy link

@VishalGawade1 I don’t believe anyone is actively working on it. Thank you for your interest—please feel free to take it on!

Thanks a lot! I'll update you soon :)

@VishalGawade1
Copy link

Hello @zzl0 ,
So here is what I have done:

  1. I added the --email option, which activates email-style formatting when specified.
 ("", "email", False, _("format export in email style")),
  1. Inside the export function, if --email is detected, I generate email headers like From, Date, Subject, and Message-Id for each changeset.
if opts.get("email"):
       for idx, rev in enumerate(revs, 1):
           ctx = repo[rev]
           author = ctx.user()
           date_tuple = ctx.date()
           date_str = email.utils.formatdate(date_tuple[0], localtime=True)
           subject = ctx.description().splitlines()[0]
           commit_hash = ctx.hex()
           total_patches = len(revs)

           # Format headers for email style
           ui.write(f"From {commit_hash} {date_str}\n")
           ui.write(f"From: {author}\n")
           ui.write(f"Date: {date_str}\n")
           ui.write(f"Subject: [PATCH {idx}/{total_patches}] {subject}\n")
           ui.write(f"Message-Id: <{commit_hash}@{repo.root}>\n")
           ui.write("Content-Type: text/plain; charset=UTF-8\n")
           ui.write("\n")
  1. After the headers, I add the full commit message, followed by diffstat and the actual diff to show file modifications.
# Write the full commit message
           ui.write(ctx.description())
           ui.write("\n\n---\n\n")

            # Include diffstat
           diffopts = patch.diffopts(ui, opts)
           m = scmutil.match(ctx, opts.get("pattern", []), opts)
           diff = patch.diff(repo, ctx.p1(), ctx, m, opts=diffopts)
           diffstat = patch.diffstat(util.iterlines(diff), git=True)
           ui.write(diffstat)
           ui.write("\n\n")

           # Include the diff
           diff = patch.diff(repo, ctx.p1(), ctx, m, opts=diffopts)
           ui.write(''.join(diff))
           ui.write("\n")
  1. If --email isn’t specified, the function runs the usual export flow.
else:
      cmdutil.export(
          repo,
          revs,
          fntemplate=opts.get("output"),
          switch_parent=opts.get("switch_parent"),
          opts=patch.diffallopts(ui, opts),
          match=m,
      )

Let me know if this approach works for you, and I can go ahead with raising a PR. Or, if there’s anything else you’d like me to adjust

@VishalGawade1
Copy link

Hello @zzl0 ,
Just wanted to check in and see if I can raise a PR for this

@williewillus
Copy link
Author

Go ahead :)

@VishalGawade1
Copy link

Hello @williewillus ,
I have raised a PR with all the changes, please have a look :)

@zzl0
Copy link
Contributor

zzl0 commented Nov 14, 2024

@VishalGawade1 sorry for the late reply, how do you think about this comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants