19 Commits

Author SHA1 Message Date
Joel Brobecker
2178791fa7 encode input in call to git.check_attr
This is another preparation patch for the transition to Python 3.x,
where the input first needs to be encoded before it is passed to
the git command to be executed.

Change-Id: I2d8aac02a17b5d5765ab5e2c357bc15ead4f2c64
TN: U530-006
2021-10-06 11:27:20 -07:00
Joel Brobecker
9c82498e7b Introduce (the concept of) git command output decoding
This commit is preparation work for the transition to Python 3.x,
where the output obtained by running Git commands will become
bytes as opposed to a string. In the vast majority of cases,
we'll want to decode that output into a string. Ideally, we would
want to do this in a way that is both compatible with Python 2.x
and Python 3.x, but we have found that this requires a lot of
work with many changes spread all over the code. So, instead,
what this commit does is introduce the concept of decoding
the output, but with the decoding only occurring when running
under Python 3.x.

That way, we can make progress towards Python 3.x while preserving
the behavior under Python 2.x intact.

Change-Id: I189577798ee96cba1fa55c7356babf102575642f
TN: U530-006
2021-10-06 11:27:20 -07:00
Joel Brobecker
a075b1653e reformat all the code using black
Change-Id: Idbc70777233ab2d40ab59765abb9cbbeeb88ec63
2021-04-18 14:59:01 +04:00
Joel Brobecker
e70a745ab5 Handle filenames with special characters properly
For Q224-008.
2017-02-27 08:54:09 +01:00
Joel Brobecker
b427e31c30 remove hard-coded attribute name in call to git.check_attr 2017-02-27 08:54:08 +01:00
Joel Brobecker
1d1d4e7b3a crash in git_attrs.git_attribute function
A recent change in this function sometimes causes a crash when
pushing a commit. This happens in a situation such as the following:

The user has a repository that looks like this:

     <root>/
        subdir/
           .gitattributes
           sub_sub_dir/
              .gitattributes
              some_file

If the user creates a commit which modifies some_file, the git_attribute
function will be passed a list of files which includes:

    subdir/sub_sub_dir/some_file

It will process that file by first looking at subdir/sub_sub_dir,
check if there is a .gitattributes in it (yes), so create that
directory, add it to the dirs_with_changes "list" so we know
we've already processed that directory. So far, so good.

Loop again, this time with os.path.dirname('subdir/sub_sub_dir'),
thus with 'subdir'. Is that directory in dirs_with_changes? No.
Does it have a .gitattribute in it? Yes.  So, rince-repeat, which
means first creating the subdir. That leads to the crash, since
we already just created it as a side-effect of creating its subdir.

This patch fixes the issue by simply remembering when a directory
has been created for a given file in filename_list.  Once that's
done, we know that the next iterations on the dir_path loop are
necessarily for parent directories, which have therefore been
created, even if they are not listed in the dirs_with_changes
"list" yet.

Another possible fix, which would be safer, would be to just
check the filesystem directly. But this code can be a hot-spot
in terms of performance, so we'll try really hard to avoid it.

Fixes P601-011.
Related to P531-036.
2016-06-07 09:27:28 -07:00
Joel Brobecker
9a7944833e Improve performance handling no-precommit-check .gitattributes.
For a commit for which there are 4,500 files being modified and
for which all files have the no-precommit-check attribute set,
this reduces the amount of time it takes for the update hook
to process that commit from 20-25 seconds down to less than a second.

For P531-036.
2016-06-07 09:27:27 -07:00
Joel Brobecker
26462873eb Fix handling of nested .gitattributes file, add new test for it.
For N114-003.
2014-01-17 08:31:55 +04:00
Joel Brobecker
93924241bd git_attrs.py: fix style violations 2013-12-26 14:40:07 +04:00
Joel Brobecker
fe91e6983b Rework comment in git_attr.py from previous commit.
The comment I added in function git_attributes to explain why we may
have to create the "info/" directory was not quite correct. This
patch improves it, now that we have a little more info about the
source of the condition (most likely differences in git versions).

Part of MC16-012.
2013-12-18 17:47:20 +04:00
Joel Brobecker
3bf9f94fc3 Handle the case where the <GIT_DIR>/info/ directory is missing.
Fixes MC16-012.
2013-12-18 16:42:55 +04:00
Joel Brobecker
d5849611f8 Delete info/attributes before re-creating it.
This is another attempt at fixing the error raised when trying
to overwrite the info/attributes file when this file was left
by another user during the previous update.

For M116-004.
2013-01-18 07:40:38 +04:00
Joel Brobecker
cca0aa4e14 Revert "Make sure the info/attributes file is group-writable."
It turns out that making info/attributes group-writable is not
sufficient: A second user is allowed to overwrite the file, but
then the hooks fail when trying to change the file permissions
to make it group-writable.

We will use a different approach which should not need this anymore.

Part of M116-004.
2013-01-18 07:27:23 +04:00
Joel Brobecker
fc20bd3285 Make sure the info/attributes file is group-writable.
A user needs to be able to overwrite this file, so we make it
group-writable.

Update the testsuite to verify this requirement for both
a repository's .gitattribute file, as well as the bare
repository's default_attribute file.
2013-01-16 12:23:04 +04:00
Joel Brobecker
82dec9bfb5 git_attrs.py: cache all calls to git.file_exists.
Experience shows that this is a very repetive operations, involving
multiple calls for each file being changed (the number of calls
per file being changed is equal to the depth of the file, in terms
of number of sub-directories). Caching it this way has been measured
to reduce the amount of time spent by about 10% for small commits
in the GDB repository (12 files changed). For commits involving
a larger number of files (3717), it improves performance by about 60%!
2013-01-03 15:56:41 +04:00
Joel Brobecker
7c47ef951c Use a constant instead of hardcoded 'unspecified' string.
No functional change.
2012-06-10 21:45:45 -07:00
Joel Brobecker
78d43cbfcc Minor cleanup: Use constant instead of hard-coded 'info/attributes' 2012-06-10 21:41:45 -07:00
Joel Brobecker
283ec10395 Add support for info/default_attributes file in bare repo. 2012-06-10 21:39:12 -07:00
Joel Brobecker
6ac6d2674a Add initial branch-update support. Update the testsuite accordingly. 2012-05-20 12:19:19 +02:00