2017-07-12 10:31:36 -04:00
|
|
|
# Gitaly note: JV: will probably be migrated indirectly by migrating the call sites.
|
|
|
|
|
Accept environment variables from the `pre-receive` script.
1. Starting version 2.11, git changed the way the pre-receive flow works.
- Previously, the new potential objects would be added to the main repo. If the
pre-receive passes, the new objects stay in the repo but are linked up. If
the pre-receive fails, the new objects stay orphaned in the repo, and are
cleaned up during the next `git gc`.
- In 2.11, the new potential objects are added to a temporary "alternate object
directory", that git creates for this purpose. If the pre-receive passes, the
objects from the alternate object directory are migrated to the main repo. If
the pre-receive fails the alternate object directory is simply deleted.
2. In our workflow, the pre-recieve script (in `gitlab-shell) calls the
`/allowed` endpoint, which calls out directly to git to perform
various checks. These direct calls to git do _not_ have the necessary
environment variables set which allow access to the "alternate object
directory" (explained above). Therefore these calls to git are not able to
access any of the new potential objects to be added during this push.
3. We fix this by accepting the relevant environment variables
(GIT_ALTERNATE_OBJECT_DIRECTORIES, GIT_OBJECT_DIRECTORY) on the
`/allowed` endpoint, and then include these environment variables while
calling out to git.
4. This commit includes (whitelisted) these environment variables while making
the "force push" check. A `Gitlab::Git::RevList` module is extracted to
prevent `ForcePush` from being littered with these checks.
2016-12-07 02:55:49 -05:00
|
|
|
module Gitlab
|
|
|
|
module Git
|
|
|
|
class RevList
|
2017-09-12 17:52:43 -04:00
|
|
|
include Gitlab::Git::Popen
|
|
|
|
|
2018-01-31 14:25:38 -05:00
|
|
|
attr_reader :oldrev, :newrev, :repository
|
2017-04-05 03:34:50 -04:00
|
|
|
|
2018-01-31 14:25:38 -05:00
|
|
|
def initialize(repository, newrev:, oldrev: nil)
|
2017-04-05 03:34:50 -04:00
|
|
|
@oldrev = oldrev
|
|
|
|
@newrev = newrev
|
2018-01-31 14:25:38 -05:00
|
|
|
@repository = repository
|
Accept environment variables from the `pre-receive` script.
1. Starting version 2.11, git changed the way the pre-receive flow works.
- Previously, the new potential objects would be added to the main repo. If the
pre-receive passes, the new objects stay in the repo but are linked up. If
the pre-receive fails, the new objects stay orphaned in the repo, and are
cleaned up during the next `git gc`.
- In 2.11, the new potential objects are added to a temporary "alternate object
directory", that git creates for this purpose. If the pre-receive passes, the
objects from the alternate object directory are migrated to the main repo. If
the pre-receive fails the alternate object directory is simply deleted.
2. In our workflow, the pre-recieve script (in `gitlab-shell) calls the
`/allowed` endpoint, which calls out directly to git to perform
various checks. These direct calls to git do _not_ have the necessary
environment variables set which allow access to the "alternate object
directory" (explained above). Therefore these calls to git are not able to
access any of the new potential objects to be added during this push.
3. We fix this by accepting the relevant environment variables
(GIT_ALTERNATE_OBJECT_DIRECTORIES, GIT_OBJECT_DIRECTORY) on the
`/allowed` endpoint, and then include these environment variables while
calling out to git.
4. This commit includes (whitelisted) these environment variables while making
the "force push" check. A `Gitlab::Git::RevList` module is extracted to
prevent `ForcePush` from being littered with these checks.
2016-12-07 02:55:49 -05:00
|
|
|
end
|
|
|
|
|
2017-08-24 21:30:12 -04:00
|
|
|
# This method returns an array of new commit references
|
2017-04-05 03:34:50 -04:00
|
|
|
def new_refs
|
2018-01-31 14:25:38 -05:00
|
|
|
repository.rev_list(including: newrev, excluding: :all).split("\n")
|
2016-12-14 21:23:46 -05:00
|
|
|
end
|
|
|
|
|
2017-08-24 21:30:12 -04:00
|
|
|
# Finds newly added objects
|
|
|
|
# Returns an array of shas
|
|
|
|
#
|
|
|
|
# Can skip objects which do not have a path using required_path: true
|
|
|
|
# This skips commit objects and root trees, which might not be needed when
|
|
|
|
# looking for blobs
|
|
|
|
#
|
2017-11-03 10:33:06 -04:00
|
|
|
# When given a block it will yield objects as a lazy enumerator so
|
|
|
|
# the caller can limit work done instead of processing megabytes of data
|
|
|
|
def new_objects(require_path: nil, not_in: nil, &lazy_block)
|
2018-01-31 14:25:38 -05:00
|
|
|
opts = {
|
|
|
|
including: newrev,
|
|
|
|
excluding: not_in.nil? ? :all : not_in,
|
|
|
|
require_path: require_path
|
|
|
|
}
|
2017-08-24 21:30:12 -04:00
|
|
|
|
2018-01-31 14:25:38 -05:00
|
|
|
get_objects(opts, &lazy_block)
|
2017-08-24 21:30:12 -04:00
|
|
|
end
|
|
|
|
|
2017-11-03 10:33:06 -04:00
|
|
|
def all_objects(require_path: nil, &lazy_block)
|
2018-01-31 14:25:38 -05:00
|
|
|
get_objects(including: :all, require_path: require_path, &lazy_block)
|
2017-08-24 21:30:12 -04:00
|
|
|
end
|
|
|
|
|
2017-04-05 03:34:50 -04:00
|
|
|
# This methods returns an array of missed references
|
2017-07-12 10:31:36 -04:00
|
|
|
#
|
|
|
|
# Should become obsolete after https://gitlab.com/gitlab-org/gitaly/issues/348.
|
2017-04-05 03:34:50 -04:00
|
|
|
def missed_ref
|
2018-01-31 14:25:38 -05:00
|
|
|
repository.missed_ref(oldrev, newrev).split("\n")
|
Accept environment variables from the `pre-receive` script.
1. Starting version 2.11, git changed the way the pre-receive flow works.
- Previously, the new potential objects would be added to the main repo. If the
pre-receive passes, the new objects stay in the repo but are linked up. If
the pre-receive fails, the new objects stay orphaned in the repo, and are
cleaned up during the next `git gc`.
- In 2.11, the new potential objects are added to a temporary "alternate object
directory", that git creates for this purpose. If the pre-receive passes, the
objects from the alternate object directory are migrated to the main repo. If
the pre-receive fails the alternate object directory is simply deleted.
2. In our workflow, the pre-recieve script (in `gitlab-shell) calls the
`/allowed` endpoint, which calls out directly to git to perform
various checks. These direct calls to git do _not_ have the necessary
environment variables set which allow access to the "alternate object
directory" (explained above). Therefore these calls to git are not able to
access any of the new potential objects to be added during this push.
3. We fix this by accepting the relevant environment variables
(GIT_ALTERNATE_OBJECT_DIRECTORIES, GIT_OBJECT_DIRECTORY) on the
`/allowed` endpoint, and then include these environment variables while
calling out to git.
4. This commit includes (whitelisted) these environment variables while making
the "force push" check. A `Gitlab::Git::RevList` module is extracted to
prevent `ForcePush` from being littered with these checks.
2016-12-07 02:55:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2017-04-05 03:34:50 -04:00
|
|
|
def execute(args)
|
2018-01-31 14:25:38 -05:00
|
|
|
repository.rev_list(args).split("\n")
|
Accept environment variables from the `pre-receive` script.
1. Starting version 2.11, git changed the way the pre-receive flow works.
- Previously, the new potential objects would be added to the main repo. If the
pre-receive passes, the new objects stay in the repo but are linked up. If
the pre-receive fails, the new objects stay orphaned in the repo, and are
cleaned up during the next `git gc`.
- In 2.11, the new potential objects are added to a temporary "alternate object
directory", that git creates for this purpose. If the pre-receive passes, the
objects from the alternate object directory are migrated to the main repo. If
the pre-receive fails the alternate object directory is simply deleted.
2. In our workflow, the pre-recieve script (in `gitlab-shell) calls the
`/allowed` endpoint, which calls out directly to git to perform
various checks. These direct calls to git do _not_ have the necessary
environment variables set which allow access to the "alternate object
directory" (explained above). Therefore these calls to git are not able to
access any of the new potential objects to be added during this push.
3. We fix this by accepting the relevant environment variables
(GIT_ALTERNATE_OBJECT_DIRECTORIES, GIT_OBJECT_DIRECTORY) on the
`/allowed` endpoint, and then include these environment variables while
calling out to git.
4. This commit includes (whitelisted) these environment variables while making
the "force push" check. A `Gitlab::Git::RevList` module is extracted to
prevent `ForcePush` from being littered with these checks.
2016-12-07 02:55:49 -05:00
|
|
|
end
|
2017-08-24 21:30:12 -04:00
|
|
|
|
2018-01-31 14:25:38 -05:00
|
|
|
def get_objects(including: [], excluding: [], require_path: nil)
|
|
|
|
opts = { including: including, excluding: excluding, objects: true }
|
2017-11-03 10:33:06 -04:00
|
|
|
|
2018-01-31 14:25:38 -05:00
|
|
|
repository.rev_list(opts) do |lazy_output|
|
|
|
|
objects = objects_from_output(lazy_output, require_path: require_path)
|
2017-11-03 10:33:06 -04:00
|
|
|
|
2018-01-31 14:25:38 -05:00
|
|
|
yield(objects)
|
2017-11-03 10:33:06 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def objects_from_output(object_output, require_path: nil)
|
|
|
|
object_output.map do |output_line|
|
2017-08-24 21:30:12 -04:00
|
|
|
sha, path = output_line.split(' ', 2)
|
|
|
|
|
2018-01-12 16:08:30 -05:00
|
|
|
next if require_path && path.to_s.empty?
|
2017-08-24 21:30:12 -04:00
|
|
|
|
|
|
|
sha
|
|
|
|
end.reject(&:nil?)
|
|
|
|
end
|
Accept environment variables from the `pre-receive` script.
1. Starting version 2.11, git changed the way the pre-receive flow works.
- Previously, the new potential objects would be added to the main repo. If the
pre-receive passes, the new objects stay in the repo but are linked up. If
the pre-receive fails, the new objects stay orphaned in the repo, and are
cleaned up during the next `git gc`.
- In 2.11, the new potential objects are added to a temporary "alternate object
directory", that git creates for this purpose. If the pre-receive passes, the
objects from the alternate object directory are migrated to the main repo. If
the pre-receive fails the alternate object directory is simply deleted.
2. In our workflow, the pre-recieve script (in `gitlab-shell) calls the
`/allowed` endpoint, which calls out directly to git to perform
various checks. These direct calls to git do _not_ have the necessary
environment variables set which allow access to the "alternate object
directory" (explained above). Therefore these calls to git are not able to
access any of the new potential objects to be added during this push.
3. We fix this by accepting the relevant environment variables
(GIT_ALTERNATE_OBJECT_DIRECTORIES, GIT_OBJECT_DIRECTORY) on the
`/allowed` endpoint, and then include these environment variables while
calling out to git.
4. This commit includes (whitelisted) these environment variables while making
the "force push" check. A `Gitlab::Git::RevList` module is extracted to
prevent `ForcePush` from being littered with these checks.
2016-12-07 02:55:49 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|