summaryrefslogtreecommitdiff
path: root/git.py
Commit message (Collapse)AuthorAgeFilesLines
* Auto-format the code with blackAlberto Bertogli2020-05-241-112/+146
| | | | | | | | | | | | | This patch applies auto-formatting of the source code using black (https://github.com/psf/black). This makes the code style more uniform and simplifies editing. Note I also tried yapf, and IMO produced nicer output and handled some corner cases much better, but unfortunately it doesn't yet support type annotations, which will be introduced in later commits. So in the future we might switch to yapf instead.
* Move to Python 3Alberto Bertogli2020-05-241-49/+38
| | | | | | | | | | | Python 3 was released more than 10 years ago, and support for Python 2 is going away, with many Linux distributions starting to phase it out. This patch migrates git-arr to Python 3. The generated output is almost exactly the same, there are some minor differences such as HTML characters being quoted more aggresively, and handling of paths with non-utf8 values.
* git: Don't use an empty pathspec when listingAlberto Bertogli2017-08-271-1/+4
| | | | | | | | | | An empty string as a pathspec element matches all paths, but git has recently started complaining about it, as it could be problematic for some operations like rm. In the future, it will be considered an error. So this patch uses "." instead of the empty pathspec, as recommended. https://github.com/git/git/commit/d426430e6ec2a05bf0a4ee88c319dd6072908504
* Repo: retire new_in_branch() and notion of "bound" branch0.14Eric Sunshine2015-01-171-13/+3
| | | | | | | | | | | | | | | | Binding (or "pegging") a Repo at a particular branch via new_in_branch() increases the cognitive burden since the reader must maintain a mental model of which Repo instances are pegged and which are not. This burden outweighs whatever minor convenience (if any) is gained by pegging the Repo at a particular branch. It is easier to reason about the code when the branch name is passed to clients directly rather than indirectly via a pegged Repo. Preceding patches retired all callers of new_in_branch(), therefore remove it. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
* Repo.blob: respect reported blob sizeEric Sunshine2015-01-131-2/+2
| | | | | | | | | | | | | | | | | | | Batch output of git-cat-file has the form: <sha1> SP <type> SP <size> LF <contents> LF It unconditionally includes a trailing line-feed which Repo.blob() incorrectly returns as part of blob content. For textual blobs, this extra character is often benign, however, for binary blobs, it can easily change the meaning of the data in unexpected or disastrous ways. Fix this by respecting the blob size reported by git-cat-file. (The alternate approach of unconditionally dropping the final LF also works, however, respecting the reported size is perhaps a bit more robust and "correct".) Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
* Blob: vend raw or cooked contentEric Sunshine2015-01-131-8/+12
| | | | | | | | | | | | | | Some blob representations require raw blob content, however, the 'blob' view is unconditionally handed cooked (utf8-encoded) content, thus representations which need raw content are forced to reload the blob in raw form, which is ugly and expensive. The ultimate goal is to eliminate the wasteful blob reloading when raw content is needed. Toward that end, teach Blob how to vend raw or cooked content. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
* git.py: introduce Blob abstractionEric Sunshine2015-01-131-2/+11
| | | | | | | | | | | | | | | | | | Some blob representations (such as embedded images) require raw blob content, however, the 'blob' view is unconditionally handed cooked (utf8-encoded) content, thus representations which need raw content are forced to reload the blob in raw form, which is ugly and expensive (due to shelling out to git-cat-file a second time). The ultimate goal is to eliminate the wasteful blob reloading when raw content is needed. As a first step, introduce a Blob abstraction to be returned by Repo.blob() rather than the cooked content. A subsequent change will flesh out Blob, allowing it to return raw or cooked content on demand without the client having to specify one or the other when invoking Repo.blob(). Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
* Repo.blob: employ formal mechanism for requesting raw command outputEric Sunshine2015-01-131-4/+1
| | | | | | | | | Sneakily extracting the raw 'fd' from the utf8-encoding wrapper returned by GitCommand.run() is ugly and fragile. Instead, take advantage of the new formal API for requesting raw command output. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
* GitCommand: teach run() how to return raw output streamEric Sunshine2015-01-131-1/+8
| | | | | | | | | | Currently, clients which want the raw output from a Git command must sneakily extract the raw 'fd' from the utf8-encoding wrapper returned by GitCommand.run(). This is ugly and fragile. Instead, provide a formal mechanism for requesting raw output. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
* run_git: add option to return raw output streamEric Sunshine2015-01-131-1/+4
| | | | | | | | | | Currently, clients which want the raw output from a Git command must sneakily extract the raw 'fd' from the utf8-encoding wrapper returned by run_git(). This is ugly and fragile. Instead, provide a formal mechanism for requesting raw output. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
* repo: diff: add option to show "creation event" diff for root commitEric Sunshine2015-01-111-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | At its inception, Git did not show a "creation event" diff for a project's root commit since early projects, such as the Linux kernel, were already well established, and a large root diff was considered uninteresting noise. On the other hand, new projects adopting Git typically have small root commits, and such a "creation event" is likely to have meaning, rather than being pure noise. Consequently, git-diff-tree gained a --root flag in dc26bd89 (diff-tree: add "--root" flag to show a root commit as a big creation event, 2005-05-19), though it was disabled by default. Displaying the root "creation event" diff, however, became the default behavior when configuration option 'log.showroot' was added to git-log in 0f03ca94 (config option log.showroot to show the diff of root commits; 2006-11-23). And, gitk (belatedly) followed suit when it learned to respect 'log.showroot' in b2b76d10 (gitk: Teach gitk to respect log.showroot; 2011-10-04). By default, these tools now all show the root diff as a "creation event", however, git-arr suppresses it unconditionally. Resolve this shortcoming by adding a new git-arr configuration option "rootdiff" to control the behavior (enabled by default). Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
* git: Add '--' to "git rev-list" runs to avoid ambiguous argumentsAlberto Bertogli2014-12-311-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | If there is a branch and a file with the same name, git-arr will fail to generate, as git will complain when running git rev-list. For example, if there is both a file and a branch called "hooks" in the repository, git-arr would fail as follows: === git-arr running: ['git', '--git-dir=/some/repo', 'rev-list', '--max-count=1', '--header', u'hooks']) fatal: ambiguous argument 'hooks': both revision and filename Use '--' to separate paths from revisions, like this: 'git <command> [<revision>...] -- [<file>...]' Traceback (most recent call last): File "./git-arr", line 457, in <module> main() File "./git-arr", line 452, in main skip_index = len(opts.only) > 0) File "./git-arr", line 388, in generate branch_mtime = r.commit(bn).committer_date.epoch AttributeError: 'NoneType' object has no attribute 'committer_date' To fix that, this patch appends a "--" as the last argument to rev-list, which indicates that it has completed the revision list, which disambiguates the argument. While at it, a minor typo in a comment is also fixed. Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
* git.py: Parse timestamps from UTC, not from local timeAlberto Bertogli2014-10-051-1/+1
| | | | | | | | | | | The current parsing of dates from git incorrectly uses datetime.fromtimestamp(), which returns the *local* date and time corresponding to the given timestamp. Instead, it should be using datetime.utcfromtimestamp() which returns the UTC date and time, as the rest of the code expects. Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
* Show the age of a repository in the index, via javascriptAlberto Bertogli2013-11-021-1/+12
| | | | | | | | | This patch adds the age of the repository to the index view, using javascript to give a nice human string for the age. When javascript is not available, the element remains hidden. Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
* Add embed data URI image blob supportVanya Sergeev2013-11-021-1/+5
|
* Fix parsing of empty commit messagesVanya Sergeev2013-10-121-1/+6
|
* Improve the way we find repo pathsAlberto Bertogli2012-11-111-3/+9
| | | | | | | | | | This patch improves the way we find the path to the repositories, both in the recursive and in the non-recursive cases. We now support specifying non-bare repositories directly, and also recursing on them. Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
* Initial commit0.01Alberto Bertogli2012-11-101-0/+522
Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>