Commit Graph

19 Commits

Author SHA1 Message Date
Alberto Bertogli
20b99ee568 Introduce type annotations
This patch introduces type annotations, which can be checked with mypy.

The coverage is not very comprehensive for now, but it is a starting
point and will be expanded in later patches.
2020-05-24 16:04:24 +01:00
Alberto Bertogli
ad950208bf Auto-format the code with black
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.
2020-05-24 16:04:04 +01:00
Alberto Bertogli
1183d6f817 Move to Python 3
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.
2020-05-24 04:50:39 +01:00
Alberto Bertogli
891a944381 git: Don't use an empty pathspec when listing
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.

d426430e6e
2017-08-27 17:37:12 +01:00
Eric Sunshine
5568fd50c2 Repo: retire new_in_branch() and notion of "bound" branch
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>
2015-01-17 13:11:46 +00:00
Eric Sunshine
58037e57c5 Repo.blob: respect reported blob size
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>
2015-01-13 19:51:44 +00:00
Eric Sunshine
1d79988228 Blob: vend raw or cooked content
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>
2015-01-13 19:51:44 +00:00
Eric Sunshine
0ba89d75e6 git.py: introduce Blob abstraction
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>
2015-01-13 19:51:44 +00:00
Eric Sunshine
6b83e32bc1 Repo.blob: employ formal mechanism for requesting raw command output
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>
2015-01-13 19:51:44 +00:00
Eric Sunshine
43f4132bf1 GitCommand: teach run() how to return raw output stream
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>
2015-01-13 19:51:44 +00:00
Eric Sunshine
66afd72d6d run_git: add option to return raw output stream
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>
2015-01-13 19:51:44 +00:00
Eric Sunshine
bebc7fa3f0 repo: diff: add option to show "creation event" diff for root commit
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>
2015-01-11 21:18:22 +00:00
Alberto Bertogli
df00293a7c git: Add '--' to "git rev-list" runs to avoid ambiguous arguments
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>
2014-12-31 17:07:38 +00:00
Alberto Bertogli
7898b2becd git.py: Parse timestamps from UTC, not from local time
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>
2014-10-05 22:15:54 +01:00
Alberto Bertogli
e49c69da2e Show the age of a repository in the index, via javascript
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>
2013-11-02 22:18:33 +00:00
Vanya Sergeev
21522f8a3a Add embed data URI image blob support 2013-11-02 19:07:59 +00:00
Vanya Sergeev
d3bf98ea00 Fix parsing of empty commit messages 2013-10-12 01:19:57 +01:00
Alberto Bertogli
ba3b2132f5 Improve the way we find repo paths
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>
2012-11-11 13:43:02 +00:00
Alberto Bertogli
80ef0017d4 Initial commit
Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>
2012-11-10 17:49:54 +00:00