././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1734602618.4745853 pristine-lfs-20241219.0/0000755000000000000000000000000014730767572013315 5ustar00rootroot././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1612888561.0 pristine-lfs-20241219.0/CONTRIBUTORS0000664000000000000000000000041414010534761015155 0ustar00rootroot * Andrej Shadura 2019—2021 * Emmanuel Arias 2019 * Sjoerd Simons 2019 The manual page is based on the original manual page for pristine-tar by: * Joey Hess ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1529923888.0 pristine-lfs-20241219.0/COPYING0000644000000000000000000004325413314144460014336 0ustar00rootroot GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1612965182.0 pristine-lfs-20241219.0/MANIFEST.in0000664000000000000000000000004014010762476015034 0ustar00rootrootexclude */stubs/* exclude .git* ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1734602618.4745853 pristine-lfs-20241219.0/PKG-INFO0000644000000000000000000000605714730767572014422 0ustar00rootrootMetadata-Version: 2.1 Name: pristine-lfs Version: 20241219.0 Summary: a pristine-tar replacement that works with Git LFS Home-page: https://salsa.debian.org/pristine-lfs-team/pristine-lfs Author: Andrej Shadura Author-email: andrew.shadura@collabora.co.uk License: GPL-2+ Classifier: Development Status :: 4 - Beta Classifier: Environment :: Console Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: GNU General Public License (GPL) Classifier: License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+) Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: 3.12 Classifier: Programming Language :: Python :: 3.13 Classifier: Topic :: Software Development :: Build Tools Classifier: Topic :: Software Development :: Version Control :: Git Requires-Python: >=3.7 Description-Content-Type: text/x-rst Provides-Extra: test License-File: COPYING ============ pristine-lfs ============ About ----- **pristine-lfs** is a tool to replace *pristine-tar* by the means of using Git LFS to store tarballs. The original *pristine-tar* tool is a way to store binary tarballs in Git by regenerating them using only a small binary delta file and a checkout of the upstream branch. On the contrary, *pristine-lfs* only uses the Git LFS storage, only uploading or downloading binary blobs as they’re needed, which helps reduce the Git repository size (compared to storing tarballs directly in Git) and the checkout times (compared to the plain Git LFS usage, which would download all tarballs each time the LFS-managed branch is checked out). Installation ------------ *pristine-lfs* assumes you have Python 3.6 or later installed as ``/usr/bin/python3``. *pristine-lfs* ships with a setup.py installer based on setuptools. To install *pristine-lfs*, simply type:: ./setup.py install This will install *pristine-lfs* itself, its manpage and this README file into their proper locations. Alternatively, to install via ``pip``, run:: pip install pristine-lfs License ------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version 2 text for more details. You should have received a copy of the GNU General Public License along with this package; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Authors ------- For the list of contributors, see CONTRIBUTORS. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1574435729.0 pristine-lfs-20241219.0/README.rst0000644000000000000000000000354513565775621015012 0ustar00rootroot============ pristine-lfs ============ About ----- **pristine-lfs** is a tool to replace *pristine-tar* by the means of using Git LFS to store tarballs. The original *pristine-tar* tool is a way to store binary tarballs in Git by regenerating them using only a small binary delta file and a checkout of the upstream branch. On the contrary, *pristine-lfs* only uses the Git LFS storage, only uploading or downloading binary blobs as they’re needed, which helps reduce the Git repository size (compared to storing tarballs directly in Git) and the checkout times (compared to the plain Git LFS usage, which would download all tarballs each time the LFS-managed branch is checked out). Installation ------------ *pristine-lfs* assumes you have Python 3.6 or later installed as ``/usr/bin/python3``. *pristine-lfs* ships with a setup.py installer based on setuptools. To install *pristine-lfs*, simply type:: ./setup.py install This will install *pristine-lfs* itself, its manpage and this README file into their proper locations. Alternatively, to install via ``pip``, run:: pip install pristine-lfs License ------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version 2 text for more details. You should have received a copy of the GNU General Public License along with this package; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Authors ------- For the list of contributors, see CONTRIBUTORS. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1613989549.0 pristine-lfs-20241219.0/pristine-lfs.rst0000664000000000000000000001005114014703255016444 0ustar00rootroot============ pristine-lfs ============ ---------------------------------- store pristine tarballs in Git LFS ---------------------------------- :Author: Andrej Shadura :Date: 2021-02-22 :Version: 20210222.0 :Manual section: 1 :Manual group: Git SYNOPSIS ======== **pristine-lfs** [-h|--help] **pristine-lfs** [OPTIONS] **commit** [OPTIONS] (--auto | `tarball`) **pristine-lfs** [OPTIONS] **import-dsc** [OPTIONS] `dsc` **pristine-lfs** [OPTIONS] **checkout** [-o `outdir`] `tarball` **pristine-lfs** [OPTIONS] **list** **pristine-lfs** [OPTIONS] **verify** `tarball` DESCRIPTION =========== pristine-lfs can store pristine upstream tarballs in Git leveraging Git LFS. Instead of storing the potentially large tarballs within the Git repository as blobs, Git LFS only stores specially prepared metadata in the repository, while storing the actual file contents out of band on a Git LFS server. Using pristine-lfs allows Debian packages to be built entirely using sources in version control, without the need to keep copies of upstream tarballs. pristine-lfs supports tarballs compressed with any compressor. Tarball signatures (any files ending with `.asc`) are committed as they are, without utilising the Git LFS mechanisms. COMMANDS ======== **pristine-lfs commit** [-b `BRANCH`] [-m `MESSAGE`] [--force-overwrite] `tarball` [`upstream`] **pristine-lfs commit** stores the specified `tarball` using Git LFS, and commits its metadata to version control. The **pristine-lfs checkout** command can later be used to recreate the original tarball based on the information stored in Git LFS. The data are not submitted to the server until **git push** command is issued. The `upstream` parameter is ignored and is supported for compatibility with **pristine-tar**. If tarball with a different hash has already been committed, it will only be overwritten if `--force-overwrite` is specified. **pristine-lfs import-dsc** [-b `BRANCH`] [-m `MESSAGE`] [--force-overwrite] [--full] `path-to-dsc` Import tarballs and their signatures from a `.dsc` file of a Debian source package. If `--full` is specified, also imports the Debian packaging and the `.dsc` file itself. If tarball with a different hash has already been committed, it will only be overwritten if `--force-overwrite` is specified. **pristine-lfs checkout** [-b `BRANCH`] [-o `outdir`] [--full] (--auto | `tarball`) Regenerate a copy of the specified tarball using information previously saved in version control by **pristine-lfs commit**. By default, the tarball is placed in the current directory. If `outdir` is specified, the file is created in that directory. For compatibility with pristine-tar, `tarball` can include the path to the output directory; this takes precedence over the `outdir` option. If `--auto` is specified, pristine-lfs will consult a file named `debian/changelog`, and if it exists, will check out all tarballs associated with the latest version the changelog mentions. If `--full` is specified and a `.dsc` file is requested, also checks the Debian packaging and the `.dsc` file itself. **pristine-lfs list** [-b `BRANCH`] List tarballs that pristine-lfs is able to checkout from version control. **pristine-lfs verify** [-b `BRANCH`] `tarball` Verify whether an existing tarball matches the one that has been committed to version control. OPTIONS ======= -m MESSAGE, --message=MESSAGE Use the given `MESSAGE` as the commit message for the metadate commits. Applies to **commit** and **import-dsc** commands. `%s` in the commit message is replaced by a comma-separated list of files committed. -b BRANCH, --branch BRANCH Branch to store Git LFS metadata on. -v, --verbose Be more verbose. --debug Show all sorts of debugging information. Implies ``--verbose``. -h Show this help message and exit. ENVIRONMENT =========== **TMPDIR** Specifies a location to place temporary files, other than the default. SEE ALSO ======== **git-lfs**\(1), **pristine-tar**\(1) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1734602618.4705853 pristine-lfs-20241219.0/pristine_lfs/0000755000000000000000000000000014730767572016016 5ustar00rootroot././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1617536099.0 pristine-lfs-20241219.0/pristine_lfs/__init__.py0000664000000000000000000000020414032322143020075 0ustar00rootrootfrom .main import ( # noqa: F401 do_commit, do_commit_files, do_checkout, do_list, do_import, do_verify, ) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1677684225.0 pristine-lfs-20241219.0/pristine_lfs/errors.py0000644000000000000000000000270514377667001017701 0ustar00rootroot# pristine-lfs # # errors for pristine-lfs # # Copyright (C) 2021 Collabora Ltd # Copyright (C) 2021 Andrej Shadura # # SPDX-License-Identifier: GPL-2.0-or-later from __future__ import annotations from gettext import gettext as _ from sh import ErrorReturnCode as CommandFailed # noqa: F401 class DifferentFilesExist(Exception): files: list[str] def __init__(self, files: list[str]): self.files = files def __str__(self): return _("would overwrite files: {files}").format(files=', '.join(self.files)) class UnsupportedHashAlgorithm(Exception): algo: str def __init__(self, algo: str): self.algo = algo def __str__(self): return _("unsupported hash algorithm {algo}").format( algo=self.algo, ) class GitError(Exception): pass class GitFileNotFound(GitError): filename: str branch: str def __init__(self, filename: str, branch: str): self.filename = filename self.branch = branch def __str__(self): return _('{filename} not found on branch {branch}').format( filename=self.filename, branch=self.branch, ) class GitBranchNotFound(GitError): branch: str def __init__(self, branch: str): self.branch = branch def __str__(self): return _('No branch {branch} found, not even among remote branches').format( branch=self.branch, ) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1677683566.0 pristine-lfs-20241219.0/pristine_lfs/gitwrap.py0000644000000000000000000000116014377665556020051 0ustar00rootroot# Wrapper for Git and Git LFS # # Copyright (C) 2021 Collabora Ltd # Copyright (C) 2021 Andrej Shadura # # SPDX-License-Identifier: GPL-2.0-or-later import os from pathlib import Path from typing import Optional from sh.contrib import git as _git def git(*args, index: Optional[Path] = None, **kwargs): """ Wrapper for Git and Git LFS Differences from sh.contrib.git: * accepts index argument to set GIT_INDEX_FILE """ e = os.environ.copy() if index: e["GIT_INDEX_FILE"] = str(index) return _git(*args, **kwargs, _env=e) git.lfs = _git.lfs ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1677684225.0 pristine-lfs-20241219.0/pristine_lfs/gitwrap.pyi0000644000000000000000000000041714377667001020211 0ustar00rootroot# Extremely simplified type stubs for the Git wrapper. # Extend as needed. # # Copyright (C) 2021 Collabora Ltd # Copyright (C) 2021 Andrej Shadura from sh.contrib import git as sh_git class Git(sh_git): lfs: sh_git.lfs git: Git ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1617534282.0 pristine-lfs-20241219.0/pristine_lfs/log.py0000664000000000000000000000036014032316512017125 0ustar00rootroot# pristine-lfs # # logging # # Copyright (C) 2021 Collabora Ltd # Copyright (C) 2021 Andrej Shadura # # SPDX-License-Identifier: GPL-2.0-or-later import logging logger = logging.getLogger("pristine-lfs") ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1677683566.0 pristine-lfs-20241219.0/pristine_lfs/main.py0000644000000000000000000002540514377665556017330 0ustar00rootroot# pristine-lfs # # store pristine tarballs in Git LFS # # Copyright (C) 2019—2021 Collabora Ltd # Copyright (C) 2019—2021 Andrej Shadura # # SPDX-License-Identifier: GPL-2.0-or-later import argparse import logging import os import sys from fnmatch import fnmatch from gettext import gettext as _ from pathlib import Path from typing import ( IO, Iterable, Optional, Sequence, Union ) import sh from debian import deb822 from debian.changelog import Changelog, Version from .errors import ( CommandFailed, DifferentFilesExist, GitError, UnsupportedHashAlgorithm, ) from .log import logger from .util import ( check_branch, checkout_lfs_file, checkout_package, commit_lfs_file, commit_lfs_files, find_branch, find_remote_branches, list_git_files, track_remote_branch, verify_lfs_file, ) def do_commit(tarball: IO[bytes], branch: str, message: Optional[str] = None, force_overwrite: bool = False, **kwargs): """ Commit the open file to a branch using Git LFS. Set force_overwrite to overwrite an existing file with the same name and a different checksum. Message may contain "%s" which gets replaced with a comma-separate list of the file committed. """ if check_branch(branch) is None: if find_remote_branches(branch): track_remote_branch(branch) commit_lfs_file(tarball, branch, message, overwrite=force_overwrite) def do_commit_files(tarballs: Sequence[IO[bytes]], branch: str, message: Optional[str] = None, force_overwrite: bool = False, **kwargs): """ Commit open files to a branch using Git LFS. Set force_overwrite to overwrite existing files with same names and different checksums. Message may contain "%s" which gets replaced with a comma-separate list of the file committed. """ if check_branch(branch) is None: if find_remote_branches(branch): track_remote_branch(branch) commit_lfs_files(tarballs, branch, message, overwrite=force_overwrite) def do_checkout(branch: str, tarball: Optional[str] = None, outdir: Union[str, Path] = '.', full: bool = False, package: Optional[str] = None, version: Union[str, Version, None] = None, **kwargs): """ Check out one or multiple files. If tarball is non-None: * file name only: tarball to check out to outdir. * path with to file: the location where to check out to If tarball is None: * if package and version are specified, that version is checked out * a tarball corresponding to the latest entry in debian/changelog is found and checked out When full is set, tarball is a name of a .dsc file; all corresponding tarball *and* the .dsc file are checked out. If None, debian/changelog is used to find the set of files to check out. """ branch = find_branch(branch) if tarball: path, slash, tarball = tarball.rpartition('/') if path: outdir = path else: if not package or not version: changelog = Path("debian/changelog") with changelog.open() as f: ch = Changelog(f, max_blocks=1) package, version = ch.package, ch.version outdir = Path(outdir) outdir.mkdir(parents=True, exist_ok=True) if full: if tarball: dsc_file = tarball else: fver = Version(version) fver.epoch = None dsc_file = f'{package}_{fver}.dsc' logger.info(_("Checking out file {} in {}").format(dsc_file, outdir)) checkout_lfs_file(branch, dsc_file, outdir) if dsc_file.endswith('.dsc'): with (outdir / dsc_file).open('r') as dsc: d = deb822.Dsc(dsc) package = str(d['Source']) version = Version(d['Version']) files = [f["name"] for f in d["Files"]] checkout_package(package, version, branch, outdir, files) else: if tarball: logger.info(_("Checking out file {} in {}").format(tarball, outdir)) checkout_lfs_file(branch, tarball, outdir) else: checkout_package(str(package), Version(version), branch, outdir) def do_list(branch: str, **kwargs) -> Iterable[str]: """ List all files on the specified branch except .gitattributes. """ branch = find_branch(branch) for f in list_git_files(branch): if f != '.gitattributes': yield f def do_import(dsc: IO[str], branch: str, message: Optional[str] = None, force_overwrite: bool = False, full: bool = False, **kwargs): """ Import all tarballs and detached signatures related to an open .dsc file. Set force_overwrite to overwrite an existing file with the same name and a different checksum. Message may contain "%s" which gets replaced with a comma-separate list of the file committed. When full is set, the .dsc file and the Debian packaging tarball are also imported. """ d = deb822.Dsc(dsc) package = d['Source'] version = Version(d['Version']) tarball_glob = f'{package}_{version.upstream_version}.orig.tar.*' component_tarball_glob = f'{package}_{version.upstream_version}.orig-*.tar.*' dsc_dir = os.path.dirname(dsc.name) if check_branch(branch) is None: if find_remote_branches(branch): track_remote_branch(branch) tarballs = [os.path.join(dsc_dir, f['name']) for f in d['Files'] if full or fnmatch(f['name'], tarball_glob) or fnmatch(f['name'], component_tarball_glob)] if full: tarballs += [dsc.name] if tarballs: logger.info("Importing: %s" % " ".join(tarballs)) commit_lfs_files([open(tarball, 'rb') for tarball in tarballs], branch, message, overwrite=force_overwrite) def do_verify(branch: str, tarball: Union[str, Path], **kwargs) -> bool: """ Verify an existing tarball is the same as the one committed with pristine-lfs. """ branch = find_branch(branch) tarball = Path(tarball) return verify_lfs_file(branch, tarball) def main(*args): prog = os.path.basename(sys.argv[0]) parser = argparse.ArgumentParser(description=_('store pristine tarballs in Git LFS'), prog=prog) if args and hasattr(parser, 'exit_on_error'): parser.exit_on_error = False parser.add_argument('-v', '--verbose', action='count', help=_('be more verbose')) parser.add_argument('--debug', action='store_const', const=2, dest='verbose', help=_('be debuggingly verbose')) parser.set_defaults(verbose=0, func=lambda *x, **kw: parser.print_usage(file=sys.stderr)) subparsers = parser.add_subparsers(required=False) parser_commit = subparsers.add_parser('commit', help=_('commit a tarball')) parser_commit.add_argument('--force-overwrite', action='store_true', help=_('overwrite already stored files')) parser_commit.add_argument('-m', '--message', default=None, help=_('commit message')) parser_commit.add_argument('-b', '--branch', default='pristine-lfs', help=_('branch to store metadata on')) parser_commit.add_argument('tarball', type=argparse.FileType('rb'), help=_('tarball to commit')) parser_commit.add_argument('upstream', nargs='?', default=None, help=_('ignored')) parser_commit.set_defaults(func=do_commit) # we have to do some trickery since argparse doesn’t support this syntax natively parser_checkout = subparsers.add_parser('checkout', help=_('checkout a tarball')) parser_checkout.add_argument('-b', '--branch', default='pristine-lfs', help=_('branch to store metadata on')) parser_checkout.add_argument('--full', default=False, action='store_true', help=_('also check out all related files of the Debian package')) parser_checkout.add_argument('-o', '--outdir', default='.', help=_('output directory for the tarball')) checkout_group = parser_checkout.add_mutually_exclusive_group(required=True) checkout_group.add_argument('--auto', default=False, action='store_true', help=_('check out all tarballs required by the currently checked out Debian package')) checkout_group.add_argument('tarball', nargs='?', default=None, help=_('tarball to check out')) parser_checkout.set_defaults(func=do_checkout) parser_list = subparsers.add_parser('list', help=_('list tarballs stored in the repository')) parser_list.add_argument('-b', '--branch', default='pristine-lfs', help=_('branch to store metadata on')) parser_list.set_defaults(func=do_list) parser_import = subparsers.add_parser('import-dsc', help=_('import tarballs and their signatures from a .dsc')) parser_import.add_argument('dsc', type=argparse.FileType('r'), help='.dsc file to use') parser_import.add_argument('--force-overwrite', action='store_true', help=_('overwrite already stored files')) parser_import.add_argument('--full', default=False, action='store_true', help=_('also import all related files of the Debian package')) parser_import.add_argument('-m', '--message', default=None, help=_('commit message')) parser_import.add_argument('-b', '--branch', default='pristine-lfs', help=_('branch to store metadata on')) parser_import.set_defaults(func=do_import) parser_verify = subparsers.add_parser('verify', help=_('verify a tarball against Git LFS metadata')) parser_verify.add_argument('-b', '--branch', default='pristine-lfs', help=_('branch to store metadata on')) parser_verify.add_argument('tarball', help=_('tarball to verify')) parser_verify.set_defaults(func=do_verify) args = parser.parse_args(args or sys.argv[1:]) logging.basicConfig(format='{levelname[0]}: {message!s}', style='{', level=(logging.WARNING - 10 * args.verbose)) # sh is printing debug on the info channel logging.getLogger(sh.__name__).setLevel(logging.WARNING - 10 * (args.verbose - 1)) try: ret = args.func(**vars(args)) if isinstance(ret, Iterable): for item in ret: print(item) elif isinstance(ret, bool): return 0 if ret else 1 except CommandFailed as e: print(_('Failed to run %s:') % e.full_cmd, file=sys.stderr) print(e.stderr.decode(sh.DEFAULT_ENCODING, "replace"), file=sys.stderr) return e.exit_code except FileNotFoundError as e: print(_('abort: file %s not found ') % e.filename, file=sys.stderr) return os.EX_OSERR except OSError as e: print(_('I/O error: %s') % e, file=sys.stderr) return os.EX_OSERR except KeyboardInterrupt: print(file=sys.stderr) print(_('about: Interrupted by user'), file=sys.stderr) return 1 except (DifferentFilesExist, GitError, UnsupportedHashAlgorithm) as e: print(_("abort: %s\n") % e, file=sys.stderr) return 1 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727779423.0 pristine-lfs-20241219.0/pristine_lfs/util.py0000644000000000000000000004132114676751137017345 0ustar00rootroot# pristine-lfs # # Git and Git LFS routines # This requires Git and git-lfs to be installed. # # Copyright (C) 2019—2021 Collabora Ltd # Copyright (C) 2019—2021 Andrej Shadura # # SPDX-License-Identifier: GPL-2.0-or-later from __future__ import annotations import hashlib import os from contextlib import contextmanager from fnmatch import fnmatch, fnmatchcase from gettext import gettext as _ from pathlib import Path from typing import IO, Any, Generator, Iterable, Mapping, Optional, Sequence, Tuple, Union, cast import sh from debian.changelog import Version from .errors import ( DifferentFilesExist, GitBranchNotFound, GitFileNotFound, UnsupportedHashAlgorithm, ) from .gitwrap import git from .log import logger gitattributes = """*.tar.* filter=lfs diff=lfs merge=lfs -text *.tar.*.asc -filter -diff merge=binary -text *.dsc -filter !diff merge=binary !text """ pre_push_hook = """#!/bin/sh -e case "$GIT_LFS_SKIP_PUSH" in true | on | 1) exit 0 ;; *) git lfs pre-push "$@" ;; esac """ supported_lfs_hashsums = ['sha256'] RETURN_CMD = {} if sh.__version__.startswith('1.') else {'_return_cmd': True} @contextmanager def open_index(name: str) -> Generator[Path, None, None]: """Context manager for a named temporary Git index file.""" index = Path(git_dir()) / f"index-{name}" if index.exists(): index.unlink() try: yield index finally: if index.exists(): index.unlink() AttributeValue = Union[str, bool, None] Attribute = Tuple[str, AttributeValue] def parse_attr(attr: str) -> Attribute: """Parse a Git attribute into its value. >>> parse_attr('attr') ('attr', True) >>> parse_attr('-attr') ('attr', False) >>> parse_attr('!attr') ('attr', None) >>> parse_attr('attr=text') ('attr', 'text') """ if attr.startswith('!'): return attr[1:], None if attr.startswith('-'): return attr[1:], False if '=' not in attr: return attr, True return cast(Attribute, tuple(attr.split('=', maxsplit=1))) def parse_git_attributes(s: str) -> Iterable[tuple[str, Mapping[str, AttributeValue]]]: """Parse Git attributes from a string. >>> list(parse_git_attributes(''' ... ab* merge=filfre ... abc -foo -bar ... *.c frotz ... * ... ''')) [('ab*', {'merge': 'filfre'}), ('abc', {'foo': False, 'bar': False}), ('*.c', {'frotz': True}), ('*', {})] >>> list(parse_git_attributes('[attr]binary -diff -merge -text')) [('[attr]binary', {'diff': False, 'merge': False, 'text': False})] >>> list(parse_git_attributes(''' ... # this is a comment ... a* foo !bar -baz ... abc foo bar baz ... *.jpg -text -diff ... * text=auto ... *.txt text ... *.vcproj text eol=crlf ... *.sh text eol=lf ... *.jpg -text ... ''')) [('a*', {'foo': True, 'bar': None, 'baz': False}), ('abc', {'foo': True, 'bar': True, 'baz': True}), ('*.jpg', {'text': False, 'diff': False}), ('*', {'text': 'auto'}), ('*.txt', {'text': True}), ('*.vcproj', {'text': True, 'eol': 'crlf'}), ('*.sh', {'text': True, 'eol': 'lf'}), ('*.jpg', {'text': False})] """ lines = [line.strip() for line in s.splitlines()] # strip comments, split each line by consecutive spaces lines = [line.split() for line in lines if len(line) and not line.startswith('#')] for line in lines: if len(line): glob, *attrs = line yield glob, {k: v for k, v in [ parse_attr(a) for a in attrs ]} default_gitattributes = list(parse_git_attributes(gitattributes)) def check_branch(name: str) -> Optional[str]: """Check a branch exists, return the hash it points at, if it does. None if there’s no such branch. """ try: return git('show-ref', '--heads', '--hash', '--', name) except sh.ErrorReturnCode: return None def git_dir() -> str: """Return the path to the `.git` directory.""" return git('rev-parse', '--git-dir').strip('\n') def git_head() -> str: """Return the name of the current branch, or the SHA1 of the current commit if we're in a detached HEAD state.""" return git('rev-parse', '-q', '--verify', '--symbolic-full-name', 'HEAD', _ok_code=[0, 1]).strip('\n') def branch_remote(name: str) -> Optional[str]: """Find an upstream remote for a tracking branch.""" if name.startswith('refs/heads/'): name = name[len("refs/heads/"):] return git('config', 'branch.%s.remote' % name, ok_code=[0, 1]).strip('\n') or None def find_remote_branches(name: str) -> list[tuple[str, str]]: """Find remote branches with a given name. Return a list of tuples, each tuple containing the SHA1 and the full name of a remote branch. """ try: branches = [line.split(' ') for line in git('show-ref', '--', name).splitlines()] return [(b[0], b[1]) for b in branches if b[1].startswith('refs/remotes/')] except sh.ErrorReturnCode: return [] def preferred_remote_branch(remote_branches: list[tuple[str, str]]) -> tuple[str, str]: """Choose one remote branch out of a list. Return the first remote branch that matches the current remote, or the first remote branch if there is no current remote. The current remote is a remote for the currently checked out branch. """ logger.debug("Remote branches: %r", remote_branches) current_remote = branch_remote(git_head()) logger.debug("Current remote: %r", current_remote) remote_branches = [ (commit, ref) for (commit, ref) in remote_branches if current_remote and ref.startswith('refs/remotes/' + current_remote) ] + remote_branches return remote_branches[0] def track_remote_branch(name: str): """Find and track a remote branch for a given branch. Find all remote branches with a given name, and then create a local branch with the same name that tracks the remote branch picked by preferred_remote_branch. """ remote_branches = find_remote_branches(name) if len(remote_branches) == 0: raise RuntimeError('remote branch expected but not found') commit, branch = preferred_remote_branch(remote_branches) git('branch', '--track', name, branch) def find_branch(branch: str) -> str: """Find a branch. Return one of the following: * an existing branch of the given name * a remote branch picked by preferred_remote_branch Raise an exception if all fails. """ if check_branch(branch) is None: remote_branches = find_remote_branches(branch) if remote_branches: commit, branch = preferred_remote_branch(remote_branches) else: raise GitBranchNotFound(branch) return branch def store_lfs_object(io: Any) -> str: """Store a file-like object in Git LFS, and return the Git LFS pointer for the stored blob.""" return str(git.lfs.clean(io.name, _in=io)) def store_git_object(io: Any) -> str: """Store a file-like object in Git, and return its hash.""" return git('hash-object', '-w', '--stdin', _in=io).strip('\n') def stage_file(filename: Union[str, bytes], io: Any, index: Optional[Path] = None): """Take a file, store it in the Git object store, and then add it to the index.""" blob = store_git_object(io) if isinstance(filename, bytes): filename = filename.decode() git('update-index', '--add', '--replace', '--cacheinfo', "100644,%s,%s" % (blob, filename), index=index) def create_commit(branch: str, message: str, index: Optional[Path] = None) -> str: """Create a commit with the given message and index, and update the given branch to point to it.""" tree = git('write-tree', index=index).strip('\n') if not len(tree): raise RuntimeError('write-tree failed') if check_branch(branch) is not None: commit = git('commit-tree', tree, '-p', branch, _in=message).strip('\n') else: commit = git('commit-tree', tree, _in=message).strip('\n') if not len(commit): raise RuntimeError('commit-tree failed') git('update-ref', 'refs/heads/%s' % branch, commit) return commit def refresh_main_index(): """Refresh the main index, ignoring submodules, missing files and unmerged files.""" git('update-index', '--ignore-submodules', '-q', '--ignore-missing', '--unmerged', '--refresh') def parse_diff_entry(entry: str) -> Mapping[str, str]: r""" Parse an entry in git-diff-tree format into a dictionary. >>> parse_diff_entry( ... ":100644 100644 777f41fb18215a23a779a831b38d24ff6171775a c5ac094096d35c687c0cc5054b5a1433c293ebd5 M\tpristine_lfs/main.py" ... ) {'srcmode': '100644', 'dstmode': '100644', 'srchash': '777f41fb18215a23a779a831b38d24ff6171775a', 'dsthash': 'c5ac094096d35c687c0cc5054b5a1433c293ebd5', 'srcname': 'pristine_lfs/main.py', 'dstname': '', 'status': 'M'} >>> parse_diff_entry( ... ":100644 100644 f0adb461cd94419245cf0b16a0edf1e2daf6688b f0adb461cd94419245cf0b16a0edf1e2daf6688b R100\told\tnew" ... ) {'srcmode': '100644', 'dstmode': '100644', 'srchash': 'f0adb461cd94419245cf0b16a0edf1e2daf6688b', 'dsthash': 'f0adb461cd94419245cf0b16a0edf1e2daf6688b', 'srcname': 'old', 'dstname': 'new', 'status': 'R100'} """ treediff, names = entry.split('\t', maxsplit=1) srcmode, dstmode, srchash, dsthash, status = treediff.lstrip(':').split(' ') srcname, _, dstname = names.partition('\t') return { 'srcmode': srcmode, 'dstmode': dstmode, 'srchash': srchash, 'dsthash': dsthash, 'srcname': srcname, 'dstname': dstname, 'status': status, } def commit_lfs_file(io: IO[bytes], branch: str, template: Optional[str] = None, overwrite: bool = False): """Store the file in the LFS storage and commit it to a branch.""" commit_lfs_files([io], branch, template=template, overwrite=overwrite) def commit_lfs_files(ios: Sequence[IO[bytes]], branch: str, template: Optional[str] = None, overwrite: bool = False): """Store the files in the LFS storage and commit them to a branch.""" # make sure the pre-push hook has been set up hook_path = Path(git_dir()) / 'hooks' / 'pre-push' if not hook_path.is_file(): try: hook_path.parent.mkdir(exist_ok=True) hook_path.write_text(pre_push_hook) hook_path.chmod(0o755) except IOError as e: logger.warning(_('Failed to set up pre-push hook: %s') % e.strerror) with open_index("pristine-lfs") as index: # make sure we include all previously committed files if check_branch(branch) is not None: git('update-index', '--index-info', index=index, _in=git('ls-tree', '-r', '--full-name', branch)) # make sure .gitattributes is present stage_file('.gitattributes', gitattributes, index=index) for io in ios: filename = os.path.basename(io.name) if not is_lfs_managed(os.path.basename(filename), default_gitattributes): stage_file(filename, io, index=index) else: metadata = store_lfs_object(io) stage_file(filename, metadata, index=index) if check_branch(branch) is not None: diff = git('diff-index', '--cached', branch, index=index).strip().splitlines() if not diff: logger.info(_("Nothing to commit")) return parsed_diff = [parse_diff_entry(d) for d in diff] overwritten = [d['srcname'] for d in parsed_diff if d['srchash'] != ('0' * 40) and d['srcname'] != '.gitattributes'] if any(overwritten) and not overwrite: raise DifferentFilesExist(overwritten) if not template: template = "pristine-lfs data for %s" message = template.replace('%s', ', '.join([os.path.basename(io.name) for io in ios])) create_commit(branch, message, index=index) refresh_main_index() def list_lfs_files(branch: str) -> list[str]: """Return a list of all the files tracked by Git LFS in the given branch.""" return git.lfs('ls-files', '--name-only', branch).splitlines() def parse_entry(entry: str) -> tuple[str, ...]: info, name = entry.split('\t') mode, type, hash = info.split(' ') return mode, type, hash, name def list_git_files(branch: str) -> Mapping[str, str]: """Return a dictionary mapping file names to SHA1 hashes for all files in the given branch.""" entries = [parse_entry(line) for line in git('ls-tree', '-r', '--full-name', branch).splitlines()] return {e[3]: e[2] for e in entries if e[1] == 'blob'} def is_lfs_managed(filename: str, attributes: Iterable[tuple[str, Mapping[str, AttributeValue]]]): """Tell if the file is managed by Git LFS. If the filename matches a pattern in the attributes, and the filter attribute is set to lfs, then the file is LFS-managed. """ lfs_managed = False for pattern, attrs in attributes: if fnmatchcase(filename, pattern): if 'filter' in attrs: lfs_managed = attrs['filter'] == 'lfs' return lfs_managed def checkout_lfs_file(branch: str, filename: str, outdir: Union[str, Path] = '.'): """ Check out a file from a Git branch: * if it's managed by LFS, use Git LFS * otherwise check it out normally """ files = list_git_files(branch) if '.gitattributes' in files: attributes = parse_git_attributes(git('cat-file', 'blob', files['.gitattributes'])) else: attributes = [] if filename not in files: raise GitFileNotFound(filename, branch) with (Path(outdir) / filename).open(mode='wb') as tarball: if is_lfs_managed(filename, attributes): metadata = git('cat-file', 'blob', files[filename]) git.lfs.smudge(filename, _out=tarball, _in=metadata) else: git('cat-file', 'blob', files[filename], _out=tarball) def verify_lfs_file(branch: str, tarball: Path) -> bool: """Check if the tarball's hash matches the one stored in the Git repo.""" files = list_git_files(branch) filename = tarball.name if filename not in files: raise GitFileNotFound(filename, branch) metadata = git('cat-file', 'blob', files[filename], **RETURN_CMD) parsed_metadata = dict(parse_pointer(metadata)) oid = parsed_metadata['oid'] algo, hashsum = oid.split(':', 1) if algo not in supported_lfs_hashsums: raise UnsupportedHashAlgorithm(algo) h = getattr(hashlib, algo)() with open(tarball, mode='rb') as f: while True: chunk = f.read(h.block_size) if not chunk: break h.update(chunk) calc_hashsum = h.hexdigest() if hashsum == calc_hashsum: logger.info(f"{algo} hash for the tarball: {hashsum}, matches the stored one") else: logger.warning(_("%(tarball)s does not match stored hash (expected %(stored_hash)s, got %(tarball_hash)s)") % { 'tarball': filename, 'stored_hash': hashsum, 'tarball_hash': calc_hashsum, }) return hashsum == calc_hashsum def checkout_package(package: str, version: Version, branch: str, outdir: Union[str, Path], requested: Optional[Sequence[str]] = None): """Check out all files necessary for a given version of a given package.""" logger.info(_("Checking out files for {package} version {version} to {outdir}:").format( package=package, version=version, outdir=outdir )) tarball_glob = f'{package}_{version.upstream_version}.orig.tar.*' component_tarball_glob = f'{package}_{version.upstream_version}.orig-*.tar.*' files = list_git_files(branch) if requested: # TODO: handle missing files tarballs = [f for f in files if f in requested] else: tarballs = [f for f in files if fnmatch(f, tarball_glob) or fnmatch(f, component_tarball_glob)] for f in tarballs: logger.info(" ... {}".format(f)) checkout_lfs_file(branch, f, outdir) logger.info(_("Done.")) def parse_pointer(pointer: IO[str]) -> Iterable[tuple[str, str]]: """ Parse Git LFS file pointer into a mapping of keys to values. >>> from io import StringIO >>> dict(parse_pointer(StringIO('''version https://git-lfs.github.com/spec/v1 ... oid sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393 ... size 12345 ... '''))) {'version': 'https://git-lfs.github.com/spec/v1', 'oid': 'sha256:4d7a214614ab2935c943f9e0ff69d22eadbb8f32b1258daaa5e2ca24d17e2393', 'size': '12345'} """ for line in pointer: key, value = line.rstrip('\n').split(' ', 1) yield key, value ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1734602618.4705853 pristine-lfs-20241219.0/pristine_lfs.egg-info/0000755000000000000000000000000014730767572017510 5ustar00rootroot././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734602618.0 pristine-lfs-20241219.0/pristine_lfs.egg-info/PKG-INFO0000644000000000000000000000605714730767572020615 0ustar00rootrootMetadata-Version: 2.1 Name: pristine-lfs Version: 20241219.0 Summary: a pristine-tar replacement that works with Git LFS Home-page: https://salsa.debian.org/pristine-lfs-team/pristine-lfs Author: Andrej Shadura Author-email: andrew.shadura@collabora.co.uk License: GPL-2+ Classifier: Development Status :: 4 - Beta Classifier: Environment :: Console Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: GNU General Public License (GPL) Classifier: License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+) Classifier: Operating System :: OS Independent Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3.7 Classifier: Programming Language :: Python :: 3.8 Classifier: Programming Language :: Python :: 3.9 Classifier: Programming Language :: Python :: 3.10 Classifier: Programming Language :: Python :: 3.11 Classifier: Programming Language :: Python :: 3.12 Classifier: Programming Language :: Python :: 3.13 Classifier: Topic :: Software Development :: Build Tools Classifier: Topic :: Software Development :: Version Control :: Git Requires-Python: >=3.7 Description-Content-Type: text/x-rst Provides-Extra: test License-File: COPYING ============ pristine-lfs ============ About ----- **pristine-lfs** is a tool to replace *pristine-tar* by the means of using Git LFS to store tarballs. The original *pristine-tar* tool is a way to store binary tarballs in Git by regenerating them using only a small binary delta file and a checkout of the upstream branch. On the contrary, *pristine-lfs* only uses the Git LFS storage, only uploading or downloading binary blobs as they’re needed, which helps reduce the Git repository size (compared to storing tarballs directly in Git) and the checkout times (compared to the plain Git LFS usage, which would download all tarballs each time the LFS-managed branch is checked out). Installation ------------ *pristine-lfs* assumes you have Python 3.6 or later installed as ``/usr/bin/python3``. *pristine-lfs* ships with a setup.py installer based on setuptools. To install *pristine-lfs*, simply type:: ./setup.py install This will install *pristine-lfs* itself, its manpage and this README file into their proper locations. Alternatively, to install via ``pip``, run:: pip install pristine-lfs License ------- This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License version 2 text for more details. You should have received a copy of the GNU General Public License along with this package; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Authors ------- For the list of contributors, see CONTRIBUTORS. ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734602618.0 pristine-lfs-20241219.0/pristine_lfs.egg-info/SOURCES.txt0000644000000000000000000000120114730767572021366 0ustar00rootrootCONTRIBUTORS COPYING MANIFEST.in README.rst pristine-lfs.rst setup.cfg setup.py pristine_lfs/__init__.py pristine_lfs/errors.py pristine_lfs/gitwrap.py pristine_lfs/gitwrap.pyi pristine_lfs/log.py pristine_lfs/main.py pristine_lfs/util.py pristine_lfs.egg-info/PKG-INFO pristine_lfs.egg-info/SOURCES.txt pristine_lfs.egg-info/dependency_links.txt pristine_lfs.egg-info/entry_points.txt pristine_lfs.egg-info/requires.txt pristine_lfs.egg-info/top_level.txt stubs/sh.pyi stubs/sh/contrib.pyi tests/conftest.py tests/test_checkout.py tests/test_commit.py tests/test_git_works.py tests/test_import_dsc.py tests/test_list.py tests/test_verify.py././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734602618.0 pristine-lfs-20241219.0/pristine_lfs.egg-info/dependency_links.txt0000644000000000000000000000000114730767572023556 0ustar00rootroot ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734602618.0 pristine-lfs-20241219.0/pristine_lfs.egg-info/entry_points.txt0000644000000000000000000000007014730767572023003 0ustar00rootroot[console_scripts] pristine-lfs = pristine_lfs.main:main ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734602618.0 pristine-lfs-20241219.0/pristine_lfs.egg-info/requires.txt0000644000000000000000000000012014730767572022101 0ustar00rootrootpython-debian sh>=1.14 [:python_version < "3.8"] sh<=1.999 [test] pytest>=4.6 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734602618.0 pristine-lfs-20241219.0/pristine_lfs.egg-info/top_level.txt0000644000000000000000000000001514730767572022236 0ustar00rootrootpristine_lfs ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1734602618.4745853 pristine-lfs-20241219.0/setup.cfg0000644000000000000000000000404214730767572015136 0ustar00rootroot[metadata] name = pristine-lfs version = 20241219.0 author = Andrej Shadura author_email = andrew.shadura@collabora.co.uk url = https://salsa.debian.org/pristine-lfs-team/pristine-lfs description = a pristine-tar replacement that works with Git LFS long_description = file: README.rst long_description_content_type = text/x-rst license = GPL-2+ classifiers = Development Status :: 4 - Beta Environment :: Console Intended Audience :: Developers License :: OSI Approved :: GNU General Public License (GPL) License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+) Operating System :: OS Independent Programming Language :: Python Programming Language :: Python :: 3.7 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 Programming Language :: Python :: 3.12 Programming Language :: Python :: 3.13 Topic :: Software Development :: Build Tools Topic :: Software Development :: Version Control :: Git [options] python_requires = >= 3.7 packages = find: setup_requires = docutils >= 0.12 install_requires = sh >= 1.14 sh <= 1.999; python_version < "3.8" python-debian include_package_data = True tests_require = pristine-lfs[test] [options.extras_require] test = pytest >= 4.6 [sdist] owner = root group = root formats = xztar [options.entry_points] console_scripts = pristine-lfs = pristine_lfs.main:main [options.exclude_package_data] pristine_lfs = stubs/* [mypy] allow_redefinition = True mypy_path = stubs [tool:pytest] addopts = --doctest-modules junit_family = xunit2 doctest_optionflags = NORMALIZE_WHITESPACE markers = smoke [flake8] doctests = yes max-line-length = 130 exclude = .git,build,__pycache__,setup.py ignore = E121,E123,E126,E133,E226,E241,E242,E704,E261,E127,E128,W503,W504 [isort] multi_line_output = 3 include_trailing_comma = true lines_after_imports = 2 line_length = 130 reverse_relative = true default_section = THIRDPARTY [pylint.FORMAT] max-line-length = 130 [egg_info] tag_build = tag_date = 0 ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1677536022.0 pristine-lfs-20241219.0/setup.py0000775000000000000000000000312014377225426015022 0ustar00rootroot#!/usr/bin/env python3 import fnmatch import os from setuptools import setup, distutils def read(fname): return open(os.path.join(os.path.dirname(__file__), fname)).read() def glob(fname): return fnmatch.filter(os.listdir(os.path.abspath(os.path.dirname(__file__))), fname) def generate_manpage(src, dst): import docutils.core distutils.log.info("generating a manpage from %s to %s", src, dst) docutils.core.publish_file(source_path=src, destination_path=dst, writer_name='manpage') def man_name(fname): import re matches = re.compile(r'^:Manual section: *([0-9]*)', re.MULTILINE).search(read(fname)) if matches: section = matches.groups()[0] else: section = '7' base = os.path.splitext(fname)[0] manfname = base + '.' + section return manfname def man_path(fname): category = fname.rsplit('.', 1)[1] return os.path.join('share', 'man', 'man' + category), [fname] def man_files(pattern): return list(map(man_path, map(man_name, glob(pattern)))) __manpages__ = 'pristine-lfs.rst' from setuptools.command import build_py build_py_org = build_py.build_py class build_py_new(build_py_org): def run(self): build_py_org.run(self) if not self.dry_run: for page in glob(__manpages__): generate_manpage(page, man_name(page)) build_py.build_py = build_py_new __name__ = "pristine-lfs" setup( data_files = [ (os.path.join('share', 'doc', __name__), glob('*.rst')), (os.path.join('share', 'doc', __name__), ['CONTRIBUTORS', 'COPYING']) ] + man_files(__manpages__) ) ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1734602618.4705853 pristine-lfs-20241219.0/stubs/0000755000000000000000000000000014730767572014455 5ustar00rootroot././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1734602618.4705853 pristine-lfs-20241219.0/stubs/sh/0000755000000000000000000000000014730767572015067 5ustar00rootroot././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1677687682.0 pristine-lfs-20241219.0/stubs/sh/contrib.pyi0000644000000000000000000000100114377675602017241 0ustar00rootroot# Extremely simplified type stubs for git and git.lfs. # Extend as needed. # # Copyright (C) 2021 Collabora Ltd # Copyright (C) 2021 Andrej Shadura # # SPDX-License-Identifier: GPL-2.0-or-later class git: class lfs: def __init__(*args): ... def __call__(self, *args, **kwargs): ... def smudge(self, *args, **kwargs): ... def clean(self, *args, **kwargs): ... def __init__(*args, **kwargs): ... def __call__(self, *args, **kwargs): ... ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1727779208.0 pristine-lfs-20241219.0/stubs/sh.pyi0000644000000000000000000000044514676750610015607 0ustar00rootroot# Type hints for the subset of sh we use. # Extend as needed. # # Copyright (C) 2021 Collabora Ltd # Copyright (C) 2021 Andrej Shadura # # SPDX-License-Identifier: GPL-2.0-or-later class ErrorReturnCode(Exception): ... DEFAULT_ENCODING: str __version__: str ././@PaxHeader0000000000000000000000000000003400000000000010212 xustar0028 mtime=1734602618.4745853 pristine-lfs-20241219.0/tests/0000755000000000000000000000000014730767572014457 5ustar00rootroot././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734601769.0 pristine-lfs-20241219.0/tests/conftest.py0000644000000000000000000000601014730766051016642 0ustar00rootrootimport hashlib import os import tarfile from pathlib import Path from textwrap import dedent from typing import NamedTuple, Optional import pytest try: import sh except ImportError: assert False, "These tests require working python-sh" try: from sh.contrib import git except ImportError: assert False, "These tests require Git" class WorkDir(NamedTuple): path: Path tarball: Optional[Path] = None size: Optional[int] = None sha: Optional[str] = None @pytest.fixture def empty_git_repo(tmp_path): os.chdir(tmp_path) git.init() git.config('user.name', 'Committer Name') git.config('user.email', 'name@example.org') git.config('commit.gpgsign', 'false') assert (tmp_path / '.git').is_dir() yield WorkDir(tmp_path) @pytest.fixture(params=['/bin/true']) def fake_tarball(empty_git_repo, request): repo, *_ = empty_git_repo tarball = Path('true_0.orig.tar.gz') with tarfile.open(tarball, mode='w:gz') as f: f.add(request.param) size = tarball.stat().st_size h = hashlib.sha256() with open(tarball, mode='rb') as f: while True: chunk = f.read(h.block_size) if not chunk: break h.update(chunk) sha = h.hexdigest() yield WorkDir(repo, tarball, size, sha) @pytest.fixture def fake_pristine_lfs(fake_tarball): repo, tarball, size, sha = fake_tarball git.checkout('-b', 'pristine-lfs') git.lfs.track('*.tar.*') f = Path('.gitattributes') assert f.is_file() assert f.stat().st_size != 0 git.add(f) git.add(tarball) git.commit(message=f'add {tarball.name}') commit = git('rev-parse', 'pristine-lfs^{tree}').strip('\n') pointer = git('cat-file', 'blob', f"{commit}:{tarball.name}") assert pointer == dedent( f""" version https://git-lfs.github.com/spec/v1 oid sha256:{sha} size {size} """).lstrip('\n'), 'Object pointer doesn’t match the object' yield WorkDir(repo, tarball, size, sha) @pytest.fixture def test_git_repo(fake_pristine_lfs): repo, tarball, size, sha = fake_pristine_lfs # clean index empty = git('hash-object', '-t', 'tree', '/dev/null').strip('\n') git('read-tree', empty) # start a new empty branch git.checkout(orphan='debian/test') changelog = Path('debian/changelog') changelog.parent.mkdir() changelog.write_text(dedent( """ true (0-0) UNRELEASED; urgency=medium * Empty. -- Nobody Thu, 01 Jan 1970 12:00:00 +0100 """).lstrip('\n')) # noqa: W293 git.add(changelog) git.commit(message='pretend packaging') git.reset(hard=True) git.clean(force=True) yield WorkDir(repo, tarball, size, sha) def pytest_collection_modifyitems(items): # sort doctests before normal tests # but run smoke tests first def test_key(item): return type(item).__name__, not [mark.name == 'smoke' for mark in item.iter_markers()] items.sort(key=test_key) ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1734601769.0 pristine-lfs-20241219.0/tests/test_checkout.py0000644000000000000000000000426414730766051017672 0ustar00rootrootfrom pristine_lfs import do_checkout from pristine_lfs.util import Version def test_pristine_lfs_simple_checkout(fake_pristine_lfs): repo, tarball, size, sha = fake_pristine_lfs outdir = repo / 'tmp' do_checkout('pristine-lfs', tarball=tarball.name, outdir=outdir) assert len(list(outdir.glob('**/'))) == 1, list(outdir.glob('**/')) assert (outdir / tarball.name).is_file(), 'Extracted tarball not found' assert (outdir / tarball.name).stat().st_size == size, 'Extracted tarball of a wrong size' def test_pristine_lfs_auto_checkout(test_git_repo): repo, tarball, size, sha = test_git_repo outdir = repo / 'tmp-explicit' do_checkout('pristine-lfs', tarball=tarball.name, outdir=outdir) assert len(list(outdir.glob('*'))) == 1, list(outdir.glob('*')) assert (outdir / tarball.name).is_file() assert (outdir / tarball.name).stat().st_size == size outdir = repo / 'tmp-auto' do_checkout('pristine-lfs', tarball=None, outdir=outdir) assert len(list(outdir.glob('*'))) == 1, list(outdir.glob('*')) assert (outdir / tarball.name).is_file(), 'Extracted tarball not found' assert (outdir / tarball.name).stat().st_size == size, 'Extracted tarball of a wrong size' outdir = repo / 'tmp-empty' do_checkout('pristine-lfs', package='true', version='1', outdir=outdir) assert len(list(outdir.glob('*'))) == 0, list(outdir.glob('*')) assert not (outdir / tarball.name).is_file(), 'Found a tarball which should not be there' do_checkout('pristine-lfs', package='true', version=Version('1'), outdir=outdir) assert len(list(outdir.glob('*'))) == 0, list(outdir.glob('*')) assert not (outdir / tarball.name).is_file(), 'Found a tarball which should not be there' do_checkout('pristine-lfs', package='true', version='0', outdir=outdir) assert len(list(outdir.glob('*'))) == 1, list(outdir.glob('*')) assert (outdir / tarball.name).is_file(), 'Extracted tarball not found' outdir = repo / 'tmp-empty-2' do_checkout('pristine-lfs', package='true', version='0', outdir=outdir) assert len(list(outdir.glob('*'))) == 1, list(outdir.glob('*')) assert (outdir / tarball.name).is_file(), 'Extracted tarball not found' ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1625467314.0 pristine-lfs-20241219.0/tests/test_commit.py0000664000000000000000000000452514070524662017354 0ustar00rootrootfrom textwrap import dedent import pytest from sh.contrib import git from pristine_lfs import do_commit, do_commit_files from pristine_lfs.errors import DifferentFilesExist def test_pristine_lfs_commit(fake_tarball): repo, tarball, size, sha = fake_tarball do_commit(tarball.open('rb'), branch='pristine-lfs') do_commit(tarball.open('rb'), branch='pristine-lfs', message='blip %s %s %s') do_commit(tarball.open('rb'), branch='pristine-lfs', message='blip') # verify the file has indeed been committed commit = git('rev-parse', 'pristine-lfs^{tree}').strip('\n') pointer = git('cat-file', 'blob', f"{commit}:{tarball.name}") assert pointer == dedent( f""" version https://git-lfs.github.com/spec/v1 oid sha256:{sha} size {size} """).lstrip('\n'), 'Object pointer doesn’t match the object' stored = repo / '.git' / 'lfs' / 'objects' / sha[:2] / sha[2:4] / sha assert stored.is_file(), 'Object has not been stored by LFS' def test_pristine_lfs_commit_overwrite(fake_tarball): repo, tarball, size, sha = fake_tarball do_commit(tarball.open('rb'), branch='pristine-lfs') tarball.write_text('Text') with pytest.raises(DifferentFilesExist): do_commit(tarball.open('rb'), branch='pristine-lfs', message='blip %s %s %s') def test_pristine_lfs_commit_overwrite_forced(fake_tarball): repo, tarball, size, sha = fake_tarball do_commit(tarball.open('rb'), branch='pristine-lfs') tarball.write_text('Text') do_commit(tarball.open('rb'), branch='pristine-lfs', message='blip %s %s %s', force_overwrite=True) def test_pristine_lfs_commit_files(fake_tarball): repo, tarball, size, sha = fake_tarball sig = tarball.with_suffix('.gz.asc') fake_sig_text = 'Fake signature' sig.write_text(fake_sig_text) do_commit_files([tarball.open('rb'), sig.open('rb')], branch='pristine-lfs', message='blip %s %s %s') commit = git('rev-parse', 'pristine-lfs^{tree}').strip('\n') pointer = git('cat-file', 'blob', f"{commit}:{tarball.name}") assert pointer == dedent( f""" version https://git-lfs.github.com/spec/v1 oid sha256:{sha} size {size} """).lstrip('\n'), 'Object pointer doesn’t match the object' sig_text = git('cat-file', 'blob', f"{commit}:{sig.name}") assert sig_text == fake_sig_text ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1612888563.0 pristine-lfs-20241219.0/tests/test_git_works.py0000664000000000000000000000021314010534763020057 0ustar00rootrootimport pytest @pytest.mark.smoke def test_git_works(fake_pristine_lfs): """ This test succeeds when git and git-lfs work """ ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1617549282.0 pristine-lfs-20241219.0/tests/test_import_dsc.py0000664000000000000000000000247314032353742020224 0ustar00rootrootfrom textwrap import dedent from pristine_lfs import do_import, do_list def test_pristine_lfs_import_dsc(fake_tarball): repo, tarball, size, sha = fake_tarball base, *_ = tarball.name.split('.') package, version = base.split('_') outdir = repo / 'tmp' outdir.mkdir() dsc = outdir / f'{package}_{version}.dsc' dsc.write_text(dedent( f""" Format: 3.0 (quilt) Source: {package} Binary: {package} Architecture: any Version: {version} Package-List: {package} deb utils optional arch=any Checksums-Sha1: 0000000000000000000000000000000000000000 0 {tarball.name} Checksums-Sha256: 0000000000000000000000000000000000000000000000000000000000000000 0 {tarball.name} Files: 00000000000000000000000000000000 0 {tarball.name} """).lstrip('\n')) tarball.rename(outdir / tarball.name) do_import(dsc.open(), 'pristine-lfs', f'import {package}') do_import(dsc.open(), 'pristine-lfs', f'import {package}') do_import(dsc.open(), 'pristine-lfs-source', f'import {package}', full=True) ret = list(do_list(branch='pristine-lfs')) assert ['true_0.orig.tar.gz'] == ret ret = list(do_list(branch='pristine-lfs-source')) assert ['true_0.dsc', 'true_0.orig.tar.gz'] == ret ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1613392021.0 pristine-lfs-20241219.0/tests/test_list.py0000664000000000000000000000051614012464225017025 0ustar00rootrootfrom pristine_lfs import do_list def test_pristine_lfs_list(test_git_repo): ret = list(do_list(branch='pristine-lfs')) assert [test_git_repo.tarball.name] == ret, 'Expected tarball not found' ret = list(do_list(branch='debian/test')) assert ["debian/changelog"] == ret, 'This branch should only have the changelog' ././@PaxHeader0000000000000000000000000000002600000000000010213 xustar0022 mtime=1613989548.0 pristine-lfs-20241219.0/tests/test_verify.py0000664000000000000000000000123414014703254017354 0ustar00rootrootfrom pristine_lfs import do_commit, do_verify def test_pristine_lfs_commit(fake_tarball): repo, tarball, size, sha = fake_tarball do_commit(tarball.open('rb'), branch='pristine-lfs') do_commit(tarball.open('rb'), branch='pristine-lfs', message='blip %s %s %s') do_commit(tarball.open('rb'), branch='pristine-lfs', message='blip') # verify the file has indeed been committed assert do_verify(branch='pristine-lfs', tarball=tarball), 'Tarball doesn’t match the one in Git LFS' # now try a different file tarball.write_text('dummy') assert not do_verify(branch='pristine-lfs', tarball=tarball), 'Corrupted tarball not detected'